Mapcat integration for make_atomic_filterbin_map and make_coadd_atomic_map#1534
Mapcat integration for make_atomic_filterbin_map and make_coadd_atomic_map#1534davidvng wants to merge 25 commits into
Conversation
|
Not sure why the tests are failing due to the missing dependency. |
|
@iparask using |
| with settings.session() as session: | ||
| data = AtomicMapCoaddTable( | ||
| coadd_name=map_name, | ||
| prefix_path=prefix_path, | ||
| platform=platform, | ||
| interval=interval, | ||
| start_time=start_time, | ||
| stop_time=stop_time, | ||
| freq_channel=band, | ||
| geom_file_path=self.geom_file_path, | ||
| split_label=split_label, | ||
| atomic_maps=self.maps if self.coadd_atomic else [], | ||
| parent_coadds=self.maps if not self.coadd_atomic else [] | ||
| ) | ||
|
|
||
| session.add(data) | ||
| session.commit() |
There was a problem hiding this comment.
I would place this in a function similar to the depth 1 map in the PR I referenced
| with settings.session() as session: | ||
| if '+' in band: | ||
| statement = select(AtomicMapTable).where((AtomicMapTable.telescope == platform) & (AtomicMapTable.split_label == split_label) & (AtomicMapTable.ctime >= start_time) & (AtomicMapTable.ctime <= stop_time)) | ||
| else: | ||
| statement = select(AtomicMapTable).where((AtomicMapTable.telescope == platform) & (AtomicMapTable.freq_channel == band) & (AtomicMapTable.split_label == split_label) & (AtomicMapTable.ctime >= start_time) & (AtomicMapTable.ctime <= stop_time)) | ||
| maps = session.execute(statement).scalars().all() | ||
| map_ids = [m.atomic_map_id for m in maps] |
| with settings.session() as session: | ||
| statement = select(AtomicMapCoaddTable).where((AtomicMapCoaddTable.interval == interval) & (AtomicMapCoaddTable.platform == platform) & (AtomicMapCoaddTable.freq_channel == band) & (AtomicMapCoaddTable.split_label == split_label) & (AtomicMapCoaddTable.start_time == start_time) & (AtomicMapCoaddTable.stop_time == stop_time)).order_by(AtomicMapCoaddTable.coadd_id.desc()) | ||
| coadd = session.execute(statement).scalars().first() | ||
| if coadd is not None: | ||
| atomic_parent_ids = [a.atomic_map_id for a in coadd.atomic_maps] | ||
| coadd_parent_ids = [c.coadd_id for c in coadd.parent_coadds] | ||
|
|
||
| if (map_ids == atomic_parent_ids) or (map_ids == coadd_parent_ids): | ||
| return False | ||
|
|
There was a problem hiding this comment.
This can also be a function under mapcat.py
@JBorrow The tests are still failing and I'm assuming it has to do with mapcat being in the optional dependencies? Thoughts on moving it to the core list of dependencies? |
I am not sure that is the solution. #759 passes with mapcat as an optional dependency. It might be some other reason. There is similar discussion on slack. |
|
0.1.1 includes 'support' for 3.10. |
| with Settings(**mapcat_settings).session() as session: | ||
| data = AtomicMapCoaddTable( | ||
| coadd_name=map_name, | ||
| prefix_path=prefix_path, | ||
| platform=platform, | ||
| interval=interval, | ||
| start_time=start_time, | ||
| stop_time=stop_time, | ||
| freq_channel=band, | ||
| geom_file_path=self.geom_file_path, | ||
| split_label=split_label, | ||
| atomic_maps=self.maps if self.coadd_atomic else [], | ||
| parent_coadds=self.maps if not self.coadd_atomic else [] | ||
| ) | ||
|
|
||
| session.add(data) | ||
| session.commit() |
There was a problem hiding this comment.
This should be outside of the mapmaking module. Think what will happen if we decide to change mapcat with something else. We will have to change the code here as well.
Please move any database interactions in the site_pipeline scripts, and create a file for these interactions under the utils of site_pipeline to keep them.
There was a problem hiding this comment.
This line is left there from the direct integration with sqlite.
There was a problem hiding this comment.
It seems that this is not used anymore. I think you can remove it.
* fix: mapcat integration with atomic maps * fix: no need to return everything
| mapcat_database_name: str = os.environ.get('MAPCAT_DATABASE_NAME', ''), | ||
| mapcat_database_type: str = os.environ.get('MAPCAT_DATABASE_TYPE', ''), | ||
| mapcat_atomic_parent: str = os.environ.get('MAPCAT_ATOMIC_PARENT', ''), |
There was a problem hiding this comment.
You already have mapcat settings here so just use that, it reads the environment for you.
|
Other than the duplicated reading of environment variables (you should use Settings from mapcat as the variables may be specified in another manner) this looks good. |
| mapcat_settings = {"database_type": args.mapcat_database_type, | ||
| "database_name": args.mapcat_database_name, | ||
| "atomic_parent": args.mapcat_atomic_parent,} | ||
| mapcat_settings = {"database_type": Settings().database_type, |
There was a problem hiding this comment.
I don't understand this at all, why are we reading data out of the object into a dictionary with the same keys?
There was a problem hiding this comment.
The dictionary is later passed to here:
The other functions, the depth-1 ones for example, were written in this way too. I could change the atomic functions here to directly use Settings() but that would make them different from the depth-1 ones.
There was a problem hiding this comment.
mapcat_settings = Settings().model_dump(include=[
"database_type",
"database_name",
"atomic_parent"
])
Is a reasonable compromise :).
| if mapcat_database_name is None: | ||
| mapcat_database_name = Settings().database_name | ||
| if mapcat_database_type is None: | ||
| mapcat_database_type = Settings().database_type | ||
| if mapcat_atomic_parent is None: | ||
| mapcat_atomic_parent = Settings().atomic_parent | ||
| if mapcat_atomic_coadd_parent is None: | ||
| mapcat_atomic_coadd_parent = Settings().atomic_coadd_parent | ||
| self.mapcat_settings = Settings(database_name = mapcat_database_name, | ||
| database_type = mapcat_database_type, | ||
| atomic_parent = mapcat_atomic_parent, | ||
| atomic_coadd_parent = mapcat_atomic_coadd_parent) | ||
|
|
There was a problem hiding this comment.
| if mapcat_database_name is None: | |
| mapcat_database_name = Settings().database_name | |
| if mapcat_database_type is None: | |
| mapcat_database_type = Settings().database_type | |
| if mapcat_atomic_parent is None: | |
| mapcat_atomic_parent = Settings().atomic_parent | |
| if mapcat_atomic_coadd_parent is None: | |
| mapcat_atomic_coadd_parent = Settings().atomic_coadd_parent | |
| self.mapcat_settings = Settings(database_name = mapcat_database_name, | |
| database_type = mapcat_database_type, | |
| atomic_parent = mapcat_atomic_parent, | |
| atomic_coadd_parent = mapcat_atomic_coadd_parent) | |
| # Allow for CLI over-rides of environment variables | |
| self.mapcat_settings = Settings( | |
| **{ | |
| k: v for k, v in { | |
| "database_name": mapcat_database_name, | |
| "database_type": mapcat_database_type, | |
| "atomic_parent": mapcat_atomic_parent, | |
| "atomic_coadd_parent": mapcat_atomic_coadd_parent, | |
| }.items() if v is not None | |
| } | |
| ) | |
|
|
||
| if mapcat_database_name is None: | ||
| mapcat_database_name = Settings().database_name | ||
| if mapcat_database_type is None: | ||
| mapcat_database_type = Settings().database_type | ||
| if mapcat_atomic_parent is None: | ||
| mapcat_atomic_parent = Settings().atomic_parent | ||
| self.mapcat_settings = Settings(database_name = mapcat_database_name, | ||
| database_type = mapcat_database_type, | ||
| atomic_parent = mapcat_atomic_parent) |
There was a problem hiding this comment.
| if mapcat_database_name is None: | |
| mapcat_database_name = Settings().database_name | |
| if mapcat_database_type is None: | |
| mapcat_database_type = Settings().database_type | |
| if mapcat_atomic_parent is None: | |
| mapcat_atomic_parent = Settings().atomic_parent | |
| self.mapcat_settings = Settings(database_name = mapcat_database_name, | |
| database_type = mapcat_database_type, | |
| atomic_parent = mapcat_atomic_parent) | |
| # Allow for CLI over-rides of environment variables | |
| self.mapcat_settings = Settings( | |
| **{ | |
| k: v for k, v in { | |
| "database_name": mapcat_database_name, | |
| "database_type": mapcat_database_type, | |
| "atomic_parent": mapcat_atomic_parent, | |
| }.items() if v is not None | |
| } | |
| ) | |
|
@davidvng can you merge with master and the tests will pass. |
Modifies existing database querying and writing from original sqlite structure to using
mapcatfor bothmake_atomic_filterbin_mapandmake_coadd_atomic_mapRelated changes will be needed in the site-pipeline-configs, especially to set the following environment variables used by
mapcat:I've tested the coadd script and confirmed everything works as intended.
However, for the atomic mapmaking, I have not tested due to permissions issues. I'd appreciate @chervias or @JBorrow to double check the changes in
make_atomic_filterbin_map.pymake sense.