c3-time-domain / SeeChange

A time-domain data reduction pipeline (e.g., for handling images->lightcurves) for surveys like DECam and LS4
BSD 3-Clause "New" or "Revised" License
0 stars 4 forks source link

Hybrid properties for things like MJD #219

Open guynir42 opened 3 months ago

guynir42 commented 3 months ago

There are some attributes of the image (like MJD) that can be queried on for other classes, but only using a join.
For example we can get all SourceList objects with a certain MJD using: session.scalars(sa.select(SourceList).join(Image).where(Image.mjd == some_mjd)).all()

But we cannot currently do something intuitive like this: session.scalars(sa.select(SourceList).where(SourceList.mjd == some_mjd)).all()

To do that we'd have to make a hybrid property that folds the additional tables into an expression using a scalar subquery.

This may be more complicated (and slow) than is worth actually fixing.

Some references: https://docs.sqlalchemy.org/en/20/orm/extensions/hybrid.html#join-dependent-relationship-hybrid

https://stackoverflow.com/questions/19979303/hybrid-property-with-join-in-sqlalchemy

https://stackoverflow.com/questions/57578366/how-to-make-sqlalchemy-hybrid-property-select-expressions-work-for-both-select-a

guynir42 commented 3 months ago

I'm leaving this for now. Will come back to it if I have time.