From bfb9dc2028878094812db053acb6319b412560fa Mon Sep 17 00:00:00 2001 From: rcooke Date: Sun, 1 Sep 2024 12:54:11 +0100 Subject: [PATCH] replace flatfile with use_blaze --- pypeit/par/pypeitpar.py | 12 +++++------- pypeit/sensfunc.py | 3 ++- pypeit/specobjs.py | 36 ++++++++++++++++++++---------------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/pypeit/par/pypeitpar.py b/pypeit/par/pypeitpar.py index 721c8ceac1..df43949533 100644 --- a/pypeit/par/pypeitpar.py +++ b/pypeit/par/pypeitpar.py @@ -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 @@ -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 @@ -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'] diff --git a/pypeit/sensfunc.py b/pypeit/sensfunc.py index 5d4f771081..3278efc3af 100644 --- a/pypeit/sensfunc.py +++ b/pypeit/sensfunc.py @@ -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 = \ diff --git a/pypeit/specobjs.py b/pypeit/specobjs.py index 99094a1d17..e891d9671d 100644 --- a/pypeit/specobjs.py +++ b/pypeit/specobjs.py @@ -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 @@ -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. @@ -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() @@ -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) @@ -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'])