Skip to content

Commit

Permalink
more advanced input parameter estimation
Browse files Browse the repository at this point in the history
* to handle cases where extraction or background regions otherwise would default to outside of the image
  • Loading branch information
kecnry committed Aug 16, 2022
1 parent a71fdc0 commit 3b60b71
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,33 @@ def _trace_dataset_selected(self, msg=None):
width = self.trace_dataset.selected_obj.shape[0]
# estimate the pixel number by taking the median of the brightest pixel index in each column
brightest_pixel = int(np.median(np.argmax(self.trace_dataset.selected_obj.flux, axis=0)))
# default width will be 10% of cross-dispersion "height"
default_width = int(np.ceil(width / 10))
# do not allow to be an edge pixel
if brightest_pixel < 1:
brightest_pixel = 1
if brightest_pixel > width - 1:
brightest_pixel = width - 1
distance_from_edge = min(brightest_pixel, width-brightest_pixel)
# default width will be 10% of cross-dispersion "height",
# but no larger than distance from the edge
default_bg_width = int(np.ceil(width / 10))
default_width = min(default_bg_width, distance_from_edge * 2)

if self.trace_pixel == 0:
self.trace_pixel = brightest_pixel
if self.trace_window == 0:
self.trace_window = default_width
if self.bg_trace_pixel == 0:
self.bg_trace_pixel = brightest_pixel
if self.bg_separation == 0:
self.bg_separation = default_width * 2
if default_bg_width * 2 > distance_from_edge:
self.bg_type_selected = 'OneSided'
# we want positive separation if brightest_pixel near bottom
sign = 1 if (brightest_pixel < width / 2) else -1
self.bg_separation = sign * default_bg_width * 2
else:
self.bg_separation = default_bg_width * 2
if self.bg_width == 0:
self.bg_width = default_width
self.bg_width = default_bg_width
if self.ext_width == 0:
self.ext_width = default_width

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,14 @@ def test_plugin(specviz2d_helper):
pext.bg_results_label = 'should not be created'
pext.vue_create_bg()
assert 'should not be created' not in [d.label for d in specviz2d_helper.app.data_collection]


@pytest.mark.remote_data
def test_spectrum_on_top(specviz2d_helper):
fn = download_file('https://mast.stsci.edu/api/v0.1/Download/file/?uri=mast:jwst/product/jw01529-c1002_t002_miri_p750l_s2d.fits', cache=True) # noqa

specviz2d_helper.load_data(spectrum_2d=fn)

pext = specviz2d_helper.app.get_tray_item_from_name('spectral-extraction')
assert pext.bg_type_selected == 'OneSided'
assert pext.bg_separation < 0

0 comments on commit 3b60b71

Please # to comment.