Skip to content

Commit

Permalink
Implemented anamorphism correction
Browse files Browse the repository at this point in the history
Implemented for both IRDIS and IFS.

Close #32.
  • Loading branch information
avigan committed Aug 30, 2017
1 parent b317365 commit 2d64f8a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 48 deletions.
2 changes: 1 addition & 1 deletion examples/standard_ifs_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
# red.sph_ifs_science_cubes(postprocess=True, silent=True)
# red.sph_ifs_wavelength_recalibration(high_pass=False, display=False, save=True)
# red.sph_ifs_star_center(high_pass=False, display=False, save=True)
# red.sph_ifs_combine_data(cpix=True, psf_dim=80, science_dim=290, save_scaled=False)
# red.sph_ifs_combine_data(cpix=True, psf_dim=80, science_dim=290, correct_anamorphism=True, save_scaled=False)
# red.sph_ifs_clean(delete_raw=False, delete_products=False)
2 changes: 1 addition & 1 deletion examples/standard_irdis_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
# collapse_science=False, collapse_type='mean', coadd_value=2,
# collapse_psf=True, collapse_center=True)
# red.sph_ird_star_center(high_pass=False, display=False, save=True)
# red.sph_ird_combine_data(cpix=True, psf_dim=100, science_dim=400, save_scaled=False)
red.sph_ird_combine_data(cpix=True, psf_dim=100, science_dim=400, correct_anamorphism=True, save_scaled=False)
# red.sph_ird_clean(delete_raw=False, delete_products=False)
78 changes: 49 additions & 29 deletions pysphere/IFS.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def __init__(self, path):
config.read(configfile)

self._pixel = float(config.get('instrument', 'pixel'))
self._nwave = float(config.get('instrument', 'nwave'))
self._nwave = int(config.get('instrument', 'nwave'))

self._wave_cal_lasers = [float(w) for w in config.get('calibration', 'wave_cal_lasers').split(',')]
except configparser.Error as e:
Expand Down Expand Up @@ -461,21 +461,19 @@ def create_static_calibrations(self):
Create all static calibrations, mainly with esorex
'''

self.sph_ifs_cal_dark(silent=True)
self.sph_ifs_cal_detector_flat(silent=True)
self.sph_ifs_cal_specpos(silent=True)
self.sph_ifs_cal_wave(silent=True)
self.sph_ifs_cal_ifu_flat(silent=True)
self.sph_ifs_cal_dark()
self.sph_ifs_cal_detector_flat()
self.sph_ifs_cal_specpos()
self.sph_ifs_cal_wave()
self.sph_ifs_cal_ifu_flat()


def preprocess_science(self):
'''
Collapse and correct raw IFU images
'''

self.sph_ifs_preprocess_science(subtract_background=True, fix_badpix=True, correct_xtalk=True,
collapse_science=False, collapse_type='mean', coadd_value=2,
collapse_psf=True, collapse_center=True)
self.sph_ifs_preprocess_science()
self.sph_ifs_preprocess_wave()


Expand All @@ -485,18 +483,18 @@ def process_science(self):
center and combine cubes into final (x,y,time,lambda) cubes
'''

self.sph_ifs_science_cubes(silent=True)
self.sph_ifs_wavelength_recalibration(high_pass=False, display=False, save=True)
self.sph_ifs_star_center(high_pass=False, display=False, save=True)
self.sph_ifs_combine_data(cpix=True, psf_dim=80, science_dim=290, save_scaled=False)
self.sph_ifs_science_cubes()
self.sph_ifs_wavelength_recalibration()
self.sph_ifs_star_center()
self.sph_ifs_combine_data()


def clean(self):
'''
Clean the reduction directory
'''

self.sph_ifs_clean(delete_raw=False, delete_products=False)
self.sph_ifs_clean()


def full_reduction(self):
Expand Down Expand Up @@ -718,7 +716,7 @@ def sort_frames(self):
print('Extracting frames information')

# check if recipe can be executed
toolbox.check_recipe_execution(self._recipe_execution, 'sort_frames', self._recipe_requirements)
toolbox.check_recipe_execution(self._recipe_execution, 'sort_frames', self.recipe_requirements)

# parameters
path = self._path
Expand Down Expand Up @@ -762,7 +760,7 @@ def check_files_association(self):
'''

# check if recipe can be executed
toolbox.check_recipe_execution(self._recipe_execution, 'check_files_association', self._recipe_requirements)
toolbox.check_recipe_execution(self._recipe_execution, 'check_files_association', self.recipe_requirements)

print('Performing file association for calibrations')

Expand Down Expand Up @@ -901,7 +899,7 @@ def sph_ifs_cal_dark(self, silent=True):
'''

# check if recipe can be executed
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_cal_dark', self._recipe_requirements)
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_cal_dark', self.recipe_requirements)

print('Creating darks and backgrounds')

Expand Down Expand Up @@ -1006,7 +1004,7 @@ def sph_ifs_cal_detector_flat(self, silent=True):
'''

# check if recipe can be executed
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_cal_detector_flat', self._recipe_requirements)
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_cal_detector_flat', self.recipe_requirements)

print('Creating flats')

Expand Down Expand Up @@ -1097,7 +1095,7 @@ def sph_ifs_cal_specpos(self, silent=True):
'''

