h5yaml 0.1.1__py3-none-any.whl → 0.2.1__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.
@@ -0,0 +1,36 @@
1
+ # YAML
2
+ #
3
+ # This file is part of Python package: `h5yaml`
4
+ #
5
+ # https://github.com/rmvanhees/pyxarr.git
6
+ #
7
+ # Copyright (c) 2025 - R.M. van Hees (SRON)
8
+ # All rights reserved.
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
21
+ #
22
+ stats_dtype:
23
+ time:
24
+ - u8
25
+ - seconds since 1970-01-01T00:00:00
26
+ - timestamp
27
+ index: [u2, '1', index]
28
+ tbl_id: [u1, '1', binning id]
29
+ saa: [u1, '1', saa-flag]
30
+ coad: [u1, '1', co-addings]
31
+ texp: [f4, ms, exposure time]
32
+ lat: [f4, degree, latitude]
33
+ lon: [f4, degree, longitude]
34
+ avg: [f4, '1', '$S - S_{ref}$']
35
+ unc: [f4, '1', '\u03c3($S - S_{ref}$)']
36
+ dark_offs: [f4, '1', dark-offset]
@@ -1,20 +1,32 @@
1
1
  # YAML
2
2
  #
3
- # Configuration file to test the implementation of classes H5Yaml and NcYaml
3
+ # This file is part of Python package: `h5yaml`
4
4
  #
5
- # This file is part of h5_yaml:
6
- # https://github.com/rmvanhees/h5_yaml.git
5
+ # https://github.com/rmvanhees/pyxarr.git
7
6
  #
8
- # Copyright (c) 2025 SRON
9
- # All Rights Reserved
7
+ # Copyright (c) 2025 - R.M. van Hees (SRON)
8
+ # All rights reserved.
10
9
  #
11
- # License: BSD-3-Clause
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
12
21
  #
13
22
  # Define groups
14
23
  groups:
15
24
  - group_00
16
25
  - group_01
17
26
  - group_02
27
+ - group_03
28
+ - processing_control
29
+ - /processing_control/input_parameters
18
30
 
19
31
  # Define dimensions
20
32
  # Note dimensions with an attribute 'long_name' will also be generated as variable
@@ -28,9 +40,14 @@ dimensions:
28
40
  column:
29
41
  _dtype: u2
30
42
  _size: 640
43
+ _range: [0, 640, 1]
31
44
  row:
32
45
  _dtype: u2
33
46
  _size: 512
47
+ /group_03/viewport:
48
+ _dtype: str
49
+ _size: 5
50
+ _values: ['-50', '-20', '+0', '+20', '+50']
34
51
  time:
35
52
  _dtype: f8
36
53
  _size: 0
@@ -66,6 +83,7 @@ compounds:
66
83
 
67
84
  # Define variables
68
85
  variables:
86
+ # ---------- GROUP 00 ----------
69
87
  /group_00/detector_images:
70
88
  _dtype: u2
71
89
  _dims: [number_of_images, column, row]
@@ -75,6 +93,27 @@ variables:
75
93
  units: '1'
76
94
  valid_min: 0
77
95
  valid_max: 65534
96
+ /group_00/detector_images_chunked:
97
+ _dtype: u2
98
+ _dims: [number_of_images, column, row]
99
+ _FillValue: 65535
100
+ _chunks: [1, 640, 512]
101
+ long_name: Detector pixel values
102
+ comment: unbinned full-frame data
103
+ units: '1'
104
+ valid_min: 0
105
+ valid_max: 65534
106
+ /group_00/detector_images_autochunk:
107
+ _dtype: u2
108
+ _dims: [number_of_images, column, row]
109
+ _chunks: True
110
+ _FillValue: 65535
111
+ long_name: Detector pixel values
112
+ comment: unbinned full-frame data
113
+ units: '1'
114
+ valid_min: 0
115
+ valid_max: 65534
116
+ # ---------- GROUP 01 ----------
78
117
  /group_01/detector_images:
79
118
  _dtype: u2
80
119
  _dims: [number_of_images, samples_per_image]
@@ -85,10 +124,21 @@ variables:
85
124
  units: '1'
86
125
  valid_min: 0
87
126
  valid_max: 65534
127
+ /group_01/contiguous_image:
128
+ _dtype: u2
129
+ _dims: [row, column]
130
+ _chunks: "contiguous"
131
+ _FillValue: 65535
132
+ long_name: Detector pixel values
133
+ comment: contiguous dataset
134
+ units: '1'
135
+ valid_min: 0
136
+ valid_max: 65534
88
137
  /group_01/stats:
