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

Wavelength correction improvements #173

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
332ee42
Allow KOAID filenames, with lots of junk too
MNBrod Apr 13, 2024
9d965a2
remove extraneous prints
MNBrod Apr 13, 2024
76ca3d7
remove commented print
MNBrod Apr 16, 2024
c79de62
move print statement to logger
MNBrod Apr 16, 2024
eaa516c
modify master file primitves to allow non-local files
MNBrod Apr 16, 2024
ba86c87
move print to logger
MNBrod Apr 16, 2024
440a2a1
turn off multiprocessing in the framework
MNBrod Apr 16, 2024
ba6c1aa
fix file naming bug in the blue
MNBrod Apr 17, 2024
55096fe
adjust invens plotting level to comply with config
MNBrod Apr 17, 2024
968d1b0
update rti_pipeline to match kcwi_pipeline
MNBrod Apr 18, 2024
c371d53
update kcwi_rti to match reduce_kcwi
MNBrod Apr 18, 2024
4fba734
allow user to specify RTI config file
MNBrod Apr 18, 2024
fef73f9
fix -f bug in rti
MNBrod Apr 19, 2024
7b211ff
fix plot_level wrong in invsens
MNBrod Apr 19, 2024
a69a1b3
fix sendhttp bug
MNBrod Apr 19, 2024
24b8292
more plot_level fixes
MNBrod Apr 19, 2024
f561ce4
add auto ledge correction
MNBrod Apr 30, 2024
4935235
add cfg bodge to check_cals
MNBrod May 1, 2024
8d8ab43
add fix header to check_cals
MNBrod May 1, 2024
2c8923e
take in rti ingest level as argument, not config
MNBrod May 1, 2024
bb03c6c
add auto mode to check_cals
MNBrod May 1, 2024
e2a5f16
fix ingesttype bug
MNBrod May 2, 2024
ce3b025
typo in check_cals
MNBrod May 3, 2024
527ceff
Added print statements for humidity, temp, pressure
anthonyjlau Jun 18, 2024
f8d6cf9
Added labels to print statements
anthonyjlau Jun 18, 2024
795da02
Added refractive index equation to WavelengthCorrections.py
anthonyjlau Jun 19, 2024
694fbcc
Changed e notation to **
anthonyjlau Jun 19, 2024
0914422
added graphs for model comparison
anthonyjlau Jun 28, 2024
8088849
added combined resampling func for a2v and helio
anthonyjlau Jul 9, 2024
7e87003
Removed test prints and old funcs, added docstrings
anthonyjlau Jul 24, 2024
5288596
Merge branch 'Keck-DataReductionPipelines:master' into akamai
anthonyjlau Jul 24, 2024
c4ea2f9
Update .gitignore
anthonyjlau Jul 24, 2024
00329f3
Removed graphs
anthonyjlau Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
*__pycache__*
/build
*.egg
/dist
/dist
/graphs
2 changes: 1 addition & 1 deletion kcwidrp/configs/framework.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ http_defaultFile = ""
# The queue_manager_hostname is used for clients to connect to the server so share the event queue.
# The authentication code is arbitrary.
#
want_multiprocessing = True
want_multiprocessing = False
queue_manager_hostname = "localhost"
queue_manager_portnr = 50101
queue_manager_auth_code = b"kcwi"
Expand Down
1 change: 0 additions & 1 deletion kcwidrp/configs/rti.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ rti_retry_time = 5 # How many seconds to wait before trying connection again
rti_user = ''
rti_pass = ''
# RTI API parameters
rti_ingesttype = 'lev1'
rti_reingest = False
rti_testonly = False
rti_dev = True
1 change: 0 additions & 1 deletion kcwidrp/core/kcwi_proctab.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def update_proctab(self, frame, suffix='raw', newtype=None, filename=""):
filename]
else:
new_row = None
# print("Attempting to add %s" % str(new_row))
self.proctab.add_row(new_row)
self.proctab = unique(self.proctab, keys=['CID', 'FRAMENO', 'TYPE'],
keep='last')
Expand Down
183 changes: 127 additions & 56 deletions kcwidrp/pipelines/keck_rti_pipeline.py

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion kcwidrp/primitives/CorrectGain.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def _perform(self):
# Header keyword to update
key = 'GAINCOR'
keycom = 'Gain corrected?'
# print(self.action.args.ccddata.header)
number_of_amplifiers = self.action.args.namps
bsec, dsec, tsec, direc, amps, aoff = self.action.args.map_ccd
namps = len(amps)
Expand Down
3 changes: 2 additions & 1 deletion kcwidrp/primitives/ExtractArcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def _perform(self):
self.action.args.contbar_image_number = self.context.trace['CBARSNO']
self.action.args.contbar_image = self.context.trace['CBARSFL']
self.action.args.arc_number = self.action.args.ccddata.header['FRAMENO']
self.action.args.arc_image = self.action.args.ccddata.header['OFNAME']
self.action.args.arc_image = self.action.args.name
# self.action.args.arc_image = self.action.args.ccddata.header['OFNAME']

