Skip to content

Commit

Permalink
Merge pull request #186 from TheSkyentist/no-crds-write
Browse files Browse the repository at this point in the history
No CRDS write
  • Loading branch information
gbrammer authored Dec 18, 2023
2 parents d4f2376 + f9b86c3 commit cab21d8
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions grizli/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -6224,19 +6224,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 @@ -6250,8 +6237,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

0 comments on commit cab21d8

Please sign in to comment.