sl-shared-assets 1.0.0rc15__tar.gz → 1.0.0rc16__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of sl-shared-assets might be problematic. Click here for more details.

Files changed (51) hide show
  1. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/PKG-INFO +1 -1
  2. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/pyproject.toml +1 -1
  3. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/data_classes/session_data.py +13 -9
  4. sl_shared_assets-1.0.0rc16/src/sl_shared_assets/suite2p/multi_day.py +225 -0
  5. sl_shared_assets-1.0.0rc16/src/sl_shared_assets/suite2p/single_day.py +563 -0
  6. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/__init__.pyi +0 -71
  7. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/cli.pyi +0 -28
  8. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/data_classes/__init__.pyi +0 -61
  9. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/data_classes/configuration_data.pyi +0 -37
  10. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/data_classes/runtime_data.pyi +0 -145
  11. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/data_classes/session_data.pyi +0 -527
  12. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/data_classes/surgery_data.pyi +0 -89
  13. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/server/__init__.pyi +0 -8
  14. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/server/job.pyi +0 -94
  15. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/server/server.pyi +0 -95
  16. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/suite2p/__init__.pyi +0 -4
  17. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/suite2p/multi_day.py +0 -193
  18. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/suite2p/multi_day.pyi +0 -99
  19. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/suite2p/single_day.py +0 -479
  20. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/suite2p/single_day.pyi +0 -192
  21. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/tools/__init__.pyi +0 -5
  22. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/tools/ascension_tools.pyi +0 -68
  23. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/tools/packaging_tools.pyi +0 -52
  24. sl_shared_assets-1.0.0rc15/src/sl_shared_assets/tools/transfer_tools.pyi +0 -53
  25. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/.gitignore +0 -0
  26. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/LICENSE +0 -0
  27. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/README.md +0 -0
  28. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/docs/Makefile +0 -0
  29. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/docs/make.bat +0 -0
  30. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/docs/source/api.rst +0 -0
  31. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/docs/source/conf.py +0 -0
  32. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/docs/source/index.rst +0 -0
  33. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/docs/source/welcome.rst +0 -0
  34. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/envs/slsa_dev_lin.yml +0 -0
  35. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/envs/slsa_dev_lin_spec.txt +0 -0
  36. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/__init__.py +0 -0
  37. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/cli.py +0 -0
  38. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/data_classes/__init__.py +0 -0
  39. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/data_classes/configuration_data.py +0 -0
  40. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/data_classes/runtime_data.py +0 -0
  41. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/data_classes/surgery_data.py +0 -0
  42. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/py.typed +0 -0
  43. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/server/__init__.py +0 -0
  44. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/server/job.py +0 -0
  45. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/server/server.py +0 -0
  46. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/suite2p/__init__.py +0 -0
  47. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/tools/__init__.py +0 -0
  48. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/tools/ascension_tools.py +0 -0
  49. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/tools/packaging_tools.py +0 -0
  50. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/src/sl_shared_assets/tools/transfer_tools.py +0 -0
  51. {sl_shared_assets-1.0.0rc15 → sl_shared_assets-1.0.0rc16}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sl-shared-assets
3
- Version: 1.0.0rc15
3
+ Version: 1.0.0rc16
4
4
  Summary: Stores assets shared between multiple Sun (NeuroAI) lab data pipelines.
5
5
  Project-URL: Homepage, https://github.com/Sun-Lab-NBB/sl-shared-assets
6
6
  Project-URL: Documentation, https://sl-shared-assets-api-docs.netlify.app/
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
8
8
  # Project metdata section. Provides the genral ID information about the project.
9
9
  [project]
10
10
  name = "sl-shared-assets"
11
- version = "1.0.0rc15"
11
+ version = "1.0.0rc16"
12
12
  description = "Stores assets shared between multiple Sun (NeuroAI) lab data pipelines."
13
13
  readme = "README.md"
14
14
  license = { file = "LICENSE" }
@@ -528,13 +528,13 @@ class ConfigurationData:
528
528
  project_configuration_path: Path = Path()
529
529
  """Stores the path to the project_configuration.yaml file. This file contains the snapshot of the configuration
530
530
  parameters for the session's project."""
