xarray-selafin 0.2.1__tar.gz → 0.2.3__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,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: xarray-selafin
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary:
5
5
  Author: tomsail
6
6
  Author-email: saillour.thomas@gmail.com
@@ -10,6 +10,7 @@ Classifier: Programming Language :: Python :: 3.11
10
10
  Classifier: Programming Language :: Python :: 3.12
11
11
  Classifier: Programming Language :: Python :: 3.13
12
12
  Requires-Dist: numpy
13
+ Requires-Dist: python-serafin (>=0.2,<0.3)
13
14
  Requires-Dist: xarray
14
15
  Project-URL: Repository, https://github.com/oceanmodeling/xarray-selafin/
15
16
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "xarray-selafin"
3
- version = "0.2.1"
3
+ version = "0.2.3"
4
4
  description = ""
5
5
  authors = ["tomsail <saillour.thomas@gmail.com>", "lucduron <l.duron@cnr.tm.fr>"]
6
6
  readme = "README.md"
@@ -14,6 +14,7 @@ include = [
14
14
  python = ">=3.11"
15
15
  numpy = "*"
16
16
  xarray = "*"
17
+ python-serafin = ">=0.2,<0.3"
17
18
 
18
19
  [tool.poetry.plugins."xarray.backends"]
19
20
  selafin = "xarray_selafin.xarray_backend:SelafinBackendEntrypoint"
@@ -33,5 +34,8 @@ requires = ["poetry-core"]
33
34
  build-backend = "poetry.core.masonry.api"
34
35
 
35
36
  [tool.black]
36
- target-version = ['py37']
37
+ target-version = ['py311']
37
38
  line-length = 107
39
+
40
+ [tool.ruff.isort]
41
+ force-single-line = true
@@ -4,20 +4,26 @@ Documentation on how to implement a new backend in xarray
4
4
  * https://tutorial.xarray.dev/advanced/backends/2.Backend_with_Lazy_Loading.html
5
5
  """
6
6
  import os
7
+ import threading
7
8
  from datetime import datetime
8
9
  from datetime import timedelta
9
- import numpy as np
10
10
  from operator import attrgetter
11
- import threading
11
+
12
+ import numpy as np
12
13
  import xarray as xr
13
- from xarray.backends import BackendArray, BackendEntrypoint
14
+ from serafin import SerafinHeader
15
+ from serafin import SerafinReader
16
+ from serafin import SerafinRequestError
17
+ from serafin import SerafinWriter
18
+ from serafin.serafin import LANG
19
+ from serafin.serafin import SLF_EIT
20
+ from xarray.backends import BackendArray
21
+ from xarray.backends import BackendEntrypoint
14
22
  from xarray.core import indexing
15
23
 
16
- from xarray_selafin import Serafin
17
-
18
-
19
24
  try:
20
25
  import dask
26
+
21
27
  DASK_AVAILABLE = True
22
28
  except ImportError:
23
29
  DASK_AVAILABLE = False
@@ -40,7 +46,7 @@ def compute_duration_between_datetime(t0, time_serie):
40
46
 
41
47
 
42
48
  def read_serafin(filepath, lang):
43
- resin = Serafin.Read(filepath, lang)
49
+ resin = SerafinReader(filepath, lang)
44
50
  resin.__enter__()
45
51
  resin.read_header()
46
52
  resin.get_time()
@@ -48,7 +54,6 @@ def read_serafin(filepath, lang):
48
54
 
49
55
 
50
56
  class SelafinLazyArray(BackendArray):
51
-
52
57
  def __init__(self, filename_or_obj, shape, dtype, lock, var):
53
58
  self.filename_or_obj = filename_or_obj
54
59
  self.shape = shape
@@ -134,7 +139,6 @@ class SelafinLazyArray(BackendArray):
134
139
 
135
140
 
136
141
  class SelafinBackendEntrypoint(BackendEntrypoint):
137
-
138
142
  def open_dataset(
139
143
  self,
140
144
  filename_or_obj,
@@ -144,7 +148,7 @@ class SelafinBackendEntrypoint(BackendEntrypoint):
144
148
  # Below are custom arguments
145
149
  disable_lock=False,
146
150
  lazy_loading=True,
147
- lang=Serafin.LANG,
151
+ lang=LANG,
148
152
  # `chunks` and `cache` DO NOT go here, they are handled by xarray
149
153
  ):
150
154
  # Initialize SELAFIN reader
@@ -160,7 +164,7 @@ class SelafinBackendEntrypoint(BackendEntrypoint):
160
164
  nplan = slf.header.nb_planes
161
165
  x = slf.header.x
162
166
  y = slf.header.y
163
- vars = slf.header.var_IDs
167
+ vars = slf.header.var_ids
164
168
 
165
169
  # Create data variables
166
170
  data_vars = {}
@@ -218,7 +222,7 @@ class SelafinBackendEntrypoint(BackendEntrypoint):
218
222
 
219
223
  ds.set_close(close)
220
224
 
221
- ds.attrs["title"] = slf.header.title.decode(Serafin.SLF_EIT).strip()
225
+ ds.attrs["title"] = slf.header.title.decode(SLF_EIT).strip()
222
226
  ds.attrs["language"] = slf.header.language
223
227
  ds.attrs["float_size"] = slf.header.float_size
224
228
  ds.attrs["endian"] = slf.header.endian
@@ -228,7 +232,7 @@ class SelafinBackendEntrypoint(BackendEntrypoint):
228
232
  if not is_2d:
229
233
  ds.attrs["ikle3"] = np.reshape(slf.header.ikle, (slf.header.nb_elements, ndp3))
230
234
  ds.attrs["variables"] = {
231
- var_ID: (name.decode(Serafin.SLF_EIT).rstrip(), unit.decode(Serafin.SLF_EIT).rstrip())
235
+ var_ID: (name.decode(SLF_EIT).rstrip(), unit.decode(SLF_EIT).rstrip())
232
236
  for var_ID, name, unit in slf.header.iter_on_all_variables()
233
237
  }
234
238
  ds.attrs["date_start"] = slf.header.date
@@ -249,7 +253,6 @@ class SelafinBackendEntrypoint(BackendEntrypoint):
249
253
 
250
254
  @xr.register_dataset_accessor("selafin")
251
255
  class SelafinAccessor:
252
-
253
256
  def __init__(self, xarray_obj):
254
257
  self._ds = xarray_obj
255
258
  self._header = None
@@ -279,7 +282,7 @@ class SelafinAccessor:
279
282
 
280
283
  # Title
281
284
  title = ds.attrs.get("title", "Converted with array-serafin")
282
- header = Serafin.SerafinHeader(title)
285
+ header = SerafinHeader(title)
283
286
 
284
287
  # File precision
285
288
  float_size = ds.attrs.get("float_size", 4) # Default: single precision
@@ -311,17 +314,17 @@ class SelafinAccessor:
311
314
  header.date = DEFAULT_DATE_START
312
315
 
313
316
  # Variables
314
- header.language = ds.attrs.get("language", Serafin.LANG)
317
+ header.language = ds.attrs.get("language", LANG)
315
318
  for var in ds.data_vars:
316
319
  try:
317
320
  name, unit = ds.attrs["variables"][var]
318
321
  header.add_variable_str(var, name, unit)
319
322
  except KeyError:
320
323
  try:
321
- header.add_variable_from_ID(var)
322
- except Serafin.SerafinRequestError:
324
+ header.add_variable_from_id(var)
325
+ except SerafinRequestError:
323
326
  header.add_variable_str(var, var, "?")
324
- header.nb_var = len(header.var_IDs)
327
+ header.nb_var = len(header.var_ids)
325
328
 
326
329
  if "plan" in ds.dims: # 3D
327
330
  header.is_2d = False
@@ -376,7 +379,7 @@ class SelafinAccessor:
376
379
  """Writes header and all data frames into output file"""
377
380
  header = self._header
378
381
 
379
- with Serafin.Write(filepath, header.language, overwrite=True) as resout:
382
+ with SerafinWriter(filepath, header.language, overwrite=True) as resout:
380
383
  resout.write_header(header)
381
384
 
382
385
  t0 = np.datetime64(datetime(*header.date))
@@ -391,7 +394,7 @@ class SelafinAccessor:
391
394
  shape = (header.nb_var, header.nb_nodes)
392
395
  values = np.empty(shape, dtype=header.np_float_type)
393
396
  for time_index, time in enumerate(time_serie):
394
- for var_index, var in enumerate(header.var_IDs):
397
+ for var_index, var in enumerate(header.var_ids):
395
398
  if header.nb_frames in (0, 1):
396
399
  array = self._ds[var].values
397
400
  else: