Skip to content

Commit

Permalink
replace flatfile with use_blaze
Browse files Browse the repository at this point in the history
  • Loading branch information
rcooke-ast committed Sep 1, 2024
1 parent 02f6ad8 commit bfb9dc2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
12 changes: 5 additions & 7 deletions pypeit/par/pypeitpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ class SensFuncPar(ParSet):
For a table with the current keywords, defaults, and descriptions,
see :ref:`parameters`.
"""
def __init__(self, flatfile=None, extrap_blu=None, extrap_red=None, samp_fact=None, multi_spec_det=None, algorithm=None, UVIS=None,
def __init__(self, use_blaze=None, extrap_blu=None, extrap_red=None, samp_fact=None, multi_spec_det=None, algorithm=None, UVIS=None,
IR=None, polyorder=None, star_type=None, star_mag=None, star_ra=None, extr=None,
star_dec=None, mask_hydrogen_lines=None, mask_helium_lines=None, hydrogen_mask_wid=None):
# Grab the parameter names and values from the function arguments
Expand All @@ -1962,11 +1962,9 @@ def __init__(self, flatfile=None, extrap_blu=None, extrap_red=None, samp_fact=No
dtypes = OrderedDict.fromkeys(pars.keys())
descr = OrderedDict.fromkeys(pars.keys())

defaults['flatfile'] = None
dtypes['flatfile'] = str
descr['flatfile'] = 'Flat field file to be used if the sensitivity function model will utilize the blaze ' \
'function computed from a flat field file in the Calibrations directory, e.g.' \
'Calibrations/Flat_A_0_DET01.fits'
defaults['use_blaze'] = False
dtypes['use_blaze'] = bool
descr['use_blaze'] = 'If True, the blaze will be used when computing the sensitivity function.'

defaults['extr'] = 'OPT'
dtypes['extr'] = str
Expand Down Expand Up @@ -2069,7 +2067,7 @@ def from_dict(cls, cfg):
k = np.array([*cfg.keys()])

# Single element parameters
parkeys = ['flatfile', 'extrap_blu', 'extrap_red', 'samp_fact', 'multi_spec_det', 'algorithm',
parkeys = ['use_blaze', 'extrap_blu', 'extrap_red', 'samp_fact', 'multi_spec_det', 'algorithm',
'polyorder', 'star_type', 'star_mag', 'star_ra', 'star_dec', 'extr',
'mask_hydrogen_lines', 'mask_helium_lines', 'hydrogen_mask_wid']

Expand Down
3 changes: 2 additions & 1 deletion pypeit/sensfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ def __init__(self, spec1dfile, sensfile, par, par_fluxcalib=None, debug=False,

# Unpack standard
wave, counts, counts_ivar, counts_mask, log10_blaze_function, self.meta_spec, header \
= self.sobjs_std.unpack_object(ret_flam=False, log10blaze=True, extract_type=self.extr, remove_missing=True)
= self.sobjs_std.unpack_object(ret_flam=False, log10blaze=True, extract_blaze=par['use_blaze'],
extract_type=self.extr, remove_missing=True)

# Perform any instrument tweaks
wave_twk, counts_twk, counts_ivar_twk, counts_mask_twk, log10_blaze_function_twk = \
Expand Down
36 changes: 20 additions & 16 deletions pypeit/specobjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def nobj(self):
"""
return len(self.specobjs)

def unpack_object(self, ret_flam=False, log10blaze=False, min_blaze_value=1e-3, extract_type='OPT', remove_missing=False):
def unpack_object(self, ret_flam=False, log10blaze=False, min_blaze_value=1e-3, extract_type='OPT',
extract_blaze=False, remove_missing=False):
"""
Utility function to unpack the sobjs for one object and
return various numpy arrays describing the spectrum and meta
Expand All @@ -202,9 +203,11 @@ def unpack_object(self, ret_flam=False, log10blaze=False, min_blaze_value=1e-3,
If True return the log10 of the blaze function.
min_blaze_value (:obj:`float`, optional):
Minimum value of the blaze function to consider as good.
extract_type (:obj:`str`, optional):
extract_type (:obj:`str`, optional):
Extraction type to use. Default is 'OPT'.
remove_missing (:obj:`bool`, optional):
extract_blaze (:obj:`bool`, optional):
If True, extract the blaze function. Default is False.
remove_missing (:obj:`bool`, optional):
If True, remove any missing data (i.e. where the flux is None).
Default is False.
Expand All @@ -219,7 +222,7 @@ def unpack_object(self, ret_flam=False, log10blaze=False, min_blaze_value=1e-3,
Flambda or counts)
- flux_gpm (`numpy.ndarray`_): Good pixel mask.
True=Good
- blaze (`numpy.ndarray`_): Blaze function
- blaze (`numpy.ndarray`_, None): Blaze function
- meta_spec (dict:) Dictionary containing meta data.
The keys are defined by
spectrograph.parse_spec_header()
Expand Down Expand Up @@ -255,9 +258,8 @@ def unpack_object(self, ret_flam=False, log10blaze=False, min_blaze_value=1e-3,
flux = np.zeros((nspec, norddet))
flux_ivar = np.zeros((nspec, norddet))
flux_gpm = np.zeros((nspec, norddet), dtype=bool)
blaze = np.zeros((nspec, norddet), dtype=float)
trace_spec = np.zeros((nspec, norddet))
trace_spat = np.zeros((nspec, norddet))
if extract_blaze:
blaze = np.zeros((nspec, norddet), dtype=float)

detector = [None]*norddet
ech_orders = np.zeros(norddet, dtype=int)
Expand All @@ -270,17 +272,19 @@ def unpack_object(self, ret_flam=False, log10blaze=False, min_blaze_value=1e-3,
ech_orders[iorddet] = self[iorddet].ECH_ORDER
flux[:, iorddet] = getattr(self, flux_key)[iorddet]
flux_ivar[:, iorddet] = getattr(self, flux_key+'_IVAR')[iorddet]
blaze[:, iorddet] = getattr(self, blaze_key)[iorddet]
trace_spat[:, iorddet] = self[iorddet].TRACE_SPAT
trace_spec[:, iorddet] = self[iorddet].trace_spec
if extract_blaze:
blaze[:, iorddet] = getattr(self, blaze_key)[iorddet]

# Log10 blaze
blaze_function = np.copy(blaze)
if log10blaze:
for iorddet in range(norddet):
blaze_function_smooth = utils.fast_running_median(blaze[:, iorddet], 5)
blaze_function_norm = blaze_function_smooth / blaze_function_smooth.max()
blaze_function[:, iorddet] = np.log10(np.clip(blaze_function_norm, min_blaze_value, None))
if extract_blaze:
blaze_function = np.copy(blaze)
if log10blaze:
for iorddet in range(norddet):
blaze_function_smooth = utils.fast_running_median(blaze[:, iorddet], 5)
blaze_function_norm = blaze_function_smooth / blaze_function_smooth.max()
blaze_function[:, iorddet] = np.log10(np.clip(blaze_function_norm, min_blaze_value, None))
else:
blaze_function = None

# Populate meta data
spectrograph = load_spectrograph(self.header['PYP_SPEC'])
Expand Down

0 comments on commit bfb9dc2

Please sign in to comment.