self.action.args.source_control_points = trace['src']
self.action.args.destination_control_points = trace['dst']
Expand Down
3 changes: 2 additions & 1 deletion kcwidrp/primitives/FindBars.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def _perform(self):
self.action.args.contbar_image_number = \
self.action.args.ccddata.header['FRAMENO']
self.action.args.contbar_image = \
self.action.args.ccddata.header['OFNAME']
self.action.args.name
# self.action.args.ccddata.header['OFNAME']

log_string = FindBars.__module__
self.action.args.ccddata.header['HISTORY'] = log_string
Expand Down
2 changes: 1 addition & 1 deletion kcwidrp/primitives/FluxCalibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _perform(self):
sz[0] != mcsz[0]:
self.logger.warning("wavelength scales not identical, "
"resampling standard")
print(w0, mcw0, dw, mcdw, wav[-1], mcwav[-1], sz[0], mcsz[0])
self.logger.info(w0, mcw0, dw, mcdw, wav[-1], mcwav[-1], sz[0], mcsz[0])
mcint = interp1d(mcwav, mcal, kind='cubic',
fill_value='extrapolate')
mscal = mcint(wav) * 1.e16 / expt
Expand Down
15 changes: 8 additions & 7 deletions kcwidrp/primitives/MakeInvsens.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def _perform(self):
wlm0 = wgoo0
wlm1 = wgoo1
# interactively set wavelength limits
if self.config.instrument.plot_level >= 1:
if self.config.instrument.plot_level > 1:
print("CHECKING WAVELENGTH LIMITS")
print("Current WL limits: %.1f - %.1f Angstroms "
"(blue vertical lines)" % (wlm0, wlm1))
Expand Down Expand Up @@ -387,7 +387,8 @@ def _perform(self):
local_lmfile = os.path.basename(stdfile).split('.fits')[0] + '.lmsk'
if not os.path.exists(local_lmfile):
# then in stds directory
lmfile = stdfile.split('.fits')[0] + '.lmsk'
# lmfile = stdfile.split('.fits')[0] + '.lmsk'
lmfile = strip_fname(stdfile) + '.lmsk'
if not os.path.exists(lmfile):
lmfile = None
else:
Expand Down Expand Up @@ -428,7 +429,7 @@ def _perform(self):
else:
print("bad line: %s" % lmws)
# Now interactively identify lines if requested
if self.config.instrument.plot_level >= 1:
if self.config.instrument.plot_level >= 2:
yran = [np.min(obsspec[wl_good]), np.max(obsspec[wl_good])]
# source = ColumnDataSource(data=dict(x=w, y=obsspec))
print("MASKING SHARP FEATURES: ABSORPTION LINES/COSMIC RAYS")
Expand Down Expand Up @@ -580,7 +581,7 @@ def _perform(self):
line_color='black', line_dash='dashdot')
set_plot_lims(peff, xlim=[wall0, wall1], ylim=yran)
bokeh_plot(peff, self.context.bokeh_session)
if self.config.instrument.plot_level >= 1:
if self.config.instrument.plot_level >= 2:
input("Next? <cr>: ")
else:
time.sleep(2. * self.config.instrument.plot_pause)
Expand All @@ -601,7 +602,7 @@ def _perform(self):
pivs.line([wlm1, wlm1], yran, line_color='green')
set_plot_lims(pivs, xlim=[wall0, wall1], ylim=yran)
bokeh_plot(pivs, self.context.bokeh_session)
if self.config.instrument.plot_level >= 1:
if self.config.instrument.plot_level >= 2:
input("Next? <cr>: ")
else:
time.sleep(2. * self.config.instrument.plot_pause)
Expand All @@ -620,7 +621,7 @@ def _perform(self):
pcal.line([wlm1, wlm1], yran, line_color='green')
set_plot_lims(pcal, xlim=[wall0, wall1], ylim=yran)
bokeh_plot(pcal, self.context.bokeh_session)
if self.config.instrument.plot_level >= 1:
if self.config.instrument.plot_level >= 2:
input("Next? <cr>: ")
else:
time.sleep(2. * self.config.instrument.plot_pause)
Expand Down Expand Up @@ -650,7 +651,7 @@ def _perform(self):
line_color='black', line_dash='dashed')
set_plot_lims(prsd, xlim=[wall0, wall1], ylim=yran)
bokeh_plot(prsd, self.context.bokeh_session)
if self.config.instrument.plot_level >= 1:
if self.config.instrument.plot_level >= 2:
qstr = input("Current fit order = %d, "
"New fit order? <int>, <cr> - done: " % ford)
if len(qstr) <= 0:
Expand Down
18 changes: 11 additions & 7 deletions kcwidrp/primitives/MakeMasterArc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from keckdrpframework.primitives.base_img import BaseImg
from kcwidrp.primitives.kcwi_file_primitives import kcwi_fits_reader, \
kcwi_fits_writer, strip_fname # , get_master_name
kcwi_fits_writer, strip_fname , get_unique_STATEID_master_name

