Skip to content

Commit

Permalink
Merge pull request #1828 from Adolfo1519/develop
Browse files Browse the repository at this point in the history
fixed PHOENIX A0V atmosphere read error & identify save error
  • Loading branch information
profxj authored Aug 12, 2024
2 parents a4f1fe0 + 20a7480 commit 4cc548e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 54 deletions.
3 changes: 3 additions & 0 deletions doc/releases/1.16.1dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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.

- A new script, called `pypeit_extract_datacube`, allows 1D spectra of point
sources to be extracted from datacubes.
Expand Down
2 changes: 1 addition & 1 deletion pypeit/core/flux_calib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
96 changes: 49 additions & 47 deletions pypeit/core/gui/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -782,7 +783,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('')
Expand Down Expand Up @@ -818,24 +819,24 @@ 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]
else:
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:
Expand All @@ -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,
Expand All @@ -870,43 +871,44 @@ 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_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(' '*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(' '*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'
' 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:")
Expand Down
2 changes: 1 addition & 1 deletion pypeit/core/wavecal/autoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions pypeit/scripts/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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_multi = np.array(specdata_multi)

# If we just want the normal one-trace output
else:
arccen, arc_maskslit = wavecal.extract_arcs(slitIDs=[int(args.slits)])
Expand Down Expand Up @@ -303,8 +306,7 @@ def main(args):
waveCalib = None

fits_dicts = None
specdata = None
slits = None
specdata_multi = None
lines_pix_arr = None
lines_wav_arr = None
lines_fit_ord = None
Expand All @@ -318,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_multi = specdata_multi,
slits = slits,
lines_pix_arr = lines_pix_arr,
lines_wav_arr = lines_wav_arr,
Expand Down

0 comments on commit 4cc548e

Please sign in to comment.