diff --git a/.gitignore b/.gitignore index 0d64f33..f9bbd49 100644 --- a/.gitignore +++ b/.gitignore @@ -139,10 +139,11 @@ dmypy.json # sphinx doc/source/generated +doc/source/geo-encoded* # ruff .ruff_cache doc/source/cube.joblib.compressed doc/source/cube.pickle -cache/ \ No newline at end of file +cache/ diff --git a/doc/source/api.rst b/doc/source/api.rst index b71e19d..40a04d4 100644 --- a/doc/source/api.rst +++ b/doc/source/api.rst @@ -56,6 +56,8 @@ Methods Dataset.xvec.to_geopandas Dataset.xvec.extract_points Dataset.xvec.zonal_stats + Dataset.xvec.encode_cf + Dataset.xvec.decode_cf DataArray.xvec @@ -91,4 +93,4 @@ Methods DataArray.xvec.to_geodataframe DataArray.xvec.to_geopandas DataArray.xvec.extract_points - DataArray.xvec.zonal_stats \ No newline at end of file + DataArray.xvec.zonal_stats diff --git a/doc/source/io.ipynb b/doc/source/io.ipynb index 77b4a93..37ccbf7 100644 --- a/doc/source/io.ipynb +++ b/doc/source/io.ipynb @@ -411,38 +411,48 @@ " divorce (county, year) float64 99kB 1.859 2.62 3.747 ... 4.782 7.415\n", " age (county, year) float64 99kB 28.8 30.5 34.5 ... 28.97 35.33\n", "Indexes:\n", - " county GeometryIndex (crs=EPSG:4326)
  • " ], "text/plain": [ " Size: 420kB\n", @@ -485,22 +495,13 @@ "source": [ "## CF conventions and netCDF, Zarr\n", "\n", - "Use `cf_xarray.geometry.encode_geometries` and `cf_xarray.geometry.decode_geometries` to encode geometry arrays with CF conventions to a form that is compatible with any array storage format (e.g. netCDF, Zarr).\n" + "Use `.xvec.encode_cf()` to to encode geometry arrays with CF conventions to a form that is compatible with any array storage format (e.g. netCDF, Zarr). This function uses `cf_xarray.geometry.encode_geometries` and `cf_xarray.geometry.decode_geometries` under the hood.\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [ - "import cf_xarray as cfxr" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, "outputs": [ { "data": { @@ -869,80 +870,82 @@ " fill: currentColor;\n", "}\n", "
    <xarray.Dataset> Size: 2MB\n",
    -       "Dimensions:             (county: 3085, part: 3172, node: 80563, year: 4)\n",
    +       "Dimensions:             (county: 3085, node: 80563, part: 3172, year: 4)\n",
            "Coordinates:\n",
    +       "    spatial_ref         int64 8B 0\n",
            "  * year                (year) int64 32B 1960 1970 1980 1990\n",
    -       "Dimensions without coordinates: county, part, node\n",
    +       "Dimensions without coordinates: county, node, part\n",
            "Data variables:\n",
            "    node_count          (county) int64 25kB 24 50 68 99 16 7 ... 86 32 24 32 74\n",
    -       "    interior_ring       (part) int64 25kB 0 0 0 0 0 0 0 0 0 ... 0 1 0 0 0 0 0 0\n",
    -       "    part_node_count     (part) int64 25kB 24 50 68 99 16 7 ... 28 86 32 24 32 74\n",
            "    geometry_container  float64 8B nan\n",
            "    x                   (node) float64 645kB -95.34 -95.34 ... -111.3 -111.4\n",
            "    y                   (node) float64 645kB 48.55 48.72 48.72 ... 44.73 44.75\n",
    -       "    crd_x               (county) float64 25kB -95.34 -118.9 ... -77.53 -111.4\n",
    -       "    crd_y               (county) float64 25kB 48.55 47.95 48.04 ... 38.57 44.75\n",
    +       "    lon                 (county) float64 25kB -95.34 -118.9 ... -77.53 -111.4\n",
    +       "    lat                 (county) float64 25kB 48.55 47.95 48.04 ... 38.57 44.75\n",
    +       "    part_node_count     (part) int64 25kB 24 50 68 99 16 7 ... 28 86 32 24 32 74\n",
    +       "    interior_ring       (part) int64 25kB 0 0 0 0 0 0 0 0 0 ... 0 1 0 0 0 0 0 0\n",
            "    population          (county, year) int64 99kB 4304 3987 3764 ... 55800 65077\n",
            "    unemployment        (county, year) float64 99kB 7.9 9.0 ... 7.018 5.489\n",
            "    divorce             (county, year) float64 99kB 1.859 2.62 ... 4.782 7.415\n",
    -       "    age                 (county, year) float64 99kB 28.8 30.5 ... 28.97 35.33
    • year
      PandasIndex
      PandasIndex(Index([1960, 1970, 1980, 1990], dtype='int64', name='year'))
  • " ], "text/plain": [ " Size: 2MB\n", - "Dimensions: (county: 3085, part: 3172, node: 80563, year: 4)\n", + "Dimensions: (county: 3085, node: 80563, part: 3172, year: 4)\n", "Coordinates:\n", + " spatial_ref int64 8B 0\n", " * year (year) int64 32B 1960 1970 1980 1990\n", - "Dimensions without coordinates: county, part, node\n", + "Dimensions without coordinates: county, node, part\n", "Data variables:\n", " node_count (county) int64 25kB 24 50 68 99 16 7 ... 86 32 24 32 74\n", - " interior_ring (part) int64 25kB 0 0 0 0 0 0 0 0 0 ... 0 1 0 0 0 0 0 0\n", - " part_node_count (part) int64 25kB 24 50 68 99 16 7 ... 28 86 32 24 32 74\n", " geometry_container float64 8B nan\n", " x (node) float64 645kB -95.34 -95.34 ... -111.3 -111.4\n", " y (node) float64 645kB 48.55 48.72 48.72 ... 44.73 44.75\n", - " crd_x (county) float64 25kB -95.34 -118.9 ... -77.53 -111.4\n", - " crd_y (county) float64 25kB 48.55 47.95 48.04 ... 38.57 44.75\n", + " lon (county) float64 25kB -95.34 -118.9 ... -77.53 -111.4\n", + " lat (county) float64 25kB 48.55 47.95 48.04 ... 38.57 44.75\n", + " part_node_count (part) int64 25kB 24 50 68 99 16 7 ... 28 86 32 24 32 74\n", + " interior_ring (part) int64 25kB 0 0 0 0 0 0 0 0 0 ... 0 1 0 0 0 0 0 0\n", " population (county, year) int64 99kB 4304 3987 3764 ... 55800 65077\n", " unemployment (county, year) float64 99kB 7.9 9.0 ... 7.018 5.489\n", " divorce (county, year) float64 99kB 1.859 2.62 ... 4.782 7.415\n", " age (county, year) float64 99kB 28.8 30.5 ... 28.97 35.33" ] }, - "execution_count": 4, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "encoded = cfxr.geometry.encode_geometries(cube)\n", + "encoded = cube.xvec.encode_cf()\n", "encoded" ] }, @@ -955,16 +958,16 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 5, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -978,12 +981,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "On open, use `cf_xarray.decode_geometries` to recover the array" + "On open, use `.xvec.decode_cf` to recover the array. This function uses `cf_xarray.decode_geometries` so again `cf_xarray` must be installed." ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -1355,22 +1358,22 @@ "
    <xarray.Dataset> Size: 420kB\n",
            "Dimensions:       (county: 3085, year: 4)\n",
            "Coordinates:\n",
    -       "  * year          (year) int64 32B 1960 1970 1980 1990\n",
            "  * county        (county) object 25kB POLYGON ((-95.34258270263672 48.546703...\n",
    +       "  * year          (year) int64 32B 1960 1970 1980 1990\n",
            "Data variables:\n",
            "    age           (county, year) float64 99kB dask.array<chunksize=(3085, 4), meta=np.ndarray>\n",
            "    divorce       (county, year) float64 99kB dask.array<chunksize=(3085, 4), meta=np.ndarray>\n",
            "    population    (county, year) int64 99kB dask.array<chunksize=(3085, 4), meta=np.ndarray>\n",
            "    unemployment  (county, year) float64 99kB dask.array<chunksize=(3085, 4), meta=np.ndarray>\n",
            "Indexes:\n",
    -       "    county   GeometryIndex (crs=EPSG:4326)