# check if recipe can be executed
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_cal_specpos', self._recipe_requirements)
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_cal_specpos', self.recipe_requirements)

print('Creating specpos')

Expand Down Expand Up @@ -1184,7 +1182,7 @@ def sph_ifs_cal_wave(self, silent=True):
'''

# check if recipe can be executed
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_cal_wave', self._recipe_requirements)
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_cal_wave', self.recipe_requirements)

print('Creating wavelength calibration')

Expand Down Expand Up @@ -1286,7 +1284,7 @@ def sph_ifs_cal_ifu_flat(self, silent=True):
'''

# check if recipe can be executed
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_cal_ifu_flat', self._recipe_requirements)
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_cal_ifu_flat', self.recipe_requirements)

print('Creating IFU flat')

Expand Down Expand Up @@ -1455,7 +1453,7 @@ def sph_ifs_preprocess_science(self,
'''

# check if recipe can be executed
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_preprocess_science', self._recipe_requirements)
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_preprocess_science', self.recipe_requirements)

print('Pre-processing science files')

Expand Down Expand Up @@ -1640,7 +1638,7 @@ def sph_ifs_preprocess_wave(self):
'''

# check if recipe can be executed
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_preprocess_wave', self._recipe_requirements)
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_preprocess_wave', self.recipe_requirements)

# parameters
path = self._path
Expand Down Expand Up @@ -1710,7 +1708,7 @@ def sph_ifs_science_cubes(self, silent=True):
'''

# check if recipe can be executed
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_science_cubes', self._recipe_requirements)
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_science_cubes', self.recipe_requirements)

print('Creating the (x,y,lambda) science cubes')

Expand Down Expand Up @@ -1854,7 +1852,7 @@ def sph_ifs_wavelength_recalibration(self, high_pass=False, display=False, save=
'''

# check if recipe can be executed
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_wavelength_recalibration', self._recipe_requirements)
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_wavelength_recalibration', self.recipe_requirements)

print('Recalibrating wavelength')

Expand Down Expand Up @@ -2053,7 +2051,7 @@ def sph_ifs_star_center(self, high_pass=False, display=False, save=True):
'''

# check if recipe can be executed
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_star_center', self._recipe_requirements)
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_star_center', self.recipe_requirements)

print('Star centers determination')

Expand Down Expand Up @@ -2125,7 +2123,7 @@ def sph_ifs_star_center(self, high_pass=False, display=False, save=True):
self._recipe_execution['sph_ifs_star_center'] = True


def sph_ifs_combine_data(self, cpix=True, psf_dim=80, science_dim=290, save_scaled=False):
def sph_ifs_combine_data(self, cpix=True, psf_dim=80, science_dim=290, correct_anamorphism=True, save_scaled=False):
'''
Combine and save the science data into final cubes
Expand Down Expand Up @@ -2166,14 +2164,18 @@ def sph_ifs_combine_data(self, cpix=True, psf_dim=80, science_dim=290, save_scal
Size of the science images (star centers and standard
coronagraphic images). Default is 290, 290 pixels
save_scaled : bool
correct_anamorphism : bool
Correct the optical anamorphism of the instrument. Default
is True. See user manual for details.
save_scaled : bool
Also save the wavelength-rescaled cubes. Makes the process
much longer. The default is False
'''

# check if recipe can be executed
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_combine_data', self._recipe_requirements)
toolbox.check_recipe_execution(self._recipe_execution, 'sph_ifs_combine_data', self.recipe_requirements)

print('Combine science data')

Expand Down Expand Up @@ -2256,6 +2258,12 @@ def sph_ifs_combine_data(self, cpix=True, psf_dim=80, science_dim=290, save_scal

psf_cube[wave_idx, file_idx] = nimg[:psf_dim, :psf_dim]

# correct anamorphism
if correct_anamorphism:
nimg = psf_cube[wave_idx, file_idx]
nimg = imutils.scale(nimg, (1.0059, 1.0011), method='interp')
psf_cube[wave_idx, file_idx] = nimg

# wavelength-scaled version
if save_scaled:
nimg = psf_cube[wave_idx, file_idx]
Expand Down Expand Up @@ -2328,6 +2336,12 @@ def sph_ifs_combine_data(self, cpix=True, psf_dim=80, science_dim=290, save_scal

cen_cube[wave_idx, file_idx] = nimg[:science_dim, :science_dim]

# correct anamorphism
if correct_anamorphism:
nimg = cen_cube[wave_idx, file_idx]
nimg = imutils.scale(nimg, (1.0059, 1.0011), method='interp')
cen_cube[wave_idx, file_idx] = nimg

# wavelength-scaled version
if save_scaled:
nimg = cen_cube[wave_idx, file_idx]
Expand Down Expand Up @@ -2410,6 +2424,12 @@ def sph_ifs_combine_data(self, cpix=True, psf_dim=80, science_dim=290, save_scal

sci_cube[wave_idx, file_idx] = nimg[:science_dim, :science_dim]

# correct anamorphism
if correct_anamorphism:
nimg = sci_cube[wave_idx, file_idx]
nimg = imutils.scale(nimg, (1.0059, 1.0011), method='interp')
sci_cube[wave_idx, file_idx] = nimg

# wavelength-scaled version
if save_scaled:
nimg = sci_cube[wave_idx, file_idx]
Expand Down
Loading

0 comments on commit 2d64f8a

Please sign in to comment.