import os
import ccdproc
Expand Down Expand Up @@ -58,14 +58,15 @@ def _perform(self):

combine_list = list(self.combine_list['filename'])
# get master arc output name
maname = strip_fname(combine_list[0]) + '_' + suffix + '.fits'
# maname = strip_fname(combine_list[0]) + '_' + suffix + '.fits'
if self.action.args.min_files > 1:
stack = []
stackf = []
for arc in combine_list:
# get arc intensity (int) image file name in redux directory
stackf.append(arc.split('.fits')[0] + '_int.fits')
arcfn = os.path.join(args.in_directory, stackf[-1])
stackf.append(strip_fname(arc) + '_int.fits')
arcfn = os.path.join(self.config.instrument.cwd,
self.config.instrument.output_directory, stackf[-1])
# using [0] gets just the image data
stack.append(kcwi_fits_reader(arcfn)[0])

Expand All @@ -86,15 +87,18 @@ def _perform(self):
"stack input file")
stacked.header['HISTORY'] = log_string
self.action.args.ccddata = stacked
# maname = get_unique_STATEID_master_name(stacked, suffix)
maname = strip_fname(combine_list[0]) + '_' + suffix + '.fits'

kcwi_fits_writer(stacked, output_file=maname,
output_dir=self.config.instrument.output_directory)
self.context.proctab.update_proctab(frame=stacked, suffix=suffix,
newtype=args.new_type,
filename=stacked.header[
'OFNAME'])
self.action.args.name = stacked.header['OFNAME']
filename=self.action.args.name) ### HERE
# self.action.args.name = maname
# self.action.args.name = stacked.header['OFNAME']
else:
maname = strip_fname(combine_list[0]) + '_' + suffix + '.fits'
self.action.args.ccddata.header['IMTYPE'] = args.new_type
self.action.args.ccddata.header['HISTORY'] = log_string
kcwi_fits_writer(self.action.args.ccddata, output_file=maname,
Expand Down
13 changes: 9 additions & 4 deletions kcwidrp/primitives/MakeMasterBias.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from keckdrpframework.models.arguments import Arguments
from keckdrpframework.primitives.base_img import BaseImg
from kcwidrp.primitives.kcwi_file_primitives import kcwi_fits_reader, \
kcwi_fits_writer, parse_imsec, strip_fname
kcwi_fits_writer, parse_imsec, strip_fname, get_unique_CCD_master_name
from kcwidrp.core.bokeh_plotting import bokeh_plot
from kcwidrp.core.kcwi_plotting import save_plot

Expand Down Expand Up @@ -64,15 +64,17 @@ def _perform(self):
combine_list = list(self.combine_list['filename'])
# get master bias output name
# mbname = combine_list[-1].split('.fits')[0] + '_' + suffix + '.fits'
mbname = strip_fname(combine_list[0]) + '_' + suffix + '.fits'
# mbname = strip_fname(combine_list[0]) + '_' + suffix + '.fits'

# mbname = master_bias_name(self.action.args.ccddata)
bsec, dsec, tsec, direc, amps, aoff = self.action.args.map_ccd

# loop over amps
stack = []
stackf = []
for bias in combine_list:
inbias = bias.split('.fits')[0] + '_intb.fits'
# inbias = bias.split('.fits')[0] + '_intb.fits'
inbias = strip_fname(bias) + '_intb.fits'
stackf.append(inbias)
# using [0] drops the table and leaves just the image
stack.append(kcwi_fits_reader(
Expand Down Expand Up @@ -158,11 +160,14 @@ def _perform(self):
stacked.header['HISTORY'] = log_string
self.logger.info(log_string)

mbname = get_unique_CCD_master_name(stacked)


kcwi_fits_writer(stacked, output_file=mbname,
output_dir=self.config.instrument.output_directory)
self.context.proctab.update_proctab(frame=stacked, suffix=suffix,
newtype=self.action.args.new_type,
filename=stacked.header['OFNAME'])
filename=self.action.args.name)
self.context.proctab.write_proctab(tfil=self.config.instrument.procfile)
return Arguments(name=mbname)
# END: class ProcessBias()
22 changes: 12 additions & 10 deletions kcwidrp/primitives/MakeMasterContbars.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from keckdrpframework.primitives.base_img import BaseImg
from kcwidrp.primitives.kcwi_file_primitives import kcwi_fits_reader, \
kcwi_fits_writer, strip_fname # , get_master_name
kcwi_fits_writer, strip_fname , get_unique_STATEID_master_name

import os
import ccdproc
Expand Down Expand Up @@ -57,15 +57,14 @@ def _perform(self):
log_string = MakeMasterContbars.__module__

combine_list = list(self.combine_list['filename'])
# get master arc output name
maname = strip_fname(combine_list[0]) + '_' + suffix + '.fits'

if self.action.args.min_files > 1:
stack = []
stackf = []
for cbs in combine_list:
# get arc intensity (int) image file name in redux directory
stackf.append(cbs.split('.fits')[0] + '_int.fits')
cbsfn = os.path.join(args.in_directory, stackf[-1])
stackf.append(strip_fname(cbs) + '_int.fits')
cbsfn = os.path.join(self.config.instrument.cwd, self.config.instrument.output_directory, stackf[-1])
# using [0] gets just the image data
stack.append(kcwi_fits_reader(cbsfn)[0])

Expand All @@ -87,17 +86,20 @@ def _perform(self):
stacked.header['HISTORY'] = log_string
self.action.args.ccddata = stacked

kcwi_fits_writer(stacked, output_file=maname,
# get master arc output name
mcbars_name = strip_fname(combine_list[0]) + '_' + suffix + '.fits'

kcwi_fits_writer(stacked, output_file=mcbars_name,
output_dir=self.config.instrument.output_directory)
self.context.proctab.update_proctab(frame=stacked, suffix=suffix,
newtype=args.new_type,
filename=stacked.header[
'OFNAME'])
self.action.args.name = stacked.header['OFNAME']
filename=self.action.args.name) ### HERE
# self.action.args.name = stacked.header['OFNAME']
else:
mcbars_name = strip_fname(combine_list[0]) + '_' + suffix + '.fits'
self.action.args.ccddata.header['IMTYPE'] = args.new_type
self.action.args.ccddata.header['HISTORY'] = log_string
kcwi_fits_writer(self.action.args.ccddata, output_file=maname,
kcwi_fits_writer(self.action.args.ccddata, output_file=mcbars_name,
output_dir=self.config.instrument.output_directory)
self.context.proctab.update_proctab(frame=self.action.args.ccddata,
suffix=suffix,
Expand Down
12 changes: 7 additions & 5 deletions kcwidrp/primitives/MakeMasterDark.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from keckdrpframework.primitives.base_img import BaseImg
from kcwidrp.primitives.kcwi_file_primitives import kcwi_fits_reader, \
kcwi_fits_writer, strip_fname # , get_master_name
kcwi_fits_writer, strip_fname, get_unique_STATEID_master_name # , get_master_name

import os
import ccdproc
Expand Down Expand Up @@ -54,13 +54,15 @@ def _perform(self):

combine_list = list(self.combine_list['filename'])
# get master dark output name
mdname = strip_fname(combine_list[0]) + '_' + suffix + '.fits'
# mdname = strip_fname(combine_list[0]) + '_' + suffix + '.fits'
mdname = get_unique_STATEID_master_name(self.action.args.ccddata, suffix="mdark")
stack = []
stackf = []
for dark in combine_list:
# get dark intensity (int) image file name in redux directory
stackf.append(dark.split('.fits')[0] + '_int.fits')
darkfn = os.path.join(args.in_directory, stackf[-1])
stackf.append(strip_fname(dark) + '_int.fits')
darkfn = os.path.join(self.config.instrument.cwd,
self.config.instrument.output_directory, stackf[-1])
# using [0] gets just the image data
stack.append(kcwi_fits_reader(darkfn)[0])

Expand All @@ -87,7 +89,7 @@ def _perform(self):
output_dir=self.config.instrument.output_directory)
self.context.proctab.update_proctab(frame=stacked, suffix=suffix,
newtype=args.new_type,
filename=stacked.header['OFNAME'])
filename=self.action.args.name) ### HERE
self.context.proctab.write_proctab(tfil=self.config.instrument.procfile)
return self.action.args
# END: class MakeMasterDark()
24 changes: 15 additions & 9 deletions kcwidrp/primitives/MakeMasterFlat.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _perform(self):
self.logger.error("Geometry not solved!")
return self.action.args

mroot = strip_fname(tab['filename'][-1])
mroot = strip_fname(tab['filename'][-1]) # ??????????????????

# Wavelength map image
wmf = mroot + '_wavemap.fits'
Expand Down Expand Up @@ -435,7 +435,7 @@ def _perform(self):
trm = int(len(deriv)/5)
deriv = deriv[trm:-trm]
xvals = fpoints[trm:-trm]
peaks, _ = find_peaks(deriv, height=20)
peaks, properties = find_peaks(deriv, height=20)
self.logger.info("%d Peak(s) found" % len(peaks))

p = figure(title=plab +
Expand Down Expand Up @@ -466,11 +466,16 @@ def _perform(self):
bokeh_plot(p, self.context.bokeh_session)
if len(peaks) != 1:
self.logger.warning("Single peak not found!")
print("Please indicate the integer pixel value of the peak")
spk = input("Peak? <int>: ")
while not spk.isnumeric():
if self.config.instrument.plot_level >= 2:
print("Please indicate the integer pixel value of the peak")
spk = input("Peak? <int>: ")
ipk = int(spk)
while not spk.isnumeric():
spk = input("Peak? <int>: ")
ipk = int(spk)
else:
# Pick the highest peak, using the peaks properties
self.logger.warning("Picking the highest peak. This may not be the correct peak!")
ipk = properties['peak_heights'].argmax()
else:
ipk = peaks[0]
apk = xvals[ipk]
Expand Down Expand Up @@ -915,7 +920,7 @@ def _perform(self):
ratio.flat[qq] = 1.0

# get master flat output name
mfname = stack_list[0].split('.fits')[0] + '_' + suffix + '.fits'
mfname = strip_fname(stack_list[0]) + '_' + suffix + '.fits'

log_string = MakeMasterFlat.__module__
stacked.header['IMTYPE'] = self.action.args.new_type
Expand All @@ -933,9 +938,10 @@ def _perform(self):
output_dir=self.config.instrument.output_directory)
self.context.proctab.update_proctab(frame=stacked, suffix=suffix,
newtype=self.action.args.new_type,
filename=stacked.header['OFNAME'])
filename=stack_list[0]) ### HERE
self.context.proctab.write_proctab(tfil=self.config.instrument.procfile)
self.action.args.name = stacked.header['OFNAME']
# self.action.args.name = stacked.header['OFNAME']
# self.action.args.name = mfname

self.logger.info(log_string)
return self.action.args
Expand Down
Loading