SimbioReader 0.7.0__tar.gz → 0.9.0__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.
@@ -1,5 +1,29 @@
1
- ![Version 0.7.0](https://img.shields.io/badge/version-0.7.0-blue?style=plastic)
2
- ![Language Python 3.13](https://img.shields.io/badge/python-3.13-orange?style=plastic&logo=python)
1
+ Metadata-Version: 2.3
2
+ Name: SimbioReader
3
+ Version: 0.9.0
4
+ Summary: Python Reader for the data from SIMBIO-SYS instrument suite on-board the ESA mission BepiColombo
5
+ Keywords: data reader,Space Mission,BepiColombo,SIMBIO-SYS
6
+ Author: Romolo Politi
7
+ Author-email: Romolo Politi <Romolo.Politi@inaf.it>
8
+ Classifier: Programming Language :: Python :: 3.11
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Programming Language :: Python :: 3.13
11
+ Classifier: Programming Language :: Python :: 3.14
12
+ Classifier: Development Status :: 4 - Beta
13
+ Requires-Dist: numpy>=2.3.3,<3.0.0
14
+ Requires-Dist: pandas>=3.0.1,<4.0.0
15
+ Requires-Dist: rich-click>=1.8.9,<2.0.0
16
+ Requires-Dist: update-checker>=0.18.0,<0.19.0
17
+ Requires-Dist: importlib-metadata>=8.7.0,<9.0.0
18
+ Requires-Dist: pillow>=12.0.0,<13.0.0
19
+ Requires-Dist: semantic-version-tools>=1.4.1,<2.0.0
20
+ Requires-Dist: mystrtools>=0.1.0,<0.2.0
21
+ Requires-Python: >=3.14, <4.0
22
+ Project-URL: Repository, https://github.com/SIMBIO-SYS/SimbioReader
23
+ Description-Content-Type: text/markdown
24
+
25
+ ![Version 0.9.0](https://img.shields.io/badge/version-0.9.0-blue?style=plastic)
26
+ ![Language Python 3.14](https://img.shields.io/badge/python-3.14-orange?style=plastic&logo=python)
3
27
  ![BepiColombo SIMBIO-SYS](https://img.shields.io/badge/BepiColombo-SIMBIO--SYS-blue?style=plastic)
4
28
  [![SimbioReader Test](https://github.com/SIMBIO-SYS/SimbioReader/actions/workflows/test.yml/badge.svg)](https://github.com/SIMBIO-SYS/SimbioReader/actions/workflows/test.yml)
5
29
  [![Documentation Status](https://readthedocs.org/projects/simbioreader/badge/?version=latest)](https://simbioreader.readthedocs.io/en/latest/?badge=latest)
@@ -19,22 +43,39 @@ To install the reader you can use the command:
19
43
  $ python3 -m pip install SimbioReader
20
44
  ```
21
45
 
22
- or using poetry
46
+ or using uv
23
47
 
24
48
  ```console
25
- $ poetry add SimbioReader
49
+ $ uv add SimbioReader
50
+ ```
51
+
52
+ ## Development
53
+
54
+ Install the project and its development dependencies with uv:
55
+
56
+ ```console
57
+ uv sync --locked --group test --group devel
58
+ uv run pytest
59
+ uv run ruff check src test
60
+ uv build
61
+ uv run --no-project --with-requirements docs/requirements.txt --with . python -m sphinx -b html docs/source docs/build/html
26
62
  ```
27
63
 
28
64
  ## Usage
29
65
 
30
- The package contain a class that read and decode the SIMBIO-SYS image
66
+ The package provides a class to read PDS4 labels and decode SIMBIO-SYS products. Python 3.14 or later is required.
31
67
 
32
68
  ```python
33
69
  from SimbioReader import SimbioReader as SR
34
70
 
35
- dat = SimbioReader("sim_raw_sc_vihi_internal_cruise_ico4_2020-12-14_001.dat")
71
+ dat = SR("sim_raw_sc_vihi_internal_cruise_ico4_2020-12-14_001.dat")
36
72
  ```
37
73
 
74
+ Filter display is guarded for product types that do not expose filter metadata,
75
+ so requesting filter output on those products no longer raises an attribute
76
+ error. See [`FLUSSO_DATI.md`](FLUSSO_DATI.md) for the reader's parsing and data
77
+ flow.
78
+
38
79
  ## Command line tools
39
80
 
40
81
  In the package are included two command line tools:
@@ -52,19 +93,22 @@ will show the main information about the product.
52
93
 
53
94
  Are avalaible some options:
54
95
 
96
+ - **--summarize**, **-s** displays product, target and filter summaries for products with filter metadata
97
+ - **--debug**, **-d** enables debug output
98
+ - **--verbose**, **-v** enables verbose output
55
99
  - **--all** will display all the avilable information
56
100
  - **--hk** wil display also the housekeeping
57
101
  - **--detector** will display all the detector information
58
102
  - **--data-structure** will display the data structure of the file
59
- - **--filter** will display the information about the used filter if the data come from HRIC or STC, otherwise the option will be ignored
103
+ - **--filters** will display the information about the used filter if the data come from HRIC or STC, otherwise the option will be ignored
60
104
 
61
105
  For any details you can use the option **--help**.
62
106
 
63
- Using the option **--version** will be shown the software version and the datamodel version implemented in it.
107
+ Use `simbioReader FILE --version` to display the software and data-model versions. The current CLI requires an existing `FILE` even with this option.
64
108
 
65
109
  ### simbioInfo
66
110
 
67
- ***simbioInfo*** tool is a command line interface (cli) wiith three subcommands:
111
+ ***simbioInfo*** tool is a command line interface (cli) with four subcommands:
68
112
 
69
113
  - **filters** Show the definition of filter(s) of a specific channel
70
114
  - **phases** Show the past mission phase(s);
@@ -73,10 +117,10 @@ Using the option **--version** will be shown the software version and the datamo
73
117
 
74
118
  #### filters
75
119
 
76
- The subcommand **filter** has an argument, the channel and an option ***--name***.
120
+ The subcommand **filters** has an argument, the channel and an option ***--name***.
77
121
 
78
122
  If the user provides only the channel, all the filters specific to that channel will be shown.
79
- If the user adds the -name option, only the selected filter will be displayed, if found.
123
+ If the user adds the --name option, only the selected filter will be displayed, if found.
80
124
 
81
125
  A description of argument and options coul be required using the option ***--help***
82
126
 
@@ -89,7 +133,7 @@ simbioInfo filters hric
89
133
  will show all the filters of the channel HRIC
90
134
 
91
135
  ```console
92
- simbioInfo flters hric -n pan-l
136
+ simbioInfo filters hric -n pan-l
93
137
  ```
94
138
 
95
139
  will show the *HRIC* filter with the name *PAN-L*
@@ -178,7 +222,7 @@ will show all the SIMBIO-SYS tests.
178
222
 
179
223
  ```console
180
224
  simbioInfo tests -d 2024-04-08\ 2:00:00
181
- ````
225
+ ```
182
226
 
183
227
  will show the test that SIMBIO-SYS was performing at 2:00:00 on 2024-04-08, the *Interference Test* in the subphase *ico11*
184
228
 
@@ -188,12 +232,26 @@ simbioInfo tests --name hric\ functional --subphase ico9
188
232
  will show the test with the name that contain the string *hric functional* performed during the subphase *ico9*
189
233
 
190
234
 
235
+ ## Mission database
236
+
237
+ Mission phases may contain multiple non-contiguous intervals. `simbioInfo phases --all`
238
+ lists intervals chronologically. The bundled database includes the `fimgs`
239
+ subphase (Mercury First Images) and the `first_images` test, both covering
240
+ 2026-10-18 from 07:00:00 to 21:00:00.
241
+
242
+ ```console
243
+ simbioInfo subphases --name fimgs
244
+ simbioInfo tests --subphase fimgs
245
+ ```
246
+
191
247
  ## Class Description
192
248
 
193
249
  ### Methods
194
250
 
195
- + **Show()** display the main information related to the data file
251
+ + **show()** display the main information related to the data file
196
252
 
197
253
  ```python
198
- dat.Show()
254
+ from rich import print
255
+
256
+ print(dat.show())
199
257
  ```
@@ -1,30 +1,5 @@
1
- Metadata-Version: 2.4
2
- Name: SimbioReader
3
- Version: 0.7.0
4
- Summary: Python Reader for the data from SIMBIO-SYS instrument suite on-board the ESA mission BepiColombo
5
- License-File: LICENSE
6
- Keywords: data reader,Space Mission,BepiColombo,SIMBIO-SYS
7
- Author: Romolo Politi
8
- Author-email: Romolo.Politi@inaf.it
9
- Requires-Python: >=3.14, <4.0
10
- Classifier: Programming Language :: Python :: 3.11
11
- Classifier: Programming Language :: Python :: 3.12
12
- Classifier: Programming Language :: Python :: 3.13
13
- Classifier: Programming Language :: Python :: 3.14
14
- Classifier: Development Status :: 4 - Beta
15
- Requires-Dist: importlib-metadata (>=8.7.0,<9.0.0)
16
- Requires-Dist: mystrtools (>=0.1.0,<0.2.0)
17
- Requires-Dist: numpy (>=2.3.3,<3.0.0)
18
- Requires-Dist: pandas (>=3.0.1,<4.0.0)
19
- Requires-Dist: pillow (>=12.0.0,<13.0.0)
20
- Requires-Dist: rich-click (>=1.8.9,<2.0.0)
21
- Requires-Dist: semantic-version-tools (>=1.4.1,<2.0.0)
22
- Requires-Dist: update-checker (>=0.18.0,<0.19.0)
23
- Project-URL: Repository, https://github.com/SIMBIO-SYS/SimbioReader
24
- Description-Content-Type: text/markdown
25
-
26
- ![Version 0.7.0](https://img.shields.io/badge/version-0.7.0-blue?style=plastic)
27
- ![Language Python 3.13](https://img.shields.io/badge/python-3.13-orange?style=plastic&logo=python)
1
+ ![Version 0.9.0](https://img.shields.io/badge/version-0.9.0-blue?style=plastic)
2
+ ![Language Python 3.14](https://img.shields.io/badge/python-3.14-orange?style=plastic&logo=python)
28
3
  ![BepiColombo SIMBIO-SYS](https://img.shields.io/badge/BepiColombo-SIMBIO--SYS-blue?style=plastic)
29
4
  [![SimbioReader Test](https://github.com/SIMBIO-SYS/SimbioReader/actions/workflows/test.yml/badge.svg)](https://github.com/SIMBIO-SYS/SimbioReader/actions/workflows/test.yml)
30
5
  [![Documentation Status](https://readthedocs.org/projects/simbioreader/badge/?version=latest)](https://simbioreader.readthedocs.io/en/latest/?badge=latest)
@@ -44,22 +19,39 @@ To install the reader you can use the command:
44
19
  $ python3 -m pip install SimbioReader
45
20
  ```
46
21
 
47
- or using poetry
22
+ or using uv
48
23
 
49
24
  ```console
50
- $ poetry add SimbioReader
25
+ $ uv add SimbioReader
26
+ ```
27
+
28
+ ## Development
29
+
30
+ Install the project and its development dependencies with uv:
31
+
32
+ ```console
33
+ uv sync --locked --group test --group devel
34
+ uv run pytest
35
+ uv run ruff check src test
36
+ uv build
37
+ uv run --no-project --with-requirements docs/requirements.txt --with . python -m sphinx -b html docs/source docs/build/html
51
38
  ```
52
39
 
53
40
  ## Usage
54
41
 
55
- The package contain a class that read and decode the SIMBIO-SYS image
42
+ The package provides a class to read PDS4 labels and decode SIMBIO-SYS products. Python 3.14 or later is required.
56
43
 
57
44
  ```python
58
45
  from SimbioReader import SimbioReader as SR
59
46
 
60
- dat = SimbioReader("sim_raw_sc_vihi_internal_cruise_ico4_2020-12-14_001.dat")
47
+ dat = SR("sim_raw_sc_vihi_internal_cruise_ico4_2020-12-14_001.dat")
61
48
  ```
62
49
 
50
+ Filter display is guarded for product types that do not expose filter metadata,
51
+ so requesting filter output on those products no longer raises an attribute
52
+ error. See [`FLUSSO_DATI.md`](FLUSSO_DATI.md) for the reader's parsing and data
53
+ flow.
54
+
63
55
  ## Command line tools
64
56
 
65
57
  In the package are included two command line tools:
@@ -77,19 +69,22 @@ will show the main information about the product.
77
69
 
78
70
  Are avalaible some options:
79
71
 
72
+ - **--summarize**, **-s** displays product, target and filter summaries for products with filter metadata
73
+ - **--debug**, **-d** enables debug output
74
+ - **--verbose**, **-v** enables verbose output
80
75
  - **--all** will display all the avilable information
81
76
  - **--hk** wil display also the housekeeping
82
77
  - **--detector** will display all the detector information
83
78
  - **--data-structure** will display the data structure of the file
84
- - **--filter** will display the information about the used filter if the data come from HRIC or STC, otherwise the option will be ignored
79
+ - **--filters** will display the information about the used filter if the data come from HRIC or STC, otherwise the option will be ignored
85
80
 
86
81
  For any details you can use the option **--help**.
87
82
 
88
- Using the option **--version** will be shown the software version and the datamodel version implemented in it.
83
+ Use `simbioReader FILE --version` to display the software and data-model versions. The current CLI requires an existing `FILE` even with this option.
89
84
 
90
85
  ### simbioInfo
91
86
 
92
- ***simbioInfo*** tool is a command line interface (cli) wiith three subcommands:
87
+ ***simbioInfo*** tool is a command line interface (cli) with four subcommands:
93
88
 
94
89
  - **filters** Show the definition of filter(s) of a specific channel
95
90
  - **phases** Show the past mission phase(s);
@@ -98,10 +93,10 @@ Using the option **--version** will be shown the software version and the datamo
98
93
 
99
94
  #### filters
100
95
 
101
- The subcommand **filter** has an argument, the channel and an option ***--name***.
96
+ The subcommand **filters** has an argument, the channel and an option ***--name***.
102
97
 
103
98
  If the user provides only the channel, all the filters specific to that channel will be shown.
104
- If the user adds the -name option, only the selected filter will be displayed, if found.
99
+ If the user adds the --name option, only the selected filter will be displayed, if found.
105
100
 
106
101
  A description of argument and options coul be required using the option ***--help***
107
102
 
@@ -114,7 +109,7 @@ simbioInfo filters hric
114
109
  will show all the filters of the channel HRIC
115
110
 
116
111
  ```console
117
- simbioInfo flters hric -n pan-l
112
+ simbioInfo filters hric -n pan-l
118
113
  ```
119
114
 
120
115
  will show the *HRIC* filter with the name *PAN-L*
@@ -203,7 +198,7 @@ will show all the SIMBIO-SYS tests.
203
198
 
204
199
  ```console
205
200
  simbioInfo tests -d 2024-04-08\ 2:00:00
206
- ````
201
+ ```
207
202
 
208
203
  will show the test that SIMBIO-SYS was performing at 2:00:00 on 2024-04-08, the *Interference Test* in the subphase *ico11*
209
204
 
@@ -213,13 +208,26 @@ simbioInfo tests --name hric\ functional --subphase ico9
213
208
  will show the test with the name that contain the string *hric functional* performed during the subphase *ico9*
214
209
 
215
210
 
211
+ ## Mission database
212
+
213
+ Mission phases may contain multiple non-contiguous intervals. `simbioInfo phases --all`
214
+ lists intervals chronologically. The bundled database includes the `fimgs`
215
+ subphase (Mercury First Images) and the `first_images` test, both covering
216
+ 2026-10-18 from 07:00:00 to 21:00:00.
217
+
218
+ ```console
219
+ simbioInfo subphases --name fimgs
220
+ simbioInfo tests --subphase fimgs
221
+ ```
222
+
216
223
  ## Class Description
217
224
 
218
225
  ### Methods
219
226
 
220
- + **Show()** display the main information related to the data file
227
+ + **show()** display the main information related to the data file
221
228
 
222
229
  ```python
223
- dat.Show()
224
- ```
230
+ from rich import print
225
231
 
232
+ print(dat.show())
233
+ ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "SimbioReader"
3
- version = "0.7.0"
3
+ version = "0.9.0"
4
4
  description="Python Reader for the data from SIMBIO-SYS instrument suite on-board the ESA mission BepiColombo"
5
5
  dependencies = [
6
6
 
@@ -42,15 +42,13 @@ simbioInfo = "SimbioReader.infocli:cli"
42
42
 
43
43
 
44
44
 
45
- [tool.poetry]
46
- packages =[
47
- {include ="SimbioReader", from ="src"}]
48
-
49
-
45
+ [tool.uv.build-backend]
46
+ module-name = "SimbioReader"
50
47
 
51
48
  [build-system]
52
- requires = ["poetry-core>=2.0.0"]
53
- build-backend = "poetry.core.masonry.api"
49
+ requires = ["uv_build>=0.11.28,<0.12.0"]
50
+ build-backend = "uv_build"
51
+
54
52
  [dependency-groups]
55
53
  test = [
56
54
  "pytest (>=9.0.2,<10.0.0)",
@@ -98,9 +96,12 @@ pythonpath = ["."]
98
96
  branch=true
99
97
  omit=["test/*","./prova.py"]
100
98
 
99
+ [tool.ruff]
100
+ target-version = "py314"
101
+
101
102
  [tool.pyright]
102
103
  pythonVersion = "3.14"
103
104
  typeCheckingMode = "basic"
104
105
  include = ["src"]
105
- venvPath = "/home/romolo/Documenti/Progetti/SIMBIO-SYS/Software/SimbioReader"
106
- venv = "venv"
106
+ venvPath = "."
107
+ venv = ".venv"
@@ -0,0 +1,8 @@
1
+ {
2
+ "folders": [
3
+ {
4
+ "path": "../.."
5
+ }
6
+ ],
7
+ "settings": {}
8
+ }
@@ -1,9 +1,12 @@
1
- from rich.console import Console
2
- from SimbioReader.sr import SimbioReader,version
1
+ from pathlib import Path
2
+
3
3
  import rich_click as click
4
- from SimbioReader.constants import CONTEXT_SETTINGS,datamodel, progEpilog
4
+ from rich.console import Console
5
5
  from rich_click import rich_config
6
- from pathlib import Path
6
+
7
+ from SimbioReader.constants import CONTEXT_SETTINGS, datamodel, progEpilog
8
+ from SimbioReader.sr import SimbioReader, version
9
+
7
10
  # from semantic_version_tools import Vers
8
11
  # from importlib.metadata import version as get_version
9
12
 
@@ -89,75 +89,51 @@ stcFilters={
89
89
  }
90
90
  hricFilters={
91
91
  "fpan":{
92
- "name" : "PAN-L",
93
- "desc" : "Fraction of the CCD used by the PAN-L filter",
94
- "id" : "L_P700",
95
- "bandwidth" : "204.3",
96
- "centerFilter" : "699.5",
97
- "interframeDel": "0.8",
98
- "fistLine" : "1227",
99
- "firstSample" : "576",
100
- "line" : "384",
101
- "sample" : "896"
92
+ "name" : "FPAN",
93
+ "desc" : "Portion of CMOS with panchromatic filter",
94
+ "id" : "FPAN",
95
+ "bandwidth" : "504.9",
96
+ "centerFilter" : "652.3",
97
+ "interframeDel": "__",
98
+ "fistLine" : "938",
99
+ "firstSample" : "0",
100
+ "line" : "640",
101
+ "sample" : "2048"
102
102
  },
103
103
  "f550":{
104
- "name" : "F550-L",
105
- "desc" : "Fraction of the CCD used by the F550-L filter",
106
- "id" : "L_F550",
107
- "bandwidth" : "20",
108
- "centerFilter" : "550",
109
- "interframeDel": "0.8",
110
- "fistLine" : "1745",
111
- "firstSample" : "576",
112
- "line" : "64",
113
- "sample" : "896"
104
+ "name" : "F550",
105
+ "desc" : "Portion of CMOS with broadband F550 filter",
106
+ "id" : "F550",
107
+ "bandwidth" : "40.4",
108
+ "centerFilter" : "549.3",
109
+ "interframeDel": "__",
110
+ "fistLine" : "1662",
111
+ "firstSample" : "0",
112
+ "line" : "384",
113
+ "sample" : "2048"
114
114
  },
115
115
  "f750":{
116
- "name" : "F750-H",
117
- "desc" : "Fraction of the CCD used by the F880-H filter",
118
- "id" : "H_F420",
119
- "bandwidth" : "20",
120
- "centerFilter" : "420",
121
- "interframeDel": "0.8",
122
- "fistLine" : "240",
123
- "firstSample" : "576",
124
- "line" : "64",
125
- "sample" : "896"
126
- },
127
- "f880":{
128
- "name" : "F880-H",
129
- "desc" : "Fraction of the CCD used by the F880-H filter",
130
- "id" : "H_F750",
131
- "bandwidth" : "20",
132
- "centerFilter" : "750",
133
- "interframeDel": "0.8",
134
- "fistLine" : "32",
135
- "firstSample" : "576",
136
- "line" : "64",
137
- "sample" : "896"
138
- },
139
- "cust0":{
140
- "name" : "PAN-L - custom",
141
- "desc" : "Fraction of the CCD used by the PAN-L filter",
142
- "id" : "CUST-0",
143
- "bandwidth" : "204.3",
144
- "centerFilter" : "699.5",
145
- "interframeDel": "0.8",
146
- "fistLine" : "1227",
147
- "firstSample" : "576",
116
+ "name" : "F750",
117
+ "desc" : "Portion of CMOS with broadband F750 filter",
118
+ "id" : "F750",
119
+ "bandwidth" : "39.9",
120
+ "centerFilter" : "752.9",
121
+ "interframeDel": "__",
122
+ "fistLine" : "2",
123
+ "firstSample" : "0",
148
124
  "line" : "384",
149
- "sample" : "896"
125
+ "sample" : "2048"
150
126
  },
151
- "cust1":{
152
- "name" : "PAN-L - custom",
153
- "desc" : "Fraction of the CCD used by the PAN-L filter",
154
- "id" : "CUST-1",
155
- "bandwidth" : "204.3",
156
- "centerFilter" : "699.5",
157
- "interframeDel": "0.8",
158
- "fistLine" : "1227",
159
- "firstSample" : "576",
127
+ "f880":{
128
+ "name" : "F880",
129
+ "desc" : "Portion of CMOS with broadband F750 filter",
130
+ "id" : "F880",
131
+ "bandwidth" : "39.8",
132
+ "centerFilter" : "880.1",
133
+ "interframeDel": "__",
134
+ "fistLine" : "470",
135
+ "firstSample" : "0",
160
136
  "line" : "384",
161
- "sample" : "896"
137
+ "sample" : "2048"
162
138
  },
163
139
  }
@@ -0,0 +1,31 @@
1
+ phases = {
2
+ "necp": [
3
+ {
4
+ "start": "2018-12-10 00:00:00",
5
+ "end": "2018-12-12 23:59:59",
6
+ "LPName": "Near-Earth Commissioning Phase",
7
+ }
8
+ ],
9
+ "cruise": [
10
+ {
11
+ "start": "2018-12-13 00:00:00",
12
+ "end": "2025-01-08 02:59:00",
13
+ "LPName": "Cruise",
14
+ },
15
+ {
16
+ "start": "2025-01-08 06:15:01",
17
+ "end": "2030-04-08 04:00:00",
18
+ "LPName": "Cruise",
19
+ },
20
+ ],
21
+ "mga6": [
22
+ {
23
+ "start": "2025-01-08 03:00:00",
24
+ "end": "2025-01-08 06:15:00",
25
+ "LPName": "Mercury Gravity Assist 6",
26
+ }
27
+ ],
28
+ "None": [
29
+ {"start": "2030-04-08 04:00:01", "end": "2030-12-31 23:59:59", "LPName": "None"}
30
+ ],
31
+ }
@@ -36,9 +36,10 @@ class Phase:
36
36
  ValueError: If neither name nor dt is provided, or if no phase is found.
37
37
  """
38
38
  if name:
39
- phase_data = phases.get(name)
40
- if not phase_data:
39
+ intervals = phases.get(name)
40
+ if not intervals:
41
41
  raise ValueError(f"Phase '{name}' not found.")
42
+ phase_data = self._merge_intervals(name, intervals)
42
43
  elif dt:
43
44
  if isinstance(dt, str):
44
45
  dt = parse(dt,ignoretz=True)
@@ -47,27 +48,56 @@ class Phase:
47
48
  raise ValueError(f"No phase found for the given date. (dt: {dt})")
48
49
  else:
49
50
  raise ValueError("You must provide a phase name or a date.")
50
-
51
+
51
52
  self.name = phase_data["name"]
52
- self.start = parse(phase_data["start"],ignoretz=True)
53
- self.end = parse(phase_data["end"],ignoretz=True)
53
+ self.start = phase_data["start"]
54
+ self.end = phase_data["end"]
54
55
  self.extended_name = phase_data["LPName"]
55
56
 
57
+ @staticmethod
58
+ def _merge_intervals(name, intervals):
59
+ """
60
+ Combines every interval registered for a phase name into a single span,
61
+ since a phase name (e.g. "cruise") may now be split across several
62
+ non-contiguous date intervals.
63
+
64
+ Args:
65
+ name (str): The name of the phase.
66
+ intervals (list[dict]): The list of intervals registered for that name.
67
+
68
+ Returns:
69
+ dict: Phase data with the earliest start and latest end of all intervals.
70
+ """
71
+ starts = [parse(interval["start"], ignoretz=True) for interval in intervals]
72
+ ends = [parse(interval["end"], ignoretz=True) for interval in intervals]
73
+ return {
74
+ "name": name,
75
+ "start": min(starts),
76
+ "end": max(ends),
77
+ "LPName": intervals[0]["LPName"],
78
+ }
79
+
56
80
  def _find_phase_by_date(self, dt):
57
81
  """
58
- Finds a phase by a given date.
82
+ Finds the phase interval that contains a given date.
59
83
 
60
84
  Args:
61
85
  dt (datetime): The date to find the corresponding phase.
62
86
 
63
87
  Returns:
64
- dict | None: The phase data if found, otherwise None.
65
- """
66
- for phase_name, phase_data in phases.items():
67
- start = parse(phase_data["start"],ignoretz=True)
68
- end = parse(phase_data["end"],ignoretz=True)
69
- if start <= dt <= end:
70
- return phase_data
88
+ dict | None: The matching interval's phase data if found, otherwise None.
89
+ """
90
+ for phase_name, intervals in phases.items():
91
+ for interval in intervals:
92
+ start = parse(interval["start"],ignoretz=True)
93
+ end = parse(interval["end"],ignoretz=True)
94
+ if start <= dt <= end:
95
+ return {
96
+ "name": phase_name,
97
+ "start": start,
98
+ "end": end,
99
+ "LPName": interval["LPName"],
100
+ }
71
101
  return None
72
102
 
73
103
  def __str__(self)-> str:
@@ -100,12 +130,17 @@ class Phase:
100
130
  tb.add_column('Phase Name')
101
131
  tb.add_column('Start Time')
102
132
  tb.add_column('End Time')
103
- for phase_name, phase_data in phases.items():
104
- if phase_name == "None":
105
- continue
106
- tb.add_row(f"{phase_data['LPName']} ({phase_name})",
107
- parse(phase_data['start']).strftime(dateFormat),
108
- parse(phase_data['end']).strftime(dateFormat))
133
+ rows = [
134
+ (phase_name, interval)
135
+ for phase_name, intervals in phases.items()
136
+ if phase_name != "None"
137
+ for interval in intervals
138
+ ]
139
+ rows.sort(key=lambda row: parse(row[1]['start'], ignoretz=True))
140
+ for phase_name, interval in rows:
141
+ tb.add_row(f"{interval['LPName']} ({phase_name})",
142
+ parse(interval['start']).strftime(dateFormat),
143
+ parse(interval['end']).strftime(dateFormat))
109
144
  return tb
110
145
 
111
146
  def show(self):