89
138
  _dtype: stats_dtype
90
139
  _dims: [time]
91
140
  comment: detector map statistics
141
+ # ---------- GROUP 02 ----------
92
142
  /group_02/detector_images:
93
143
  _dtype: u2
94
144
  _dims: [number_of_images]
@@ -104,3 +154,100 @@ variables:
104
154
  _vlen: True
105
155
  _dims: [time]
106
156
  comment: detector map statistics (vlen)
157
+ # ---------- GROUP 03 ----------
158
+ /group_03/ds_01:
159
+ _dtype: u1
160
+ _dims: [number_of_images]
161
+ long_name: unsigned byte dataset
162
+ units: '1'
163
+ valid_min: 0
164
+ valid_max: 255
165
+ flag_values: [1, 2, 4, 8, 16]
166
+ /group_03/ds_02:
167
+ _dtype: i1
168
+ _dims: [number_of_images]
169
+ long_name: signed byte dataset
170
+ units: '1'
171
+ valid_min: -128
172
+ valid_max: 127
173
+ /group_03/ds_03:
174
+ _dtype: u2
175
+ _dims: [number_of_images]
176
+ long_name: unsigned short dataset
177
+ units: '1'
178
+ valid_min: 0
179
+ valid_max: 1024
180
+ /group_03/ds_04:
181
+ _dtype: i2
182
+ _dims: [number_of_images]
183
+ long_name: signed short dataset
184
+ units: '1'
185
+ valid_min: -1024
186
+ valid_max: 1024
187
+ /group_03/ds_05:
188
+ _dtype: u4
189
+ _dims: [number_of_images]
190
+ long_name: unsigned int dataset
191
+ units: '1'
192
+ valid_min: 0
193
+ valid_max: 1000000
194
+ /group_03/ds_06:
195
+ _dtype: i4
196
+ _dims: [number_of_images]
197
+ long_name: signed int dataset
198
+ units: '1'
199
+ valid_min: -1000000
200
+ valid_max: 1000000
201
+ /group_03/ds_07:
202
+ _dtype: u8
203
+ _dims: [number_of_images]
204
+ long_name: unsigned long dataset
205
+ units: '1'
206
+ valid_min: 0
207
+ valid_max: 999999
208
+ /group_03/ds_08:
209
+ _dtype: i8
210
+ _dims: [number_of_images]
211
+ long_name: signed long dataset
212
+ units: '1'
213
+ valid_min: -999999
214
+ valid_max: 999999
215
+ /group_03/ds_09:
216
+ _dtype: f2
217
+ _dims: [number_of_images]
218
+ long_name: half float dataset
219
+ units: '1'
220
+ valid_min: -999.9
221
+ valid_max: 999.9
222
+ /group_03/ds_10:
223
+ _dtype: f4
224
+ _dims: [number_of_images, /group_03/viewport]
225
+ long_name: float dataset
226
+ units: '1'
227
+ valid_min: -999.9
228
+ valid_max: 999.9
229
+ /group_03/ds_11:
230
+ _dtype: f8
231
+ _dims: [number_of_images]
232
+ long_name: double dataset
233
+ units: '1'
234
+ valid_min: -999999.9
235
+ valid_max: 999999.9
236
+ /group_03/ds_12:
237
+ _dtype: complex64
238
+ _dims: [number_of_images]
239
+ long_name: complex64 dataset
240
+ valid_min: 0j
241
+ valid_max: 999999.9j
242
+ /group_03/ds_13:
243
+ _dtype: str
244
+ _dims: [number_of_images]
245
+ long_name: string dataset
246
+ /group_03/ds_14:
247
+ _dtype: str
248
+ _dims: [scalar]
249
+ long_name: scalar(str)
250
+ /group_03/ds_15:
251
+ _dtype: int
252
+ _dims: [scalar]
253
+ long_name: scalar(int)
@@ -0,0 +1,56 @@
1
+ # YAML
2
+ #
3
+ # This file is part of Python package: `h5yaml`
4
+ #
5
+ # https://github.com/rmvanhees/pyxarr.git
6
+ #
7
+ # Copyright (c) 2025 - R.M. van Hees (SRON)
8
+ # All rights reserved.
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
21
+ #
22
+ # Define dimensions
23
+ # Note dimensions with an attribute 'long_name' will also be generated as variable
24
+ # Define groups
25
+ groups:
26
+ - group_00
27
+
28
+ dimensions:
29
+ number_of_images:
30
+ _dtype: u2
31
+ _size: 0
32
+ time:
33
+ _dtype: f8
34
+ _size: 0
35
+ _FillValue: -32767
36
+ long_name: Attitude sample time (seconds of day)
37
+ calendar: proleptic_gregorian
38
+ units: seconds since %Y-%m-%d %H:%M:%S
39
+ valid_min: 0
40
+ valid_max: 92400
41
+
42
+ # Define compound types
43
+ # - compound elements must have a data-type, and can have a unit and long_name
44
+ compounds:
45
+ - h5_compound.yaml
46
+ - h5_nocompound.yaml
47
+
48
+ # Define variables
49
+ variables:
50
+ ds_01:
51
+ _dtype: f8
52
+ _dims: [time, number_of_images]
53
+ long_name: double dataset
54
+ units: '1'
55
+ valid_min: -999999.9
56
+ valid_max: 999999.9
@@ -1,20 +1,32 @@
1
1
  # YAML
