SimbioReader 0.5.10__tar.gz → 0.6.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.
- {simbioreader-0.5.10/src/SimbioReader.egg-info → simbioreader-0.6.0}/PKG-INFO +5 -3
- {simbioreader-0.5.10 → simbioreader-0.6.0}/pyproject.toml +21 -4
- simbioreader-0.6.0/src/SimbioReader/__init__.py +2 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader/__main__.py +1 -1
- simbioreader-0.6.0/src/SimbioReader/cli.py +32 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader/constants.py +2 -1
- simbioreader-0.6.0/src/SimbioReader/sr.py +719 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader/tools.py +2 -2
- {simbioreader-0.5.10 → simbioreader-0.6.0/src/SimbioReader.egg-info}/PKG-INFO +5 -3
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader.egg-info/SOURCES.txt +3 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader.egg-info/entry_points.txt +1 -1
- simbioreader-0.6.0/test/test_new_format.py +99 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/test/test_tools.py +2 -2
- simbioreader-0.5.10/src/SimbioReader/__init__.py +0 -2
- {simbioreader-0.5.10 → simbioreader-0.6.0}/LICENSE +0 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/README.md +0 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/setup.cfg +0 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader/exceptions.py +0 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader/filters.py +0 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader/filters_tools.py +0 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader/infocli.py +0 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader/phases.py +0 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader/simbioInfo.py +0 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader/subphases.py +0 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader/tests.py +0 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader/version.py +0 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader.egg-info/dependency_links.txt +0 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader.egg-info/requires.txt +0 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/src/SimbioReader.egg-info/top_level.txt +0 -0
- {simbioreader-0.5.10 → simbioreader-0.6.0}/test/test_db.py +0 -0
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: SimbioReader
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Python Reader for the data from SIMBIO-SYS instrument suite on-board the ESA mission BepiColombo
|
|
5
5
|
Author-email: Romolo Politi <Romolo.Politi@inaf.it>
|
|
6
|
-
License: GNU GPL ver3
|
|
7
6
|
Project-URL: Repository, https://github.com/SIMBIO-SYS/SimbioReader
|
|
8
7
|
Keywords: data reader,Space Mission,BepiColombo,SIMBIO-SYS
|
|
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
|
|
9
12
|
Classifier: Development Status :: 2 - Pre-Alpha
|
|
10
|
-
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
11
13
|
Requires-Python: >=3.11
|
|
12
14
|
Description-Content-Type: text/markdown
|
|
13
15
|
License-File: LICENSE
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "SimbioReader"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.6.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
|
|
|
@@ -14,15 +14,21 @@ dependencies = [
|
|
|
14
14
|
requires-python = ">=3.11"
|
|
15
15
|
|
|
16
16
|
authors = [{name="Romolo Politi", email ="Romolo.Politi@inaf.it" }]
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
readme = "README.md"
|
|
19
19
|
|
|
20
20
|
keywords = ["data reader", "Space Mission", "BepiColombo", "SIMBIO-SYS"]
|
|
21
21
|
classifiers = [
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Programming Language :: Python :: 3.14",
|
|
22
26
|
"Development Status :: 2 - Pre-Alpha",
|
|
23
|
-
|
|
27
|
+
|
|
24
28
|
]
|
|
25
29
|
|
|
30
|
+
|
|
31
|
+
|
|
26
32
|
[project.urls]
|
|
27
33
|
Repository = "https://github.com/SIMBIO-SYS/SimbioReader"
|
|
28
34
|
|
|
@@ -30,7 +36,7 @@ Repository = "https://github.com/SIMBIO-SYS/SimbioReader"
|
|
|
30
36
|
docs = ["sphinx"]
|
|
31
37
|
|
|
32
38
|
[project.scripts]
|
|
33
|
-
simbioReader = "SimbioReader.
|
|
39
|
+
simbioReader = "SimbioReader.cli:cli"
|
|
34
40
|
simbioInfo = "SimbioReader.infocli:cli"
|
|
35
41
|
|
|
36
42
|
|
|
@@ -38,6 +44,17 @@ simbioInfo = "SimbioReader.infocli:cli"
|
|
|
38
44
|
requires = ["setuptools"]
|
|
39
45
|
build-backend = "setuptools.build_meta"
|
|
40
46
|
|
|
47
|
+
[tool.poetry]
|
|
48
|
+
packages =[
|
|
49
|
+
{include ="SimbioReader", from ="src"}]
|
|
50
|
+
|
|
41
51
|
[tool.poetry.group.test.dependencies]
|
|
42
52
|
pytest = "^8.4.2"
|
|
43
53
|
|
|
54
|
+
|
|
55
|
+
[tool.poetry.group.dev.dependencies]
|
|
56
|
+
pylint = "^4.0.4"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
@@ -496,7 +496,7 @@ class SimbioReader:
|
|
|
496
496
|
dtype = np.int16
|
|
497
497
|
elif self.data_stucture.data_type == "IEEE754LSBSingle":
|
|
498
498
|
dtype = np.float32
|
|
499
|
-
|
|
499
|
+
|
|
500
500
|
if self.verbose:
|
|
501
501
|
self.console.print(f"{MSG.INFO}Loading: {self.fileName}")
|
|
502
502
|
if self.data_stucture.axes == 3:
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from rich.console import Console
|
|
2
|
+
from SimbioReader.sr import SimbioReader, version
|
|
3
|
+
import rich_click as click
|
|
4
|
+
from SimbioReader.constants import CONTEXT_SETTINGS,datamodel
|
|
5
|
+
from rich_click import rich_config
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def sh_version(ctx, self, value):
|
|
10
|
+
"""Display version and exit"""
|
|
11
|
+
console = Console()
|
|
12
|
+
console.print(f"SimbioReader version [blue bold]{version.short()}[/]")
|
|
13
|
+
console.print(f"DataModel version [blue bold]{datamodel}[/]")
|
|
14
|
+
ctx.exit()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@click.command(context_settings=CONTEXT_SETTINGS)
|
|
18
|
+
@rich_config(help_config={'header_text': f"SIMBIO-SYS Data Reader, version [blue]{version.short()}[/blue]"})
|
|
19
|
+
@click.argument('file', type=click.Path(exists=True), required=True)
|
|
20
|
+
@click.option('--hk', is_flag=True, help='Show the HouseKeeping', default=False)
|
|
21
|
+
@click.option('--detector', is_flag=True, help='Show the Detector', default=False)
|
|
22
|
+
@click.option('--data-structure', is_flag=True, help='Show the Data Structure', default=False)
|
|
23
|
+
@click.option('--all', 'all_info', is_flag=True, help='Show all the information', default=False)
|
|
24
|
+
@click.option('--filter', 'filter_flag', is_flag=True, help='Show the filters for the given channel', default=False)
|
|
25
|
+
@click.option('-d', '--debug', is_flag=True, help='Debug mode', default=False)
|
|
26
|
+
@click.option('-v', '--verbose', is_flag=True, help='Verbose mode', default=False)
|
|
27
|
+
@click.option('--version', is_flag=True, help='Show the version and exit', default=False,callback=sh_version)
|
|
28
|
+
def cli(file: str=None, hk: bool = False, detector: bool=False, data_structure: bool = False, all_info: bool = False,
|
|
29
|
+
filter_flag : bool =False, debug: bool = False, verbose: bool = False, version:bool = False):
|
|
30
|
+
console = Console()
|
|
31
|
+
dat = SimbioReader(file, console=console, debug=debug, verbose=verbose)
|
|
32
|
+
console.print(dat.summary())
|
|
@@ -19,7 +19,8 @@ CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
|
|
|
19
19
|
progEpilog = "- For any information or suggestion please contact " \
|
|
20
20
|
"[bold magenta]Romolo.Politi@inaf.it[/bold magenta]"
|
|
21
21
|
|
|
22
|
-
VERSION = (0,
|
|
22
|
+
VERSION = (0,6,0,'f',1)
|
|
23
|
+
|
|
23
24
|
|
|
24
25
|
datamodel='1.22.0.0'
|
|
25
26
|
|
|
@@ -0,0 +1,719 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import numpy as np
|
|
3
|
+
from PIL import Image as im
|
|
4
|
+
from rich.console import Console
|
|
5
|
+
from xml.dom.minidom import Element, parse
|
|
6
|
+
from SimbioReader.tools import getElement, getValue, camel_case
|
|
7
|
+
from dateutil import parser
|
|
8
|
+
import pandas as pd
|
|
9
|
+
from rich.panel import Panel
|
|
10
|
+
from rich.table import Table
|
|
11
|
+
from rich.columns import Columns
|
|
12
|
+
from SimbioReader.constants import MSG,data_types
|
|
13
|
+
from SimbioReader.filters_tools import Filter
|
|
14
|
+
from SimbioReader.exceptions import SizeError
|
|
15
|
+
from SimbioReader.tools import gen_filename, lidUpdate, lvidUpdate, updateXML, pretty_print
|
|
16
|
+
from datetime import datetime
|
|
17
|
+
from xml.dom.minidom import parse, parseString, Element, Document
|
|
18
|
+
import hashlib
|
|
19
|
+
from SimbioReader.version import version
|
|
20
|
+
__version__ = version.full()
|
|
21
|
+
|
|
22
|
+
class Detector:
|
|
23
|
+
"""
|
|
24
|
+
A class representing a detector in a SIMBIO-SYS image.
|
|
25
|
+
|
|
26
|
+
This class extracts and initializes various attributes related to a detector
|
|
27
|
+
in a SIMBIO-SYS image, such as the first line, first sample, and number of lines.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
dat (Element): An XML Element containing the detector information.
|
|
31
|
+
|
|
32
|
+
Attributes:
|
|
33
|
+
first_line (int): The first line number of the detector.
|
|
34
|
+
first_sample (int): The first sample number of the detector.
|
|
35
|
+
lines (int): The number of lines in the detector.
|
|
36
|
+
"""
|
|
37
|
+
def __init__(self,dat:Element) -> None:
|
|
38
|
+
detector = getElement(dat, 'img:Subframe')
|
|
39
|
+
self.first_line = int(getValue(detector,'img:first_line'))
|
|
40
|
+
self.first_sample = int(getValue(detector,'img:first_sample'))
|
|
41
|
+
self.lines = int(getValue(detector,'img:lines'))
|
|
42
|
+
self.samples = int(getValue(detector,'img:samples'))
|
|
43
|
+
self.line_fov = float(getValue(detector,'img:line_fov'))
|
|
44
|
+
self.sample_fov = float(getValue(detector,'img:sample_fov'))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def __str__(self) -> str:
|
|
48
|
+
"""
|
|
49
|
+
Returns a string representation of the Detector object.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
str: A string representation of the Detector object.
|
|
53
|
+
"""
|
|
54
|
+
return f"Detector object"
|
|
55
|
+
|
|
56
|
+
def __repr__(self) -> str:
|
|
57
|
+
"""
|
|
58
|
+
Returns a string representation of the Detector object for debugging.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
str: A string representation of the Detector object.
|
|
62
|
+
"""
|
|
63
|
+
return self.__str__()
|
|
64
|
+
|
|
65
|
+
def show(self)-> Panel:
|
|
66
|
+
"""
|
|
67
|
+
Displays the detector information in a formatted table.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
Panel: A Panel object containing the formatted detector information.
|
|
71
|
+
"""
|
|
72
|
+
sep=' = '
|
|
73
|
+
dt=Table.grid()
|
|
74
|
+
dt.add_column(style='yellow',justify='right')
|
|
75
|
+
dt.add_column()
|
|
76
|
+
dt.add_column(style='cyan',justify='left')
|
|
77
|
+
dt.add_row('First Line',sep,str(self.first_line))
|
|
78
|
+
dt.add_row('First Sample',sep,str(self.first_sample))
|
|
79
|
+
dt.add_row('Lines',sep,str(self.lines))
|
|
80
|
+
dt.add_row('Samples',sep,str(self.samples))
|
|
81
|
+
dt.add_row('Line FOV',sep,str(self.line_fov))
|
|
82
|
+
dt.add_row('Sample FOV',sep,str(self.sample_fov))
|
|
83
|
+
return Panel(dt,title='Detector',border_style='yellow',expand=False)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class DataStructure:
|
|
87
|
+
"""
|
|
88
|
+
A class representing the data structure of a SIMBIO-SYS file.
|
|
89
|
+
|
|
90
|
+
This class extracts and initializes various attributes related to the data
|
|
91
|
+
structure of a SIMBIO-SYS file, such as creation time, file size, and axes
|
|
92
|
+
configuration, based on an XML Element.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
dat (Element): An XML Element containing the data structure information.
|
|
96
|
+
channel (str): The channel identifier (e.g., 'HRIC', 'STC', 'VIHI').
|
|
97
|
+
|
|
98
|
+
Attributes:
|
|
99
|
+
creation_time (datetime): The creation time of the file.
|
|
100
|
+
file_size (int): The size of the file.
|
|
101
|
+
md5 (str): The MD5 checksum of the file.
|
|
102
|
+
axes (int): The number of axes in the data structure.
|
|
103
|
+
band (int): The band information (default is 1).
|
|
104
|
+
data_type (str): The type of data (e.g., 'UnsignedLSB2', 'IEEE754LSBSingle').
|
|
105
|
+
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
def __init__(self, dat:Element, channel:str):
|
|
109
|
+
# fao=getElement(dat,'File_Area_Observational')
|
|
110
|
+
fl=getElement(dat,'File')
|
|
111
|
+
self.creation_time = parser.parse(getValue(fl,'creation_date_time'))
|
|
112
|
+
self.file_size = int(getValue(fl,'file_size'))
|
|
113
|
+
self.md5 = getValue(fl,'md5_checksum')
|
|
114
|
+
self.axes = int(getValue(dat,'axes'))
|
|
115
|
+
self.band= None
|
|
116
|
+
if self.axes == 3 and channel != 'VIHI':
|
|
117
|
+
raise ValueError("The number of axes is wrong for the channel")
|
|
118
|
+
for i in range(self.axes):
|
|
119
|
+
axis = getElement(dat,'Axis_Array',i)
|
|
120
|
+
setattr(self,getValue(axis,'axis_name').lower(),int(getValue(axis,'elements')))
|
|
121
|
+
if self.axes == 3:
|
|
122
|
+
dat=getElement(dat,'Array_3D_Spectrum')
|
|
123
|
+
elif self.axes == 2:
|
|
124
|
+
dat=getElement(dat,'Array_2D_Image')
|
|
125
|
+
self.data_type = getValue(dat,'data_type')
|
|
126
|
+
if self.band is None:
|
|
127
|
+
self.band = 1
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def __str__(self)->str:
|
|
131
|
+
"""
|
|
132
|
+
Returns a string representation of the Datastructure.
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
str: A string in the format 'DataStructure Object'.
|
|
136
|
+
"""
|
|
137
|
+
return f"DataStructure object"
|
|
138
|
+
|
|
139
|
+
def __repr__(self) -> str:
|
|
140
|
+
"""
|
|
141
|
+
Returns a string representation for debugging purposes.
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
str: A string in the format 'DataStructure Object'.
|
|
145
|
+
"""
|
|
146
|
+
return self.__str__()
|
|
147
|
+
|
|
148
|
+
def show(self):
|
|
149
|
+
"""
|
|
150
|
+
Displays the data structure information in a formatted table.
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
Panel: A rich Panel object containing the formatted table of data structure information.
|
|
154
|
+
"""
|
|
155
|
+
sep=' = '
|
|
156
|
+
dt=Table.grid()
|
|
157
|
+
dt.add_column(style='yellow',justify='right')
|
|
158
|
+
dt.add_column()
|
|
159
|
+
dt.add_column(style='cyan',justify='left')
|
|
160
|
+
for item in self.__dict__:
|
|
161
|
+
dt.add_row(item,sep,str(self.__dict__[item]))
|
|
162
|
+
# dt.add_row('Creation Time',sep,datetime.strftime(self.creation_time,"%Y-%m-%d"))
|
|
163
|
+
# dt.add_row('File Size',sep,str(self.file_size))
|
|
164
|
+
# dt.add_row('MD5 Checksum',sep,self.md5)
|
|
165
|
+
# dt.add_row('Axes',sep,str(self.axes))
|
|
166
|
+
return Panel(dt,title='Data Structure',border_style='yellow',expand=False)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
class HK:
|
|
170
|
+
"""
|
|
171
|
+
A class representing housekeeping data for a SIMBIO-SYS image.
|
|
172
|
+
|
|
173
|
+
This class initializes various attributes from a pandas DataFrame containing
|
|
174
|
+
housekeeping data and provides methods to display this information.
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
df (pd.DataFrame): A pandas DataFrame containing housekeeping data.
|
|
178
|
+
|
|
179
|
+
Attributes:
|
|
180
|
+
df (pd.DataFrame): The DataFrame containing housekeeping data.
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
def __init__(self, df: pd.DataFrame):
|
|
184
|
+
"""
|
|
185
|
+
Initializes the HK object by extracting information from the DataFrame.
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
df (pd.DataFrame): A pandas DataFrame containing housekeeping data.
|
|
189
|
+
"""
|
|
190
|
+
self.df = df
|
|
191
|
+
for i in df.columns:
|
|
192
|
+
if type(df[i].values[0]) is str:
|
|
193
|
+
val = df[i].values[0].strip()
|
|
194
|
+
else:
|
|
195
|
+
val = df[i].values[0]
|
|
196
|
+
setattr(self, i.strip().lower(), val)
|
|
197
|
+
|
|
198
|
+
def show(self) -> Panel:
|
|
199
|
+
"""
|
|
200
|
+
Displays the housekeeping information in a formatted table.
|
|
201
|
+
|
|
202
|
+
Returns:
|
|
203
|
+
Panel: A Panel object containing the formatted housekeeping information.
|
|
204
|
+
"""
|
|
205
|
+
sep = " = "
|
|
206
|
+
dt = Table.grid()
|
|
207
|
+
dt.add_column(style="yellow", justify="right")
|
|
208
|
+
dt.add_column()
|
|
209
|
+
dt.add_column(style="cyan", justify="left")
|
|
210
|
+
for i in self.df.columns:
|
|
211
|
+
dt.add_row(
|
|
212
|
+
" ".join(i.split("_")).title(), sep, f"{self.df[i].values[0]}".strip()
|
|
213
|
+
)
|
|
214
|
+
return Panel(dt, title="HouseKeeping", border_style="yellow", expand=False)
|
|
215
|
+
|
|
216
|
+
def __str__(self) -> str:
|
|
217
|
+
"""
|
|
218
|
+
Returns a string representation of the HK object.
|
|
219
|
+
|
|
220
|
+
Returns:
|
|
221
|
+
str: A string representation of the HK object.
|
|
222
|
+
"""
|
|
223
|
+
return f"HK object"
|
|
224
|
+
|
|
225
|
+
def __repr__(self) -> str:
|
|
226
|
+
"""
|
|
227
|
+
Returns a string representation of the HK object for debugging.
|
|
228
|
+
|
|
229
|
+
Returns:
|
|
230
|
+
str: A string representation of the HK object.
|
|
231
|
+
"""
|
|
232
|
+
return self.__str__()
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
class Target:
|
|
236
|
+
def __init__(self, name: str, target_type: str):
|
|
237
|
+
self.name = name
|
|
238
|
+
self.target_type = target_type
|
|
239
|
+
|
|
240
|
+
# other attributes will be added after the integration of the observation log in the PDS label
|
|
241
|
+
|
|
242
|
+
def show(self):
|
|
243
|
+
sep = " = "
|
|
244
|
+
tb = Table.grid()
|
|
245
|
+
tb.add_column(style="yellow", justify="right")
|
|
246
|
+
tb.add_column()
|
|
247
|
+
tb.add_column()
|
|
248
|
+
tb.add_row("Name", sep, self.name)
|
|
249
|
+
tb.add_row("Type", sep, self.target_type)
|
|
250
|
+
return Panel(tb, title="Target Info", border_style="blue", expand=False)
|
|
251
|
+
|
|
252
|
+
def __str__(self):
|
|
253
|
+
return f"Target(name={self.name}, type={self.target_type})"
|
|
254
|
+
|
|
255
|
+
def __repr__(self):
|
|
256
|
+
return self.__str__()
|
|
257
|
+
|
|
258
|
+
class SimbioObject:
|
|
259
|
+
def __init__(self, file_name: str, filter_name: str, channel: str,
|
|
260
|
+
imaging: Element, geometry: Element,file_obs: Element, console: Console = None, debug:bool=False, verbose:bool=False):
|
|
261
|
+
if console is None:
|
|
262
|
+
self.console = Console()
|
|
263
|
+
else:
|
|
264
|
+
self.console = console
|
|
265
|
+
self.file_name = file_name
|
|
266
|
+
self.filter_name = filter_name
|
|
267
|
+
self.channel = channel
|
|
268
|
+
self.imaging = imaging
|
|
269
|
+
self.geometry = geometry
|
|
270
|
+
self.exposure_time = getValue(imaging, "img:exposure_duration")
|
|
271
|
+
subFrame = getElement(imaging, "img:Subframe")
|
|
272
|
+
self.firstLine = int(getValue(subFrame, 'img:first_line'))
|
|
273
|
+
self.firstSample = int(getValue(subFrame, 'img:first_sample'))
|
|
274
|
+
self.lines = int(getValue(subFrame, 'img:lines'))
|
|
275
|
+
self.samples = int(getValue(subFrame, 'img:samples'))
|
|
276
|
+
self.lineFov = float(getValue(subFrame, 'img:line_fov'))
|
|
277
|
+
self.sampleFov = float(getValue(subFrame, 'img:sample_fov'))
|
|
278
|
+
self.data_stucture = DataStructure(file_obs, self.channel)
|
|
279
|
+
self.samples=self.data_stucture.sample
|
|
280
|
+
self.lines=self.data_stucture.line
|
|
281
|
+
self.bands=self.data_stucture.band
|
|
282
|
+
if self.channel != 'VIHI':
|
|
283
|
+
flt = getElement(imaging, 'img:Optical_Filter')
|
|
284
|
+
self.filter=Filter(channel=self.channel,name=getValue(flt,'img:filter_name'))
|
|
285
|
+
self.detector = Detector(imaging)
|
|
286
|
+
if self.data_stucture.data_type == "UnsignedLSB2":
|
|
287
|
+
dtype = np.int16
|
|
288
|
+
elif self.data_stucture.data_type == "IEEE754LSBSingle":
|
|
289
|
+
dtype = np.float32
|
|
290
|
+
|
|
291
|
+
if verbose:
|
|
292
|
+
console.print(f"{MSG.INFO}Loading: {self.file_name}")
|
|
293
|
+
if self.data_stucture.axes == 3:
|
|
294
|
+
console.print(f"{MSG.INFO}Image size: {self.samples}x{self.lines}x{self.bands}")
|
|
295
|
+
imgSize = self.samples*self.lines*self.bands*data_types[self.data_stucture.data_type]['bits']
|
|
296
|
+
else:
|
|
297
|
+
console.print(f"{MSG.INFO}Image size: {self.samples}x{self.lines}")
|
|
298
|
+
imgSize = self.samples*self.lines*data_types[self.data_stucture.data_type]['bits']
|
|
299
|
+
|
|
300
|
+
console.print(f"{MSG.INFO}File size: {self.file_name.stat().st_size*8}")
|
|
301
|
+
console.print(
|
|
302
|
+
f"{MSG.INFO}Computed File Size: {imgSize}")
|
|
303
|
+
if self.file_name.stat().st_size*8 != imgSize:
|
|
304
|
+
raise SizeError(self.file_name.stat().st_size *
|
|
305
|
+
8,imgSize)
|
|
306
|
+
#print(img_data['samples'],img_data['lines'],img_data['bands'])
|
|
307
|
+
if self.data_stucture.axes == 3:
|
|
308
|
+
self.img = np.fromfile(self.file_name, dtype=dtype,
|
|
309
|
+
count=self.samples*self.lines*self.bands)
|
|
310
|
+
else:
|
|
311
|
+
self.img = np.fromfile(self.file_name, dtype=dtype,
|
|
312
|
+
count=self.samples*self.lines)
|
|
313
|
+
if self.data_stucture.axes == 3:
|
|
314
|
+
if self.lines==1:
|
|
315
|
+
self.img.shape = ( self.samples,self.bands)
|
|
316
|
+
else:
|
|
317
|
+
self.img.shape = (self.lines,self.samples, self.bands )
|
|
318
|
+
else:
|
|
319
|
+
self.img.shape = (self.samples, self.lines)
|
|
320
|
+
if verbose:
|
|
321
|
+
self.console.print(f"{MSG.INFO}Dimension of the old image array: {self.img.ndim}")
|
|
322
|
+
# print(f"Size of the old image array: {self.img.size}")
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def show(self)->Panel:
|
|
326
|
+
sep = " = "
|
|
327
|
+
tb = Table.grid()
|
|
328
|
+
tb.add_column(style="yellow", justify="right")
|
|
329
|
+
tb.add_column()
|
|
330
|
+
tb.add_column()
|
|
331
|
+
tb.add_row("File Name", sep, str(self.file_name))
|
|
332
|
+
tb.add_row("Filter Name", sep, self.filter_name)
|
|
333
|
+
tb.add_row("Channel", sep, self.channel.upper())
|
|
334
|
+
tb.add_row("Exposure Time (s)", sep, str(self.exposure_time))
|
|
335
|
+
pl=Panel(tb, title="Simbio Filter General Info", border_style="cyan", expand=False)
|
|
336
|
+
return Panel(Columns([pl,self.filter.show(),self.data_stucture.show(),self.detector.show()]), title=f"Filter {self.filter_name.upper()} Info", border_style="magenta", expand=False)
|
|
337
|
+
|
|
338
|
+
def __str__(self):
|
|
339
|
+
return f"Filter(name={self.filter_name})"
|
|
340
|
+
|
|
341
|
+
def __repr__(self):
|
|
342
|
+
return self.__str__()
|
|
343
|
+
|
|
344
|
+
def savePreview(self,img_type:str='png',quality:int=100, outFolder:Path=None, tree:Document=None)->str|None:
|
|
345
|
+
new_filename=gen_filename(self.file_name)
|
|
346
|
+
if img_type in ['png','tif']:
|
|
347
|
+
data = im.fromarray(self.img)
|
|
348
|
+
image_file= f"{outFolder}/{new_filename}.{img_type}"
|
|
349
|
+
if 'cal' in self.file_name.stem:
|
|
350
|
+
data.convert('RGB').save(image_file, quality=quality)
|
|
351
|
+
else:
|
|
352
|
+
data.save(image_file, quality=quality)
|
|
353
|
+
if tree:
|
|
354
|
+
fab=tree.createElement("File_Area_Browse")
|
|
355
|
+
fl=tree.createElement("File")
|
|
356
|
+
fln=tree.createElement("file_name")
|
|
357
|
+
fln.appendChild(tree.createTextNode(f"{new_filename}.{img_type}"))
|
|
358
|
+
fl.appendChild(fln)
|
|
359
|
+
fl_ct=tree.createElement("creation_date_time")
|
|
360
|
+
creatTime=datetime.now()
|
|
361
|
+
fl_ct.appendChild(tree.createTextNode(creatTime.strftime("%Y-%m-%d")))
|
|
362
|
+
fl.appendChild(fl_ct)
|
|
363
|
+
fl_fs=tree.createElement("file_size")
|
|
364
|
+
fl_fs.appendChild(tree.createTextNode(str(Path(image_file).stat().st_size)))
|
|
365
|
+
fl.appendChild(fl_fs)
|
|
366
|
+
fl_md5=tree.createElement("md5_checksum")
|
|
367
|
+
fl_md5.appendChild(tree.createTextNode(hashlib.md5(
|
|
368
|
+
open(image_file, 'rb').read()).hexdigest()))
|
|
369
|
+
fl.appendChild(fl_md5)
|
|
370
|
+
fab.appendChild(fl)
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
enc_img=tree.createElement("Encoding_Image")
|
|
375
|
+
enc_offset=tree.createElement("offset")
|
|
376
|
+
enc_offset.appendChild(tree.createTextNode("0"))
|
|
377
|
+
enc_offset.setAttribute("unit","bytes")
|
|
378
|
+
enc_stid=tree.createElement("encoding_standard_id")
|
|
379
|
+
enc_stid.appendChild(tree.createTextNode("PNG"))
|
|
380
|
+
enc_img.appendChild(enc_offset)
|
|
381
|
+
enc_img.appendChild(enc_stid)
|
|
382
|
+
|
|
383
|
+
fab.appendChild(enc_img)
|
|
384
|
+
return fab
|
|
385
|
+
elif img_type == 'jpg':
|
|
386
|
+
data = im.fromarray(self.img,mode='L')
|
|
387
|
+
# print(data.getpixel((50,50)))
|
|
388
|
+
data.save(f"{outFolder}/{new_filename}.{img_type}",
|
|
389
|
+
quality=quality)
|
|
390
|
+
# print(self.img[0,0])
|
|
391
|
+
|
|
392
|
+
class Data:
|
|
393
|
+
def __init__(
|
|
394
|
+
self,
|
|
395
|
+
channel: str,
|
|
396
|
+
level: str,
|
|
397
|
+
source_path: Path,
|
|
398
|
+
file_obs: list,
|
|
399
|
+
imaging: list,
|
|
400
|
+
geometry: list,
|
|
401
|
+
debug: bool = False,
|
|
402
|
+
verbose: bool = False,
|
|
403
|
+
console=None,
|
|
404
|
+
):
|
|
405
|
+
if console is None:
|
|
406
|
+
self.console = Console()
|
|
407
|
+
else:
|
|
408
|
+
self.console = console
|
|
409
|
+
self.filters =[]
|
|
410
|
+
self.items_number = len(file_obs)
|
|
411
|
+
self.channel = channel
|
|
412
|
+
self.level = level
|
|
413
|
+
for i, fo in enumerate(file_obs):
|
|
414
|
+
file_name = source_path.joinpath(getValue(fo, "file_name"))
|
|
415
|
+
if verbose or debug:
|
|
416
|
+
self.console.print(
|
|
417
|
+
f"{MSG.INFO}Processing file {i+1}/{self.items_number}: {file_name.name}"
|
|
418
|
+
)
|
|
419
|
+
if not file_name.exists():
|
|
420
|
+
raise FileNotFoundError(f"The data file {file_name} does not exist.")
|
|
421
|
+
if file_name.suffix.lower() == ".csv":
|
|
422
|
+
|
|
423
|
+
# read CSV file
|
|
424
|
+
if verbose or debug:
|
|
425
|
+
self.console.print(
|
|
426
|
+
f"{MSG.INFO}Reading CSV file: {file_name}"
|
|
427
|
+
)
|
|
428
|
+
df = pd.read_csv(file_name, sep=",", header=0)
|
|
429
|
+
self.hk = HK(df)
|
|
430
|
+
elif file_name.suffix.lower() in [".qub", ".dat"]:
|
|
431
|
+
if channel in ["stc", "hric"]:
|
|
432
|
+
filter = getValue(imaging[i], "img:filter_name")
|
|
433
|
+
self.filters.append(filter.lower())
|
|
434
|
+
setattr(self, f"filter_{filter.lower()}", SimbioObject(file_name,filter_name=filter,channel=channel,imaging=imaging[i],geometry=geometry[i],file_obs=file_obs[i],console=self.console,debug=debug,verbose=verbose ))
|
|
435
|
+
|
|
436
|
+
if debug:
|
|
437
|
+
self.console.print(
|
|
438
|
+
f"{MSG.DEBUG}Found filter: {filter}"
|
|
439
|
+
)
|
|
440
|
+
pass
|
|
441
|
+
else:
|
|
442
|
+
# qube /segments
|
|
443
|
+
pass
|
|
444
|
+
|
|
445
|
+
def savePreview(self,img_type:str='png',quality:int=100, outFolder:Path=None,tree:Document=None)->str|None:
|
|
446
|
+
filter_prevs=[]
|
|
447
|
+
for item in self.filters:
|
|
448
|
+
disp=getattr(self,f'filter_{item.lower()}')
|
|
449
|
+
filter_prevs.append(disp.savePreview(img_type=img_type,quality=quality,outFolder=outFolder,tree=tree) )
|
|
450
|
+
return filter_prevs
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def __str__(self):
|
|
454
|
+
return f"Data(channel={self.channel}, level={self.level}, items_number={self.items_number})"
|
|
455
|
+
|
|
456
|
+
def __repr__(self):
|
|
457
|
+
return self.__str__()
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
class SimbioReader:
|
|
461
|
+
def __init__(
|
|
462
|
+
self, file_path: Path, debug: bool = False, verbose: bool = False, console=None
|
|
463
|
+
):
|
|
464
|
+
# Initialize the SimbioReader with a file path and optional console for output
|
|
465
|
+
self.pdsLabel: Path = None
|
|
466
|
+
if console is None:
|
|
467
|
+
self.console = Console()
|
|
468
|
+
else:
|
|
469
|
+
self.console = console
|
|
470
|
+
|
|
471
|
+
if debug:
|
|
472
|
+
self.console.print(
|
|
473
|
+
f"{MSG.DEBUG}Initializing SimbioReader with file path: {file_path}"
|
|
474
|
+
)
|
|
475
|
+
# Check the filename extension
|
|
476
|
+
if isinstance(file_path, str):
|
|
477
|
+
file_path = Path(file_path)
|
|
478
|
+
|
|
479
|
+
self.pdsLabel = self.label_name(file_path)
|
|
480
|
+
|
|
481
|
+
# check if the file exists
|
|
482
|
+
if debug:
|
|
483
|
+
self.console.print(
|
|
484
|
+
f"{MSG.DEBUG}Checking if file exists: {self.pdsLabel}"
|
|
485
|
+
)
|
|
486
|
+
if self.pdsLabel is None or not self.pdsLabel.exists():
|
|
487
|
+
# self.console.print(f"[red]Error:[/red] The file {self.pdsLabel} does not exist.")
|
|
488
|
+
raise FileNotFoundError(f"The file {self.pdsLabel} does not exist.")
|
|
489
|
+
|
|
490
|
+
if verbose or debug:
|
|
491
|
+
self.console.print(
|
|
492
|
+
f"{MSG.INFO}Reading PDS label file: {self.pdsLabel}"
|
|
493
|
+
)
|
|
494
|
+
label = parse(self.pdsLabel.as_posix())
|
|
495
|
+
self.channel = getValue(label, "psa:identifier").lower()
|
|
496
|
+
if self.channel not in ["stc", "hric", "vihi"]:
|
|
497
|
+
raise ValueError(f"Unknown channel '{self.channel}' found in label.")
|
|
498
|
+
self.level = getValue(label, "processing_level").lower()
|
|
499
|
+
self.lid = getValue(label, "logical_identifier")
|
|
500
|
+
self.version = getValue(label, "version_id")
|
|
501
|
+
self.title = getValue(label, "title")
|
|
502
|
+
self.dataModelVersion = getValue(label, "information_model_version")
|
|
503
|
+
mission_phase=getElement(label,"psa:Mission_Phase")
|
|
504
|
+
self.phaseName = getValue(mission_phase, 'psa:name')
|
|
505
|
+
if debug:
|
|
506
|
+
self.console.print(
|
|
507
|
+
f"{MSG.DEBUG}Initialized SimbioReader with channel: {self.title}, version: {self.level}, Datamodel: {self.dataModelVersion}"
|
|
508
|
+
)
|
|
509
|
+
|
|
510
|
+
# Observation Time
|
|
511
|
+
|
|
512
|
+
obsArea = getElement(label, "Observation_Area")
|
|
513
|
+
timeCoords = getElement(obsArea, "Time_Coordinates")
|
|
514
|
+
self.startTime = parser.parse(getValue(timeCoords, "start_date_time"))
|
|
515
|
+
self.stopTime = parser.parse(getValue(timeCoords, "stop_date_time"))
|
|
516
|
+
|
|
517
|
+
self.start_scet = getValue(label, "psa:spacecraft_clock_start_count")
|
|
518
|
+
self.stop_scet = getValue(label, "psa:spacecraft_clock_start_count")
|
|
519
|
+
if debug:
|
|
520
|
+
self.console.print(
|
|
521
|
+
f"{MSG.DEBUG}Observation start time: {self.startTime}, stop time: {self.stopTime}"
|
|
522
|
+
)
|
|
523
|
+
self.console.print(
|
|
524
|
+
f"{MSG.DEBUG}Spacecraft clock start count: {self.start_scet}, stop count: {self.stop_scet}"
|
|
525
|
+
)
|
|
526
|
+
|
|
527
|
+
# Target Information
|
|
528
|
+
targetInfo = getElement(obsArea, "Target_Identification")
|
|
529
|
+
self.target = Target(
|
|
530
|
+
name=getValue(targetInfo, "name"), target_type=getValue(targetInfo, "type")
|
|
531
|
+
)
|
|
532
|
+
|
|
533
|
+
if debug:
|
|
534
|
+
self.console.print(f"{MSG.DEBUG}Target information: {self.target}")
|
|
535
|
+
|
|
536
|
+
# Read the channels data
|
|
537
|
+
self.data = Data(
|
|
538
|
+
channel=self.channel,
|
|
539
|
+
level=self.level,
|
|
540
|
+
source_path=self.pdsLabel.parent,
|
|
541
|
+
file_obs=label.getElementsByTagName("File_Area_Observational"),
|
|
542
|
+
imaging=label.getElementsByTagName("img:Imaging"),
|
|
543
|
+
geometry=label.getElementsByTagName("geom:Geometry"),
|
|
544
|
+
debug=debug,
|
|
545
|
+
verbose=verbose,
|
|
546
|
+
console=self.console,
|
|
547
|
+
)
|
|
548
|
+
|
|
549
|
+
@property
|
|
550
|
+
def lvid(self) -> str:
|
|
551
|
+
"""Returns the LIDVID of the SIMBIO-SYS file.
|
|
552
|
+
|
|
553
|
+
Returns:
|
|
554
|
+
str: The LIDVID of the SIMBIO-SYS file.
|
|
555
|
+
"""
|
|
556
|
+
|
|
557
|
+
return f"{self.lid}::{self.version}"
|
|
558
|
+
|
|
559
|
+
def label_name(self, file_path: Path) -> None:
|
|
560
|
+
if file_path.is_dir():
|
|
561
|
+
lst = list(file_path.glob("*.lblx"))
|
|
562
|
+
if len(lst) == 0:
|
|
563
|
+
# self.console.print(f"[red]Error:[/red] No .lblx files found in directory {file_path}.")
|
|
564
|
+
raise FileNotFoundError(
|
|
565
|
+
f"No .lblx files found in directory {file_path}."
|
|
566
|
+
)
|
|
567
|
+
elif len(lst) > 1:
|
|
568
|
+
# self.console.print(f"[red]Error:[/red] Multiple .lblx files found in directory {file_path}. Please specify a single file.")
|
|
569
|
+
raise FileExistsError(
|
|
570
|
+
f"Multiple .lblx files found in directory {file_path}. Please specify a single file."
|
|
571
|
+
)
|
|
572
|
+
else:
|
|
573
|
+
return lst[0]
|
|
574
|
+
elif file_path.is_file():
|
|
575
|
+
if not file_path.suffix == ".lblx":
|
|
576
|
+
self.console.print(
|
|
577
|
+
f"{MSG.ERROR}The file {file_path} does not have a .lblx extension."
|
|
578
|
+
)
|
|
579
|
+
parts = file_path.stem.split("_")
|
|
580
|
+
pdsLabel = f"{('_').join(parts[:-5])}__{'_'.join(parts[-2:])}.lblx"
|
|
581
|
+
return file_path.parent.joinpath(pdsLabel)
|
|
582
|
+
else:
|
|
583
|
+
return file_path
|
|
584
|
+
|
|
585
|
+
def __str__(self) -> str:
|
|
586
|
+
return f"SimbioReader(channel={self.channel}, level={self.level}, lid={self.lid}, version={self.version})"
|
|
587
|
+
|
|
588
|
+
def __repr__(self) -> str:
|
|
589
|
+
return self.__str__()
|
|
590
|
+
|
|
591
|
+
def show(self) -> Panel:
|
|
592
|
+
dt = Table.grid()
|
|
593
|
+
dt.add_column(style="yellow", justify="right")
|
|
594
|
+
dt.add_column()
|
|
595
|
+
dt.add_column(style="cyan", justify="left")
|
|
596
|
+
|
|
597
|
+
sep = " = "
|
|
598
|
+
dt.add_row("Channel", sep, self.channel.upper())
|
|
599
|
+
dt.add_row("Processing Level", sep, self.level)
|
|
600
|
+
dt.add_row("Mission Phase", sep, self.phaseName)
|
|
601
|
+
dt.add_row("Logical Identifier", sep, self.lid)
|
|
602
|
+
dt.add_row("Version", sep, self.version)
|
|
603
|
+
dt.add_row("Title", sep, self.title)
|
|
604
|
+
dt.add_row("Data Model Version", sep, self.dataModelVersion)
|
|
605
|
+
dt.add_row("Observation Start Time", sep, self.startTime.isoformat())
|
|
606
|
+
dt.add_row("Observation Stop Time", sep, self.stopTime.isoformat())
|
|
607
|
+
dt.add_row("Spacecraft Clock Start Count", sep, self.start_scet)
|
|
608
|
+
dt.add_row("Spacecraft Clock Stop Count", sep, self.stop_scet)
|
|
609
|
+
|
|
610
|
+
return Panel(dt, title="SimbioReader Info", border_style="green", expand=False)
|
|
611
|
+
|
|
612
|
+
def summary(self) -> Panel:
|
|
613
|
+
filters=[]
|
|
614
|
+
for item in self.data.filters:
|
|
615
|
+
disp=getattr(self.data,f'filter_{item.lower()}')
|
|
616
|
+
filters.append(disp.show())
|
|
617
|
+
col = Columns(
|
|
618
|
+
[self.show(), self.target.show(), self.data.hk.show(),*filters], expand=True
|
|
619
|
+
)
|
|
620
|
+
|
|
621
|
+
return Panel(
|
|
622
|
+
col, title=f"SimbioReader Summary: {self.pdsLabel.stem}", border_style="green", expand=False
|
|
623
|
+
)
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
def __getattr__(self, name:str):
|
|
628
|
+
if name.startswith('segment') and self.channel in ['stc','hric']:
|
|
629
|
+
self.console.print(f"{MSG.ERROR}Attribute [blue]{name}[/blue] not available. The current Channel id is {self.channel.upper()}.")
|
|
630
|
+
elif name.startswith('segment') and self.channel == 'vihi':
|
|
631
|
+
self.console.print(f"{MSG.ERROR}Segment {name} not available.")
|
|
632
|
+
elif name.startswith('filter') and self.channel == 'vihi':
|
|
633
|
+
self.console.print(f"{MSG.ERROR}Attribute [blue]{name}[/blue] not available. The current Channel id is {self.channel.upper()}.")
|
|
634
|
+
|
|
635
|
+
return None
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
def savePreview(self,img_type:str='png',quality:int=100, outFolder:Path=None, template:Path=None, description:str = "This is the first version.")->str|None:
|
|
641
|
+
"""Saves a preview image of the loaded data.
|
|
642
|
+
|
|
643
|
+
Args:
|
|
644
|
+
img_type: The desired image format. Supported formats are 'png', 'tif', and 'jpg'. Defaults to 'png'.
|
|
645
|
+
quality: The quality of the saved image (applicable for 'png' and 'jpg' formats only). Ranges from 0 (worst) to 100 (best). Defaults to 100.
|
|
646
|
+
out_folder: The output folder path where the preview image will be saved. Defaults to the same directory as the original Simbio file.
|
|
647
|
+
template: name of the PDS4 template that will be generated. If None no template will be written. If the template is not none the img_type
|
|
648
|
+
is forced to png
|
|
649
|
+
|
|
650
|
+
Raises:
|
|
651
|
+
ValueError: If the provided image format is not supported.
|
|
652
|
+
TypeError: If the `out_folder` argument is not a `Path` object.
|
|
653
|
+
"""
|
|
654
|
+
if template:
|
|
655
|
+
img_type = 'png'
|
|
656
|
+
if outFolder is None:
|
|
657
|
+
dest = self.pdsLabel.parent
|
|
658
|
+
else:
|
|
659
|
+
if type(outFolder) is not Path:
|
|
660
|
+
outFolder = Path(outFolder)
|
|
661
|
+
dest=outFolder
|
|
662
|
+
if dest.exists() is False:
|
|
663
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
664
|
+
ret=self.data.savePreview(img_type=img_type,quality=quality,outFolder=dest)
|
|
665
|
+
if template:
|
|
666
|
+
if not isinstance(template,Path):
|
|
667
|
+
template = Path(template)
|
|
668
|
+
if not template.exists():
|
|
669
|
+
raise FileNotFoundError(f"The template {template.name} was not found")
|
|
670
|
+
new_filename=gen_filename(self.pdsLabel)
|
|
671
|
+
new_label=dest.joinpath(new_filename).with_suffix(".lblx")
|
|
672
|
+
# template.rename(new_label)
|
|
673
|
+
# from xml.dom.minidom import parse, parseString, Element
|
|
674
|
+
tree = parse(template.as_posix())
|
|
675
|
+
for item in tree.getElementsByTagName("File_Area_Browse"):
|
|
676
|
+
item.parentNode.removeChild(item)
|
|
677
|
+
|
|
678
|
+
if 'cal' in Path(new_filename).stem:
|
|
679
|
+
calib=True
|
|
680
|
+
else:
|
|
681
|
+
calib=False
|
|
682
|
+
new_lid=lidUpdate(tree, new_label,calib=calib)
|
|
683
|
+
creatTime=datetime.now()
|
|
684
|
+
updateXML(tree, "modification_date", creatTime.strftime("%Y-%m-%d"), idx=0)
|
|
685
|
+
file_version=new_filename.split('__')[1].split('.')[0]
|
|
686
|
+
file_version=file_version.replace('_','.')
|
|
687
|
+
updateXML(tree,"version_id",file_version, idx=0)
|
|
688
|
+
updateXML(tree,"version_id",file_version, idx=1)
|
|
689
|
+
updateXML(tree,"description",description, idx=0)
|
|
690
|
+
lvidUpdate(tree,new_label, file_version)
|
|
691
|
+
ret=self.data.savePreview(img_type=img_type,quality=quality,outFolder=dest, tree=tree)
|
|
692
|
+
br=getElement(tree,"Product_Browse")
|
|
693
|
+
for item in ret:
|
|
694
|
+
br.appendChild(item)
|
|
695
|
+
|
|
696
|
+
dom2 = parseString(pretty_print(tree))
|
|
697
|
+
with open(new_label, "w") as xmlFile:
|
|
698
|
+
dom2.writexml(xmlFile, encoding="utf-8")
|
|
699
|
+
return f"{new_lid}::{file_version}"
|
|
700
|
+
else:
|
|
701
|
+
ret=self.data.savePreview(img_type=img_type,quality=quality,outFolder=dest)
|
|
702
|
+
|
|
703
|
+
def image(self)->im:
|
|
704
|
+
"""Returns a PIL Image object representing the loaded image data.
|
|
705
|
+
|
|
706
|
+
This method returns a Pillow (PIL Fork) Image object containing the image data
|
|
707
|
+
loaded from the Simbio file. The image data is assumed to be a single-band
|
|
708
|
+
or multi-band array, depending on the channel type.
|
|
709
|
+
|
|
710
|
+
Returns:
|
|
711
|
+
A PIL Image object representing the loaded image data.
|
|
712
|
+
|
|
713
|
+
Raises:
|
|
714
|
+
ValueError: If the loaded image data cannot be converted to a PIL Image
|
|
715
|
+
object due to unsupported data type or shape.
|
|
716
|
+
"""
|
|
717
|
+
data = im.fromarray(self.img)
|
|
718
|
+
return data
|
|
719
|
+
|
|
@@ -87,7 +87,7 @@ def snake_case(text)->str:
|
|
|
87
87
|
text.replace('-', ' '))).split()).lower()
|
|
88
88
|
|
|
89
89
|
|
|
90
|
-
def gen_filename(old_filename:Path)->
|
|
90
|
+
def gen_filename(old_filename:Path)->Path:
|
|
91
91
|
new_filename=copy.copy(old_filename.stem)
|
|
92
92
|
# new_filename=new_filename.split('__')[0]
|
|
93
93
|
if 'raw' in new_filename:
|
|
@@ -133,7 +133,7 @@ def new_lvid(old:str, file_name: Path, file_version:str):
|
|
|
133
133
|
parts=old.split('::')
|
|
134
134
|
new_main=parts[0].split(':')
|
|
135
135
|
if 'cal' in file_name.stem:
|
|
136
|
-
new_main[-2]='
|
|
136
|
+
new_main[-2]='data_calibrated'
|
|
137
137
|
newLVID=f"{':'.join(new_main[0:-1])}:{file_name.stem.split('__')[0]}::{file_version}"
|
|
138
138
|
return newLVID
|
|
139
139
|
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: SimbioReader
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Python Reader for the data from SIMBIO-SYS instrument suite on-board the ESA mission BepiColombo
|
|
5
5
|
Author-email: Romolo Politi <Romolo.Politi@inaf.it>
|
|
6
|
-
License: GNU GPL ver3
|
|
7
6
|
Project-URL: Repository, https://github.com/SIMBIO-SYS/SimbioReader
|
|
8
7
|
Keywords: data reader,Space Mission,BepiColombo,SIMBIO-SYS
|
|
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
|
|
9
12
|
Classifier: Development Status :: 2 - Pre-Alpha
|
|
10
|
-
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
11
13
|
Requires-Python: >=3.11
|
|
12
14
|
Description-Content-Type: text/markdown
|
|
13
15
|
License-File: LICENSE
|
|
@@ -3,6 +3,7 @@ README.md
|
|
|
3
3
|
pyproject.toml
|
|
4
4
|
src/SimbioReader/__init__.py
|
|
5
5
|
src/SimbioReader/__main__.py
|
|
6
|
+
src/SimbioReader/cli.py
|
|
6
7
|
src/SimbioReader/constants.py
|
|
7
8
|
src/SimbioReader/exceptions.py
|
|
8
9
|
src/SimbioReader/filters.py
|
|
@@ -10,6 +11,7 @@ src/SimbioReader/filters_tools.py
|
|
|
10
11
|
src/SimbioReader/infocli.py
|
|
11
12
|
src/SimbioReader/phases.py
|
|
12
13
|
src/SimbioReader/simbioInfo.py
|
|
14
|
+
src/SimbioReader/sr.py
|
|
13
15
|
src/SimbioReader/subphases.py
|
|
14
16
|
src/SimbioReader/tests.py
|
|
15
17
|
src/SimbioReader/tools.py
|
|
@@ -21,4 +23,5 @@ src/SimbioReader.egg-info/entry_points.txt
|
|
|
21
23
|
src/SimbioReader.egg-info/requires.txt
|
|
22
24
|
src/SimbioReader.egg-info/top_level.txt
|
|
23
25
|
test/test_db.py
|
|
26
|
+
test/test_new_format.py
|
|
24
27
|
test/test_tools.py
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
from SimbioReader.sr import SimbioReader
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
def test_simbio_reader_init_file_dat():
|
|
6
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_001/sim_cal_sc_stc_cruise_ico11_2024-04-08_001_winx_internal__0_1.dat")
|
|
7
|
+
reader = SimbioReader(file_path=file_path)
|
|
8
|
+
assert reader.pdsLabel.name == "sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx"
|
|
9
|
+
|
|
10
|
+
def test_simbio_reader_init_file_lblx():
|
|
11
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_001/sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx")
|
|
12
|
+
reader = SimbioReader(file_path=file_path)
|
|
13
|
+
assert reader.pdsLabel.name == "sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx"
|
|
14
|
+
|
|
15
|
+
def test_simbio_reader_init_file_lblx_notexist():
|
|
16
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_002/sim_cal_sc_stc_cruise_ico11_2024-04-08_003__0_1.lblx")
|
|
17
|
+
with pytest.raises(FileNotFoundError,match="does not exist"):
|
|
18
|
+
reader = SimbioReader(file_path=file_path)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_simbio_reader_init_folder():
|
|
22
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_001")
|
|
23
|
+
reader = SimbioReader(file_path=file_path)
|
|
24
|
+
assert reader.pdsLabel.name == "sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx"
|
|
25
|
+
|
|
26
|
+
def test_simbio_reader_init_folder_multi_lblx():
|
|
27
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_002")
|
|
28
|
+
with pytest.raises(FileExistsError,match="Multiple .lblx files found in directory"):
|
|
29
|
+
reader = SimbioReader(file_path=file_path)
|
|
30
|
+
|
|
31
|
+
def test_simbio_reader_init_channel():
|
|
32
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_001/sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx")
|
|
33
|
+
reader = SimbioReader(file_path=file_path)
|
|
34
|
+
assert reader.channel == "stc"
|
|
35
|
+
|
|
36
|
+
def test_simbio_reader_init_unknown_channel():
|
|
37
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_002/sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx")
|
|
38
|
+
with pytest.raises(ValueError,match="Unknown channel 'unknown' found in label."):
|
|
39
|
+
reader = SimbioReader(file_path=file_path)
|
|
40
|
+
|
|
41
|
+
def test_simbio_reader_init_level():
|
|
42
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_001/sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx")
|
|
43
|
+
reader = SimbioReader(file_path=file_path)
|
|
44
|
+
assert reader.level == "calibrated"
|
|
45
|
+
|
|
46
|
+
def test_simbio_reader_init_lid():
|
|
47
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_001/sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx")
|
|
48
|
+
reader = SimbioReader(file_path=file_path)
|
|
49
|
+
assert reader.lid == "urn:esa:psa:bc_mpo_simbio-sys:data_calibrated:sim_cal_sc_stc_cruise_ico11_2024-04-08_001"
|
|
50
|
+
|
|
51
|
+
def test_simbio_reader_init_version():
|
|
52
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_001/sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx")
|
|
53
|
+
reader = SimbioReader(file_path=file_path)
|
|
54
|
+
assert reader.version == "0.1"
|
|
55
|
+
|
|
56
|
+
def test_simbio_reader_init_title():
|
|
57
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_001/sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx")
|
|
58
|
+
reader = SimbioReader(file_path=file_path)
|
|
59
|
+
assert reader.title == "BEPICOLOMBO MPO SIMBIO-SYS MERCURY ORBIT STC CALIBRATED DATA PRODUCT"
|
|
60
|
+
|
|
61
|
+
def test_simbio_reader_init_lvid():
|
|
62
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_001/sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx")
|
|
63
|
+
reader = SimbioReader(file_path=file_path)
|
|
64
|
+
assert reader.lvid == "urn:esa:psa:bc_mpo_simbio-sys:data_calibrated:sim_cal_sc_stc_cruise_ico11_2024-04-08_001::0.1"
|
|
65
|
+
|
|
66
|
+
def test_simbio_reader_init_datamodel_version():
|
|
67
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_001/sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx")
|
|
68
|
+
reader = SimbioReader(file_path=file_path)
|
|
69
|
+
assert reader.dataModelVersion == "1.22.0.0"
|
|
70
|
+
|
|
71
|
+
def test_simbio_reader_init_start_stop_time():
|
|
72
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_001/sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx")
|
|
73
|
+
reader = SimbioReader(file_path=file_path)
|
|
74
|
+
assert reader.startTime.isoformat() == "2024-04-08T01:05:18.055390+00:00"
|
|
75
|
+
assert reader.stopTime.isoformat() == "2024-04-08T01:05:18.055390+00:00"
|
|
76
|
+
|
|
77
|
+
def test_simbio_reader_init_start_stop_scet():
|
|
78
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_001/sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx")
|
|
79
|
+
reader = SimbioReader(file_path=file_path)
|
|
80
|
+
assert reader.start_scet == "1/0777258316:00904"
|
|
81
|
+
assert reader.stop_scet == "1/0777258316:00904"
|
|
82
|
+
|
|
83
|
+
def test_simbio_reader_init_target():
|
|
84
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_001/sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx")
|
|
85
|
+
reader = SimbioReader(file_path=file_path)
|
|
86
|
+
assert reader.target.name == "MERCURY"
|
|
87
|
+
assert reader.target.target_type == "Planet"
|
|
88
|
+
|
|
89
|
+
def test_simbio_reader_init_target_str():
|
|
90
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_001/sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx")
|
|
91
|
+
reader = SimbioReader(file_path=file_path)
|
|
92
|
+
assert str(reader.target) == "Target(name=MERCURY, type=Planet)"
|
|
93
|
+
|
|
94
|
+
# temporary
|
|
95
|
+
def test_simbio_reader_init_files():
|
|
96
|
+
file_path = Path("test/data/sim_cal_stc_cruise_ico11_2024-04-08_001/sim_cal_sc_stc_cruise_ico11_2024-04-08_001__0_1.lblx")
|
|
97
|
+
reader = SimbioReader(file_path=file_path)
|
|
98
|
+
assert reader.data.items_number == 4
|
|
99
|
+
|
|
@@ -13,7 +13,7 @@ def test_filename_cal():
|
|
|
13
13
|
|
|
14
14
|
def test_lvid():
|
|
15
15
|
oldLVID="urn:esa:psa:bc_mpo_sim:data_raw:sim_raw_sc_hric_template::0.1"
|
|
16
|
-
file_name=Path("
|
|
16
|
+
file_name=Path("sim_cal_sc_hric_cruise_cruise_2021-04-24_001_cust0_internal__0_1.dat")
|
|
17
17
|
file_version='0.1'
|
|
18
18
|
newLVID=new_lvid(oldLVID, file_name, file_version)
|
|
19
|
-
assert newLVID == "urn:esa:psa:bc_mpo_sim:
|
|
19
|
+
assert newLVID == "urn:esa:psa:bc_mpo_sim:data_calibrated:sim_cal_sc_hric_cruise_cruise_2021-04-24_001_cust0_internal::0.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|