Skip to content

Commit

Permalink
Deprecate path parameter for saving to netcdf
Browse files Browse the repository at this point in the history
  • Loading branch information
aazuspan committed Jun 11, 2023
1 parent 5bcffe2 commit 4fdaec8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions wxee/collection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import tempfile
import warnings
from typing import List, Optional

import ee # type: ignore
Expand Down Expand Up @@ -74,8 +75,6 @@ def to_xarray(
Parameters
----------
path : str, optional
The path to save the dataset to as a NetCDF. If none is given, the dataset will be stored in memory.
region : ee.Geometry, optional
The region to download the images within. If none is provided, the :code:`geometry` of the image collection
will be used. If geometry varies between images in the collection, the region will encompass all images
Expand Down Expand Up @@ -115,7 +114,6 @@ def to_xarray(
>>> col.wx.to_xarray(scale=40000, crs="EPSG:5070", nodata=-9999)
"""
with tempfile.TemporaryDirectory(prefix=constants.TMP_PREFIX) as tmp:

files = self._obj.wx.to_tif(
out_dir=tmp,
region=region,
Expand All @@ -132,6 +130,11 @@ def to_xarray(
ds = _dataset_from_files(files, masked, nodata)

if path:
msg = (
"The path argument is deprecated and will be removed in a future "
"release. Use the `xarray.Dataset.to_netcdf` method instead."
)
warnings.warn(category=DeprecationWarning, message=msg)
ds.to_netcdf(path, mode="w")

return ds
Expand Down
7 changes: 5 additions & 2 deletions wxee/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ def to_xarray(
Parameters
----------
path : str, optional
The path to save the dataset to as a NetCDF. If none is given, the dataset will be stored in memory.
region : ee.Geometry, optional
The region to download the image within. If none is provided, the :code:`geometry` of the image will be used.
scale : int, optional
Expand Down Expand Up @@ -92,6 +90,11 @@ def to_xarray(
ds = _dataset_from_files(files, masked, nodata)

if path:
msg = (
"The path argument is deprecated and will be removed in a future "
"release. Use the `xarray.Dataset.to_netcdf` method instead."
)
warnings.warn(category=DeprecationWarning, message=msg)
ds.to_netcdf(path, mode="w")

return ds
Expand Down

0 comments on commit 4fdaec8

Please sign in to comment.