Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xarray version update #323

Merged
merged 14 commits into from
May 12, 2023
2 changes: 1 addition & 1 deletion ci3.8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ dependencies:
- requests=2.28.1
- netcdf4=1.6.1
- rioxarray=0.12.2
- xarray=2022.10.0
- xarray-beam=0.3.1
- ecmwf-api-client=1.6.3
- fsspec=2022.10.0
Expand All @@ -31,5 +30,6 @@ dependencies:
- pygrib=2.1.4
- pip:
- earthengine-api==0.1.329
- xarray==2023.1.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second though: we may get weird link errors with our conda deploy if we don't include this as a conda dependency. Has this been published on conda forge yet?

Copy link
Collaborator Author

@dabhicusp dabhicusp May 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While trying to install the xarray=2023.1.0 package in the CI/CD pipeline via the conda-forge channel, I encountered an error. However, the installation process worked without any issues when I tried it locally. Here's an error message that I received during the CI/CD run:
image
Link
Do you have any suggestions for resolving this issue?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like 2023.4.2 is available on conda (I think this is the latest release). How about we try upgrading to that version?

https://github.com/conda-forge/xarray-feedstock#current-release-info

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the PR Description This is the last updated version of xarray that python 3.8 supported.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm getting ahead of myself. I'm happy to keep the pip (vs the conda) version, if we can test our local and docker deployment to prove that there are no link errors. Let's also create a follow-up CL to deprecate python 3.8 and include python 3.10. How does this sound?

Copy link
Collaborator Author

@dabhicusp dabhicusp May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @alxmrs, I have tested both the local and docker deployments and did not encounter any errors.

Yes, this sounds good to me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for confirming!

- ruff==0.0.260
- .[test]
2 changes: 1 addition & 1 deletion ci3.9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ dependencies:
- requests=2.28.1
- netcdf4=1.6.1
- rioxarray=0.12.2
- xarray=2022.10.0
- xarray-beam=0.3.1
- ecmwf-api-client=1.6.3
- fsspec=2022.10.0
Expand All @@ -31,5 +30,6 @@ dependencies:
- pygrib=2.1.4
- pip:
- earthengine-api==0.1.329
- xarray==2023.1.0
- ruff==0.0.260
- .[test]
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies:
- python=3.8.13
- apache-beam=2.40.0
- xarray-beam=0.3.1
- xarray=2022.11.0
- xarray=2023.1.0
- fsspec=2022.11.0
- gcsfs=2022.11.0
- rioxarray=0.12.2
Expand Down
2 changes: 1 addition & 1 deletion weather_dl/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"ecmwf-api-client==1.6.3",
"numpy>=1.19.1",
"pandas==1.5.1",
"xarray==2022.11.0",
"xarray==2023.1.0",
"requests>=2.24.0",
"urllib3==1.26.5",
"google-cloud-firestore==2.6.0",
Expand Down
47 changes: 46 additions & 1 deletion weather_mv/loader_pipeline/sinks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import contextlib
import datetime
import unittest
from functools import wraps
import numpy as np
import tempfile
import tracemalloc
import unittest
import xarray as xr

import weather_mv
from .sinks import match_datetime, open_dataset
Expand All @@ -38,6 +43,40 @@ def decorated(*args, **kwargs):
return decorated


@contextlib.contextmanager
def limit_memory(max_memory=30):
''''Measure memory consumption of the function.
'memory limit' in MB
'''
try:
tracemalloc.start()
yield
finally:
current, peak = tracemalloc.get_traced_memory()
tracemalloc.stop()
assert peak / 1024 ** 2 <= max_memory, f"Memory usage {peak / 1024 ** 2} exceeded {max_memory} MB limit."


@contextlib.contextmanager
def write_netcdf():
"""Generates temporary netCDF file using xarray."""
lat_dim = 3210
lon_dim = 3440
lat = np.linspace(-90, 90, lat_dim)
lon = np.linspace(-180, 180, lon_dim)
data_arr = np.random.uniform(low=0, high=0.1, size=(5, lat_dim, lon_dim))

ds = xr.Dataset(
{"var_1": (('time', 'lat', 'lon'), data_arr)},
coords={
"lat": lat,
"lon": lon,
})
with tempfile.NamedTemporaryFile() as fp:
ds.to_netcdf(fp.name)
yield fp.name


class OpenDatasetTest(TestDataBase):

def setUp(self) -> None:
Expand Down Expand Up @@ -67,6 +106,12 @@ def test_opens_tif_files(self):
self.assertIsNotNone(ds)
self.assertDictContainsSubset({'is_normalized': False}, ds.attrs)

def test_open_dataset__fits_memory_bounds(self):
alxmrs marked this conversation as resolved.
Show resolved Hide resolved
with write_netcdf() as test_netcdf_path:
with limit_memory(max_memory=30):
with open_dataset(test_netcdf_path) as _:
pass


class DatetimeTest(unittest.TestCase):

Expand Down
4 changes: 2 additions & 2 deletions weather_mv/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"dataclasses",
"numpy==1.22.4",
"pandas==1.5.1",
"xarray==2022.11.0",
"xarray==2023.1.0",
"cfgrib==0.9.10.2",
"netcdf4==1.6.1",
"geojson==2.5.0",
Expand All @@ -62,7 +62,7 @@
packages=find_packages(),
author='Anthromets',
author_email='[email protected]',
version='0.2.12',
version='0.2.13',
url='https://weather-tools.readthedocs.io/en/latest/weather_mv/',
description='A tool to load weather data into BigQuery.',
install_requires=beam_gcp_requirements + base_requirements,
Expand Down
2 changes: 1 addition & 1 deletion weather_sp/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"pygrib==2.1.4",
"eccodes",
"numpy>=1.20.3",
"xarray==2022.11.0",
"xarray==2023.1.0",
"scipy==1.9.3",
]

Expand Down