Skip to content

Getting TODs from Depth 1 maps #7

@iparask

Description

@iparask

As we discussed in the last TRP dev call. I tried to get the TODs of an existing depth 1 map. I see two different behaviors. The first is when the map select is together with the tods line:

In [1]: from mapcat.helper import settings
   ...: from mapcat.database import DepthOneMapTable, TODDepthOneTable
   ...: map_name = "17569/depth1_1756951955_i1_f090"
   ...: with settings.session() as session:
   ...:     existing_map = session.query(DepthOneMapTable).filter_by(map_name=map_name).first()
   ...:     map_tods = existing_map.tods
   ...:

In [2]: map_tods
Out[2]:
[TODDepthOneTable(ctime=1756951955.5577126, frequency='f090', el_throw=0.0009, start_time=1756951955.5577126, scan_type='obs', roll_center=60.0, stop_time=1756954380.7577126, subtype='cmb', roll_throw=0.0015, nsamples=485041, wafer_count=3, wafer_slots_list='ws0,ws1,ws2', telescope='lat', duration=2425.2000000476837, stream_ids_list='ufm_mv21,ufm_mv24,ufm_mv28', obs_id='obs_1756951929_lati1_111', telescope_flavor='lat', az_center=250.8445, tod_id=5, tube_slot='i1', az_throw=12.0033, pwv=None, tube_flavor='mf', el_center=140.0002),
 TODDepthOneTable(ctime=1756954562.2477126, frequency='f090', el_throw=0.001, start_time=1756954562.2477126, scan_type='obs', roll_center=60.0003, stop_time=1756957110.4527125, subtype='cmb', roll_throw=0.0016, nsamples=509642, wafer_count=3, wafer_slots_list='ws0,ws1,ws2', telescope='lat', duration=2548.204999923706, stream_ids_list='ufm_mv21,ufm_mv24,ufm_mv28', obs_id='obs_1756954534_lati1_111', telescope_flavor='lat', az_center=250.8447, tod_id=6, tube_slot='i1', az_throw=12.0028, pwv=None, tube_flavor='mf', el_center=140.0002),
 TODDepthOneTable(ctime=1756957278.9727125, frequency='f090', el_throw=0.0009, start_time=1756957278.9727125, scan_type='obs', roll_center=60.0002, stop_time=1756959840.1677125, subtype='cmb', roll_throw=0.0015, nsamples=512240, wafer_count=3, wafer_slots_list='ws0,ws1,ws2', telescope='lat', duration=2561.194999933243, stream_ids_list='ufm_mv21,ufm_mv24,ufm_mv28', obs_id='obs_1756957257_lati1_111', telescope_flavor='lat', az_center=250.8445, tod_id=7, tube_slot='i1', az_throw=12.0027, pwv=None, tube_flavor='mf', el_center=140.0002),
 TODDepthOneTable(ctime=1756960007.7327125, frequency='f090', el_throw=0.0009, start_time=1756960007.7327125, scan_type='obs', roll_center=60.0003, stop_time=1756963440.7577126, subtype='cmb', roll_throw=0.0015, nsamples=686606, wafer_count=3, wafer_slots_list='ws0,ws1,ws2', telescope='lat', duration=3433.0250000953674, stream_ids_list='ufm_mv21,ufm_mv24,ufm_mv28', obs_id='obs_1756959981_lati1_111', telescope_flavor='lat', az_center=250.8447, tod_id=8, tube_slot='i1', az_throw=12.0025, pwv=None, tube_flavor='mf', el_center=140.0001)]

whereas:

In [1]: from mapcat.helper import settings
   ...: from mapcat.database import DepthOneMapTable, TODDepthOneTable
   ...: map_name = "17569/depth1_1756951955_i1_f090"
   ...: with settings.session() as session:
   ...:     existing_map = session.query(DepthOneMapTable).filter_by(map_name=map_name).first()
   ...: with settings.session() as session:
   ...:     map_tods = existing_map.tods
   ...:
---------------------------------------------------------------------------
DetachedInstanceError                     Traceback (most recent call last)
Cell In[1], line 7
      5     existing_map = session.query(DepthOneMapTable).filter_by(map_name=map_name).first()
      6 with settings.session() as session:
----> 7     map_tods = existing_map.tods

File /scratch/gpfs/SIMONSOBS/env/dev/soconda_dev/lib/python3.12/site-packages/sqlalchemy/orm/attributes.py:569, in InstrumentedAttribute.__get__(self, instance, owner)
    567 except AttributeError as err:
    568     raise orm_exc.UnmappedInstanceError(instance) from err
--> 569 return self.impl.get(state, dict_)

File /scratch/gpfs/SIMONSOBS/env/dev/soconda_dev/lib/python3.12/site-packages/sqlalchemy/orm/attributes.py:1096, in AttributeImpl.get(self, state, dict_, passive)
   1093 if not passive & CALLABLES_OK:
   1094     return PASSIVE_NO_RESULT
-> 1096 value = self._fire_loader_callables(state, key, passive)
   1098 if value is PASSIVE_NO_RESULT or value is NO_VALUE:
   1099     return value

File /scratch/gpfs/SIMONSOBS/env/dev/soconda_dev/lib/python3.12/site-packages/sqlalchemy/orm/attributes.py:1131, in AttributeImpl._fire_loader_callables(self, state, key, passive)
   1129     return callable_(state, passive)
   1130 elif self.callable_:
-> 1131     return self.callable_(state, passive)
   1132 else:
   1133     return ATTR_EMPTY

File /scratch/gpfs/SIMONSOBS/env/dev/soconda_dev/lib/python3.12/site-packages/sqlalchemy/orm/strategies.py:922, in LazyLoader._load_for_state(self, state, passive, loadopt, extra_criteria, extra_options, alternate_effective_path, execution_options)
    919     if passive & PassiveFlag.NO_RAISE:
    920         return LoaderCallableStatus.PASSIVE_NO_RESULT
--> 922     raise orm_exc.DetachedInstanceError(
    923         "Parent instance %s is not bound to a Session; "
    924         "lazy load operation of attribute '%s' cannot proceed"
    925         % (orm_util.state_str(state), self.key)
    926     )
    928 # if we have a simple primary key load, check the
    929 # identity map without generating a Query at all
    930 if use_get:

DetachedInstanceError: Parent instance <DepthOneMapTable at 0x14cad8fb4e10> is not bound to a Session; lazy load operation of attribute 'tods' cannot proceed (Background on this error at: https://sqlalche.me/e/20/bhk3)

I think it should be the same behavior. If you want it to be lazy under the session, can we have a way to get all the information from the DB?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions