-
Notifications
You must be signed in to change notification settings - Fork 171
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-2096: Cube build stage3 #6093
Changes from all commits
484bfa2
b37940e
da1ae3c
9e230c7
d1e4ddb
44e097f
3c60bb4
da720e8
8fb11b3
d45ffa2
3686ecb
36f0ef2
e6bbc2b
fabb5e6
e8e734a
ec1b3d4
3764bb5
17cd929
80d21e8
b01ec6e
ba41124
de3f107
e506588
0de907f
b173565
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,50 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
""" Map the detector pixels to the cube coordinate system. | ||||||||||||||||||||||||||||||||||||||||||||||||||
This is where the weight functions are used. | ||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
import numpy as np | ||||||||||||||||||||||||||||||||||||||||||||||||||
import logging | ||||||||||||||||||||||||||||||||||||||||||||||||||
log = logging.getLogger(__name__) | ||||||||||||||||||||||||||||||||||||||||||||||||||
log.setLevel(logging.DEBUG) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
def blot_overlap(ipt, xstart, | ||||||||||||||||||||||||||||||||||||||||||||||||||
xcenter, ycenter, | ||||||||||||||||||||||||||||||||||||||||||||||||||
x_cube, y_cube, | ||||||||||||||||||||||||||||||||||||||||||||||||||
flux_cube, | ||||||||||||||||||||||||||||||||||||||||||||||||||
blot_xsize, | ||||||||||||||||||||||||||||||||||||||||||||||||||
blot_flux, blot_weight): | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
""" Blot the median sky image back to the detector | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
ipt is the median element. | ||||||||||||||||||||||||||||||||||||||||||||||||||
xcenter, ycenter are the detector pixel arrays | ||||||||||||||||||||||||||||||||||||||||||||||||||
xstart is only valid for MIRI and is the start of the x detector value for channel | ||||||||||||||||||||||||||||||||||||||||||||||||||
0 for channels on left and ~512 for channels on right | ||||||||||||||||||||||||||||||||||||||||||||||||||
x_cube, y_cube: median cube IFU mapped backwards to detector | ||||||||||||||||||||||||||||||||||||||||||||||||||
flux_cube: median flux | ||||||||||||||||||||||||||||||||||||||||||||||||||
blot_flux & blot_weight: blotted values of flux_cube to detector | ||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
roi_det = 1.0 # Just large enough that we don't get holes | ||||||||||||||||||||||||||||||||||||||||||||||||||
xdistance = np.absolute(x_cube[ipt] - xcenter) | ||||||||||||||||||||||||||||||||||||||||||||||||||
ydistance = np.absolute(y_cube[ipt] - ycenter) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
index_x = np.where(xdistance <= roi_det) | ||||||||||||||||||||||||||||||||||||||||||||||||||
index_y = np.where(ydistance <= roi_det) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
if len(index_x[0]) > 0 and len(index_y[0]) > 0: | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
d1pix = x_cube[ipt] - xcenter[index_x] | ||||||||||||||||||||||||||||||||||||||||||||||||||
d2pix = y_cube[ipt] - ycenter[index_y] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
dxy = [(dx * dx + dy * dy) for dy in d2pix for dx in d1pix] | ||||||||||||||||||||||||||||||||||||||||||||||||||
dxy = np.array(dxy) | ||||||||||||||||||||||||||||||||||||||||||||||||||
dxy = np.sqrt(dxy) | ||||||||||||||||||||||||||||||||||||||||||||||||||
weight_distance = np.exp(-dxy) | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+36
to
+43
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.
Suggested change
or, alternatively:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
weighted_flux = weight_distance * flux_cube[ipt] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
index2d = [iy * blot_xsize + ix for iy in index_y[0] for ix in (index_x[0] + xstart)] | ||||||||||||||||||||||||||||||||||||||||||||||||||
index2d = np.array(index2d) | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+46
to
+47
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
blot_flux[index2d] = blot_flux[index2d] + weighted_flux | ||||||||||||||||||||||||||||||||||||||||||||||||||
blot_weight[index2d] = blot_weight[index2d] + weight_distance |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
from gwcs import wcstools | ||
from . import instrument_defaults | ||
|
||
from . import blot_cube | ||
|
||
log = logging.getLogger(__name__) | ||
log.setLevel(logging.DEBUG) | ||
|
||
|
@@ -199,16 +201,15 @@ def blot_images_miri(self): | |
# pixel. | ||
# the Regular grid is on the x,y detector | ||
|
||
blot_flux = self.blot_overlap_quick(model, xcenter, ycenter, | ||
xstart, x_cube, y_cube, | ||
flux_cube) | ||
blot_flux = self.blot_overlap_miri(model, xcenter, ycenter, | ||
xstart, x_cube, y_cube, | ||
flux_cube) | ||
blot.data = blot_flux | ||
blot_models.append(blot) | ||
return blot_models | ||
# ________________________________________________________________________________ | ||
|
||
def blot_overlap_quick(self, model, xcenter, ycenter, xstart, | ||
x_cube, y_cube, flux_cube): | ||
def blot_overlap_miri(self, model, xcenter, ycenter, xstart, | ||
x_cube, y_cube, flux_cube): | ||
|
||
# blot_overlap_quick finds to overlap between the blotted sky values | ||
# (x_cube, y_cube) and the detector pixels. | ||
|
@@ -223,31 +224,16 @@ def blot_overlap_quick(self, model, xcenter, ycenter, xstart, | |
blot_weight = np.ndarray.flatten(blot_weight) | ||
|
||
# loop over valid points in cube (not empty edge pixels) | ||
roi_det = 1.0 # Just large enough that we don't get holes | ||
ivalid = np.nonzero(np.absolute(flux_cube)) | ||
|
||
ivalid = np.nonzero(np.absolute(flux_cube)) | ||
t0 = time.time() | ||
for ipt in ivalid[0]: | ||
# search xcenter and ycenter seperately. These arrays are smallsh. | ||
# xcenter size = naxis1 on detector (for MIRI only 1/2 array) | ||
# ycenter size = naxis2 on detector | ||
xdistance = np.absolute(x_cube[ipt] - xcenter) | ||
ydistance = np.absolute(y_cube[ipt] - ycenter) | ||
|
||
index_x = np.where(xdistance <= roi_det) | ||
index_y = np.where(ydistance <= roi_det) | ||
|
||
if len(index_x[0]) > 0 and len(index_y[0]) > 0: | ||
d1pix = np.array(x_cube[ipt] - xcenter[index_x]) | ||
d2pix = np.array(y_cube[ipt] - ycenter[index_y]) | ||
|
||
dxy = [(dx * dx + dy * dy) for dy in d2pix for dx in d1pix] | ||
dxy = np.sqrt(dxy) | ||
weight_distance = np.exp(-dxy) | ||
weighted_flux = weight_distance * flux_cube[ipt] | ||
index2d = [iy * blot_xsize + ix for iy in index_y[0] for ix in (index_x[0] + xstart)] | ||
blot_flux[index2d] = blot_flux[index2d] + weighted_flux | ||
blot_weight[index2d] = blot_weight[index2d] + weight_distance | ||
blot_cube.blot_overlap(ipt, xstart, | ||
xcenter, ycenter, | ||
x_cube, y_cube, | ||
flux_cube, | ||
blot_xsize, | ||
blot_flux, blot_weight) | ||
|
||
t1 = time.time() | ||
log.debug(f"Time to blot median image to input model = {t1-t0:.1f}") | ||
|
@@ -257,7 +243,6 @@ def blot_overlap_quick(self, model, xcenter, ycenter, xstart, | |
blot_flux = blot_flux.reshape((blot_ysize, blot_xsize)) | ||
return blot_flux | ||
|
||
# ************************************************************************ | ||
def blot_images_nirspec(self): | ||
""" Core blotting routine for NIRSPEC | ||
|
||
|
@@ -299,7 +284,7 @@ def blot_images_nirspec(self): | |
nslices = 30 | ||
log.info('Looping over 30 slices on NIRSPEC detector, this takes a little while') | ||
t0 = time.time() | ||
roi_det = 1.0 # Just large enough that we don't get holes | ||
|
||
for ii in range(nslices): | ||
ts0 = time.time() | ||
# for each slice pull out the blotted values that actually fall on the slice region | ||
|
@@ -338,30 +323,17 @@ def blot_images_nirspec(self): | |
y_slice = y_slice[fuse] | ||
flux_slice = flux_slice[fuse] | ||
|
||
xstart = 0 | ||
nn = flux_slice.size | ||
for ipt in range(nn): | ||
# search xcenter and ycenter seperately. These arrays are smallish. | ||
# xcenter size = naxis1 on detector | ||
# ycenter size = naxis2 on detector | ||
xdistance = np.absolute(x_slice[ipt] - xcenter) | ||
ydistance = np.absolute(y_slice[ipt] - ycenter) | ||
|
||
index_x = np.where(xdistance <= roi_det) | ||
index_y = np.where(ydistance <= roi_det) | ||
|
||
if len(index_x[0]) > 0 and len(index_y[0]) > 0: | ||
d1pix = np.array(x_slice[ipt] - xcenter[index_x]) | ||
d2pix = np.array(y_slice[ipt] - ycenter[index_y]) | ||
|
||
dxy = [(dx * dx + dy * dy) for dy in d2pix for dx in d1pix] | ||
dxy = np.sqrt(dxy) | ||
weight_distance = np.exp(-dxy) | ||
weighted_flux = weight_distance * flux_slice[ipt] | ||
index2d = [iy * blot_xsize + ix for iy in index_y[0] for ix in (index_x[0])] | ||
blot_flux[index2d] = blot_flux[index2d] + weighted_flux | ||
blot_weight[index2d] = blot_weight[index2d] + weight_distance | ||
blot_cube.blot_overlap(ipt, xstart, | ||
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. Maybe just set 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. holding off on blot changes - I have opened a separate ticket on blotting |
||
xcenter, ycenter, | ||
x_slice, y_slice, | ||
flux_slice, | ||
blot_xsize, | ||
blot_flux, blot_weight) | ||
ts1 = time.time() | ||
log.debug(f"Time to map 1 slice = {ts1-ts0:.1f}") | ||
log.debug(f"Time to blot 1 slice on NIRspec = {ts1-ts0:.1f}") | ||
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 timing for one slice relevant even for debugging purposes? 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. it is for NIRSPEC. It can take several seconds per slice. Once we get it faster I will remove the debug timing |
||
# done mapping median cube to this input model | ||
t1 = time.time() | ||
log.debug(f"Time to blot median image to input model = {t1-t0:.1f}") | ||
|
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.
I am not familiar with the algorithm, but it seems like
index_x
andindex_y
, in principle, could have different lengths or point to different "pixels". Would, this be an issue? Especially different lengths in the code just below.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.
I am going to hold off making changes to blot_cube.py because I have another JP ticket to work just on blot cube after I get the c extensions in this PR committed. I will come back to these changes suggestions later this week.