2
2
  #
3
- # Configuration file to test the implementation of classes H5Yaml and NcYaml
3
+ # This file is part of Python package: `h5yaml`
4
4
  #
5
- # This file is part of h5_yaml:
6
- # https://github.com/rmvanhees/h5_yaml.git
5
+ # https://github.com/rmvanhees/pyxarr.git
7
6
  #
8
- # Copyright (c) 2025 SRON
9
- # All Rights Reserved
7
+ # Copyright (c) 2025 - R.M. van Hees (SRON)
8
+ # All rights reserved.
10
9
  #
11
- # License: BSD-3-Clause
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
12
21
  #
13
22
  # Define groups
14
23
  groups:
15
24
  - group_00
16
25
  - group_01
17
26
  - group_02
27
+ - group_03
28
+ - processing_control
29
+ - /processing_control/input_parameters
18
30
 
19
31
  # Define dimensions
20
32
  # Note dimensions with an attribute 'long_name' will also be generated as variable
@@ -28,9 +40,14 @@ dimensions:
28
40
  column:
29
41
  _dtype: u2
30
42
  _size: 640
43
+ _range: [0, 640, 1]
31
44
  row:
32
45
  _dtype: u2
33
46
  _size: 512
47
+ /group_03/viewport:
48
+ _dtype: str
49
+ _size: 5
50
+ _values: ['-50', '-20', '+0', '+20', '+50']
34
51
  time:
35
52
  _dtype: f8
36
53
  _size: 0
@@ -62,6 +79,7 @@ compounds:
62
79
 
63
80
  # Define variables
64
81
  variables:
82
+ # ---------- GROUP 00 ----------
65
83
  /group_00/detector_images:
66
84
  _dtype: u2
67
85
  _dims: [number_of_images, column, row]
@@ -71,6 +89,17 @@ variables:
71
89
  units: '1'
72
90
  valid_min: 0
73
91
  valid_max: 65534
92
+ /group_00/detector_images_chunked:
93
+ _dtype: u2
94
+ _dims: [number_of_images, column, row]
95
+ _FillValue: 65535
96
+ _chunks: [1, 640, 512]
97
+ long_name: Detector pixel values
98
+ comment: unbinned full-frame data
99
+ units: '1'
100
+ valid_min: 0
101
+ valid_max: 65534
102
+ # ---------- GROUP 01 ----------
74
103
  /group_01/detector_images:
75
104
  _dtype: u2
76
105
  _dims: [number_of_images, samples_per_image]
@@ -81,10 +110,21 @@ variables:
81
110
  units: '1'
82
111
  valid_min: 0
83
112
  valid_max: 65534
113
+ /group_01/contiguous_image:
114
+ _dtype: u2
115
+ _dims: [row, column]
116
+ _chunks: "contiguous"
117
+ _FillValue: 65535
118
+ long_name: Detector pixel values
119
+ comment: contiguous dataset
120
+ units: '1'
121
+ valid_min: 0
122
+ valid_max: 65534
84
123
  /group_01/stats:
85
124
  _dtype: stats_dtype
86
125
  _dims: [time]
87
126
  comment: detector map statistics
127
+ # ---------- GROUP 02 ----------
88
128
  /group_02/detector_images:
89
129
  _dtype: u2
