xarray-selafin 0.2.1__tar.gz → 0.2.2__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.2
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.1.0)
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.2"
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.1.0"
17
18
 
18
19
  [tool.poetry.plugins."xarray.backends"]
19
20
  selafin = "xarray_selafin.xarray_backend:SelafinBackendEntrypoint"
@@ -4,20 +4,27 @@ 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 Read
15
+ from serafin import SerafinHeader
16
+ from serafin import SerafinRequestError
17
+ from serafin import Write
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
24
 
19
25
  try:
20
26
  import dask
27
+
21
28
  DASK_AVAILABLE = True
22
29
  except ImportError:
23
30
  DASK_AVAILABLE = False
@@ -40,7 +47,7 @@ def compute_duration_between_datetime(t0, time_serie):
40
47
 
41
48
 
42
49
  def read_serafin(filepath, lang):
43
- resin = Serafin.Read(filepath, lang)
50
+ resin = Read(filepath, lang)
44
51
  resin.__enter__()
45
52
  resin.read_header()
46
53
  resin.get_time()
@@ -48,7 +55,6 @@ def read_serafin(filepath, lang):
48
55
 
49
56
 
50
57
  class SelafinLazyArray(BackendArray):
51
-
52
58
  def __init__(self, filename_or_obj, shape, dtype, lock, var):
53
59
  self.filename_or_obj = filename_or_obj
54
60
  self.shape = shape
@@ -134,7 +140,6 @@ class SelafinLazyArray(BackendArray):
134
140
 
135
141
 
136
142
  class SelafinBackendEntrypoint(BackendEntrypoint):
137
-
138
143
  def open_dataset(
139
144
  self,
140
145
  filename_or_obj,
@@ -144,7 +149,7 @@ class SelafinBackendEntrypoint(BackendEntrypoint):
144
149
  # Below are custom arguments
145
150
  disable_lock=False,
146
151
  lazy_loading=True,
147
- lang=Serafin.LANG,
152
+ lang=LANG,
148
153
  # `chunks` and `cache` DO NOT go here, they are handled by xarray
149
154
  ):
150
155
  # Initialize SELAFIN reader
@@ -218,7 +223,7 @@ class SelafinBackendEntrypoint(BackendEntrypoint):
218
223
 
219
224
  ds.set_close(close)
220
225
 
221
- ds.attrs["title"] = slf.header.title.decode(Serafin.SLF_EIT).strip()
226
+ ds.attrs["title"] = slf.header.title.decode(SLF_EIT).strip()
222
227
  ds.attrs["language"] = slf.header.language
223
228
  ds.attrs["float_size"] = slf.header.float_size
224
229
  ds.attrs["endian"] = slf.header.endian
@@ -228,7 +233,7 @@ class SelafinBackendEntrypoint(BackendEntrypoint):
228
233
  if not is_2d:
229
234
  ds.attrs["ikle3"] = np.reshape(slf.header.ikle, (slf.header.nb_elements, ndp3))
230
235
  ds.attrs["variables"] = {
231
- var_ID: (name.decode(Serafin.SLF_EIT).rstrip(), unit.decode(Serafin.SLF_EIT).rstrip())
236
+ var_ID: (name.decode(SLF_EIT).rstrip(), unit.decode(SLF_EIT).rstrip())
232
237
  for var_ID, name, unit in slf.header.iter_on_all_variables()
233
238
  }
234
239
  ds.attrs["date_start"] = slf.header.date
@@ -249,7 +254,6 @@ class SelafinBackendEntrypoint(BackendEntrypoint):
249
254
 
250
255
  @xr.register_dataset_accessor("selafin")
251
256
  class SelafinAccessor:
252
-
253
257
  def __init__(self, xarray_obj):
254
258
  self._ds = xarray_obj
255
259
  self._header = None
@@ -279,7 +283,7 @@ class SelafinAccessor:
279
283
 
280
284
  # Title
281
285
  title = ds.attrs.get("title", "Converted with array-serafin")
282
- header = Serafin.SerafinHeader(title)
286
+ header = SerafinHeader(title)
283
287
 
284
288
  # File precision
285
289
  float_size = ds.attrs.get("float_size", 4) # Default: single precision
@@ -311,7 +315,7 @@ class SelafinAccessor:
311
315
  header.date = DEFAULT_DATE_START
312
316
 
313
317
  # Variables
314
- header.language = ds.attrs.get("language", Serafin.LANG)
318
+ header.language = ds.attrs.get("language", LANG)
315
319
  for var in ds.data_vars:
316
320
  try:
317
321
  name, unit = ds.attrs["variables"][var]
@@ -319,7 +323,7 @@ class SelafinAccessor:
319
323
  except KeyError:
320
324
  try:
321
325
  header.add_variable_from_ID(var)
322
- except Serafin.SerafinRequestError:
326
+ except SerafinRequestError:
323
327
  header.add_variable_str(var, var, "?")
324
328
  header.nb_var = len(header.var_IDs)
325
329
 
@@ -376,7 +380,7 @@ class SelafinAccessor:
376
380
  """Writes header and all data frames into output file"""
377
381
  header = self._header
378
382
 
379
- with Serafin.Write(filepath, header.language, overwrite=True) as resout:
383
+ with Write(filepath, header.language, overwrite=True) as resout:
380
384
  resout.write_header(header)
381
385
 
382
386
  t0 = np.datetime64(datetime(*header.date))