francbelf / jwst_kernels

Code to generate kernels to move between JWST bands and between a JWST band and an arbitrary Gaussian PSF
MIT License
4 stars 0 forks source link

Can't run example #2

Open wjcramer opened 6 months ago

wjcramer commented 6 months ago

Hi,

I tried to run the example code with two filters from my data:

from jwst_kernels.make_kernels import make_jwst_cross_kernel

input_filter = {'camera':'MIRI', 'filter':'F560W'}

target_filter = {'camera':'MIRI', 'filter':'F770W'}

kk = make_jwst_cross_kernel(input_filter, target_filter, psf_dir=None, outdir=None, detector_effects=True)

But I get this error: --------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) Cell In[19], line 7 3 input_filter = {'camera':'MIRI', 'filter':'F560W'} 5 target_filter = {'camera':'MIRI', 'filter':'F770W'} ----> 7 kk = make_jwst_cross_kernel(input_filter, target_filter, psf_dir=None, outdir=None, detector_effects=True)

File ~/Downloads/jwst_kernels-master/src/jwst_kernels/make_kernels.py:82, in make_jwst_cross_kernel(input_filter, target_filter, psf_dir, outdir, save_kernel, common_pixscale, detector_effects, naming_convention, verbose) 80 outdir = '/'.join(path.dirname(path.realpath(jwst_kernels.file)).split('/')[:-2])+'/data/kernels/' 81 if save_kernel==True: ---> 82 kk.write_out_kernel(outdir =outdir, add_keys =dict_extension ,naming_convention=naming_convention) 83 return kk

File ~/Downloads/jwst_kernels-master/src/jwst_kernels/kernel_core.py:677, in MakeConvolutionKernel.write_out_kernel(self, outdir, add_keys, naming_convention) 674 for key in add_keys: 675 hdu.header[key] = add_keys[key] --> 677 hdu.writeto(file_name, overwrite=True)

File ~/miniconda3/envs/jwst/lib/python3.11/site-packages/astropy/io/fits/hdu/base.py:405, in _BaseHDU.writeto(self, name, output_verify, overwrite, checksum) 402 from .hdulist import HDUList 404 hdulist = HDUList([self]) --> 405 hdulist.writeto(name, output_verify, overwrite=overwrite, checksum=checksum)

File ~/miniconda3/envs/jwst/lib/python3.11/site-packages/astropy/io/fits/hdu/hdulist.py:1020, in HDUList.writeto(self, fileobj, output_verify, overwrite, checksum) 1016 mode = FILE_MODES[fileobj_mode(fileobj)] if isfile(fileobj) else "ostream" 1018 # This can accept an open file object that's open to write only, or in 1019 # append/update modes but only if the file doesn't exist. -> 1020 fileobj = _File(fileobj, mode=mode, overwrite=overwrite) 1021 hdulist = self.fromfile(fileobj) 1022 try:

File ~/miniconda3/envs/jwst/lib/python3.11/site-packages/astropy/io/fits/file.py:218, in _File.init(self, fileobj, mode, memmap, overwrite, cache, use_fsspec, fsspec_kwargs, decompress_in_memory) 216 self._open_fileobj(fileobj, mode, overwrite) 217 elif isinstance(fileobj, (str, bytes)): --> 218 self._open_filename(fileobj, mode, overwrite) 219 else: 220 self._open_filelike(fileobj, mode, overwrite)

File ~/miniconda3/envs/jwst/lib/python3.11/site-packages/astropy/io/fits/file.py:641, in _File._open_filename(self, filename, mode, overwrite) 638 ext = os.path.splitext(self.name)[1] 640 if not self._try_read_compressed(self.name, magic, mode, ext=ext): --> 641 self._file = open(self.name, IO_FITS_MODES[mode]) 642 self.close_on_error = True 644 # Make certain we're back at the beginning of the file 645 # BZ2File does not support seek when the file is open for writing, but 646 # when opening a file for write, bz2.BZ2File always truncates anyway.

FileNotFoundError: [Errno 2] No such file or directory: '/Users/wcramer2/Downloads/jwst_kernels-master/data/kernels/f560w_to_f770w.fits'

From reading the source code, since I have not specified a psf directory, it should be generating a psf with webbpsf. I've verified this is installed correctly and the path is set. I'm not sure why it's searching in the jwst_kernels directory for files that aren't there.

thanks!

wjcramer commented 6 months ago

I found the fix to this issue: the output directory has to be specified. I had assumed it would default to the working directory if one was not set, but instead it tries to write some files to where the jwst_kernels package is installed, causing a crash.

thomaswilliamsastro commented 6 months ago

I also ran into this as well! I think probably if psf_dir or outdir are None then it shouldn't try to save anywhere, rather than what it currently does. And should move to os.path.join() rather than e.g. outdir+"psf_name", since that can lead to weird things if you don't have a trailing / at the end of your directory name