AllenInstitute / npc_lims

Tools to fetch and update paths, metadata and state for Mindscope Neuropixels sessions, in the cloud.
https://alleninstitute.github.io/npc_lims/
MIT License
0 stars 0 forks source link

Fix `SessionInfo.id[:]` returning a path #12

Closed bjhardcastle closed 8 months ago

bjhardcastle commented 10 months ago
>>> npc_lims.get_session_info()[0].id[:]        # should be '626791_2022-08-15'
'//allen/programs/mindscope/workgroups/dynamicrouting/PilotEphys/Task 2 pilot/DRpilot_626791_20220815'
bjhardcastle commented 10 months ago

@samgale @arjunsridhar12345 This is fixed here: https://github.com/alleninstitute/npc_session/commit/3e9bec592e7e7fe2bce7f50dda62282fa827caa4

Try to avoid slicing SessionInfo.id and parsing it yourself though - we might change the format at some point. It's a SessionRecord instance and provides attributes for all the metadata components that can be extracted - use them instead:

>>> from npc_session import SessionRecord;

>>> s = SessionRecord('//allen/programs/mindscope/workgroups/templeton/TTOC/2022-07-26_14-09-36_366122')
>>> s
'366122_2022-07-26'
>>> s.idx
0
>>> s.subject
366122
>>> s.date
'2022-07-26'
>>> s.date.dt
datetime.date(2022, 7, 26)
>>> s.date.year
2022

>>> s_1 = SessionRecord('//allen/programs/mindscope/workgroups/templeton/TTOC/2022-07-26_14-09-36_366122_1')
>>> s_1.idx
1
>>> s_2 = s_1.with_idx(2)
>>> s_2.idx
2
bjhardcastle commented 10 months ago

To make it clearer, I can change this:

>>> SessionRecord('2022-07-26_14-09-36_366122')
'366122_2022-07-26'

back to this:

>>> SessionRecord('2022-07-26_14-09-36_366122')
SessionRecord('366122_2022-07-26')

printing would still access __str__:

>>> print(SessionRecord('2022-07-26_14-09-36_366122'))
'366122_2022-07-26'