aresys_io 0.0.0.dev0__py3-none-any.whl

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.
Files changed (47) hide show
  1. aresys_io/__init__.py +6 -0
  2. aresys_io/core/__init__.py +8 -0
  3. aresys_io/core/debugio.py +65 -0
  4. aresys_io/core/parsing.py +134 -0
  5. aresys_io/core/raster_io.py +618 -0
  6. aresys_io/product/__init__.py +8 -0
  7. aresys_io/product/metadata/__init__.py +12 -0
  8. aresys_io/product/metadata/channel.py +933 -0
  9. aresys_io/product/metadata/create_attitude.py +37 -0
  10. aresys_io/product/metadata/create_orbit.py +30 -0
  11. aresys_io/product/metadata/elements.py +795 -0
  12. aresys_io/product/metadata/io.py +85 -0
  13. aresys_io/product/metadata/models/__init__.py +90 -0
  14. aresys_io/product/metadata/models/aresys_generic_metadata.py +214 -0
  15. aresys_io/product/metadata/models/aresys_types.py +2901 -0
  16. aresys_io/product/metadata/polynomials.py +420 -0
  17. aresys_io/product/metadata/raster_io_from_metadata.py +304 -0
  18. aresys_io/product/metadata/translate.py +1880 -0
  19. aresys_io/product/pf/__init__.py +9 -0
  20. aresys_io/product/pf/channel_iteration.py +134 -0
  21. aresys_io/product/pf/layout.py +160 -0
  22. aresys_io/product/pf/manifest.py +97 -0
  23. aresys_io/product/pf/product_folder.py +571 -0
  24. aresys_io/product/point_target/__init__.py +7 -0
  25. aresys_io/product/point_target/nominal_point_targets.py +94 -0
  26. aresys_io/product/point_target/point_target_binary.py +442 -0
  27. aresys_io/sarsystem/__init__.py +16 -0
  28. aresys_io/sarsystem/models/__init__.py +56 -0
  29. aresys_io/sarsystem/models/swath_parameter_table.py +118 -0
  30. aresys_io/sarsystem/models/time_line_table.py +319 -0
  31. aresys_io/sarsystem/models/trajectory_file.py +333 -0
  32. aresys_io/sarsystem/sat_table.py +30 -0
  33. aresys_io/sarsystem/sat_table_read.py +82 -0
  34. aresys_io/sarsystem/swathtable.py +92 -0
  35. aresys_io/sarsystem/swathtable_read.py +41 -0
  36. aresys_io/sarsystem/swathtable_write.py +87 -0
  37. aresys_io/sarsystem/timeline_table.py +278 -0
  38. aresys_io/sarsystem/timeline_table_read.py +17 -0
  39. aresys_io/sarsystem/timeline_table_write.py +120 -0
  40. aresys_io/sarsystem/trajectory.py +355 -0
  41. aresys_io/sarsystem/trajectory_read.py +102 -0
  42. aresys_io/sarsystem/trajectory_write.py +253 -0
  43. aresys_io/sarsystem/utils.py +122 -0
  44. aresys_io-0.0.0.dev0.dist-info/METADATA +78 -0
  45. aresys_io-0.0.0.dev0.dist-info/RECORD +47 -0
  46. aresys_io-0.0.0.dev0.dist-info/WHEEL +4 -0
  47. aresys_io-0.0.0.dev0.dist-info/licenses/LICENSE.txt +21 -0
