Skip to content

Commit eb5c537

Browse files
committed
ENH: added possibility to cut data at vmin/vmax for intercomp scatter plots
1 parent 458dcf6 commit eb5c537

File tree

5 files changed

+45
-83
lines changed

5 files changed

+45
-83
lines changed

src/pyrad_proc/pyrad/graph/plots.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,8 @@ def plot_scatter(
534534
rad2_name="RADAR002",
535535
titl="colocated radar gates",
536536
cmap=None,
537+
vmin=None,
538+
vmax=None,
537539
):
538540
"""
539541
2D histogram
@@ -563,6 +565,10 @@ def plot_scatter(
563565
cmap : str or None
564566
name of the colormap. If None it will be choosen the default for the
565567
field_name
568+
vmin: float
569+
Minimum value of the 2D histogram.
570+
vmax: float
571+
Maximum value of the 2D histogram.
566572
567573
Returns
568574
-------
@@ -616,6 +622,10 @@ def plot_scatter(
616622
ax.set_ylabel(labely)
617623
ax.set_title(titl)
618624

625+
if vmin and vmax:
626+
ax.set_xlim([vmin, vmax])
627+
ax.set_ylim([vmin, vmax])
628+
619629
cb = fig.colorbar(cax)
620630
cb.set_label(label)
621631

src/pyrad_proc/pyrad/prod/process_intercomp_products.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ def generate_intercomp_products(dataset, prdcfg):
8787
vmax: float
8888
Maximum value of the density plot. If vmin or vmax are not define the range limits
8989
of the field as defined in the Py-ART config file are going to be used.
90+
cap_limits: bool
91+
If set to 1, all values larger than vmax or smaller than vmin will be discarded from the
92+
scatter plot. If set to 0, they will be kept and assigned to the smallest/largest bin
93+
of the histogram. Default is 0.
9094
scatter_type: str
9195
Type of scatter plot. Can be a plot for each radar volume
9296
(instant) or at the end of the processing period
@@ -214,6 +218,7 @@ def generate_intercomp_products(dataset, prdcfg):
214218
step = prdcfg.get("step", None)
215219
vmin = prdcfg.get("vmin", None)
216220
vmax = prdcfg.get("vmax", None)
221+
cap_limits = prdcfg.get("cap_limits", 0)
217222

218223
fname_list = []
219224
for i in range(len(range_bins) - 1): # loop on range bins
@@ -260,6 +265,7 @@ def generate_intercomp_products(dataset, prdcfg):
260265
transform=transform,
261266
vmin=vmin,
262267
vmax=vmax,
268+
cap_limits=cap_limits,
263269
)
264270
if hist_2d is None:
265271
return None
@@ -306,6 +312,8 @@ def generate_intercomp_products(dataset, prdcfg):
306312
lin_regr_slope1=stats["intercep_slope_1"],
307313
rad1_name=dataset["intercomp_dict"]["rad1_name"],
308314
rad2_name=dataset["intercomp_dict"]["rad2_name"],
315+
vmin=vmin,
316+
vmax=vmax,
309317
)
310318

311319
fname_list.extend(f_list)

src/pyrad_proc/pyrad/util/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,4 @@
9898
from .data_retrieval_utils import retrieve_CPCCV # noqa
9999
from .data_retrieval_utils import retrieve_AQC_XLS # noqa
100100

101-
from .math_utils import bit_pack # noqa
102-
from .math_utils import bit_unpack # noqa
103-
104101
__all__ = [s for s in dir() if not s.startswith("_")]

src/pyrad_proc/pyrad/util/math_utils.py

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/pyrad_proc/pyrad/util/radar_utils.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,7 @@ def compute_2d_stats(
18121812
vmin=None,
18131813
vmax=None,
18141814
transform=None,
1815+
cap_limits=False,
18151816
):
18161817
"""
18171818
computes a 2D histogram and statistics of the data
@@ -1827,13 +1828,16 @@ def compute_2d_stats(
18271828
step2 : float
18281829
size of the bins along dimension 2
18291830
vmin: float
1830-
Minimum value of the density plot. If vmin or vmax are not define the range limits
1831+
Minimum value of the 2D histogram. If vmin or vmax are not define the range limits
18311832
of the field as defined in the Py-ART config file are going to be used.
18321833
vmax: float
1833-
Maximum value of the density plot. If vmin or vmax are not define the range limits
1834+
Maximum value of the 2D histogram. If vmin or vmax are not define the range limits
18341835
of the field as defined in the Py-ART config file are going to be used.
18351836
transform : func
18361837
A function to use to transform the data prior to computing the stats
1838+
cap_limits: bool
1839+
If true, all values larger than vmax or smaller than vmin will be discarded from the
1840+
scatter plot. Otherwise, they will be kept and assigned to the smallest/largest bin
18371841
18381842
Returns
18391843
-------
@@ -1875,6 +1879,7 @@ def compute_2d_stats(
18751879
transform=transform,
18761880
vmin=vmin,
18771881
vmax=vmax,
1882+
cap_limits=cap_limits,
18781883
)
18791884
step_aux1 = bin_edges1[1] - bin_edges1[0]
18801885
bin_centers1 = bin_edges1[:-1] + step_aux1 / 2.0
@@ -1960,9 +1965,10 @@ def compute_2d_hist(
19601965
field_name2,
19611966
step1=None,
19621967
step2=None,
1963-
transform=None,
19641968
vmin=None,
19651969
vmax=None,
1970+
transform=None,
1971+
cap_limits=False,
19661972
):
19671973
"""
19681974
computes a 2D histogram of the data
@@ -1977,10 +1983,17 @@ def compute_2d_hist(
19771983
size of the bins along dimension 1
19781984
step2 : float
19791985
size of the bins along dimension 2
1980-
1981-
1986+
vmin: float
1987+
Minimum value of the 2D histogram. If vmin or vmax are not define the range limits
1988+
of the field as defined in the Py-ART config file are going to be used.
1989+
vmax: float
1990+
Maximum value of the 2D histogram. If vmin or vmax are not define the range limits
1991+
of the field as defined in the Py-ART config file are going to be used.
19821992
transform: func
19831993
A function to use to transform the histogram bins
1994+
cap_limits: bool
1995+
If true, all values larger than vmax or smaller than vmin will be discarded from the
1996+
scatter plot. Otherwise, they will be kept and assigned to the smallest/largest bin
19841997
19851998
Returns
19861999
-------
@@ -2001,17 +2014,22 @@ def compute_2d_hist(
20012014
step_aux2 = bin_edges2[1] - bin_edges2[0]
20022015
bin_centers2 = bin_edges2[:-1] + step_aux2 / 2.0
20032016

2004-
field1[field1 < bin_centers1[0]] = bin_centers1[0]
2005-
field1[field1 > bin_centers1[-1]] = bin_centers1[-1]
2017+
if not cap_limits:
2018+
field1[field1 < bin_centers1[0]] = bin_centers1[0]
2019+
field1[field1 > bin_centers1[-1]] = bin_centers1[-1]
20062020

2007-
field2[field2 < bin_centers2[0]] = bin_centers2[0]
2008-
field2[field2 > bin_centers2[-1]] = bin_centers2[-1]
2021+
field2[field2 < bin_centers2[0]] = bin_centers2[0]
2022+
field2[field2 > bin_centers2[-1]] = bin_centers2[-1]
2023+
hist_range = None
2024+
else:
2025+
hist_range = [[vmin, vmax], [vmin, vmax]]
20092026

20102027
fill_value = pyart.config.get_fillvalue()
20112028
return np.histogram2d(
20122029
field1.filled(fill_value=fill_value),
20132030
field2.filled(fill_value=fill_value),
20142031
bins=[bin_edges1, bin_edges2],
2032+
range=hist_range,
20152033
)
20162034

20172035

0 commit comments

Comments
 (0)