JarronL / webbpsf_ext

WebbPSF Extension Tools
MIT License
4 stars 1 forks source link

bosz2024_grids spaceKLIP errors #15

Closed kglidic closed 3 weeks ago

kglidic commented 3 weeks ago

These grids are not available automatically in spectral_data/bosz2024_grids. I see that there was a function to call the download of these files download_BOSZ_2024, but because this isn't run automatically, all calls in spaceKLIP crash. Should the default be set to False for use_2024 instead of True in webbpsf_ext for the time being?


TypeError Traceback (most recent call last) File /System/Volumes/Data/user/kglidic/spaceKLIP/spaceKLIP/starphot.py:134, in get_stellar_magnitudes(starfile, spectral_type, instrume, return_si, output_dir, kwargs) 133 try: --> 134 spec = webbpsf_ext.spectra.source_spectrum(name='Input Data & SED', sptype=spectral_type, 135 mag_val=bp_mag, bp=bp_k, votable_file=starfile, 136 kwargs) 137 except:

TypeError: source_spectrum.init() missing 1 required positional argument: 'votable_input'

During handling of the above exception, another exception occurred:

OSError Traceback (most recent call last) Cell In[31], line 2 1 # Extract companions. ----> 2 analysistools.extract_companions(companions=[[comp_dra, comp_ddec, 1e-4]], # Delta RA, delta Dec, estimated contrast. 3 starfile=star_photometry_vot, # Stellar photometry. 4 mstar_err=0., # Stellar photometry uncertainty. 5 spectral_type=star_spectral_type, # Spectral type. 6 highpass=False, # Apply high-pass filter? 7 remove_background=False, # Remove a constant background level? 8 use_fm_psf=True, # Use a FM PSF generated with pyKLIP? 9 fitmethod='mcmc', # Sampling algorithm. 10 fitkernel='diag', # Covariance kernel which shall be used for the Gaussian process regression. 11 klmode='max', # KL mode for which the companions shall be extracted. If 'max', then the maximum possible KL mode will be used. 12 date='auto', # Grab observation date from FITS header to query for the wavefront measurement closest in time to the given date. 13 subtract=True, # Subtract each extracted companion from the pyKLIP dataset before fitting the next one in the list. 14 inject=False, # Instead of fitting for a companion at the guessed location and contrast, inject one into the data. 15 save_preklip=False, # Save the stage 2 files when injecting/killing a companion? 16 overwrite=True, # Compute a new FM PSF and overwrite any existing one? 17 subdir='companions')

File /System/Volumes/Data/user/kglidic/spaceKLIP/spaceKLIP/analysistools.py:946, in extract_companions(self, companions, starfile, mstar_err, spectral_type, planetfile, klmode, date, use_fm_psf, highpass, fitmethod, fitkernel, subtract, inject, remove_background, save_preklip, overwrite, subdir, **kwargs) 944 # Set output directory. 945 output_dir = os.path.join(self.database.output_dir, subdir) --> 946 if not os.path.exists(output_dir): 947 os.makedirs(output_dir) 949 # Loop through concatenations.

File /System/Volumes/Data/user/kglidic/spaceKLIP/spaceKLIP/starphot.py:138, in get_stellar_magnitudes(starfile, spectral_type, instrume, return_si, output_dir, kwargs) 134 spec = webbpsf_ext.spectra.source_spectrum(name='Input Data & SED', sptype=spectral_type, 135 mag_val=bp_mag, bp=bp_k, votable_file=starfile, 136 kwargs) 137 except: --> 138 spec = webbpsf_ext.spectra.source_spectrum(name='Input Data & SED', sptype=spectral_type, 139 mag_val=bp_mag, bp=bp_k, votable_input=starfile, 140 **kwargs) 142 # Split between NIR and MIR exposures. 143 if instrume == 'MIRI':

File ~/miniconda3/envs/sklip/lib/python3.12/site-packages/webbpsf_ext/spectra.py:998, in source_spectrum.init(self, name, sptype, mag_val, bp, votable_input, Teff, metallicity, log_g, Av, kwargs) 996 kwargs['metallicity'] = metallicity 997 kwargs['log_g'] = log_g --> 998 self.sp0 = stellar_spectrum(sptype, mag_val, 'vegamag', bp, kwargs) 1000 # Read in a low res version for photometry matching 1001 kwargs['res'] = 200 if not kwargs.get('use_2024', True) else 500

File ~/miniconda3/envs/sklip/lib/python3.12/site-packages/webbpsf_ext/spectra.py:873, in stellar_spectrum(sptype, *renorm_args, kwargs) 870 v2 = np.interp(rank, rank_list, tup_list2) 872 if 'bosz' in catname.lower(): --> 873 sp = call_bosz(v0,v1,v2,kwargs) 874 else: 875 if ('ck04models' in catname.lower()) and (v0<3500):

File ~/miniconda3/envs/sklip/lib/python3.12/site-packages/webbpsf_ext/spectra.py:726, in stellar_spectrum..call_bosz(v0, v1, v2, use_2024, kwargs) 724 v0 = 2800 725 _log.warning("BOSZ models start at 2800K. Setting Teff=2800.") --> 726 return BOSZ_2024_spectrum(v0, v2, v1, kwargs) 727 else: 728 if v0 > 35000:

File ~/miniconda3/envs/sklip/lib/python3.12/site-packages/webbpsf_ext/spectra.py:462, in BOSZ_2024_spectrum(Teff, log_g, metallicity, res, interpolate, fluxout, **kwargs) 459 res_dir = os.path.join(model_dir, f'R{res:.0f}/') 461 if not os.path.isdir(model_dir): --> 462 raise IOError(f'BOSZ model directory does not exist: {model_dir}') 463 if not os.path.isdir(res_dir): 464 os.makedirs(res_dir)

OSError: BOSZ model directory does not exist: /Users/kglidic/miniconda3/envs/sklip/lib/python3.12/site-packages/webbpsf_ext/spectral_data/bosz2024_grids/

JarronL commented 3 weeks ago

The bosz2024_grids directory is empty by default and gets populated over time with downloaded spectra from STScI. Unfortunately, because it starts out as empty, PyPi ignores it when packing things for pip, which causes webbpsf_ext to fail because it doesn't exist. As a fix, I'm adding a README file to that directory, which will keep it alive during the packaging and also updating the functions to create it at the appropriate location if it doesn't already exist.

I will try to get these fixes uploaded today in a new version on pip.