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

Unpin Xarray: dataArray -> dataArray.variable #492

Merged
merged 13 commits into from
Nov 10, 2023
2 changes: 1 addition & 1 deletion build_envs/asv-bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
- pint
- setuptools
- setuptools_scm
- xarray<=2023.02.0
- xarray
- xskillscore
- pip
- pip:
Expand Down
2 changes: 1 addition & 1 deletion build_envs/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies:
- pre_commit
- geocat-datafiles
- geocat-viz
- xarray<=2023.02.0 #pin per issue #381
- xarray
- netcdf4
- pint
- ipykernel
Expand Down
2 changes: 1 addition & 1 deletion build_envs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
- numba
- numpy<1.24 # 1.24 not yet fully compatible with numba
- pint
- xarray<=2023.02.0 #pin per issue #381
- xarray
- xskillscore
# Packages listed below are for testing
- geocat-datafiles
Expand Down
2 changes: 2 additions & 0 deletions docs/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ Documentation
Bug Fixes
^^^^^^^^^
* Fix Python version in upstream CI by `Philip Chmielowiec`_ in (:pr:`436`)
* Unpin xarray in enviroment builds with changes to interpolation.py (specify dims in xr.DataArray) and climatologies.py (replace loffset with to_offset) by `Cora Schneck`_ in (:pr:`381`)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this still needs to get bumped up to a v2023.11.0 (unreleased) section.

Otherwise, things look good to me!

Copy link
Member

Choose a reason for hiding this comment

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

Seconded, I'll approve after this, too!


Internal Changes
^^^^^^^^^^^^^^^^
* Add benchmarking to commits to main and tagged releases by `Anissa Zacharias`_ in (:pr:`496`)
* Fix benchmarking workflow failures by `Anissa Zacharias`_ in (:pr:`499`)


v2023.10.0 (Oct 3, 2023)
-----------------------
This release adds a code of conduct, minor edits to our contributor's guide, and
Expand Down
19 changes: 16 additions & 3 deletions geocat/comp/climatologies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import cf_xarray
import cftime
import numpy as np
import pandas as pd
import typing
import xarray as xr
import warnings
Expand All @@ -12,8 +13,8 @@ def _contains_datetime_like_objects(d_arr):
"""Check if a variable contains datetime like objects (either
np.datetime64, or cftime.datetime)"""
return np.issubdtype(
d_arr.dtype,
np.datetime64) or xr.core.common.contains_cftime_datetimes(d_arr)
d_arr.dtype, np.datetime64) or xr.core.common.contains_cftime_datetimes(
d_arr.variable)


def _validate_freq(freq):
Expand Down Expand Up @@ -302,7 +303,19 @@ def month_to_season(
# Group the months into three and take the mean
means = data_filter.resample({
time_coord_name: quarter
}, loffset='MS').mean(keep_attrs=keep_attrs)
}).mean(keep_attrs=keep_attrs)
# Set offset for supported array formats
if isinstance(means.indexes[time_coord_name],
xr.coding.cftimeindex.CFTimeIndex):
means[time_coord_name] = means.indexes[
time_coord_name] + xr.coding.cftime_offsets.to_offset(freq="MS")
elif isinstance(means.indexes[time_coord_name], pd.DatetimeIndex):
means[time_coord_name] = means.indexes[
time_coord_name] + pd.tseries.frequencies.to_offset(freq="MS")
else:
raise ValueError(
f"unsupported array type - {type(means.indexes[time_coord_name])}. Valid types include: (xr.coding.cftimeindex.CFTimeIndex, pandas.core.indexes.datetimes.DatetimeIndex)"
)
cyschneck marked this conversation as resolved.
Show resolved Hide resolved

# The line above tries to take the mean for all quarters even if there is not data for some of them
# Therefore, we must filter out the NaNs
Expand Down
12 changes: 6 additions & 6 deletions geocat/comp/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,19 +593,19 @@ def interp_sigma_to_hybrid(data: xr.DataArray,
output = data_stacked[:, :len(hyam)].copy()

for idx, (d, s) in enumerate(zip(data_stacked, sigma_stacked)):
output[idx, :] = xr.DataArray(
_vertical_remap(func_interpolate, s.data, sig_coords.data,
d.data))
output[idx, :] = xr.DataArray(_vertical_remap(
func_interpolate, s.data, sig_coords.data, d.data),
dims=[lev_dim])
cyschneck marked this conversation as resolved.
Show resolved Hide resolved

# Make output shape same as data shape
output = output.unstack().transpose(*data.dims)
else:
h_coords = sigma

output = data[:len(hyam)].copy()
output[:len(hyam)] = xr.DataArray(
_vertical_remap(func_interpolate, sigma.data, sig_coords.data,
data.data))
output[:len(hyam)] = xr.DataArray(_vertical_remap(
func_interpolate, sigma.data, sig_coords.data, data.data),
dims=[lev_dim])

# Set output dims and coords
output = output.rename({lev_dim: 'hlev'})
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ eofs
metpy
numpy
scipy
xarray<=2023.02.0 #pin per issue #381
xarray
xskillscore
packaging
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ install_requires =
eofs
metpy
scipy
xarray<=2023.02.0 #pin per issue #381
xarray
xskillscore
packaging
tests_require =
Expand Down
Loading