spyglass
spyglass copied to clipboard
Class-specific implementation of _merge_restrict_parents
Is your feature request related to a problem? Please describe.
Selecting data from a merge table that is downstream of another merge table can be difficult. For example, LinearizedPositionV1
does not have nwb_file_name
or interval_list_name
as keys. This means that LinearizedPositionOutput.fetch_nwb()
with these restrictions will not be able to restrict the parent and will return the whole part table.
Instead, users must first look up the pos_merge_id
and then use that to restrict the call
Describe the solution you'd like
A class-specific version of _merge_restrict_parents for these tables that looks upstream of the earlier merge table for these restrictions. An example for LinearizedPositionOutput
is shown below:
from spyglass.position import PositionOutput
from spyglass.linearization import LinearizedPositionOutput
key = {'nwb_file_name' : "Yoshi20220509_.nwb"}
def _merge_restrict_parents_linearization(restriction: dict = {}):
restricted_parents = []
parent_table_list = LinearizedPositionOutput._merge_restrict_parents(restriction)
for parent_table in parent_table_list:
if 'pos_merge_id' in parent_table.heading.names:
parent_table_list_2 = PositionOutput._merge_restrict_parts(restriction)
for parent_table_2 in parent_table_list_2:
# proj merge id from Position table to pos_merge_id so restricts when joined
parent_table_2 = parent_table_2.proj(pos_merge_id='merge_id')
# proj analysis_file_name from Position table to pos_analysis_file_name to avoid conflict in column name
parent_table_2 = parent_table_2.proj(pos_analysis_file_name='analysis_file_name')
restricted_parents.append(parent_table * parent_table_2)
else:
restricted_parents.append(parent_table)
return restricted_parents
_merge_restrict_parents_linearization(key)
Alternative Solution
An edit to the parent class Merge._merge_restrict_parents()
that can check for upstream merge tables and do this. Not sure if this is viable though.