Skip to content

Commit

Permalink
Update flagmap and filter
Browse files Browse the repository at this point in the history
Update trail source filter and unit tests
  • Loading branch information
bsmartradio committed Mar 1, 2024
1 parent 61a7c33 commit 6a82ca4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
11 changes: 10 additions & 1 deletion data/association-flag-map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ columns:
doc: parent source, ignored; only valid for HsmShape
- name: ext_trailedSources_Naive_flag_edge
bit: 27
doc: source is trailed and extends off chip
doc: Trail beginning or end falls on edge pixels or extends off image
- name: base_PixelFlags_flag_streak
bit: 28
doc: Streak in the Source footprint
Expand All @@ -109,3 +109,12 @@ columns:
- name: base_PixelFlags_flag_injected_templateCenter
bit: 33
doc: Fake source template injection center in source footprint
- name: ext_trailedSources_Naive_flag_off_image
bit: 34
doc: Trail extends off image
- name: ext_trailedSources_Naive_flag_nan
bit: 35
doc: Trail start or end pixels contain nan
- name: ext_trailedSources_Naive_flag_suspect_long_trail
bit: 36
doc: Trail longer than three psf radii
21 changes: 16 additions & 5 deletions python/lsst/ap/association/trailedSourceFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ def run(self, dia_sources, exposure_time):
longTrailedDiaSources=dia_sources[trail_mask].reset_index(drop=True))

def _check_dia_source_trail(self, dia_sources, exposure_time, flags):
"""Find DiaSources that have long trails.
"""Find DiaSources that have long trails or trails with indeterminant
end points.
Return a mask of sources with lengths greater than
``config.max_trail_length`` multiplied by the exposure time in seconds
or have ext_trailedSources_Naive_flag_edge set.
``config.max_trail_length`` multiplied by the exposure time in
seconds. Additionally, set mask if
``ext_trailedSources_Naive_flag_off_image`` is set or if
``ext_trailedSources_Naive_flag_suspect_long_trail`` and
``ext_trailedSources_Naive_flag_edge`` are both set.
Parameters
----------
Expand All @@ -115,11 +119,18 @@ def _check_dia_source_trail(self, dia_sources, exposure_time, flags):
-------
trail_mask : `pandas.DataFrame`
Boolean mask for DIASources which are greater than the
cutoff length and have the edge flag set.
cutoff length or have off_image or suspect_long_trail
flag set.
"""
trail_mask = (dia_sources.loc[:, "trailLength"].values[:]
>= (self.config.max_trail_length*exposure_time))

trail_mask[np.where(flags['ext_trailedSources_Naive_flag_edge'])] = True
long_flags = flags['ext_trailedSources_Naive_flag_suspect_long_trail']
edge_flags = flags['ext_trailedSources_Naive_flag_edge']

trail_mask[np.where(flags['ext_trailedSources_Naive_flag_off_image'])] = True
for index, value in enumerate(long_flags):
if value and edge_flags[index]:
trail_mask[index] = True

return trail_mask
3 changes: 2 additions & 1 deletion tests/test_trailedSourceFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def setUp(self):
"flags": 0}
for idx in range(self.nSources)])

self.edgeDiaSources.loc[[1, 4], 'flags'] = np.power(2, 27)
self.edgeDiaSources.loc[[1, 4], 'flags'] = np.power(2, 27) + np.power(2, 36)

def test_run(self):
"""Run trailedSourceFilterTask with the default max distance.
Expand Down Expand Up @@ -116,6 +116,7 @@ def test_run_edge(self):
"""
trailedSourceFilterTask = TrailedSourceFilterTask()

results = trailedSourceFilterTask.run(self.edgeDiaSources, self.exposure_time)
results = trailedSourceFilterTask.run(self.edgeDiaSources, self.exposure_time)

self.assertEqual(len(results.diaSources), 3)
Expand Down

0 comments on commit 6a82ca4

Please sign in to comment.