From 824799cf082678206f302ba71b9ee24288473622 Mon Sep 17 00:00:00 2001 From: thijsvl Date: Thu, 20 Jun 2024 15:05:55 +0200 Subject: [PATCH] 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