Skip to content

Commit

Permalink
Merge branch 'main' into reduce-freedom-in-parameter-naming
Browse files Browse the repository at this point in the history
  • Loading branch information
bdestombe committed Jul 27, 2023
2 parents 63fe767 + ee6a919 commit b72d407
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.9', '3.10']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Introduced limitations

* Standardized parameter names. Reduced the freedom in choosing parameter names and dimension names in favor of simplifying the code.

Removed

* Removed ds.resample_datastore() in favor of using xarray's resample function. See example notebook 2.

2.0.0 (2023-05-24)
------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,9 @@
"metadata": {},
"outputs": [],
"source": [
"# We use the logic from xarray to resample. However, it returns an xarray dataset type\n",
"import xarray as xr\n",
"ds_xarray = xr.Dataset(ds).resample(time=\"47S\").mean()\n",
"\n",
"# Therefore we convert it back to the dtscalibration Datastore type.\n",
"# We use the logic from xarray to resample. However, it returns an xarray dataset type. Therefore we convert it back to the dtscalibration Datastore type.\n",
"from dtscalibration import DataStore\n",
"ds_resampled2 = DataStore(ds_xarray)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the resample function from dtscalibration has been removed in v2.0.1. The above example works versions from before 2.0.1 as well. Starting with version 2.0.1 the `xr.Dataset(ds).resample()` may become `ds.resample()`."
"ds_resampled = DataStore(ds.resample(time=\"47S\").mean())"
]
},
{
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ name = "dtscalibration"
description = "A Python package to load raw DTS files, perform a calibration, and plot the result."
readme = "README.rst"
license = "BSD-3-Clause"
requires-python = ">=3.8, <3.11"
requires-python = ">=3.9, <3.11"
authors = [
{email = "[email protected]"},
{name = "Bas des Tombe, Bart Schilperoort"}
Expand All @@ -46,7 +46,6 @@ classifiers = [
"Operating System :: POSIX",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Utilities",
Expand Down Expand Up @@ -118,7 +117,7 @@ build = [
features = ["dev"]

[[tool.hatch.envs.matrix_test.matrix]]
python = ["3.8", "3.9", "3.10"]
python = ["3.9", "3.10"]

[tool.hatch.envs.matrix_test.scripts]
test = ["pytest ./src/ ./tests/",] # --doctest-modules
Expand Down
5 changes: 5 additions & 0 deletions src/dtscalibration/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -5260,6 +5260,11 @@ def func(a):

return out

def resample_datastore(*args, **kwargs):
raise "ds.resample_datastore() is deprecated. Use " \
"from dtscalibration import DataStore; DataStore(ds.resample()) " \
"instead. See example notebook 2."


class ParameterIndexDoubleEnded:
"""
Expand Down
10 changes: 8 additions & 2 deletions src/dtscalibration/datastore_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,21 @@ def merge_double_ended_times(ds_fw, ds_bw, verify_timedeltas=True, verbose=True)
if verify_timedeltas:
dt = (ds_bw.isel(time=iuse_chbw).time.values - ds_fw.isel(time=iuse_chfw).time.values) /\
np.array(1000000000, dtype='timedelta64[ns]')
dt = (
(ds_bw.isel(time=iuse_chbw).time.values - ds_fw.isel(time=iuse_chfw).time.values) /
np.timedelta64(1, "s"))
leaveout = np.zeros_like(dt, dtype=bool)
leaveout[1:-1] = np.isclose(dt[:-2], dt[2:], atol=1.5, rtol=0.) * ~np.isclose(dt[:-2], dt[1:-1], atol=1.5, rtol=0.)
iuse_chfw2 = np.array(iuse_chfw)[~leaveout]
iuse_chbw2 = np.array(iuse_chbw)[~leaveout]

if verbose:
for itfw, itbw in zip(np.array(iuse_chfw)[leaveout], np.array(iuse_chbw)[leaveout]):
print(f"FW: {ds_fw.isel(time=itfw).time.values} and BW: {ds_bw.isel(time=itbw).time.values} do not "
f"belong together as their timedelta is larger than their neighboring timedeltas. Thrown out.")
print(
"The following measurements do not belong together, as the time difference\n"
"between the\forward and backward measurements is more than 1.5 seconds\n"
"larger than the neighboring measurements.\n"
f"FW: {ds_fw.isel(time=itfw).time.values} and BW: {ds_bw.isel(time=itbw).time.values}")

else:
iuse_chfw2 = iuse_chfw
Expand Down
2 changes: 1 addition & 1 deletion tests/test_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def test_resample_datastore():
directory=filepath, timezone_netcdf='UTC', file_ext='*.xml')
assert ds.time.size == 3

ds_resampled = DataStore(xr.Dataset(ds).resample(time="47S").mean())
ds_resampled = DataStore(ds.resample(time="47S").mean())

assert ds_resampled.time.size == 2
assert ds_resampled.st.dims == ('x', 'time'), 'The dimension have to ' \
Expand Down

0 comments on commit b72d407

Please sign in to comment.