Skip to content

Commit

Permalink
Fix implementation of the default -1.75° true North offset
Browse files Browse the repository at this point in the history
Ticket #88
  • Loading branch information
avigan committed Dec 19, 2020
1 parent 2a9ce96 commit 775e78f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 34 deletions.
25 changes: 16 additions & 9 deletions sphere/IFS.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def __new__(cls, path, log_level='info', sphere_handler=None):
reduction._logger.warning('angles. The offset value can be modified in the configuration of ')
reduction._logger.warning('the reduction: ')
reduction._logger.warning(' ')
reduction._logger.warning(' >>> reduction.config[\'true_north\'] = xxx ')
reduction._logger.warning(' >>> reduction.config[\'cal_true_north\'] = xxx ')
reduction._logger.warning(' ')
reduction._logger.warning('To avoid any issues, make sure to: ')
reduction._logger.warning(' * either reprocess data previously processed with version <1.4 ')
Expand Down Expand Up @@ -609,6 +609,12 @@ def show_config(self):
for key in keys:
print('{0:<30s}{1}'.format(key, dico[key]))

# calibrations
print('-'*35)
keys = [key for key in dico if key.startswith('cal')]
for key in keys:
print('{0:<30s}{1}'.format(key, dico[key]))

# pre-processing
print('-'*35)
keys = [key for key in dico if key.startswith('preproc')]
Expand Down Expand Up @@ -1067,7 +1073,7 @@ def sort_frames(self):
toolbox.compute_times(frames_info, logger=self._logger)

# compute angles (ra, dec, parang)
true_north = self.config['true_north']
true_north = self.config['cal_true_north']
ret = toolbox.compute_angles(frames_info, true_north, logger=self._logger)
if ret == sphere.ERROR:
self._update_recipe_status('sort_frames', sphere.ERROR)
Expand Down Expand Up @@ -2162,27 +2168,28 @@ def sph_ifs_preprocess_science(self,
img = img[np.newaxis, ...]

# collapse
true_north = self.config['cal_true_north']
if (typ == 'OBJECT,CENTER'):
if collapse_center:
self._logger.info(' ==> collapse: mean ({0} -> 1 frame, 0 dropped)'.format(len(img)))
img = np.mean(img, axis=0, keepdims=True)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'mean', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'mean', logger=self._logger)
else:
frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'none', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'none', logger=self._logger)
elif (typ == 'OBJECT,FLUX'):
if collapse_psf:
self._logger.info(' ==> collapse: mean ({0} -> 1 frame, 0 dropped)'.format(len(img)))
img = np.mean(img, axis=0, keepdims=True)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'mean', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'mean', logger=self._logger)
else:
frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'none', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'none', logger=self._logger)
elif (typ == 'OBJECT'):
if collapse_science:
if collapse_type == 'mean':
self._logger.info(' ==> collapse: mean ({0} -> 1 frame, 0 dropped)'.format(len(img)))
img = np.mean(img, axis=0, keepdims=True)

frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'mean', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'mean', logger=self._logger)
elif collapse_type == 'coadd':
if (not isinstance(coadd_value, int)) or (coadd_value <= 1):
self._logger.error('coadd_value must be an integer >1')
Expand All @@ -2207,13 +2214,13 @@ def sph_ifs_preprocess_science(self,
nimg[f] = np.mean(img[f*coadd_value:(f+1)*coadd_value], axis=0)
img = nimg

frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'coadd', coadd_value=coadd_value, logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'coadd', coadd_value=coadd_value, logger=self._logger)
else:
self._logger.error('Unknown collapse type {0}'.format(collapse_type))
self._update_recipe_status('sph_ifs_preprocess_science', sphere.ERROR)
return
else:
frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'none', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'none', logger=self._logger)

