Skip to content

DM-54275: Filter diaSources based on bbox when trailed sources unavailable #362

Merged
bsmartradio merged 1 commit into
mainfrom
tickets/DM-54275
Jun 25, 2026
Merged

DM-54275: Filter diaSources based on bbox when trailed sources unavailable #362
bsmartradio merged 1 commit into
mainfrom
tickets/DM-54275

Conversation

@bsmartradio

Copy link
Copy Markdown
Contributor

No description provided.

@bsmartradio bsmartradio requested a review from mrawls May 27, 2026 18:26

@mrawls mrawls left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm convinced this does what you want, but it's necessary to get pretty deep in the weeds to figure out what it is doing. My main suggestion is to please add a detailed class docstring that explains all the various ways diaSources are filtered and what the resulting flag situation looks like in each case.

rejected_mask |= trail_mask
diaSourceCat = diaSourceCat[~rejected_mask].copy(deep=True)

self.log.info("%i DiaSources exceed max_trail_length %f arcseconds per second, "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest breaking this into 2 log messages that only print when num_X_filtered > 0.
In addition,

    Suggested change
  


  
      
        
                    self.log.info("%i DiaSources exceed max_trail_length %f arcseconds per second, "
      
      
        
                    self.log.info("%i DiaSources exceed max_trail_length (%f arcseconds per second), "

self.log.info("%i DiaSources exceed max_trail_length %f arcseconds per second, "
"dropping from source catalog. %i DiaSources had no"
"trail calculation and their bounding box exceeded"
"%f arcseconds in either direction or across the diagonal,"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"%f arcseconds in either direction or across the diagonal,"
"max_trail_length (%f arcseconds per second) in either direction or across the diagonal,"

"""Check bounding boxes of DiaSources with failed trail measurements.

For sources where the trail measurement flag is set (indicating the
trail length is unreliable), fall back to checking the footprint

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unreliable or unable to be measured, or both?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to type unavailable, but I think swapping it to unable to be measured is the most clear.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes more sense - yes, I like "unable to be measured" best. I don't think you've implemented that change yet.

Returns
-------
bbox_mask : `numpy.ndarray`
Boolean mask for diaSources whose bounding box width, height,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Boolean mask for diaSources whose bounding box width, height,
Boolean mask for diaSources whose footprint bounding box width, height,

Comment thread python/lsst/ap/association/filterDiaSourceCatalog.py
Comment thread tests/test_filterDiaSourceCatalog.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this Task is getting a bit complicated, it's definitely time to please add a full class docstring. See https://developer.lsst.io/python/numpydoc.html#documenting-classes

Comment thread tests/test_filterDiaSourceCatalog.py Outdated
Comment on lines +388 to +389
"""Test sources with ext_trailedSources_Naive_flag set but a small bounding
box should are not flagged.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Test sources with ext_trailedSources_Naive_flag set but a small bounding
box should are not flagged.
"""Test that sources with ext_trailedSources_Naive_flag set but with a small bounding
box are not flagged.

# threshold for max_trail_length * exposure_time / pixelScale
self.assertFalse(bbox_mask[0])

def test_check_dia_source_trail_bbox_flag_large_bbox(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ever possible to have ext_trailedSources_Naive_flag not set and to have a bbox measured? (asking as a possible other unit test to run)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added one more unit check that checks that sources with no flag but large bboxes do not get filtered


if self.config.doTrailedSourceFilter:
trail_mask = self._check_dia_source_trail(diaSourceCat, exposure_time)
bbox_mask = self._check_dia_source_trail_bbox(diaSourceCat, exposure_time)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to only run this if the initial trail measurement fails? It looks like you calculate it every time, but perhaps there's a reason for that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do, but only in the function. Doing that here would maybe be a bit messy because I'm sending the whole source catalog. Instead I've done an initial filter inside the function so that it doesn't bother checking each source individually. I probably should have done it that way to begin with for speed.

@bsmartradio bsmartradio force-pushed the tickets/DM-54275 branch 2 times, most recently from 31cb6c2 to 496f312 Compare June 17, 2026 14:28
"""Filter sources from the supplied DiaSource catalog.

Sources are filtered based on their trail length, sky sources, and bad
flags. Aby source which meets the filtering criteria is removed from

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo (Aby --> Any) and also some odd indentation happening here.

Suggested rephrase: "DiaSources are filtered based on criteria including trail length, whether they are a sky source, and whether they have one or more bad flags. Any source which meets a filtering criteria is removed from the main output catalog and optionally saved in one or more separate output catalogs."

@mrawls

mrawls commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

It looks like you've resolved most of the review comments, thank you. There are a couple final minor items. Please address those, rebase your commits, run pep8/black if you haven't (a few funky formatting things seem to exist and it doesn't appear auto-enforced on this repo 😬), and summarize what you did on the Jira ticket.

@bsmartradio bsmartradio merged commit a403a70 into main Jun 25, 2026
4 checks passed
@bsmartradio bsmartradio deleted the tickets/DM-54275 branch June 25, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants