Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No CRDS write #186

Merged
merged 7 commits into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 17 additions & 13 deletions grizli/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -6196,19 +6196,6 @@ def get_jwst_wfssbkg_file(file, valid_flat=[0.6, 1.3], make_figure=False):
from jwst.wfss_contam import WfssContamStep
from jwst.flatfield import FlatFieldStep


with pyfits.open(file) as im:
if im[0].header['INSTRUME'] == 'NIRISS':
# Test local file
bkg_file = "nis-{0}-{1}_skyflat.fits"
bkg_file = os.path.join(GRIZLI_PATH, 'CONF',
bkg_file.format(im[0].header['PUPIL'],
im[0].header['FILTER']))
bkg_file = bkg_file.lower()

if os.path.exists(bkg_file):
return bkg_file

bkg_file = WfssContamStep().get_reference_file(file, 'wfssbkg')

# Not a FITS file? e.g., N/A for imaging exposures
Expand All @@ -6222,8 +6209,25 @@ def get_jwst_wfssbkg_file(file, valid_flat=[0.6, 1.3], make_figure=False):
_im.close()
return bkg_file

h = pyfits.getheader(file,0)
if h['INSTRUME'] == 'NIRISS':

# Test local file
local_bkg_file = "nis-{0}-{1}_skyflat.fits"
local_bkg_file = local_bkg_file.format(h['PUPIL'],h['FILTER'])
local_bkg_file = local_bkg_file.lower()
local_bkg_file = os.path.join(GRIZLI_PATH, 'CONF',local_bkg_file)

# If local file exists and is up-to-date, use it
if os.path.exists(local_bkg_file) and pyfits.getval(local_bkg_file,'DATE',0) == h['DATE']:
return local_bkg_file

flat_file = FlatFieldStep().get_reference_file(file, 'flat')

# If we don't have write access copy to local file
if (not os.access(bkg_file,os.W_OK)) or (('CRDS_READONLY_CACHE' in os.environ) and (os.environ['CRDS_READONLY_CACHE'] == '1')):
shutil.copy(bkg_file,local_bkg_file)
bkg_file = local_bkg_file
wf = pyfits.open(bkg_file, mode='update')
key = f"{wf[0].header['FILTER']} {wf[0].header['PUPIL']}"

Expand Down