# check for any error during collapse of frame information
if frames_info_new is None:
Expand Down
25 changes: 16 additions & 9 deletions sphere/IRDIS/ImagingReduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __new__(cls, path, log_level='info', sphere_handler=None):
reduction._logger.warning('angles. The offset value can be modified in the configuration of ')
reduction._logger.warning('the reduction: ')
reduction._logger.warning(' ')
reduction._logger.warning(' >>> reduction.config[\'true_north\'] = xxx ')
reduction._logger.warning(' >>> reduction.config[\'cal_true_north\'] = xxx ')
reduction._logger.warning(' ')
reduction._logger.warning('To avoid any issues, make sure to: ')
reduction._logger.warning(' * either reprocess data previously processed with version <1.4 ')
Expand Down Expand Up @@ -274,6 +274,12 @@ def show_config(self):
for key in keys:
print('{0:<30s}{1}'.format(key, dico[key]))

# calibrations
print('-'*35)
keys = [key for key in dico if key.startswith('cal')]
for key in keys:
print('{0:<30s}{1}'.format(key, dico[key]))

# pre-processing
print('-'*35)
keys = [key for key in dico if key.startswith('preproc')]
Expand Down Expand Up @@ -690,7 +696,7 @@ def sort_frames(self):
toolbox.compute_times(frames_info, logger=self._logger)

# compute angles (ra, dec, parang)
true_north = self.config['true_north']
true_north = self.config['cal_true_north']
ret = toolbox.compute_angles(frames_info, true_north, logger=self._logger)
if ret == sphere.ERROR:
self._update_recipe_status('sort_frames', sphere.ERROR)
Expand Down Expand Up @@ -1262,27 +1268,28 @@ def sph_ird_preprocess_science(self,
img[:, :, 1966:] = np.nan

# collapse
true_north = self.config['cal_true_north']
if (typ == 'OBJECT,CENTER'):
if collapse_center:
self._logger.info(' ==> collapse: mean')
img = np.mean(img, axis=0, keepdims=True)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'mean', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'mean', logger=self._logger)
else:
frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'none', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'none', logger=self._logger)
elif (typ == 'OBJECT,FLUX'):
if collapse_psf:
self._logger.info(' ==> collapse: mean')
img = np.mean(img, axis=0, keepdims=True)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'mean', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'mean', logger=self._logger)
else:
frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'none', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'none', logger=self._logger)
elif (typ == 'OBJECT'):
if collapse_science:
if collapse_type == 'mean':
self._logger.info(' ==> collapse: mean ({0} -> 1 frame, 0 dropped)'.format(len(img)))
img = np.mean(img, axis=0, keepdims=True)

frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'mean', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'mean', logger=self._logger)
elif collapse_type == 'coadd':
if (not isinstance(coadd_value, int)) or (coadd_value <= 1):
self._logger.error('coadd_value must be an integer >1')
Expand All @@ -1307,13 +1314,13 @@ def sph_ird_preprocess_science(self,
nimg[f] = np.mean(img[f*coadd_value:(f+1)*coadd_value], axis=0)
img = nimg

frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'coadd', coadd_value=coadd_value, logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'coadd', coadd_value=coadd_value, logger=self._logger)
else:
self._logger.error('Unknown collapse type {0}'.format(collapse_type))
self._update_recipe_status('sph_ird_preprocess_science', sphere.ERROR)
return
else:
frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'none', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'none', logger=self._logger)

# check for any error during collapse of frame information
if frames_info_new is None:
Expand Down
21 changes: 14 additions & 7 deletions sphere/IRDIS/SpectroReduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ def show_config(self):
for key in keys:
print('{0:<30s}{1}'.format(key, dico[key]))

# calibrations
print('-'*35)
keys = [key for key in dico if key.startswith('cal')]
for key in keys:
print('{0:<30s}{1}'.format(key, dico[key]))

# pre-processing
print('-'*35)
keys = [key for key in dico if key.startswith('preproc')]
Expand Down Expand Up @@ -747,7 +753,7 @@ def sort_frames(self):
toolbox.compute_times(frames_info, logger=self._logger)

