Skip to main content

No project description provided

Project description

Available on pypi CI

xarray backend for Selafin formats

Supports lazy loading by default.

Install

To have the backend working in xarray, you need to follow these steps:

pip install xarray-selafin

or, if you are using conda/mamba:

conda install -c conda-forge xarray_selafin

Read Selafin

import xarray as xr

with xr.open_dataset("tests/data/r3d_tidal_flats.slf", engine="selafin") as ds:
    print(ds)  # do something with `ds`...
    # `ds.close()` not necessary

ds = xr.open_dataset("tests/data/r3d_tidal_flats.slf", lang="fr", engine="selafin")  # if variables are in French
print(ds)  # do something with `ds`...
ds.close()  # avoid a ResourceWarning (unclosed file)
<xarray.Dataset> Size: 5MB
Dimensions:  (time: 17, plan: 21, node: 648)
Coordinates:
    x        (node) float32 3kB ...
    y        (node) float32 3kB ...
  * time     (time) datetime64[ns] 136B 1900-01-01 ... 1900-01-02T20:26:40
Dimensions without coordinates: plan, node
Data variables:
    Z        (time, plan, node) float32 925kB ...
    U        (time, plan, node) float32 925kB ...
    V        (time, plan, node) float32 925kB ...
    W        (time, plan, node) float32 925kB ...
    MUD      (time, plan, node) float32 925kB ...
Attributes:
    title:       Sloped flume Rouse profile test
    language:    en
    float_size:  4
    endian:      >
    params:      (1, 0, 0, 0, 0, 0, 21, 5544, 0, 1)
    ipobo:       [   1  264  263 ... 5411 5412 5413]
    ikle2:       [[155 153 156]\n [310 307 305]\n [308 310 305]\n ...\n [537 ...
    ikle3:       [[  155   153   156   803   801   804]\n [  310   307   305 ...
    variables:   {'Z': ('ELEVATION Z', 'M'), 'U': ('VELOCITY U', 'M/S'), 'V':...
    date_start:  (1900, 1, 1, 0, 0, 0)

Indexing

ds_last = ds.isel(time=-1)  # last frame

Manipulate variables

ds = ds.assign(UTIMES100=lambda x: x.U * 100)  # Add a new variable
# ds.attrs["variables"]["UTIMES100"] = ("UTIMES100", "My/Unit")  # To provide variable name and unit (optional)
ds.drop_vars(["W"])  # Remove variable `VELOCITY W`

Extracting a specific layer from a 3D DataSet

ds_bottom = ds.selafin.get_dataset_as_2d(plan=0)  # bottom layer

Write Selafin

ds.selafin.write("output_file.slf")

DataSet content

Dimensions

In 2D:

  1. time
  2. node

in 3D:

  1. time
  2. plan
  3. node

Coordinates

Coordinate Description
x East mesh coordinates
y North mesh coordinates
time Datetime serie

Attributes

All attributes are optional except ikle2:

Attribute Description Default value
title Serafin title "Converted with array-serafin"
language Language for variable detection "en"
float_size Float size 4 (single precision)
endian File endianness ">"
params Table of integer parameters (can be rebuilt)
ikle2 Connectivity table in 2D (1-indexed) -
ikle3 Connectivity table in 3D (1-indexed, only in 3D, optional) (can be rebuilt from 2D)
variables Dictionary with variable names and units (key is variable abbreviation) -
date_start Starting date with integers (year to seconds) (from first time serie)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xarray_selafin-0.2.3.tar.gz (29.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xarray_selafin-0.2.3-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file xarray_selafin-0.2.3.tar.gz.

File metadata

  • Download URL: xarray_selafin-0.2.3.tar.gz
  • Upload date:
  • Size: 29.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.11.10 Linux/6.8.0-124-generic

File hashes

Hashes for xarray_selafin-0.2.3.tar.gz
Algorithm Hash digest
SHA256 f963fd31f130ed0b2c03177e20351d33fd7fd7c06541d29a22c7023efd243187
MD5 613418cb5d0619983deb4254654b0fcb
BLAKE2b-256 f64aac6861ba9b6f5545c1ffd9e0014d8cadbb2253d09d792702dcba5f7275ce

See more details on using hashes here.

File details

Details for the file xarray_selafin-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: xarray_selafin-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 29.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.11.10 Linux/6.8.0-124-generic

File hashes

Hashes for xarray_selafin-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0e37c5daa39958939c101c26e13570d3c016204ffd81a48cac072a627302de90
MD5 56ac5d7db4a915571ca3724d57d5e2df
BLAKE2b-256 325601bb9aeb5e7563361e048c2c9233932ee1c12b4a1a8df49a8bffc2e40f14

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page