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#1534
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.
| with Settings(**mapcat_settings).session() as session: | ||
| statement = select(AtomicMapCoaddTable) | ||
| statement = statement.where(AtomicMapCoaddTable.interval == lower_interval) | ||
| statement = statement.where(AtomicMapCoaddTable.platform == platform) | ||
| statement = statement.where(AtomicMapCoaddTable.freq_channel == band) | ||
| statement = statement.where(AtomicMapCoaddTable.split_label == split_label) | ||
| statement = statement.where(AtomicMapCoaddTable.start_time >= start_time) | ||
| statement = statement.where(AtomicMapCoaddTable.stop_time <= stop_time) | ||
| maps = session.execute(statement).scalars().all() | ||
| map_ids = [m.coadd_id for m in maps] | ||
|
|
There was a problem hiding this comment.
As I said before this script needs to be database agnostic. You can get the map_ids before and pass them as an argument.
There was a problem hiding this comment.
Apologies, could you clarify what you mean by this? Do you mean to create map names based on the provided info to query and get the map_ids? I don't understand why this is needed when this has been tested and works.
As for the atomic maps, I understand you can use mapmaking.build_obslists to create the map names as you do in your depth1 script. However, in this case, the make_atomic_filterbin_map.py script, which runs separately, already does this and is the script that commits to the database. I don't understand the need to repeat that in this coadd script when the entries for atomic maps already exist.
| with Settings(**mapcat_settings).session() as session: | ||
| statement = select(AtomicMapTable) | ||
| statement = statement.where(AtomicMapTable.telescope == platform) | ||
| statement = statement.where(AtomicMapTable.split_label == split_label) | ||
| statement = statement.where(AtomicMapTable.ctime >= start_time) | ||
| statement = statement.where(AtomicMapTable.ctime <= stop_time) | ||
| if '+' not in band: | ||
| statement = statement.where(AtomicMapTable.freq_channel == band) | ||
| maps = session.execute(statement).scalars().all() | ||
| map_ids = [m.atomic_map_id for m in maps] |
There was a problem hiding this comment.
Yeah I'm not sure what this means either, can you clarify how this is not datbaase agnostic?
There was a problem hiding this comment.
The mapmaker itself knows about the database, right? It is not so much the type of database as it is the fact that it needs access to one. I do understand with the site_pipeline script needs to have access to the database, but not the mapmaker itself.
I would expect the mapmaker to take the information it needs to create the coadd, how they arrived or selected is the responsibility of the script that calls the mapmaker.
| with Settings(**mapcat_settings).session() as session: | ||
| statement = select(AtomicMapCoaddTable) | ||
| statement = statement.where(AtomicMapCoaddTable.interval == interval) | ||
| statement = statement.where(AtomicMapCoaddTable.platform == platform) | ||
| statement = statement.where(AtomicMapCoaddTable.freq_channel == band) | ||
| statement = statement.where(AtomicMapCoaddTable.split_label == split_label) | ||
| statement = statement.where(AtomicMapCoaddTable.start_time == start_time) | ||
| statement = statement.where(AtomicMapCoaddTable.stop_time == stop_time) | ||
| statement = statement.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] | ||
|
|
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. |
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.