# compute angles (ra, dec, parang)
true_north = self.config['true_north']
true_north = self.config['cal_true_north']
ret = toolbox.compute_angles(frames_info, true_north, logger=self._logger)
if ret == sphere.ERROR:
self._update_recipe_status('sort_frames', sphere.ERROR)
Expand Down Expand Up @@ -1520,28 +1526,29 @@ def sph_ird_preprocess_science(self,
img[:, :, 1966:] = np.nan

# collapse
true_north = self.config['cal_true_north']
if (typ == 'OBJECT,CENTER'):
if collapse_center:
self._logger.info(' ==> collapse: mean')
img = np.mean(img, axis=0, keepdims=True)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'mean', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'mean', logger=self._logger)
else:
frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'none', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'none', logger=self._logger)
elif (typ == 'OBJECT,FLUX'):
if collapse_psf:
self._logger.info(' ==> collapse: mean')
img = np.mean(img, axis=0, keepdims=True)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'mean', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'mean', logger=self._logger)
else:
frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'none', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'none', logger=self._logger)
elif (typ == 'OBJECT'):
if collapse_science:
self._logger.info(' ==> collapse: mean ({0} -> 1 frame, 0 dropped)'.format(len(img)))
img = np.mean(img, axis=0, keepdims=True)

frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'mean', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'mean', logger=self._logger)
else:
frames_info_new = toolbox.collapse_frames_info(finfo, fname, 'none', logger=self._logger)
frames_info_new = toolbox.collapse_frames_info(finfo, fname, true_north, 'none', logger=self._logger)

# check for any error during collapse of frame information
if frames_info_new is None:
Expand Down
6 changes: 3 additions & 3 deletions sphere/instruments/IFS.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ default_center = (290//2, 290//2)
# field orientation offset
orientation_offset = 102

# true North
true_north = -1.75

#
# default reduction parameters
#
Expand All @@ -32,6 +29,9 @@ true_north = -1.75
misc_silent_esorex = True
misc_plot = True

# true North
cal_true_north = -1.75

# pre-processing
preproc_subtract_background = True
preproc_fix_badpix = True
Expand Down
6 changes: 3 additions & 3 deletions sphere/instruments/IRDIS.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ default_center = ((485, 520), (486, 508))
# field orientation offset
orientation_offset = 0

# true North
true_north = -1.75

[calibration-spectro]

# LRS parameters
Expand All @@ -45,6 +42,9 @@ wave_max_mrs = 1820
misc_silent_esorex = True
misc_plot = True

# true North
cal_true_north = -1.75

#
# default reduction parameters for imaging
#
Expand Down
9 changes: 6 additions & 3 deletions sphere/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def compute_bad_pixel_map(bpm_files, dtype=np.uint8, logger=_log):
return bpm


def collapse_frames_info(finfo, fname, collapse_type, coadd_value=2, logger=_log):
def collapse_frames_info(finfo, fname, true_north, collapse_type, coadd_value=2, logger=_log):
'''
Collapse frame info to match the collapse operated on the data
Expand All @@ -358,6 +358,9 @@ def collapse_frames_info(finfo, fname, collapse_type, coadd_value=2, logger=_log
fname : str
The name of the current file
true_north : float
True North offset correction, in degrees
collapse_type : str
Type of collapse. Possible values are mean or coadd. Default
is mean.
Expand Down Expand Up @@ -402,7 +405,7 @@ def collapse_frames_info(finfo, fname, collapse_type, coadd_value=2, logger=_log
(finfo.loc[(fname, imax), 'TIME END'] - finfo.loc[(fname, imin), 'TIME START']) / 2

# recompute angles
ret = compute_angles(nfinfo, logger=logger)
ret = compute_angles(nfinfo, true_north, logger=logger)
if ret == sphere.ERROR:
return None
elif collapse_type == 'coadd':
Expand Down Expand Up @@ -431,7 +434,7 @@ def collapse_frames_info(finfo, fname, collapse_type, coadd_value=2, logger=_log
(finfo.loc[(fname, imax), 'TIME END'] - finfo.loc[(fname, imin), 'TIME START']) / 2

# recompute angles
ret = compute_angles(nfinfo, logger=logger)
ret = compute_angles(nfinfo, true_north, logger=logger)
if ret == sphere.ERROR:
return None
else:
Expand Down

0 comments on commit 775e78f

Please sign in to comment.