aresys_io/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ # SPDX-FileCopyrightText: Aresys S.r.l. <info@aresys.it>
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ """Aresys products I/O management package."""
5
+
6
+ __version__ = "0.0.0.dev0"
@@ -0,0 +1,8 @@
1
+ # SPDX-FileCopyrightText: Aresys S.r.l. <info@aresys.it>
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ """Core package."""
5
+
6
+ from aresys_io.core.debugio import *
7
+ from aresys_io.core.parsing import *
8
+ from aresys_io.core.raster_io import *
@@ -0,0 +1,65 @@
1
+ # SPDX-FileCopyrightText: Aresys S.r.l. <info@aresys.it>
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ """Binary debug data file management module."""
5
+
6
+ import struct
7
+ from pathlib import Path
8
+
9
+ import numpy as np
10
+
11
+ __all__ = ["read_debug"]
12
+
13
+ # The debug data file binary header is expected to be a sequence of three 32-bit integers,
14
+ # representing:
15
+ # * the cell type identifier
16
+ # * the number of samples of the data matrix
17
+ # * the number of lines of the data matrix
18
+ _HEADER_FORMAT = "iii"
19
+ _HEADER_SIZE = struct.calcsize(_HEADER_FORMAT)
20
+
21
+ _CELLTYPE_TO_DTYPE_MAP = {
22
+ 0: "float32",
23
+ 1: "complex64",
24
+ 2: "float64",
25
+ 3: "complex128",
26
+ 4: "int16",
27
+ 5: "int8",
28
+ 6: "int32",
29
+ 7: "int64",
30
+ }
31
+
32
+
33
+ def read_debug(filename: str | Path) -> np.ndarray:
34
+ """Read binary debug data file content.
35
+
36
+ Parameters
37
+ ----------
38
+ filename : str | Path
39
+ binary debug data file name
40
+
41
+ Returns
42
+ -------
43
+ np.ndarray
44
+ array containing the data read from the input binary debug data file
45
+
46
+ Raises
47
+ ------
48
+ RuntimeError
49
+ in case of invalid content cell type
50
+ """
51
+ with Path(filename).open(mode="rb") as fdesc:
52
+ header = fdesc.read(_HEADER_SIZE)
53
+
54
+ celltype, samples, lines = struct.unpack(_HEADER_FORMAT, header)
55
+
56
+ if celltype not in _CELLTYPE_TO_DTYPE_MAP:
57
+ msg = f"Unknown cell type (cell type id = {celltype})"
58
+ raise RuntimeError(msg)
59
+
60
+ dtype = _CELLTYPE_TO_DTYPE_MAP[celltype]
61
+
62
+ if samples == 0 or lines == 0:
63
+ return np.empty((lines, samples), dtype)
64
+
65
+ return np.fromfile(fdesc, dtype).reshape((lines, samples))
@@ -0,0 +1,134 @@
1
+ # SPDX-FileCopyrightText: Aresys S.r.l. <info@aresys.it>
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ """Parsing.
5
+
6
+ Numpy scalar types (float32, float64, int32, int64) are supported in both
7
+ parsing and serialization. When serializing, values assigned to XML ``int``
8
+ fields are always written as plain integers (e.g. ``7``, never ``7.0``);
9
+ assigning a float with a fractional part to an ``int`` field raises
10
+ ``ValueError``. Values assigned to XML ``float`` fields are written using
11
+ their natural float representation.
12
+ """
13
+
14
+ from typing import Any, TypeVar
15
+
16
+ import numpy as np
17
+ import xsdata.exceptions
18
+ from xsdata.formats.converter import Converter, converter
19
+ from xsdata.formats.dataclass.context import XmlContext
20
+ from xsdata.formats.dataclass.parsers import XmlParser
21
+ from xsdata.formats.dataclass.parsers.config import ParserConfig
22
+ from xsdata.formats.dataclass.serializers import XmlSerializer
23
+ from xsdata.formats.dataclass.serializers.config import SerializerConfig
24
+
25
+ __all__ = ["parse", "serialize"]
26
+
27
+
28
+ def _float_to_int_lossless(value: float) -> int:
29
+ """Convert a float to int, raising ValueError if there is any loss of precision."""
30
+ int_value = int(value)
31
+ if int_value != value:
32
+ msg = f"Cannot losslessly convert {value!r} to int: fractional part would be lost"
33
+ raise ValueError(msg)
34
+ return int_value
35
+
36
+
37
+ # DEV NOTE: two separate mechanisms are used to support numpy types during serialization.
38
+ # _NumpyConverter (below) handles *type registration*: xsdata's converter dispatch is
39
+ # value-type-based, so it never sees numpy scalars unless they are explicitly registered.
40
+ # However, at converter level the declared XML field type is not available, so the
41
+ # converter cannot distinguish "np.float64 in a float field" from "np.float64 in an int
42
+ # field". That distinction is handled by _NormalizedXmlSerializer.encode_primitive
43
+ # (below), which runs before converter dispatch and has access to var.types. The two
44
+ # mechanisms cannot be merged: _NumpyConverter cannot see the field type;
45
+ # encode_primitive cannot register new value types.
46
+ class _NormalizedXmlSerializer(XmlSerializer):
47
+ """XmlSerializer that coerces float values assigned to int-typed fields."""
48
+
49
+ @classmethod
50
+ def encode_primitive(cls, value: Any, var: Any) -> Any: # ruff: ignore[any-type]
51
+ if int in var.types and isinstance(value, (float, np.floating)):
52
+ value = _float_to_int_lossless(float(value))
53
+ return super().encode_primitive(value, var)
54
+
55
+
56
+ _CONTEXT = XmlContext()
57
+ _PARSER_CONFIGURATION = ParserConfig(fail_on_converter_warnings=True)
58
+ _PARSER = XmlParser(context=_CONTEXT, config=_PARSER_CONFIGURATION)
59
+ _SERIALIZER_CONFIGURATION = SerializerConfig(indent=" ", encoding="utf-8")
60
+ _SERIALIZER = _NormalizedXmlSerializer(context=_CONTEXT, config=_SERIALIZER_CONFIGURATION)
61
+
62
+ ModelT = TypeVar("ModelT")
63
+
64
+
65
+ class _NumpyConverter(Converter):
66
+ """Converter that normalizes numpy scalar values through a native XML type."""
67
+
68
+ def __init__(self, numpy_type: type, xml_type: type) -> None:
69
+ self._numpy_type = numpy_type
70
+ self._xml_type = xml_type
71
+ self._xml_converter = converter.type_converter(xml_type)
72
+
73
+ def deserialize(self, value: Any, **kwargs) -> Any: # ruff: ignore[missing-type-kwargs, any-type]
74
+ parsed_value = self._xml_converter.deserialize(value, **kwargs)
75
+ return self._numpy_type(parsed_value)
76
+
77
+ def serialize(self, value: Any, **kwargs) -> str: # ruff: ignore[missing-type-kwargs, any-type]
78
+ return self._xml_converter.serialize(self._xml_type(value), **kwargs)
79
+
80
+
81
+ converter.register_converter(np.float32, _NumpyConverter(np.float32, float))
82
+ converter.register_converter(np.float64, _NumpyConverter(np.float64, float))
83
+ converter.register_converter(np.int32, _NumpyConverter(np.int32, int))
84
+ converter.register_converter(np.int64, _NumpyConverter(np.int64, int))
85
+
86
+
87
+ def parse(xml_string: str, model: type[ModelT]) -> ModelT:
88
+ """Parse a string according to an XSD model.
89
+
90
+ Parameters
91
+ ----------
92
+ xml_string : str
93
+ input xml string to parse
94
+ model : Type
95
+ xsd model type
96
+
97
+ Returns
98
+ -------
99
+ ModelT
100
+ The content as a structure of type model
101
+
102
+ Raises
103
+ ------
104
+ RuntimeError
105
+ in case the xml_string is incompatible with the XSD model
106
+ """
107
+ try:
108
+ model_obj = _PARSER.from_string(xml_string, model)
109
+ except xsdata.exceptions.ParserError as exc:
110
+ msg = "Parsing error"
111
+ raise RuntimeError(msg) from exc
112
+ except TypeError as exc:
113
+ msg = "Parsing error"
114
+ raise RuntimeError(msg) from exc
115
+
116
+ return model_obj
117
+
118
+
119
+ def serialize(model: Any, **kwargs) -> str: # ruff: ignore[missing-type-kwargs, any-type]
120
+ """Serialize an XSD object to a string.
121
+
122
+ Parameters
123
+ ----------
124
+ model :
125
+ Object to serialize
126
+
127
+ kwargs are forwarded to serializer render method
128
+
129
+ Returns
130
+ -------
131
+ str
132
+ XML string
133
+ """
134
+ return _SERIALIZER.render(model, **kwargs)