From 2d9cad221c82fb5e4964b93cc4ddd177a8afe288 Mon Sep 17 00:00:00 2001 From: Adolfo Carvalho Date: Fri, 5 Jul 2024 10:12:33 -0700 Subject: [PATCH 1/6] fixed PHOENIX A0V atmosphere read error & identify save error --- pypeit/core/flux_calib.py | 2 +- pypeit/scripts/identify.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pypeit/core/flux_calib.py b/pypeit/core/flux_calib.py index b94e1bdf4d..95089958a2 100644 --- a/pypeit/core/flux_calib.py +++ b/pypeit/core/flux_calib.py @@ -431,7 +431,7 @@ def get_standard_spectrum(star_type=None, star_mag=None, ra=None, dec=None): elif 'PHOENIX' in star_type: msgs.info('Getting PHOENIX 10000 K, logg = 4.0 spectrum') ## Vega model from TSPECTOOL - vega_file = data.Paths.standards / 'PHOENIX_10000K_4p0.fits' + vega_file = dataPaths.standards.get_file_path('PHOENIX_10000K_4p0.fits') vega_data = table.Table.read(vega_file, format='fits') std_dict = dict(cal_file='PHOENIX_10000K_4p0', name=star_type, Vmag=star_mag, std_ra=ra, std_dec=dec) diff --git a/pypeit/scripts/identify.py b/pypeit/scripts/identify.py index 610241dc81..a8ca152dc6 100644 --- a/pypeit/scripts/identify.py +++ b/pypeit/scripts/identify.py @@ -304,7 +304,6 @@ def main(args): fits_dicts = None specdata = None - slits = None lines_pix_arr = None lines_wav_arr = None lines_fit_ord = None From ad7b51a710077affb50b49d4c5dae0d0ae3875dd Mon Sep 17 00:00:00 2001 From: Adolfo Carvalho Date: Fri, 5 Jul 2024 14:54:41 -0700 Subject: [PATCH 2/6] patched issue with specdata not being passed properly in identify --- pypeit/core/gui/identify.py | 2 +- pypeit/scripts/identify.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pypeit/core/gui/identify.py b/pypeit/core/gui/identify.py index 271abefdda..3d7e398cc0 100644 --- a/pypeit/core/gui/identify.py +++ b/pypeit/core/gui/identify.py @@ -782,7 +782,7 @@ def store_solution(self, final_fit, binspec, rmstol=0.15, if ans == 'y': # Arxiv solution # prompt the user to give the orders that were used here - if '"echelle": true' in wvcalib.strpar: + if wvcalib is not None and '"echelle": true' in wvcalib.strpar: while True: try: print('') diff --git a/pypeit/scripts/identify.py b/pypeit/scripts/identify.py index a8ca152dc6..f4548622ee 100644 --- a/pypeit/scripts/identify.py +++ b/pypeit/scripts/identify.py @@ -266,6 +266,9 @@ def main(args): if args.new_sol: wv_calib.copy_calib_internals(msarc) + # convert specdata into an array, since it's currently a list + specdata = np.array(specdata) + # If we just want the normal one-trace output else: arccen, arc_maskslit = wavecal.extract_arcs(slitIDs=[int(args.slits)]) @@ -317,7 +320,7 @@ def main(args): rmstol=args.rmstol, force_save=args.force_save, multi = args.multi, fits_dicts = fits_dicts, - specdata = np.array(specdata), + specdata = specdata, slits = slits, lines_pix_arr = lines_pix_arr, lines_wav_arr = lines_wav_arr, From 33f77fbc04b3c61fae20637a04c8d05702be8168 Mon Sep 17 00:00:00 2001 From: Adolfo Carvalho Date: Fri, 5 Jul 2024 16:07:41 -0700 Subject: [PATCH 3/6] fixed script/identify and gui/identify for longslit --- pypeit/core/gui/identify.py | 72 ++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/pypeit/core/gui/identify.py b/pypeit/core/gui/identify.py index 3d7e398cc0..905794fde9 100644 --- a/pypeit/core/gui/identify.py +++ b/pypeit/core/gui/identify.py @@ -870,43 +870,43 @@ def store_solution(self, final_fit, binspec, rmstol=0.15, wvcalib.to_file(outfname, overwrite=True) msgs.info("A WaveCalib container was written to wvcalib.fits") - # Ask if overwrite the existing WVCalib file only if force_save=False, otherwise don't overwrite - ow_wvcalib = '' - if not force_save: - while ow_wvcalib != 'y' and ow_wvcalib != 'n': - print('') - msgs.warn('Do you want to overwrite existing Calibrations/WaveCalib*.fits file? ' + msgs.newline() + - 'NOTE: To use this WaveCalib file the user will need to delete the other files in Calibrations/ ' + msgs.newline() + - ' and re-run run_pypeit. ') - print('') - ow_wvcalib = input('Proceed with overwrite? (y/[n]): ') - - if ow_wvcalib == 'y': - wvcalib.to_file() - if multi: - slit_list_str = ''; slit_list = np.arange(np.shape(specdata)[0]) - for islit in slit_list: - if islit < len(slit_list) - 1: - slit_list_str += str(islit) + ',' - else: slit_list_str += str(islit) - - if slits: - print(' ') - msgs.info('Unflagging Slits from WaveCalib: ') - slits.mask = np.zeros(slits.nslits, dtype=slits.bitmask.minimum_dtype()) - slits.ech_order = order_vec - slits.to_file() - print(' ') - print(' ') - # ask to clean up the Calibrations directory only if force_save=False, otherwise don't clean up + # Ask if overwrite the existing WVCalib file only if force_save=False, otherwise don't overwrite + ow_wvcalib = '' if not force_save: - clean_calib = input('Clean up the Calibrations/ directory? This will delete all of the existing' - ' calibrations except the Arcs and WaveCalib files. y/[n]: ') - if clean_calib == 'y': - cal_root = Path('Calibrations').resolve() - for cal in ['Tilt', 'Flat', 'Edge', 'Slit']: - for f in cal_root.glob(f'{cal}*'): - f.unlink() + while ow_wvcalib != 'y' and ow_wvcalib != 'n': + print('') + msgs.warn('Do you want to overwrite existing Calibrations/WaveCalib*.fits file? ' + msgs.newline() + + 'NOTE: To use this WaveCalib file the user will need to delete the other files in Calibrations/ ' + msgs.newline() + + ' and re-run run_pypeit. ') + print('') + ow_wvcalib = input('Proceed with overwrite? (y/[n]): ') + + if ow_wvcalib == 'y': + wvcalib.to_file() + if multi: + slit_list_str = ''; slit_list = np.arange(np.shape(specdata)[0]) + for islit in slit_list: + if islit < len(slit_list) - 1: + slit_list_str += str(islit) + ',' + else: slit_list_str += str(islit) + + if slits: + print(' ') + msgs.info('Unflagging Slits from WaveCalib: ') + slits.mask = np.zeros(slits.nslits, dtype=slits.bitmask.minimum_dtype()) + slits.ech_order = order_vec + slits.to_file() + print(' ') + print(' ') + # ask to clean up the Calibrations directory only if force_save=False, otherwise don't clean up + if not force_save: + clean_calib = input('Clean up the Calibrations/ directory? This will delete all of the existing' + ' calibrations except the Arcs and WaveCalib files. y/[n]: ') + if clean_calib == 'y': + cal_root = Path('Calibrations').resolve() + for cal in ['Tilt', 'Flat', 'Edge', 'Slit']: + for f in cal_root.glob(f'{cal}*'): + f.unlink() # Print some helpful information print("\n\nPlease visit the following site if you want to include your solution in PypeIt:") From 101c6753e2c014114a09eb6bac0d28603304d277 Mon Sep 17 00:00:00 2001 From: Adolfo Carvalho Date: Mon, 8 Jul 2024 11:50:51 -0700 Subject: [PATCH 4/6] patched identify, renamed the multidim specdata to specdata_multi --- pypeit/core/gui/identify.py | 29 +++++++++++++++-------------- pypeit/scripts/identify.py | 10 +++++----- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/pypeit/core/gui/identify.py b/pypeit/core/gui/identify.py index 905794fde9..4c3185cef7 100644 --- a/pypeit/core/gui/identify.py +++ b/pypeit/core/gui/identify.py @@ -716,7 +716,7 @@ def get_results(self): def store_solution(self, final_fit, binspec, rmstol=0.15, force_save=False, wvcalib=None, multi=False, - fits_dicts=None, specdata=None, slits=None, + fits_dicts=None, specdata_multi=None, slits=None, lines_pix_arr=None, lines_wav_arr=None, lines_fit_ord=None, custom_wav=None, custom_wav_ind=None): """Check if the user wants to store this solution in the reid arxiv, when doing the wavelength solution @@ -737,8 +737,9 @@ def store_solution(self, final_fit, binspec, rmstol=0.15, Flag if the template has multiple slits/traces. fits_dict : list, optional List of dictionaries containing the _fitdict of previous calls, if multi-trace data - specdata : array, optional - Numpy array containing the flux information from all the traces + specdata_multi : array, optional + Numpy array containing the flux information from all the traces, if multiple traces are + being fit. wvcalib : :class:`pypeit.wavecalib.WaveCalib`, optional Wavelength solution lines_pix_arr : array, optional @@ -818,15 +819,15 @@ def store_solution(self, final_fit, binspec, rmstol=0.15, if make_arxiv != 'n': if multi: # check that specdata is defined - if specdata is None: + if specdata_multi is None: msgs.warn('Skipping arxiv save because arc line spectra are not defined by pypeit/scripts/identify.py') # check that the number of spectra in specdata is the same as the number of wvcalib solutions - elif specdata is not None and np.shape(specdata)[0] != len(wvcalib.wv_fits): + elif specdata_multi is not None and np.shape(specdata_multi)[0] != len(wvcalib.wv_fits): msgs.warn('Skipping arxiv save because there are not enough orders for full template') msgs.warn('To generate a valid arxiv to save, please rerun with the "--slits all" option.') else: - norder = np.shape(specdata)[0] - wavelengths = np.copy(specdata) + norder = np.shape(specdata_multi)[0] + wavelengths = np.copy(specdata_multi) for iord in range(norder): if fits_dicts is not None: fitdict = fits_dicts[iord] @@ -834,8 +835,8 @@ def store_solution(self, final_fit, binspec, rmstol=0.15, msgs.warn('skipping saving fits because fits_dicts is not defined by pypeit/scripts/identify.py') fitdict = None if fitdict is not None and fitdict['full_fit'] is not None: - wavelengths[iord,:] = fitdict['full_fit'].eval(np.arange(specdata[iord,:].size) / - (specdata[iord,:].size - 1)) + wavelengths[iord,:] = fitdict['full_fit'].eval(np.arange(specdata_multi[iord,:].size) / + (specdata_multi[iord,:].size - 1)) elif wvcalib is not None and wvcalib.wv_fits[iord] is None and iord in custom_wav_ind: wavelengths[iord,:] = custom_wav[np.where(iord == custom_wav_ind)[0]] else: @@ -858,7 +859,7 @@ def store_solution(self, final_fit, binspec, rmstol=0.15, wvarxiv_name = wvarxiv_name_new # Write the wvarxiv file - _specdata = specdata if specdata is not None else self.specdata + _specdata = specdata_multi if specdata_multi is not None else self.specdata order_vec = np.flip(order_vec, axis=0) if order_vec is not None else None wvutils.write_template(wavelengths, _specdata, binspec, './', wvarxiv_name, to_cache=True, order = order_vec, @@ -884,20 +885,20 @@ def store_solution(self, final_fit, binspec, rmstol=0.15, if ow_wvcalib == 'y': wvcalib.to_file() if multi: - slit_list_str = ''; slit_list = np.arange(np.shape(specdata)[0]) + slit_list_str = ''; slit_list = np.arange(np.shape(specdata_multi)[0]) for islit in slit_list: if islit < len(slit_list) - 1: slit_list_str += str(islit) + ',' else: slit_list_str += str(islit) if slits: - print(' ') + print(' '*10) msgs.info('Unflagging Slits from WaveCalib: ') slits.mask = np.zeros(slits.nslits, dtype=slits.bitmask.minimum_dtype()) slits.ech_order = order_vec slits.to_file() - print(' ') - print(' ') + print(' '*10) + print(' '*10) # ask to clean up the Calibrations directory only if force_save=False, otherwise don't clean up if not force_save: clean_calib = input('Clean up the Calibrations/ directory? This will delete all of the existing' diff --git a/pypeit/scripts/identify.py b/pypeit/scripts/identify.py index f4548622ee..d55c2a69c2 100644 --- a/pypeit/scripts/identify.py +++ b/pypeit/scripts/identify.py @@ -158,7 +158,7 @@ def main(args): else: slits_inds = np.array(list(slits.strip('[]').split(",")), dtype=int) fits_dicts = [] - specdata = [] + specdata_multi = [] wv_fits_arr = [] lines_pix_arr = [] lines_wav_arr = [] @@ -201,7 +201,7 @@ def main(args): return arcfitter, msarc final_fit = arcfitter.get_results() fits_dicts.append(arcfitter._fitdict) - specdata.append(arccen[:,slit_val]) + specdata_multi.append(arccen[:,slit_val]) # Build here to avoid circular import # Note: This needs to be duplicated in test_scripts.py # Wavecalib (wanted when dealing with multiple detectors, eg. GMOS) @@ -267,7 +267,7 @@ def main(args): wv_calib.copy_calib_internals(msarc) # convert specdata into an array, since it's currently a list - specdata = np.array(specdata) + specdata_multi = np.array(specdata_multi) # If we just want the normal one-trace output else: @@ -306,7 +306,7 @@ def main(args): waveCalib = None fits_dicts = None - specdata = None + specdata_multi = None lines_pix_arr = None lines_wav_arr = None lines_fit_ord = None @@ -320,7 +320,7 @@ def main(args): rmstol=args.rmstol, force_save=args.force_save, multi = args.multi, fits_dicts = fits_dicts, - specdata = specdata, + specdata_multi = specdata_multi, slits = slits, lines_pix_arr = lines_pix_arr, lines_wav_arr = lines_wav_arr, From b8262ed53a8c91cbf4a5a5be4445ae766c98e1a5 Mon Sep 17 00:00:00 2001 From: Adolfo Carvalho Date: Tue, 9 Jul 2024 14:05:05 -0700 Subject: [PATCH 5/6] documented fixes --- doc/releases/1.16.1dev.rst | 3 +++ pypeit/core/gui/identify.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/releases/1.16.1dev.rst b/doc/releases/1.16.1dev.rst index 33b59d4259..84f7416b2a 100644 --- a/doc/releases/1.16.1dev.rst +++ b/doc/releases/1.16.1dev.rst @@ -26,6 +26,9 @@ Script Changes expansion of and changes to the cache system. - Added ``pypeit_clean_cache`` script to facilitate both viewing and removing files in the cache. +- Changed the name of the multi-dimensional specdata to specdata_multi in pypeit_identify + and improved the robustness of the saving dialog when calibrating single trace spectra. +- Fixed a read-in error for the high resolution A0V PHOENIX model. Datamodel Changes ----------------- diff --git a/pypeit/core/gui/identify.py b/pypeit/core/gui/identify.py index 4c3185cef7..6a232579af 100644 --- a/pypeit/core/gui/identify.py +++ b/pypeit/core/gui/identify.py @@ -885,7 +885,8 @@ def store_solution(self, final_fit, binspec, rmstol=0.15, if ow_wvcalib == 'y': wvcalib.to_file() if multi: - slit_list_str = ''; slit_list = np.arange(np.shape(specdata_multi)[0]) + slit_list_str = '' + slit_list = np.arange(np.shape(specdata_multi)[0]) for islit in slit_list: if islit < len(slit_list) - 1: slit_list_str += str(islit) + ',' From ec1043c5961bfae7e22d721791b078fe67b5a69f Mon Sep 17 00:00:00 2001 From: Adolfo Carvalho Date: Mon, 15 Jul 2024 14:28:27 -0700 Subject: [PATCH 6/6] fixed issue with full_template where multi-trace arxivs were not flattened --- pypeit/core/wavecal/autoid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pypeit/core/wavecal/autoid.py b/pypeit/core/wavecal/autoid.py index 4fcebb1add..7980016910 100644 --- a/pypeit/core/wavecal/autoid.py +++ b/pypeit/core/wavecal/autoid.py @@ -1150,7 +1150,7 @@ def full_template(spec, lamps, par, ok_mask, det, binspectral, nsnippet=2, slit_ ncomb = temp_spec.size # Remove the continuum before adding the padding to obs_spec_i _, _, _, _, obs_spec_cont_sub = wvutils.arc_lines_from_spec(obs_spec_i) - _, _, _, _, templ_spec_cont_sub = wvutils.arc_lines_from_spec(temp_spec) + _, _, _, _, templ_spec_cont_sub = wvutils.arc_lines_from_spec(temp_spec.reshape(-1)) # Pad pad_spec = np.zeros_like(temp_spec) nspec = len(obs_spec_i)