cf-xarray 0.9.0__tar.gz → 0.9.1__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.
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.github/workflows/ci.yaml +2 -2
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.github/workflows/pypi.yaml +2 -2
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.github/workflows/upstream-dev-ci.yaml +1 -1
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/PKG-INFO +1 -1
- cf_xarray-0.9.1/cf_xarray/_version.py +1 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/geometry.py +3 -2
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/helpers.py +1 -1
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray.egg-info/PKG-INFO +1 -1
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/ci/doc.yml +1 -0
- cf_xarray-0.9.1/doc/geometry.md +99 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/pyproject.toml +2 -1
- cf_xarray-0.9.0/cf_xarray/_version.py +0 -1
- cf_xarray-0.9.0/doc/geometry.md +0 -7
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.binder/environment.yml +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.deepsource.toml +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.github/dependabot.yml +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.github/workflows/parse_logs.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.github/workflows/testpypi-release.yaml +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.gitignore +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.pre-commit-config.yaml +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.readthedocs.yml +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.tributors +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/CITATION.cff +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/LICENSE +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/README.rst +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/__init__.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/accessor.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/coding.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/criteria.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/datasets.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/formatting.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/options.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/py.typed +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/scripts/make_doc.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/scripts/print_versions.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/sgrid.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/__init__.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/test_accessor.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/test_coding.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/test_geometry.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/test_helpers.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/test_options.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/test_scripts.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/test_units.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/units.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/utils.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray.egg-info/SOURCES.txt +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray.egg-info/dependency_links.txt +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray.egg-info/requires.txt +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray.egg-info/top_level.txt +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/ci/environment-no-optional-deps.yml +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/ci/environment.yml +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/ci/upstream-dev-env.yml +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/codecov.yml +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/2D_bounds_averaged.png +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/2D_bounds_error.png +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/2D_bounds_nonunique.png +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/Makefile +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/_static/dataset-diagram-logo.tex +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/_static/full-logo.png +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/_static/logo.png +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/_static/logo.svg +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/_static/rich-repr-example.png +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/_static/style.css +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/api.rst +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/bounds.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/cartopy_rotated_pole.png +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/coding.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/conf.py +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/contributing.rst +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/coord_axes.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/custom-criteria.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/dsg.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/examples/introduction.ipynb +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/faq.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/flags.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/grid_mappings.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/howtouse.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/index.rst +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/make.bat +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/parametricz.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/plotting.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/provenance.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/quickstart.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/roadmap.rst +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/selecting.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/sgrid_ugrid.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/units.md +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/whats-new.rst +0 -0
- {cf_xarray-0.9.0 → cf_xarray-0.9.1}/setup.cfg +0 -0
|
@@ -50,7 +50,7 @@ jobs:
|
|
|
50
50
|
run: |
|
|
51
51
|
pytest -n auto --cov=./ --cov-report=xml
|
|
52
52
|
- name: Upload code coverage to Codecov
|
|
53
|
-
uses: codecov/codecov-action@v4.
|
|
53
|
+
uses: codecov/codecov-action@v4.3.0
|
|
54
54
|
with:
|
|
55
55
|
file: ./coverage.xml
|
|
56
56
|
flags: unittests
|
|
@@ -114,7 +114,7 @@ jobs:
|
|
|
114
114
|
run: |
|
|
115
115
|
python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report cf_xarray/
|
|
116
116
|
- name: Upload mypy coverage to Codecov
|
|
117
|
-
uses: codecov/codecov-action@v4.
|
|
117
|
+
uses: codecov/codecov-action@v4.3.0
|
|
118
118
|
with:
|
|
119
119
|
file: mypy_report/cobertura.xml
|
|
120
120
|
flags: mypy
|
|
@@ -72,7 +72,7 @@ jobs:
|
|
|
72
72
|
|
|
73
73
|
- name: Publish package to TestPyPI
|
|
74
74
|
if: github.event_name == 'push'
|
|
75
|
-
uses: pypa/gh-action-pypi-publish@v1.8.
|
|
75
|
+
uses: pypa/gh-action-pypi-publish@v1.8.12
|
|
76
76
|
with:
|
|
77
77
|
password: ${{ secrets.TESTPYPI_TOKEN }}
|
|
78
78
|
repository_url: https://test.pypi.org/legacy/
|
|
@@ -96,6 +96,6 @@ jobs:
|
|
|
96
96
|
name: releases
|
|
97
97
|
path: dist
|
|
98
98
|
- name: Publish package to PyPI
|
|
99
|
-
uses: pypa/gh-action-pypi-publish@v1.8.
|
|
99
|
+
uses: pypa/gh-action-pypi-publish@v1.8.12
|
|
100
100
|
with:
|
|
101
101
|
verbose: true
|
|
@@ -22,7 +22,7 @@ jobs:
|
|
|
22
22
|
upstream-dev:
|
|
23
23
|
name: upstream-dev
|
|
24
24
|
runs-on: ubuntu-latest
|
|
25
|
-
if: ${{ (contains( github.event.pull_request.labels.*.name, 'test-upstream') && github.event_name == 'pull_request') || github.event_name == 'workflow_dispatch' }}
|
|
25
|
+
if: ${{ (contains( github.event.pull_request.labels.*.name, 'test-upstream') && github.event_name == 'pull_request') || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
|
|
26
26
|
defaults:
|
|
27
27
|
run:
|
|
28
28
|
shell: bash -l {0}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.9.1"
|
|
@@ -94,9 +94,10 @@ def shapely_to_cf(geometries: xr.DataArray | Sequence, grid_mapping: str | None
|
|
|
94
94
|
A dataset with shapely geometry objects translated into CF-compliant variables :
|
|
95
95
|
- 'x', 'y' : the node coordinates
|
|
96
96
|
- 'crd_x', 'crd_y' : the feature coordinates (might have different names if `grid_mapping` is available).
|
|
97
|
-
- 'node_count' : The number of nodes per feature.
|
|
97
|
+
- 'node_count' : The number of nodes per feature. Always present for Lines and Polygons. For Points: only present if there are multipart geometries.
|
|
98
|
+
- 'part_node_count' : The number of nodes per individual geometry. Only for Lines with multipart geometries and for Polygons with multipart geometries or holes.
|
|
99
|
+
- 'interior_ring' : Integer boolean indicating whether rings are interior or exterior. Only for Polygons with holes.
|
|
98
100
|
- 'geometry_container' : Empty variable with attributes describing the geometry type.
|
|
99
|
-
- Other variables are not implemented as only Points are currently understood.
|
|
100
101
|
|
|
101
102
|
References
|
|
102
103
|
----------
|
|
@@ -48,7 +48,7 @@ def _guess_bounds_2d(da, dims):
|
|
|
48
48
|
# At this point, we might have different corners for adjacent cells, we average them together to have a nice grid
|
|
49
49
|
# To make this vectorized and keep the edges, we'll pad with NaNs and ignore them in the averages
|
|
50
50
|
daXYp = (
|
|
51
|
-
daXY.pad({d: (1, 1) for d in dims}, mode="constant", constant_values=np.
|
|
51
|
+
daXY.pad({d: (1, 1) for d in dims}, mode="constant", constant_values=np.nan)
|
|
52
52
|
.transpose(*dims, "Xbnds", "Ybnds")
|
|
53
53
|
.values
|
|
54
54
|
) # Tranpose for an easier notation
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
jupytext:
|
|
3
|
+
text_representation:
|
|
4
|
+
format_name: myst
|
|
5
|
+
kernelspec:
|
|
6
|
+
display_name: Python 3
|
|
7
|
+
name: python3
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
```{eval-rst}
|
|
11
|
+
.. currentmodule:: xarray
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
# Geometries
|
|
15
|
+
|
|
16
|
+
```{seealso}
|
|
17
|
+
1. [The CF conventions on Geometries](http://cfconventions.org/Data/cf-conventions/cf-conventions-1.11/cf-conventions.html#geometries)
|
|
18
|
+
1. {py:func}`cf_xarray.shapely_to_cf`
|
|
19
|
+
1. {py:func}`cf_xarray.cf_to_shapely`
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`cf_xarray` can convert between vector geometries represented as shapely objects
|
|
23
|
+
and CF-compliant array representations of those geometries.
|
|
24
|
+
|
|
25
|
+
Let's start by creating an xarray object containing some shapely geometries. This example uses
|
|
26
|
+
a `xr.DataArray` but these functions also work with a `xr.Dataset` where one of the data variables
|
|
27
|
+
contains an array of shapes.
|
|
28
|
+
|
|
29
|
+
```{code-cell}
|
|
30
|
+
import cf_xarray as cfxr
|
|
31
|
+
import xarray as xr
|
|
32
|
+
|
|
33
|
+
from shapely.geometry import MultiPoint, Point
|
|
34
|
+
|
|
35
|
+
da = xr.DataArray(
|
|
36
|
+
[
|
|
37
|
+
MultiPoint([(1.0, 2.0), (2.0, 3.0)]),
|
|
38
|
+
Point(3.0, 4.0),
|
|
39
|
+
Point(4.0, 5.0),
|
|
40
|
+
Point(3.0, 4.0),
|
|
41
|
+
],
|
|
42
|
+
dims=("index",),
|
|
43
|
+
name="geometry"
|
|
44
|
+
)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```{warning}
|
|
48
|
+
`cf_xarray` does not support handle multiple types of shapes (Point, Line, Polygon) in one
|
|
49
|
+
`xr.DataArray`, but multipart geometries are supported and can be mixed with single-part
|
|
50
|
+
geometries of the same type.
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Now we can take that `xr.DataArray` containing shapely geometries and convert it to cf:
|
|
54
|
+
|
|
55
|
+
```{code-cell}
|
|
56
|
+
ds_cf = cfxr.shapely_to_cf(da)
|
|
57
|
+
ds_cf
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
This function returns a `xr.Dataset` containing the CF fields needed to reconstruct the
|
|
61
|
+
geometries. In particular there are:
|
|
62
|
+
|
|
63
|
+
- `'x'`, `'y'` : the node coordinates
|
|
64
|
+
- `'crd_x'`, `'crd_y'` : the feature coordinates (might have different names if `grid_mapping` is available).
|
|
65
|
+
- `'node_count'` : The number of nodes per feature. Always present for Lines and Polygons. For
|
|
66
|
+
Points: only present if there are multipart geometries.
|
|
67
|
+
- `'part_node_count'` : The number of nodes per individual geometry. Only for Lines with multipart
|
|
68
|
+
geometries and for Polygons with multipart geometries or holes.
|
|
69
|
+
- `'interior_ring'` : Integer boolean indicating whether ring is interior or exterior. Only for
|
|
70
|
+
Polygons with holes.
|
|
71
|
+
- `'geometry_container`' : Empty variable with attributes describing the geometry type.
|
|
72
|
+
|
|
73
|
+
Here are the attributes on `geometry_container`. This pattern mimics the convention of
|
|
74
|
+
specifying spatial reference information in the attrs of the empty array `spatial_ref`.
|
|
75
|
+
|
|
76
|
+
```{code-cell}
|
|
77
|
+
ds_cf.geometry_container.attrs
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```{note}
|
|
81
|
+
Z axis is not yet supported for any shapes.
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
This `xr.Dataset` can be converted back into a `xr.DataArray` of shapely geometries:
|
|
85
|
+
|
|
86
|
+
```{code-cell}
|
|
87
|
+
cfxr.cf_to_shapely(ds_cf)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
This conversion adds coordinates that aren't in the `xr.DataArray` that we started with.
|
|
91
|
+
By default these are called `crd_x` and `crd_y` unless `grid_mapping` is specified.
|
|
92
|
+
|
|
93
|
+
## Gotchas
|
|
94
|
+
|
|
95
|
+
For MultiPolygons with holes the CF notation is slightly ambiguous on which hole is associated
|
|
96
|
+
with which polygon. This is problematic because shapely stores holes within the polygon
|
|
97
|
+
object that they are associated with. `cf_xarray` assumes that the the shapes are interleaved
|
|
98
|
+
such that the holes (interior rings) are associated with the exteriors (exterior rings) that
|
|
99
|
+
immediately precede them.
|
|
@@ -64,6 +64,8 @@ exclude = [
|
|
|
64
64
|
".eggs",
|
|
65
65
|
"doc",
|
|
66
66
|
]
|
|
67
|
+
|
|
68
|
+
[tool.ruff.lint]
|
|
67
69
|
# E402: module level import not at top of file
|
|
68
70
|
# E501: line too long - let ruff worry about that
|
|
69
71
|
ignore = [
|
|
@@ -72,7 +74,6 @@ ignore = [
|
|
|
72
74
|
"B018",
|
|
73
75
|
"B015",
|
|
74
76
|
]
|
|
75
|
-
[tool.ruff.lint]
|
|
76
77
|
select = [
|
|
77
78
|
# Pyflakes
|
|
78
79
|
"F",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.9.0"
|
cf_xarray-0.9.0/doc/geometry.md
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|