-
Notifications
You must be signed in to change notification settings - Fork 157
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
jp-1690 calspec3 cube_build clean up #5347
Merged
jemorrison
merged 5 commits into
spacetelescope:master
from
jemorrison:JP-1690_calspec3
Sep 21, 2020
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -625,6 +625,10 @@ def build_ifucube(self): | |
# loop over the files that cover the spectral range the cube is for | ||
for k in range(nfiles): | ||
ifile = self.master_table.FileMap[self.instrument][this_par1][this_par2][k] | ||
# set up ifile_ref to be first file used to copy in basic header info | ||
# to ifucube meta data | ||
if i == 0 and k ==0: | ||
ifile_ref = ifile | ||
|
||
log.debug(f"Working on Band defined by: {this_par1} {this_par2}") | ||
# -------------------------------------------------------------------------------- | ||
|
@@ -638,18 +642,28 @@ def build_ifucube(self): | |
|
||
coord1, coord2, wave, flux, err, slice_no, rois_pixel, roiw_pixel, weight_pixel,\ | ||
softrad_pixel, scalerad_pixel, alpha_det, beta_det = pixelresult | ||
# check that there is valid data returned | ||
# If all the data is flagged as DO_NOT_USE - not common then log warning and skip data | ||
nn = wave.size | ||
no_data = False | ||
if nn == 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is
|
||
no_data = True | ||
|
||
t1 = time.time() | ||
log.info("Time to transform pixels to output frame = %.1f s" % (t1 - t0,)) | ||
log.debug("Time to transform pixels to output frame = %.1f s" % (t1 - t0,)) | ||
|
||
# If setting the DQ plane of the IFU | ||
if self.skip_dqflagging: | ||
if self.skip_dqflagging or no_data: | ||
log.info("Skipping setting DQ flagging") | ||
else: | ||
t0 = time.time() | ||
roiw_ave = np.mean(roiw_pixel) | ||
self.map_fov_to_dqplane(this_par1, coord1, coord2, wave, roiw_ave, slice_no) | ||
t1 = time.time() | ||
log.info("Time to set initial dq values = %.1f s" % (t1 - t0,)) | ||
log.debug("Time to set initial dq values = %.1f s" % (t1 - t0,)) | ||
|
||
if no_data: | ||
log.warning(f'No valid data found on file {ifile.meta.filename}') | ||
if self.weighting == 'msm' or self.weighting == 'emsm': | ||
t0 = time.time() | ||
cube_cloud.match_det2cube_msm(self.naxis1, self.naxis2, self.naxis3, | ||
|
@@ -792,7 +806,7 @@ def build_ifucube(self): | |
t1 = time.time() | ||
log.info("Time to find Cube Flux = %.1f s" % (t1 - t0,)) | ||
# result consist of ifu_cube and status | ||
result = self.setup_final_ifucube_model(0) | ||
result = self.setup_final_ifucube_model(ifile_ref) | ||
# _______________________________________________________________________ | ||
# shove Flux and iflux in the final IFU cube | ||
|
||
|
@@ -811,69 +825,73 @@ def build_ifucube_single(self): | |
""" | ||
# loop over input models | ||
single_ifucube_container = datamodels.ModelContainer() | ||
n = len(self.input_models) | ||
|
||
log.info("Number of Single IFU cubes to create = %i" % n) | ||
this_par1 = self.list_par1[0] # only one channel is used in this approach | ||
# this_par2 = None # not important for this type of mapping | ||
cube_debug = None | ||
|
||
for j in range(n): | ||
log.debug("Working on next Single IFU Cube = %i" % (j + 1)) | ||
t0 = time.time() | ||
# for each new data model create a new spaxel | ||
total_num = self.naxis1 * self.naxis2 * self.naxis3 | ||
self.spaxel_flux = np.zeros(total_num) | ||
self.spaxel_weight = np.zeros(total_num) | ||
self.spaxel_iflux = np.zeros(total_num) | ||
self.spaxel_dq = np.zeros((self.naxis3, self.naxis2 * self.naxis1), dtype=np.uint32) | ||
self.spaxel_var = np.zeros(total_num) | ||
|
||
subtract_background = False | ||
|
||
pixelresult = self.map_detector_to_outputframe(this_par1, | ||
subtract_background, | ||
self.input_models[j]) | ||
|
||
coord1, coord2, wave, flux, err, slice_no, rois_pixel, roiw_pixel, weight_pixel, \ | ||
softrad_pixel, scalerad_pixel, alpha_det, beta_det = pixelresult | ||
|
||
cube_cloud.match_det2cube_msm(self.naxis1, | ||
self.naxis2, | ||
self.naxis3, | ||
self.cdelt1, self.cdelt2, | ||
self.cdelt3_normal, | ||
self.xcenters, | ||
self.ycenters, | ||
self.zcoord, | ||
self.spaxel_flux, | ||
self.spaxel_weight, | ||
self.spaxel_iflux, | ||
self.spaxel_var, | ||
flux, | ||
err, | ||
coord1, coord2, wave, | ||
self.weighting, | ||
rois_pixel, roiw_pixel, | ||
weight_pixel, | ||
softrad_pixel, | ||
scalerad_pixel, | ||
cube_debug, | ||
self.debug_file) | ||
number_bands = len(self.list_par1) | ||
this_par1 = self.list_par1[0] # single IFUcube only have a single channel | ||
j = 0 | ||
for i in range(number_bands): | ||
this_par2 = self.list_par2[i] | ||
nfiles = len(self.master_table.FileMap[self.instrument][this_par1][this_par2]) | ||
# ________________________________________________________________________________ | ||
# loop over the files that cover the spectral range the cube is for | ||
for k in range(nfiles): | ||
ifile = self.master_table.FileMap[self.instrument][this_par1][this_par2][k] | ||
cube_debug = None | ||
log.debug("Working on next Single IFU Cube = %i" % (j + 1)) | ||
t0 = time.time() | ||
# for each new data model create a new spaxel | ||
total_num = self.naxis1 * self.naxis2 * self.naxis3 | ||
self.spaxel_flux = np.zeros(total_num) | ||
self.spaxel_weight = np.zeros(total_num) | ||
self.spaxel_iflux = np.zeros(total_num) | ||
self.spaxel_dq = np.zeros((self.naxis3, self.naxis2 * self.naxis1), dtype=np.uint32) | ||
self.spaxel_var = np.zeros(total_num) | ||
|
||
subtract_background = False | ||
|
||
pixelresult = self.map_detector_to_outputframe(this_par1, | ||
subtract_background, | ||
ifile) | ||
|
||
coord1, coord2, wave, flux, err, slice_no, rois_pixel, roiw_pixel, weight_pixel, \ | ||
softrad_pixel, scalerad_pixel, alpha_det, beta_det = pixelresult | ||
|
||
cube_cloud.match_det2cube_msm(self.naxis1, | ||
self.naxis2, | ||
self.naxis3, | ||
self.cdelt1, self.cdelt2, | ||
self.cdelt3_normal, | ||
self.xcenters, | ||
self.ycenters, | ||
self.zcoord, | ||
self.spaxel_flux, | ||
self.spaxel_weight, | ||
self.spaxel_iflux, | ||
self.spaxel_var, | ||
flux, | ||
err, | ||
coord1, coord2, wave, | ||
self.weighting, | ||
rois_pixel, roiw_pixel, | ||
weight_pixel, | ||
softrad_pixel, | ||
scalerad_pixel, | ||
cube_debug, | ||
self.debug_file) | ||
# _______________________________________________________________________ | ||
# shove Flux and iflux in the final ifucube | ||
self.find_spaxel_flux() | ||
self.find_spaxel_flux() | ||
|
||
# determine Cube Spaxel flux | ||
status = 0 | ||
result = self.setup_final_ifucube_model(j) | ||
ifucube_model, status = result | ||
t1 = time.time() | ||
log.debug("Time to Create Single ifucube = %.1f s" % (t1 - t0,)) | ||
single_ifucube_container.append(ifucube_model) | ||
if status !=0: | ||
log.debug("Possible problem with single ifu cube, no valid data in cube" ) | ||
|
||
status = 0 | ||
result = self.setup_final_ifucube_model(ifile) | ||
ifucube_model, status = result | ||
t1 = time.time() | ||
log.debug("Time to Create Single ifucube = %.1f s" % (t1 - t0,)) | ||
single_ifucube_container.append(ifucube_model) | ||
if status !=0: | ||
log.debug("Possible problem with single ifu cube, no valid data in cube" ) | ||
j = j + 1 | ||
return single_ifucube_container | ||
# ************************************************************************** | ||
|
||
|
@@ -1216,7 +1234,7 @@ def setup_ifucube_wcs(self): | |
lambda_max = [] | ||
|
||
self.num_bands = len(self.list_par1) | ||
log.info('Number of bands in cube: %i', self.num_bands) | ||
log.debug('Number of bands in cube: %i', self.num_bands) | ||
|
||
for i in range(self.num_bands): | ||
this_a = parameter1[i] | ||
|
@@ -2052,7 +2070,7 @@ def set_final_dq_flags(self): | |
|
||
# ******************************************************************************** | ||
|
||
def setup_final_ifucube_model(self, j): | ||
def setup_final_ifucube_model(self, model_ref): | ||
|
||
""" Set up the final meta WCS info of IFUCube along with other fits keywords | ||
|
||
|
@@ -2151,7 +2169,7 @@ def setup_final_ifucube_model(self, j): | |
weightmap=idata, | ||
wavetable=alldata) | ||
|
||
ifucube_model.update(self.input_models[j]) | ||
ifucube_model.update(model_ref) | ||
ifucube_model.meta.filename = self.output_name | ||
|
||
ifucube_model.data = temp_flux | ||
|
@@ -2167,9 +2185,9 @@ def setup_final_ifucube_model(self, j): | |
ifucube_model.meta.model_type = saved_model_type | ||
# ______________________________________________________________________ | ||
if self.output_type == 'single': | ||
with datamodels.open(self.input_models[j]) as input: | ||
with datamodels.open(model_ref) as input: | ||
# define the cubename for each single | ||
filename = self.input_filenames[j] | ||
filename = input.meta.filename | ||
indx = filename.rfind('.fits') | ||
self.output_name_base = filename[:indx] | ||
self.output_file = None | ||
|
@@ -2187,7 +2205,6 @@ def setup_final_ifucube_model(self, j): | |
outchannel = "".join(set(outchannel)) | ||
outchannel = "".join(sorted(outchannel)) | ||
ifucube_model.meta.instrument.channel = outchannel | ||
log.info(f'IFUChannel {ifucube_model.meta.instrument.channel}') | ||
# ______________________________________________________________________ | ||
ifucube_model.meta.wcsinfo.crval1 = self.crval1 | ||
ifucube_model.meta.wcsinfo.crval2 = self.crval2 | ||
|
@@ -2253,7 +2270,7 @@ def setup_final_ifucube_model(self, j): | |
# if non-linear wavelengths then this will be None | ||
ifucube_model.meta.ifu.weight_power = self.weight_power | ||
|
||
with datamodels.open(self.input_models[j]) as input: | ||
with datamodels.open(model_ref) as input: | ||
ifucube_model.meta.bunit_data = input.meta.bunit_data | ||
ifucube_model.meta.bunit_err = input.meta.bunit_err | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit, but could remove unused white space after %s