531
- suite2p_configuration_path: Path = Path()
532
- """Stores the path to the suite2p_configuration.yaml file stored inside the project's 'configuration' directory on
533
- the fast BioHPC server volume. This configuration file specifies the parameters for the 'single day' suite2p
534
- registration pipeline, which is applied to each session that generates brain activity data."""
535
- multiday_configuration_path: Path = Path()
536
- """Stores the path to the multiday_configuration.yaml file stored inside the project's 'configuration' directory
537
- on the fast BioHPC server volume. This configuration file specifies the parameters for the 'multiday'
531
+ single_day_s2p_configuration_path: Path = Path()
532
+ """Stores the path to the single_day_s2p_configuration.yaml file stored inside the project's 'configuration'
533
+ directory on the fast BioHPC server volume. This configuration file specifies the parameters for the 'single day'
534
+ suite2p registration pipeline, which is applied to each session that generates brain activity data."""
535
+ multi_day_s2p_configuration_path: Path = Path()
536
+ """Stores the path to the multi_day_s2p_configuration.yaml file stored inside the project's 'configuration'
537
+ directory on the fast BioHPC server volume. This configuration file specifies the parameters for the 'multiday'
538
538
  sl-suite2p-based registration pipelines used tot rack brain cells across multiple sessions."""
539
539
 
540
540
  def resolve_paths(self, root_directory_path: Path, experiment_name: str | None = None) -> None:
@@ -559,8 +559,8 @@ class ConfigurationData:
559
559
  else:
560
560
  self.experiment_configuration_path = self.configuration_path.joinpath(f"{experiment_name}.yaml")
561
561
  self.project_configuration_path = self.configuration_path.joinpath("project_configuration.yaml")
562
- self.suite2p_configuration_path = self.configuration_path.joinpath("suite2p_configuration.yaml")
563
- self.multiday_configuration_path = self.configuration_path.joinpath("multiday_configuration.yaml")
562
+ self.single_day_s2p_configuration_path = self.configuration_path.joinpath("single_day_s2p_configuration.yaml")
563
+ self.multi_day_s2p_configuration_path = self.configuration_path.joinpath("multi_day_s2p_configuration.yaml")
564
564
 
565
565
  def make_directories(self) -> None:
566
566
  """Ensures that all major subdirectories and the root directory exist."""
@@ -1162,6 +1162,7 @@ class SessionData(YamlConfig):
1162
1162
  # RAW DATA
1163
1163
  new_root = local_root.joinpath(instance.project_name, instance.animal_id, instance.session_name, "raw_data")
1164
1164
  instance.raw_data.resolve_paths(root_directory_path=new_root)
1165
+ instance.raw_data.make_directories()
1165
1166
 
1166
1167
  # Uses the adjusted raw_data section to load the ProjectConfiguration instance. This is used below to resolve
1167
1168
  # all other SessionData sections, as it stores various required root directories.
@@ -1178,10 +1179,12 @@ class SessionData(YamlConfig):
1178
1179
  root_directory_path=new_root,
1179
1180
  experiment_name=instance.experiment_name,
1180
1181
  )
1182
+ instance.configuration_data.make_directories()
1181
1183
 
1182
1184
  # DEEPLABCUT
1183
1185
  new_root = local_root.joinpath(instance.project_name, "deeplabcut")
1184
1186
  instance.deeplabcut_data.resolve_paths(root_directory_path=new_root)
1187
+ instance.deeplabcut_data.make_directories()
1185
1188
 
1186
1189
  # Resolves the roots for all VRPC-specific sections that use the data from the ProjectConfiguration instance:
1187
1190
 
@@ -1239,6 +1242,7 @@ class SessionData(YamlConfig):
1239
1242
  instance.project_name, instance.animal_id, instance.session_name, "processed_data"
1240
1243
  )
1241
1244
  )
1245
+ instance.processed_data.make_directories()
1242
1246
 
1243
1247
  # Ensures that project configuration and session data classes are present in both raw_data and processed_data
1244
1248
  # directories. This ensures that all data of the session can always be traced to the parent project, animal,
@@ -0,0 +1,225 @@
1
+ """This module stores the classes used to configure the multi-day (across-session) sl-suite2p pipeline. This pipeline
2
+ extends the original suite2p code to support tracking the same objects (cells) across multiple days. Both single-day
3
+ (original) and multi-day (extended) pipelines are available as part of the Sun lab maintained sl-suite2p package."""
4
+
5
+ from typing import Any
6
+ from dataclasses import field, asdict, dataclass
7
+ from pathlib import Path
8
+ import numpy as np
9
+ from ataraxis_base_utilities import ensure_directory_exists
10
+
11
+ from ataraxis_data_structures import YamlConfig
12
+
13
+
14
+ @dataclass()
15
+ class IO:
16
+ """Stores parameters that control data input and output during various stages of the pipeline."""
17
+
18
+ session_ids: list[str] = field(default_factory=list)
19
+ """Stores the list of session IDs to register across days. This field should have the same length and order as the
20
+ session_folders list. Primarily, session IDs are used in terminal printouts to identify processed sessions to human
21
+ operators."""
22
+
23
+ session_folders: list[str] = field(default_factory=list)
24
+ """Specifies the list of sessions to register across days, as absolute paths to their /suite2p directories
25
+ e.g: root/session/processed_data/mesoscope_data/suite2p. The suite2p directory is created as part of the
26
+ single-session suite2p processing, assuming the default value of the 'save_folder' SingleDayS2PConfiguration class
27
+ attribute was not modified. Note, each suite2p directory has to contain the 'combined' plane folder, which is
28
+ created if the 'combined' SingleDayS2PConfiguration attribute is 'True'."""
29
+
30
+
31
+ @dataclass()
32
+ class Hardware:
33
+ """Stores parameters that control how the suite2p interacts with the hardware of the host-computer to accelerate
34
+ processing speed."""
35
+
36
+ parallelize_registration: bool = True
37
+ """Determines whether to parallelize certain multi-day registration pipeline steps. Running these steps in parallel
38
+ results in faster overall processing, but increases the RAM usage. Since multi-day processing does not automatically
39
+ parallelize operations to all cores, it is generally safe and recommended to always enable this option."""
40
+
41
+ registration_workers: int = -1
42
+ """The number of parallel workers (cores) to use when parallelizing multi-day registration. Setting this to a
43
+ negative value uses all available cores. Setting this to zero or one disables parallelization."""
44
+
45
+ parallelize_extraction: bool = False
46
+ """Determines whether to extract multi-day cell fluorescence from multiple sessions at the same time. Note,
47
+ fluorescence extraction already contains automatic parallelization and will use all available cores to a certain
48
+ extent. Extracting data for multiple sessions at the same time is still faster due to a more efficient core
49
+ utilization, but typically does not not scale well (peaks for 2-3 parallel sessions) and majorly increase the RAM
50
+ usage.
51
+ """
52
+
53
+ parallel_sessions: int = 3
54
+ """The number of sessions to process in-parallel when extracting multi-day fluorescence data. Since this
55
+ parallelization works on top of existing suite2p numba-parallelization, it will use all available cores regardless
56
+ of the number of parallelized sessions. Instead, this parameter can be tuned to control the total RAM usage and
57
+ the extent of overall core utilization. Setting this to a value at or below one will disable session
58
+ parallelization."""
59
+
60
+
61
+ @dataclass()
62
+ class CellDetection:
63
+ """Stores parameters for selecting single-day-registered cells (ROIs) to be tracked across multiple sessions (days).
64
+ """
65
+
66
+ probability_threshold: float = 0.85
67
+ """The minimum required probability score assigned to the cell (ROI) by the single-day suite2p classifier. Cells
68
+ with a lower classifier score are excluded from multi-day processing."""
69
+
70
+ maximum_size: int = 1000
71
+ """The maximum allowed cell (ROI) size, in pixels. Cells with a larger pixel size are excluded from processing."""
72
+
73
+ mesoscope_stripe_borders: list[int] = field(default_factory=list)
74
+ """Stores the x-coordinates of combined mesoscope image stripe (ROI) borders. For mesoscope images, 'stripes' are
75
+ the individual imaging ROIs acquired in the 'multiple-ROI' mode. Keep this field set to an empty list to skip
76
+ stripe border-filtering or when working with non-mesoscope images.
77
+ """
78
+
79
+ stripe_margin: int = 30
80
+ """The minimum required distance, in pixels, between the center-point (the median x-coordinate) of the cell (ROI)
81
+ and the mesoscope stripe border. Cells that are too close to stripe borders are excluded from processing to avoid
82
+ ambiguities associated with tracking cells that span multiple stripes. This parameter is only used if
83
+ 'mesoscope_stripe_borders' field is not set to an empty list."""
84
+
85
+
86
+ @dataclass()
87
+ class Registration:
88
+ """Stores parameters for aligning (registering) the sessions from multiple days to the same visual (sampling) space.
89
+ """
90
+
91
+ image_type: str = "enhanced"
92
+ """The type of suite2p-generated reference image to use for across-day registration. Supported options are
93
+ 'enhanced', 'mean' and 'max'. This 'template' image is used to calculate the necessary deformation (transformations)
94
+ to register (align) all sessions to the same visual space."""
95
+
96
+ grid_sampling_factor: float = 1
97
+ """Determines to what extent the grid sampling scales with the deformed image scale. Has to be between 0 and 1. By
98
+ making this value lower than 1, the grid is relatively fine at the the higher scales, allowing for more
99
+ deformations. This is used when resizing session images as part of the registration process."""
100
+
101
+ scale_sampling: int = 30
102
+ """The number of iterations for each level (i.e. between each factor two in scale) to perform when computing the
103
+ deformations. Values between 20 and 30 are reasonable in most situations, but higher values yield better results in
104
+ general. The speed of the algorithm scales linearly with this value."""
105
+
106
+ speed_factor: float = 3
107
+ """The relative force of the deformation transform applied when registering the sessions to the same visual space.
108
+ This is the most important parameter to tune. For most cases, a value between 1 and 5 is reasonable."""
109
+
110
+
111
+ @dataclass()
112
+ class Clustering:
113
+ """Stores parameters for tracking (clustering) cell (ROI) masks across multiple registered sessions (days)."""
114
+
115
+ criterion: str = "distance"
116
+ """Specifies the criterion for clustering (grouping) cell (ROI) masks from different sessions. Currently, the only
117
+ valid option is 'distance'."""
118
+
119
+ threshold: float = 0.75
120
+ """Specifies the threshold for the clustering algorithm. Cell masks will be clustered (grouped) together if their
121
+ clustering criterion is below this threshold value."""
122
+
123
+ mask_prevalence: int = 50
124
+ """Specifies the minimum percentage of all registered sessions that must include the clustered cell mask. Cell masks
125
+ present in fewer percent of sessions than this value are excluded from processing. This parameter is used to filter
126
+ out cells that are mostly silent or not distinguishable across sessions."""
127
+
128
+ pixel_prevalence: int = 50
129
+ """Specifies the minimum percentage of all registered sessions in which a cell mask pixel must be present for it to
130
+ be used to construct the template mask. Pixels present in fewer percent of sessions than this value are not used to
131
+ define the template masks. Template masks are used to extract the cell fluorescence from the original (non-deformed)
132
+ visual space of every session. This parameter is used to isolate the part of the cell that is stable across
133
+ sessions, which is required for the extraction step to work correctly (target only the tracked cell)."""
134
+
135
+ step_sizes: list[int] = field(default_factory=lambda: [200, 200])
136
+ """Specifies the block size for the cell clustering (across-session tracking) process, in pixels, in the order of
137
+ (height, width). To reduce the memory (RAM) overhead, the algorithm divides the deformed (shared) visual space into
138
+ blocks and then processes one (or more) blocks at a time."""
139
+
140
+ bin_size: int = 50
141
+ """Specifies the size of bins used to discover cell masks within blocks during clustering. To avoid edge cases, the
142
+ algorithm clusters the cell masks within the region defined by the center-point of each cell +- bin_size. This works
143
+ on top of pre-sorting cells into spatial blocks defined by 'step_sizes'."""
144
+
145
+ maximum_distance: int = 20
146
+ """Specifies the maximum distance, in pixels, that can separate masks across multiple sessions. The clustering
147
+ algorithm will consider cell masks located at most within this distance from each-other across days as the same
148
+ cells during tacking."""
149
+
150
+ minimum_size: int = 25
151
+ """The minimum size of the non-overlapping cell (ROI) region, in pixels, that has to be covered by the template
152
+ mask, for the cell to be assigned to that template. This is used to determine which template(s) the cell belongs to
153
+ (if any), for the purpose of tracking it across sessions."""
154
+
155
+
156
+ @dataclass()
157
+ class MultiDayS2PConfiguration(YamlConfig):
158
+ """Aggregates all parameters for the multi-day suite2p pipeline used to track cells across multiple days
159
+ (sessions) and extract their activity.
160
+
161
+ These settings are used to configure the multi-day suite2p extraction pipeline, which is based on the reference
162
+ implementation here: https://github.com/sprustonlab/multiday-suite2p-public. This class behaves similar to the
163
+ SingleDayS2PConfiguration class. It can be saved and loaded from a .YAML file and translated to dictionary or
164
+ ops.npy format, expected by the multi-day sl-suite2p pipeline.
165
+ """
166
+
167
+ io: IO = field(default_factory=IO)
168
+ """Stores parameters that control data input and output during various stages of the pipeline."""
169
+ hardware: Hardware = field(default_factory=Hardware)
170
+ """Stores parameters that control how the suite2p interacts with the hardware of the host-computer to accelerate
171
+ processing speed."""
172
+ cell_detection: CellDetection = field(default_factory=CellDetection)
173
+ """Stores parameters for selecting single-day-registered cells (ROIs) to be tracked across multiple sessions (days).
174
+ """
175
+ registration: Registration = field(default_factory=Registration)
176
+ """Stores parameters for aligning (registering) the sessions from multiple days to the same visual (sampling) space.
177
+ """
178
+ clustering: Clustering = field(default_factory=Clustering)
179
+ """Stores parameters for tracking (clustering) cell (ROI) masks across multiple registered sessions (days)."""
180
+
181
+ def to_npy(self, output_directory: Path) -> None:
182
+ """Saves the managed configuration data as an 'ops.npy' file under the target directory.
183
+
184
+ This method is mostly called by internal sl-suite2p functions to translate the user-specified configuration
185
+ file into the format used by suite2p pipelines.
186
+
187
+ Notes:
188
+ If the target output directory does not exist when this method is called, it will be created.
189
+
190
+ Args:
191
+ output_directory: The path to the directory where the 'ops.npy' file should be saved.
192
+ """
193
+ ensure_directory_exists(output_directory) # Creates the directory, if necessary
194
+ file_path = output_directory.joinpath("ops.npy") # Computes the output path
195
+ np.save(file_path, self.to_ops(), allow_pickle=True) # Dumps the configuration data to 'ops.npy' file.
196
+
197
+ def to_config(self, output_directory: Path) -> None:
198
+ """Saves the managed configuration data as a 'multi_day_s2p_configuration.yaml' file under the target
199
+ directory.
200
+
201
+ This method is typically used to dump the 'default' configuration parameters to disk as a user-editable
202
+ .yaml file. The user is then expected to modify these parameters as needed, before the class data is loaded and
203
+ used by the suite2p pipeline.
204
+
205
+ Notes:
206
+ If the target output directory does not exist when this method is called, it will be created.
207
+
208
+ Args:
209
+ output_directory: The path to the directory where the 'multi_day_s2p_configuration.yaml' file should be
210
+ saved.
211
+ """
212
+ ensure_directory_exists(output_directory) # Creates the directory, if necessary
213
+ file_path = output_directory.joinpath("multi_day_s2p_configuration.yaml") # Computes the output path
214
+
215
+ # Note, this uses the same configuration name as the SessionData class, making it automatically compatible with
216
+ # Sun lab data structure.
217
+ self.to_yaml(file_path=file_path) # Dumps the data to a 'yaml' file.
218
+
219
+ def to_ops(self) -> dict[str, Any]:
220
+ """Converts the class instance to a dictionary and returns it to caller.
221
+
222
+ This method is mostly called by internal sl-suite2p functions to translate the default configuration parameters
223
+ to the dictionary format used by suite2p pipelines.
224
+ """
225
+ return asdict(self)