|
34 | 34 | # are probably the most likely to be re-visited) and read from the file |
35 | 35 | # if the user requests some data outside of those chunks |
36 | 36 | import collections.abc |
| 37 | +import warnings |
| 38 | + |
37 | 39 | import logging |
38 | 40 | import sys |
39 | 41 | import os |
@@ -615,14 +617,16 @@ def update_finite_min_max_values(self, finite_values: np.ndarray, |
615 | 617 | h_stop: int, v_stop: int): |
616 | 618 | """can return either two floats or two arrays""" |
617 | 619 |
|
618 | | - # we need initial to support empty arrays |
619 | | - vmin = np.nanmin(finite_values, initial=np.nan) |
620 | | - vmax = np.nanmax(finite_values, initial=np.nan) |
| 620 | + with warnings.catch_warnings(): |
| 621 | + warnings.simplefilter("ignore", category=RuntimeWarning) |
| 622 | + # we need initial to support empty arrays |
| 623 | + vmin = np.nanmin(finite_values, initial=np.nan) |
| 624 | + vmax = np.nanmax(finite_values, initial=np.nan) |
621 | 625 |
|
622 | | - self.vmin = ( |
623 | | - np.nanmin([self.vmin, vmin]) if self.vmin is not None else vmin) |
624 | | - self.vmax = ( |
625 | | - np.nanmax([self.vmax, vmax]) if self.vmax is not None else vmax) |
| 626 | + self.vmin = ( |
| 627 | + np.nanmin([self.vmin, vmin]) if self.vmin is not None else vmin) |
| 628 | + self.vmax = ( |
| 629 | + np.nanmax([self.vmax, vmax]) if self.vmax is not None else vmax) |
626 | 630 | return self.vmin, self.vmax |
627 | 631 |
|
628 | 632 | def get_axes_area(self): |
@@ -969,33 +973,38 @@ def update_finite_min_max_values(self, finite_values: np.ndarray, |
969 | 973 | assert isinstance(self.vmin, dict) and isinstance(self.vmax, dict) |
970 | 974 | assert h_stop >= h_start |
971 | 975 |
|
972 | | - # per column => axis=0 |
973 | | - local_vmin = np.nanmin(finite_values, axis=0, initial=np.nan) |
974 | | - local_vmax = np.nanmax(finite_values, axis=0, initial=np.nan) |
975 | 976 | num_cols = h_stop - h_start |
976 | | - assert local_vmin.shape == (num_cols,), \ |
977 | | - (f"unexpected shape: {local_vmin.shape} ({finite_values.shape=}) vs " |
978 | | - f"{(num_cols,)} ({h_start=} {h_stop=})") |
979 | 977 | # vmin or self.vmin can both be nan (if the whole section data |
980 | 978 | # is/was nan) |
981 | 979 | global_vmin = self.vmin |
982 | 980 | global_vmax = self.vmax |
983 | 981 | vmin_slice = np.empty(num_cols, dtype=np.float64) |
984 | 982 | vmax_slice = np.empty(num_cols, dtype=np.float64) |
985 | | - for global_col_idx in range(h_start, h_stop): |
986 | | - local_col_idx = global_col_idx - h_start |
987 | | - |
988 | | - col_min = np.nanmin([global_vmin.get(global_col_idx, np.nan), |
989 | | - local_vmin[local_col_idx]]) |
990 | | - # update the global vmin dict inplace |
991 | | - global_vmin[global_col_idx] = col_min |
992 | | - vmin_slice[local_col_idx] = col_min |
993 | | - |
994 | | - col_max = np.nanmax([global_vmax.get(global_col_idx, np.nan), |
995 | | - local_vmax[local_col_idx]]) |
996 | | - # update the global vmax dict inplace |
997 | | - global_vmax[global_col_idx] = col_max |
998 | | - vmax_slice[local_col_idx] = col_max |
| 983 | + |
| 984 | + # per column => axis=0 |
| 985 | + with warnings.catch_warnings(): |
| 986 | + warnings.simplefilter("ignore", category=RuntimeWarning) |
| 987 | + |
| 988 | + local_vmin = np.nanmin(finite_values, axis=0, initial=np.nan) |
| 989 | + local_vmax = np.nanmax(finite_values, axis=0, initial=np.nan) |
| 990 | + |
| 991 | + assert local_vmin.shape == (num_cols,), \ |
| 992 | + (f"unexpected shape: {local_vmin.shape} ({finite_values.shape=}) vs " |
| 993 | + f"{(num_cols,)} ({h_start=} {h_stop=})") |
| 994 | + for global_col_idx in range(h_start, h_stop): |
| 995 | + local_col_idx = global_col_idx - h_start |
| 996 | + |
| 997 | + col_min = np.nanmin([global_vmin.get(global_col_idx, np.nan), |
| 998 | + local_vmin[local_col_idx]]) |
| 999 | + # update the global vmin dict inplace |
| 1000 | + global_vmin[global_col_idx] = col_min |
| 1001 | + vmin_slice[local_col_idx] = col_min |
| 1002 | + |
| 1003 | + col_max = np.nanmax([global_vmax.get(global_col_idx, np.nan), |
| 1004 | + local_vmax[local_col_idx]]) |
| 1005 | + # update the global vmax dict inplace |
| 1006 | + global_vmax[global_col_idx] = col_max |
| 1007 | + vmax_slice[local_col_idx] = col_max |
999 | 1008 | return vmin_slice, vmax_slice |
1000 | 1009 |
|
1001 | 1010 |
|
@@ -1354,18 +1363,20 @@ def get_color_value(array, global_vmin, global_vmax, axis=None): |
1354 | 1363 | try: |
1355 | 1364 | finite_value = get_finite_numeric_values(array) |
1356 | 1365 |
|
1357 | | - vmin = np.nanmin(finite_value, axis=axis) |
1358 | | - if global_vmin is not None: |
1359 | | - # vmin or global_vmin can both be nan (if the whole section data is/was nan) |
1360 | | - global_vmin = np.nanmin([global_vmin, vmin], axis=axis) |
1361 | | - else: |
1362 | | - global_vmin = vmin |
1363 | | - vmax = np.nanmax(finite_value, axis=axis) |
1364 | | - if global_vmax is not None: |
1365 | | - # vmax or global_vmax can both be nan (if the whole section data is/was nan) |
1366 | | - global_vmax = np.nanmax([global_vmax, vmax], axis=axis) |
1367 | | - else: |
1368 | | - global_vmax = vmax |
| 1366 | + with warnings.catch_warnings(): |
| 1367 | + warnings.simplefilter("ignore", category=RuntimeWarning) |
| 1368 | + vmin = np.nanmin(finite_value, axis=axis) |
| 1369 | + if global_vmin is not None: |
| 1370 | + # vmin or global_vmin can both be nan (if the whole section data is/was nan) |
| 1371 | + global_vmin = np.nanmin([global_vmin, vmin], axis=axis) |
| 1372 | + else: |
| 1373 | + global_vmin = vmin |
| 1374 | + vmax = np.nanmax(finite_value, axis=axis) |
| 1375 | + if global_vmax is not None: |
| 1376 | + # vmax or global_vmax can both be nan (if the whole section data is/was nan) |
| 1377 | + global_vmax = np.nanmax([global_vmax, vmax], axis=axis) |
| 1378 | + else: |
| 1379 | + global_vmax = vmax |
1369 | 1380 | color_value = scale_to_01range(finite_value, global_vmin, global_vmax) |
1370 | 1381 | except (ValueError, TypeError): |
1371 | 1382 | global_vmin = None |
|
0 commit comments