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

Minor fixes for photometry with bad pixels near image edges. #385

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.15.1 (2024-02-29)
-------------------
- Minor fixes in photometry when there are bad pixels near the image edges

1.15.0 (2024-02-14)
-------------------
- Migrated photometry extraction to be done by astropy's photutils instead of SEP.
Expand Down
24 changes: 17 additions & 7 deletions banzai/photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def flag_edge_sources(image, sources, flag_value=8):
minor_xmax = sources['x'] + sources['b'] * sources['kronrad'] * np.sin(np.deg2rad(sources['theta']))
minor_ymin = sources['y'] - sources['b'] * sources['kronrad'] * np.cos(np.deg2rad(sources['theta']))
minor_ymax = sources['y'] + sources['b'] * sources['kronrad'] * np.cos(np.deg2rad(sources['theta']))
major_ymin = sources['y'] - sources['a'] * sources['kronrad'] * np.sin(np.deg2rad(sources['theta']))
major_ymax = sources['y'] + sources['a'] * sources['kronrad'] * np.sin(np.deg2rad(sources['theta']))
major_xmin = sources['x'] - sources['a'] * sources['kronrad'] * np.cos(np.deg2rad(sources['theta']))
major_xmax = sources['x'] + sources['a'] * sources['kronrad'] * np.cos(np.deg2rad(sources['theta']))
major_ymin = sources['y'] - sources['a'] * sources['kronrad'] * np.cos(np.deg2rad(sources['theta']))
major_ymax = sources['y'] + sources['a'] * sources['kronrad'] * np.cos(np.deg2rad(sources['theta']))
major_xmin = sources['x'] - sources['a'] * sources['kronrad'] * np.sin(np.deg2rad(sources['theta']))
major_xmax = sources['x'] + sources['a'] * sources['kronrad'] * np.sin(np.deg2rad(sources['theta']))

# Note we are already 1 indexed here
sources_off = np.logical_or(minor_xmin < 1, major_xmin < 1)
Expand All @@ -64,7 +64,7 @@ def flag_edge_sources(image, sources, flag_value=8):
sources_off = np.logical_or(sources_off, major_xmax > nx)
sources_off = np.logical_or(sources_off, minor_ymax > ny)
sources_off = np.logical_or(sources_off, major_ymax > ny)
sources[sources_off]['flag'] |= flag_value
sources['flag'][sources_off] |= flag_value


class SourceDetector(Stage):
Expand Down Expand Up @@ -145,10 +145,20 @@ def do_stage(self, image):
# Flag = 16 if source has cosmic ray pixels
flag_sources(sources, catalog.labels, deblended_seg_map, image.mask, flag=16, mask_value=8)

sources = array_utils.prune_nans_from_table(sources)
rows_with_nans = array_utils.find_nans_in_table(sources)
catalog = catalog[~rows_with_nans]
sources = sources[~rows_with_nans]

# Cut individual bright pixels. Often cosmic rays
sources = sources[sources['fluxrad50'] > 0.5]
not_individual_bright_pixels = sources['fluxrad50'] > 0.5
catalog = catalog[not_individual_bright_pixels]
sources = sources[not_individual_bright_pixels]

# Cut sources that are less than 2 pixels wide
thin_sources = np.logical_or((catalog.bbox_ymax - catalog.bbox_ymin) < 1.5,
(catalog.bbox_xmax - catalog.bbox_xmin) < 1.5)
catalog = catalog[~thin_sources]
sources = sources[~thin_sources]

# Calculate the FWHMs of the stars:
sources['fwhm'] = np.nan
Expand Down
3 changes: 2 additions & 1 deletion banzai/tests/test_array_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

pytestmark = pytest.mark.array_utils


def test_pruning_nans():
a = np.arange(100, dtype=float)
b = np.arange(100, dtype=float) + 100
Expand All @@ -16,7 +17,7 @@ def test_pruning_nans():
c[78] = np.nan

t = Table([a, b, c], names=('a', 'b', 'c'))
t = array_utils.prune_nans_from_table(t)
t = t[~array_utils.find_nans_in_table(t)]
assert len(t) == 97
assert 51 not in t['a']
assert 32 not in t['a']
Expand Down
4 changes: 2 additions & 2 deletions banzai/utils/array_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def array_indices_to_slices(a):
return tuple(slice(0, x, 1) for x in a.shape)


def prune_nans_from_table(table):
def find_nans_in_table(table):
nan_in_row = np.zeros(len(table), dtype=bool)
for col in table.colnames:
nan_in_row |= np.isnan(table[col])
return table[~nan_in_row]
return nan_in_row
1 change: 1 addition & 0 deletions helm-chart/banzai/templates/workers-large.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ spec:
requests:
cpu: "0.5"
memory: "10Gi"
ephemeral-storage: "128Mi"
limits:
cpu: "2"
memory: "10Gi"
Expand Down
3 changes: 2 additions & 1 deletion helm-chart/banzai/templates/workers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ spec:
requests:
cpu: "0.5"
memory: "4Gi"
ephemeral-storage: "128Mi"
limits:
cpu: "2"
memory: "4Gi"
memory: "8Gi"
volumeMounts:
- name: tmp
mountPath: /tmp
Expand Down
Loading