Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gbrammer/grizli
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrammer committed Jan 9, 2024
2 parents 7c92e59 + 5132370 commit 3662dd0
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions grizli/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -6255,18 +6255,32 @@ def get_jwst_wfssbkg_file(file, valid_flat=[0.6, 1.3], make_figure=False):
_im.close()
return bkg_file

# Test local file
# Get local background file location
local_bkg_file = f"nis-{h['PUPIL']}-{h['FILTER']}_skyflat.fits".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) == pyfits.getval(bkg_file,'DATE',0):
return local_bkg_file
# Inspect local background file if it exists
if os.path.exists(local_bkg_file):

h = pyfits.getheader(local_bkg_file,0)
if 'DATE' not in h:
msg = f'Use local wfssbkg file {local_bkg_file} (Warning: no DATE keyword)'
utils.log_comment(utils.LOGFILE, msg, verbose=True)
return local_bkg_file
elif h['DATE'] == pyfits.getval(bkg_file,'DATE',0):
msg = f'Use local wfssbkg file {local_bkg_file}'
utils.log_comment(utils.LOGFILE, msg, verbose=True)
return local_bkg_file
else:
msg = f'Local wfssbkg file {local_bkg_file} is out of date, updating'
utils.log_comment(utils.LOGFILE, msg, verbose=True)

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')):
msg = f'Copy wfssbkg file {bkg_file} to {local_bkg_file}'
utils.log_comment(utils.LOGFILE, msg, verbose=True)
shutil.copy(bkg_file,local_bkg_file)
bkg_file = local_bkg_file
wf = pyfits.open(bkg_file, mode='update')
Expand Down

0 comments on commit 3662dd0

Please sign in to comment.