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.
Files changed (90) hide show
  1. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.github/workflows/ci.yaml +2 -2
  2. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.github/workflows/pypi.yaml +2 -2
  3. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.github/workflows/upstream-dev-ci.yaml +1 -1
  4. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/PKG-INFO +1 -1
  5. cf_xarray-0.9.1/cf_xarray/_version.py +1 -0
  6. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/geometry.py +3 -2
  7. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/helpers.py +1 -1
  8. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray.egg-info/PKG-INFO +1 -1
  9. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/ci/doc.yml +1 -0
  10. cf_xarray-0.9.1/doc/geometry.md +99 -0
  11. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/pyproject.toml +2 -1
  12. cf_xarray-0.9.0/cf_xarray/_version.py +0 -1
  13. cf_xarray-0.9.0/doc/geometry.md +0 -7
  14. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.binder/environment.yml +0 -0
  15. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.deepsource.toml +0 -0
  16. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.github/dependabot.yml +0 -0
  17. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.github/workflows/parse_logs.py +0 -0
  18. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.github/workflows/testpypi-release.yaml +0 -0
  19. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.gitignore +0 -0
  20. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.pre-commit-config.yaml +0 -0
  21. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.readthedocs.yml +0 -0
  22. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/.tributors +0 -0
  23. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/CITATION.cff +0 -0
  24. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/LICENSE +0 -0
  25. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/README.rst +0 -0
  26. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/__init__.py +0 -0
  27. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/accessor.py +0 -0
  28. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/coding.py +0 -0
  29. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/criteria.py +0 -0
  30. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/datasets.py +0 -0
  31. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/formatting.py +0 -0
  32. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/options.py +0 -0
  33. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/py.typed +0 -0
  34. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/scripts/make_doc.py +0 -0
  35. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/scripts/print_versions.py +0 -0
  36. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/sgrid.py +0 -0
  37. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/__init__.py +0 -0
  38. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/test_accessor.py +0 -0
  39. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/test_coding.py +0 -0
  40. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/test_geometry.py +0 -0
  41. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/test_helpers.py +0 -0
  42. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/test_options.py +0 -0
  43. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/test_scripts.py +0 -0
  44. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/tests/test_units.py +0 -0
  45. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/units.py +0 -0
  46. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray/utils.py +0 -0
  47. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray.egg-info/SOURCES.txt +0 -0
  48. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray.egg-info/dependency_links.txt +0 -0
  49. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray.egg-info/requires.txt +0 -0
  50. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/cf_xarray.egg-info/top_level.txt +0 -0
  51. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/ci/environment-no-optional-deps.yml +0 -0
  52. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/ci/environment.yml +0 -0
  53. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/ci/upstream-dev-env.yml +0 -0
  54. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/codecov.yml +0 -0
  55. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/2D_bounds_averaged.png +0 -0
  56. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/2D_bounds_error.png +0 -0
  57. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/2D_bounds_nonunique.png +0 -0
  58. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/Makefile +0 -0
  59. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/_static/dataset-diagram-logo.tex +0 -0
  60. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/_static/full-logo.png +0 -0
  61. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/_static/logo.png +0 -0
  62. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/_static/logo.svg +0 -0
  63. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/_static/rich-repr-example.png +0 -0
  64. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/_static/style.css +0 -0
  65. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/api.rst +0 -0
  66. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/bounds.md +0 -0
  67. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/cartopy_rotated_pole.png +0 -0
  68. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/coding.md +0 -0
  69. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/conf.py +0 -0
  70. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/contributing.rst +0 -0
  71. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/coord_axes.md +0 -0
  72. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/custom-criteria.md +0 -0
  73. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/dsg.md +0 -0
  74. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/examples/introduction.ipynb +0 -0
  75. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/faq.md +0 -0
  76. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/flags.md +0 -0
  77. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/grid_mappings.md +0 -0
  78. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/howtouse.md +0 -0
  79. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/index.rst +0 -0
  80. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/make.bat +0 -0
  81. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/parametricz.md +0 -0
  82. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/plotting.md +0 -0
  83. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/provenance.md +0 -0
  84. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/quickstart.md +0 -0
  85. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/roadmap.rst +0 -0
  86. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/selecting.md +0 -0
  87. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/sgrid_ugrid.md +0 -0
  88. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/units.md +0 -0
  89. {cf_xarray-0.9.0 → cf_xarray-0.9.1}/doc/whats-new.rst +0 -0
  90. {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.0.0
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.0.0
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.11
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.11
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}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cf_xarray
3
- Version: 0.9.0
3
+ Version: 0.9.1
4
4
  Summary: A convenience wrapper for using CF attributes on xarray objects
5
5
  License: Apache License
6
6
  Version 2.0, January 2004
@@ -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. Absent if all instances are Points.
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.NaN)
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cf_xarray
3
- Version: 0.9.0
3
+ Version: 0.9.1
4
4
  Summary: A convenience wrapper for using CF attributes on xarray objects
5
5
  License: Apache License
6
6
  Version 2.0, January 2004
@@ -19,6 +19,7 @@ dependencies:
19
19
  - pooch
20
20
  - pint
21
21
  - regex
22
+ - shapely
22
23
  - furo
23
24
  - myst-nb
24
25
  - pip:
@@ -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"
@@ -1,7 +0,0 @@
1
- ```{eval-rst}
2
- .. currentmodule:: xarray
3
- ```
4
-
5
- # Geometries
6
-
7
- See {py:func}`cf_xarray.shapely_to_cf`, {py:func}`cf_xarray.cf_to_shapely`
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