90
130
  _dims: [number_of_images]
@@ -95,3 +135,100 @@ variables:
95
135
  units: '1'
96
136
  valid_min: 0
97
137
  valid_max: 65534
138
+ # ---------- GROUP 03 ----------
139
+ /group_03/ds_01:
140
+ _dtype: u1
141
+ _dims: [number_of_images]
142
+ long_name: unsigned byte dataset
143
+ units: '1'
144
+ valid_min: 0
145
+ valid_max: 255
146
+ flag_values: [1, 2, 4, 8, 16]
147
+ /group_03/ds_02:
148
+ _dtype: i1
149
+ _dims: [number_of_images]
150
+ long_name: signed byte dataset
151
+ units: '1'
152
+ valid_min: -128
153
+ valid_max: 127
154
+ /group_03/ds_03:
155
+ _dtype: u2
156
+ _dims: [number_of_images]
157
+ long_name: unsigned short dataset
158
+ units: '1'
159
+ valid_min: 0
160
+ valid_max: 1024
161
+ /group_03/ds_04:
162
+ _dtype: i2
163
+ _dims: [number_of_images]
164
+ long_name: signed short dataset
165
+ units: '1'
166
+ valid_min: -1024
167
+ valid_max: 1024
168
+ /group_03/ds_05:
169
+ _dtype: u4
170
+ _dims: [number_of_images]
171
+ long_name: unsigned int dataset
172
+ units: '1'
173
+ valid_min: 0
174
+ valid_max: 1000000
175
+ /group_03/ds_06:
176
+ _dtype: i4
177
+ _dims: [number_of_images]
178
+ long_name: signed int dataset
179
+ units: '1'
180
+ valid_min: -1000000
181
+ valid_max: 1000000
182
+ /group_03/ds_07:
183
+ _dtype: u8
184
+ _dims: [number_of_images]
185
+ long_name: unsigned long dataset
186
+ units: '1'
187
+ valid_min: 0
188
+ valid_max: 999999
189
+ /group_03/ds_08:
190
+ _dtype: i8
191
+ _dims: [number_of_images]
192
+ long_name: signed long dataset
193
+ units: '1'
194
+ valid_min: -999999
195
+ valid_max: 999999
196
+ #/group_03/ds_09:
197
+ # _dtype: f2
198
+ # _dims: [number_of_images]
199
+ # long_name: half float dataset
200
+ # units: '1'
201
+ # valid_min: -999.9
202
+ # valid_max: 999.9
203
+ /group_03/ds_10:
204
+ _dtype: f4
205
+ _dims: [number_of_images, /group_03/viewport]
206
+ long_name: float dataset
207
+ units: '1'
208
+ valid_min: -999.9
209
+ valid_max: 999.9
210
+ /group_03/ds_11:
211
+ _dtype: f8
212
+ _dims: [number_of_images]
213
+ long_name: double dataset
214
+ units: '1'
215
+ valid_min: -999999.9
216
+ valid_max: 999999.9
217
+ #/group_03/ds_12:
218
+ # _dtype: complex64
219
+ # _dims: [number_of_images]
220
+ # long_name: complex64 dataset
221
+ # valid_min: 0j
222
+ # valid_max: 999999.9j
223
+ /group_03/ds_13:
224
+ _dtype: str
225
+ _dims: [number_of_images]
226
+ long_name: string dataset
227
+ /group_03/ds_14:
228
+ _dtype: str
229
+ _dims: [scalar]
230
+ long_name: scalar(str)
231
+ /group_03/ds_15:
232
+ _dtype: int
233
+ _dims: [scalar]
234
+ long_name: scalar(int)
h5yaml/__init__.py ADDED
@@ -0,0 +1,21 @@
1
+ #
2
+ # This file is part of Python package: `h5yaml`
3
+ #
4
+ # https://github.com/rmvanhees/h5_yaml.git
5
+ #
6
+ # Copyright (c) 2025 - R.M. van Hees (SRON)
7
+ # All rights reserved.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+ """Necessary but empty file."""
h5yaml/conf_from_yaml.py CHANGED
@@ -1,11 +1,22 @@
1
1
  #
2
- # This file is part of h5_yaml:
3
- # https://github.com/rmvanhees/h5_yaml.git
2
+ # This file is part of Python package: `h5yaml`
4
3
  #
5
- # Copyright (c) 2025 SRON
6
- # All Rights Reserved
4
+ # https://github.com/rmvanhees/pyxarr.git
7
5
  #
