Skip to content

DM-50420: Inject variable sources into the template and science images#275

Open
BrunoSanchez wants to merge 2 commits into
mainfrom
tickets/DM-50420
Open

DM-50420: Inject variable sources into the template and science images#275
BrunoSanchez wants to merge 2 commits into
mainfrom
tickets/DM-50420

Conversation

@BrunoSanchez

Copy link
Copy Markdown
Member

Create the fake injection pipeline tools for injection on template images.

@BrunoSanchez BrunoSanchez changed the title tickets/DM-50420 DM-50420 May 28, 2026
@BrunoSanchez BrunoSanchez changed the title DM-50420 DM-50420: Inject variable sources into the template and science images Jun 1, 2026

@isullivan isullivan 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.

Looks good! A few comments for readability, and potential bugs.

Comment thread python/lsst/ap/pipe/createApFakes.py Outdated
Comment on lines +474 to +475
seed = int(str(visitId)+str(detId))
rng = np.random.default_rng(seed)

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
seed = int(str(visitId)+str(detId))
rng = np.random.default_rng(seed)
rng = np.random.default_rng([visitId, detId])

I am very wary of relying on string concatenation for creating the seed.


def __init__(self, **kwargs):
super().__init__(**kwargs)
self.log = logging.getLogger(__name__)

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.

Not needed, this over-writes the inherited logger.

Comment thread python/lsst/ap/pipe/createApFakes.py Outdated
randMags["mag"] = mags
return randMags

def createRandomMagnitudes(self, nFakes, rng):

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.

It looks like the only use of createRandomMagnitudes was deleted earlier. Should this method be removed?

catalog = vstack([catalog, variable_fakes])

if len(catalog) > len(np.unique(catalog["injection_id"])):
self.log.warning("Duplicate injection IDs detected after catalog assembly; reassigning them.")

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.

This might be worth raising an error if there are duplicates, instead of warning and reassigning.

Catalog of sources detected on the calibrated exposure.
visit_image : `lsst.afw.image.Exposure`
Visit image to inject synthetic sources into.
summaryMetrics : `lsst.metrics.MetricMeasurementBundle`

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.

summaryMetrics is not a parameter. Delete?

Comment thread python/lsst/ap/pipe/createApFakes.py Outdated
Comment on lines +410 to +411
min=16,
max=24,

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 could imagine someone wanting to inject fakes outside of these magnitude ranges. Probably drop the RangeField and min/max

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But we should not allow people to inject values that are none sense right? I think people will want to have a range of magnitudes. I don't know if it is wise to drop the field completely. Maybe increase the range?

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 suppose, but there isn't a physical hard limit that makes sense. If we set limits here, then it is not possible for someone using our pipelines to process data from a different observatory to overwrite the magnitude ranges in the config to anything brighter or fainter.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

What I don't want to is to leave this as non-configurable. How do we do that? Set instead of a RangeField a free value parameter field? Not sure if that's your suggestion here.

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 was just thinking of making it a standard Field, since it has a reasonable default value.

min=16,
max=24,
)
magMax = pexConfig.RangeField(

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.

As above, probably drop the RangeField

Comment thread python/lsst/ap/pipe/createApFakes.py Outdated
ymin, ymax = bbox.getMinY(), bbox.getMaxY()
visit_stats = visit_image.getInfo().getSummaryStats()

# corners = visit_image.getBBox().getCorners()

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.

Delete commented-out code?

size=n_variable_fakes
)
variable_fakes["mag"] += variable_fakes["mag_offset"]
variable_fakes["isVisitSource"] = ~variable_fakes["isVisitSource"]

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.

Worth a code comment explaining the flag negations here.

Comment thread python/lsst/ap/pipe/createApFakes.py Outdated

return Struct(outputCat=catalog)

def select_hosts(self, sourceCat, *args, **kwargs):

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.

Why include *args and **kwargs if they're not used?

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