From 824799cf082678206f302ba71b9ee24288473622 Mon Sep 17 00:00:00 2001 From: thijsvl Date: Thu, 20 Jun 2024 15:05:55 +0200 Subject: [PATCH 1/4] Suppressed performance warning for many small chunks in reorder(...) --- stmtools/stm.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/stmtools/stm.py b/stmtools/stm.py index 01b5541..bdab52e 100644 --- a/stmtools/stm.py +++ b/stmtools/stm.py @@ -7,8 +7,10 @@ import dask.array as da import geopandas as gpd import numpy as np +import pandas as pd import pymorton as pm import xarray as xr +import warnings from scipy.spatial import KDTree from shapely.geometry import Point from shapely.strtree import STRtree @@ -392,6 +394,9 @@ def reorder(self, xlabel="azimuth", ylabel="range", xscale=1.0, yscale=1.0): resolution of the ordering: only the whole-number part influences the order. While coordinates could also be offset, this has limited effect on the relative order. + Also note that reordering a dataset may be an expensive operation. Because it is applied + lazily, this preformance cost will only manifest once the elements are evaluated. + Parameters ---------- self : SpaceTimeMatrix @@ -416,7 +421,12 @@ def reorder(self, xlabel="azimuth", ylabel="range", xscale=1.0, yscale=1.0): "space": self._obj.chunksizes["space"][0], "time": self._obj.chunksizes["time"][0], } - self._obj = self._obj.sortby(self._obj.order) + with warnings.catch_warnings(): + # Trying to supporess only [...]/lib/python3.12/site-packages/xarray/core/indexing.py:1620: PerformanceWarning: Slicing with an out-of-order index is generating [...] times more chunks + # but unable to find the warning category. + #warnings.simplefilter(action="ignore", category=pd.errors.PerformanceWarning) + warnings.simplefilter(action="ignore") + self._obj = self._obj.sortby(self._obj.order) self._obj = self._obj.chunk(chunks) return self._obj From 3afe3ddaf8a2b9581f0faaf062b2debe2046241b Mon Sep 17 00:00:00 2001 From: thijsvl Date: Thu, 20 Jun 2024 15:11:48 +0200 Subject: [PATCH 2/4] Reduced length of single long comment line. --- stmtools/stm.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stmtools/stm.py b/stmtools/stm.py index bdab52e..fa49bda 100644 --- a/stmtools/stm.py +++ b/stmtools/stm.py @@ -422,7 +422,9 @@ def reorder(self, xlabel="azimuth", ylabel="range", xscale=1.0, yscale=1.0): "time": self._obj.chunksizes["time"][0], } with warnings.catch_warnings(): - # Trying to supporess only [...]/lib/python3.12/site-packages/xarray/core/indexing.py:1620: PerformanceWarning: Slicing with an out-of-order index is generating [...] times more chunks + # Trying to supporess only + # [...]/lib/python3.12/site-packages/xarray/core/indexing.py:1620: PerformanceWarning: + # Slicing with an out-of-order index is generating [...] times more chunks # but unable to find the warning category. #warnings.simplefilter(action="ignore", category=pd.errors.PerformanceWarning) warnings.simplefilter(action="ignore") From 8f5a22ce357d1ebf63cc75706fa14b7643f71ec3 Mon Sep 17 00:00:00 2001 From: thijsvl Date: Thu, 20 Jun 2024 15:13:54 +0200 Subject: [PATCH 3/4] Removed unused import from stm.py --- stmtools/stm.py | 1 - 1 file changed, 1 deletion(-) diff --git a/stmtools/stm.py b/stmtools/stm.py index fa49bda..5aa3e8a 100644 --- a/stmtools/stm.py +++ b/stmtools/stm.py @@ -7,7 +7,6 @@ import dask.array as da import geopandas as gpd import numpy as np -import pandas as pd import pymorton as pm import xarray as xr import warnings From 5fb59fbbb6b16a2088329168e624824d9f3200d5 Mon Sep 17 00:00:00 2001 From: thijsvl Date: Thu, 20 Jun 2024 15:16:45 +0200 Subject: [PATCH 4/4] Sorted stm.py imports. --- stmtools/stm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stmtools/stm.py b/stmtools/stm.py index 5aa3e8a..e2279ce 100644 --- a/stmtools/stm.py +++ b/stmtools/stm.py @@ -1,6 +1,7 @@ """space-time matrix module.""" import logging +import warnings from collections.abc import Iterable from pathlib import Path @@ -9,7 +10,6 @@ import numpy as np import pymorton as pm import xarray as xr -import warnings from scipy.spatial import KDTree from shapely.geometry import Point from shapely.strtree import STRtree