8
- # License: BSD-3-Clause
6
+ # Copyright (c) 2025 - R.M. van Hees (SRON)
7
+ # All rights reserved.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
9
20
  #
10
21
  """Read settings from a YAML file."""
11
22
 
@@ -13,21 +24,18 @@ from __future__ import annotations
13
24
 
14
25
  __all__ = ["conf_from_yaml"]
15
26
 
16
- from typing import TYPE_CHECKING
27
+ from pathlib import Path
17
28
 
18
29
  import yaml
19
30
 
20
- if TYPE_CHECKING:
21
- from pathlib import Path
22
-
23
31
 
24
32
  # - main function -----------------------------------
25
- def conf_from_yaml(file_path: Path) -> dict:
33
+ def conf_from_yaml(file_path: Path | str) -> dict:
26
34
  """Read settings from a YAML file: `file_path`.
27
35
 
28
36
  Parameters
29
37
  ----------
30
- file_path : Path
38
+ file_path : Path | str
31
39
  full path of YAML file
32
40
 
33
41
  Returns
@@ -36,13 +44,16 @@ def conf_from_yaml(file_path: Path) -> dict:
36
44
  content of the configuration file
37
45
 
38
46
  """
47
+ if isinstance(file_path, str):
48
+ file_path = Path(file_path)
49
+
39
50
  if not file_path.is_file():
40
51
  raise FileNotFoundError(f"{file_path} not found")
41
52
 
42
53
  with file_path.open("r", encoding="ascii") as fid:
43
54
  try:
44
55
  settings = yaml.safe_load(fid)
45
- except yaml.YAMLError as exc:
46
- raise RuntimeError from exc
56
+ except yaml.parser.ParserError as exc:
57
+ raise RuntimeError(f"Failed to parse {file_path}") from exc
47
58
 
48
59
  return settings
h5yaml/lib/__init__.py ADDED
@@ -0,0 +1,21 @@
1
+ #
2
+ # This file is part of Python package: `h5yaml`
3
+ #
4
+ # https://github.com/rmvanhees/h5_yaml.git
5
+ #
6
+ # Copyright (c) 2025 - R.M. van Hees (SRON)
7
+ # All rights reserved.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+ """Necessary but empty file."""
@@ -0,0 +1,79 @@
1
+ #
2
+ # This file is part of Python package: `h5yaml`
3
+ #
4
+ # https://github.com/rmvanhees/pyxarr.git
5
+ #
6
+ # Copyright (c) 2025 - R.M. van Hees (SRON)
7
+ # All rights reserved.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+ """Convert values HDF5/netCDF4 attribute."""
22
+
23
+ from __future__ import annotations
24
+
25
+ __all__ = ["adjust_attr"]
26
+
27
+ import numpy as np
28
+
29
+
30
+ # - main function ------------------------------------
31
+ def adjust_attr(dtype: str, attr_key: str, attr_val: np.generic) -> np.generic:
32
+ """Return attribute converted to the same data type as its variable.
33
+
34
+ Parameters
35
+ ----------
36
+ dtype : str
37
+ numpy data-type of variable
38
+ attr_key : str
39
+ name of the attribute
40
+ attr_val : np.generic
41
+ original value of the attribute
42
+
43
+ Returns
44
+ -------
45
+ attr_val converted to dtype
46
+ """
47
+ if attr_key in ("valid_min", "valid_max", "valid_range"):
48
+ match dtype:
49
+ case "i1":
50
+ res = np.int8(attr_val)
51
+ case "i2":
52
+ res = np.int16(attr_val)
53
+ case "i4":
54
+ res = np.int32(attr_val)
55
+ case "i8":
56
+ res = np.int64(attr_val)
57
+ case "u1":
58
+ res = np.uint8(attr_val)
59
+ case "u2":
60
+ res = np.uint16(attr_val)
61
+ case "u4":
62
+ res = np.uint32(attr_val)
63
+ case "u8":
64
+ res = np.uint64(attr_val)
65
+ case "f2":
66
+ res = np.float16(attr_val)
67
+ case "f4":
68
+ res = np.float32(attr_val)
69
+ case "f8":
70
+ res = np.float64(attr_val)
71
+ case _:
72
+ res = attr_val
73
+
74
+ return res
75
+
76
+ if attr_key == "flag_values":
77
+ return np.array(attr_val, dtype="u1")
78
+
79
+ return attr_val