Skip to content

Commit

Permalink
Add precip colorscale from blending manuscript (#294)
Browse files Browse the repository at this point in the history
* Add precip colorscale from blending manuscript

* Fix for tests

* add new colorscale to steps blending gallery example
  • Loading branch information
RubenImhoff committed Aug 10, 2022
1 parent ed76516 commit 5b2a6b8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
8 changes: 7 additions & 1 deletion examples/blended_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@
radar_precip[-1, :, :],
geodata=radar_metadata,
title=f"Radar observation at {date_str}",
colorscale="STEPS-NL",
)
plt.subplot(122)
plot_precip_field(
nwp_precip[0, :, :], geodata=nwp_metadata, title=f"NWP forecast at {date_str}"
nwp_precip[0, :, :],
geodata=nwp_metadata,
title=f"NWP forecast at {date_str}",
colorscale="STEPS-NL",
)
plt.tight_layout()
plt.show()
Expand Down Expand Up @@ -198,6 +202,7 @@
geodata=radar_metadata,
title=f"Nowcast +{leadtime} min",
axis="off",
colorscale="STEPS-NL",
colorbar=False,
)

Expand All @@ -208,6 +213,7 @@
geodata=nwp_metadata,
title=f"NWP +{leadtime} min",
axis="off",
colorscale="STEPS-NL",
colorbar=False,
)

Expand Down
1 change: 1 addition & 0 deletions pysteps/tests/test_plt_precipfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
("bom", "intensity", None, "pysteps", None, None, True, "on"),
("fmi", "intensity", None, "pysteps", None, None, True, "on"),
("knmi", "intensity", None, "pysteps", None, None, True, "on"),
("knmi", "intensity", None, "STEPS-NL", None, None, True, "on"),
("knmi", "intensity", [300, 300, 500, 500], "pysteps", None, None, True, "on"),
("opera", "intensity", None, "pysteps", None, None, True, "on"),
("saf", "intensity", None, "pysteps", None, None, True, "on"),
Expand Down
28 changes: 24 additions & 4 deletions pysteps/visualization/precipfields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -- coding: utf-8 --
# -*- coding: utf-8 -*-
"""
pysteps.visualization.precipfields
==================================
Expand Down Expand Up @@ -99,7 +99,7 @@ def plot_precip_field(
of the form (lower left x, lower left y ,upper right x, upper right y).
If 'geodata' is not None, the bbox is in map coordinates, otherwise
it represents image pixels.
colorscale : {'pysteps', 'STEPS-BE', 'BOM-RF3'}, optional
colorscale : {'pysteps', 'STEPS-BE', 'STEPS-NL', 'BOM-RF3'}, optional
Which colorscale to use. Applicable if units is 'mm/h', 'mm' or 'dBZ'.
probthr : float, optional
Intensity threshold to show in the color bar of the exceedance
Expand Down Expand Up @@ -246,7 +246,7 @@ def get_colormap(ptype, units="mm/h", colorscale="pysteps"):
units : {'mm/h', 'mm', 'dBZ'}, optional
Units of the input array. If ptype is 'prob', this specifies the unit of
the intensity threshold.
colorscale : {'pysteps', 'STEPS-BE', 'BOM-RF3'}, optional
colorscale : {'pysteps', 'STEPS-BE', 'STEPS-NL', 'BOM-RF3'}, optional
Which colorscale to use. Applicable if units is 'mm/h', 'mm' or 'dBZ'.
Returns
Expand All @@ -273,6 +273,8 @@ def get_colormap(ptype, units="mm/h", colorscale="pysteps"):
cmap.set_over("black", 1)
if colorscale == "pysteps":
cmap.set_over("darkred", 1)
if colorscale == "STEPS-NL":
cmap.set_over("darkmagenta", 1)
if colorscale == "STEPS-BE":
cmap.set_over("black", 1)
norm = colors.BoundaryNorm(clevs, cmap.N)
Expand Down Expand Up @@ -304,7 +306,7 @@ def _get_colorlist(units="mm/h", colorscale="pysteps"):
units : str
Units of the input array (mm/h, mm or dBZ)
colorscale : str
Which colorscale to use (BOM-RF3, pysteps, STEPS-BE)
Which colorscale to use (BOM-RF3, pysteps, STEPS-BE, STEPS-NL)
Returns
-------
Expand Down Expand Up @@ -428,6 +430,24 @@ def _get_colorlist(units="mm/h", colorscale="pysteps"):
clevs = np.arange(10, 65, 5)
else:
raise ValueError("Wrong units in get_colorlist: %s" % units)
elif colorscale == "STEPS-NL":
redgrey_hex = "#%02x%02x%02x" % (156, 126, 148)
color_list = [
"lightgrey",
"lightskyblue",
"deepskyblue",
"blue",
"darkblue",
"yellow",
"gold",
"darkorange",
"red",
"darkred",
]
if units in ["mm/h", "mm"]:
clevs = [0.1, 0.5, 1.0, 1.6, 2.5, 4.0, 6.4, 10.0, 16.0, 25.0, 40.0]
else:
raise ValueError("Wrong units in get_colorlist: %s" % units)
elif colorscale == "STEPS-BE":
color_list = [
"cyan",
Expand Down

0 comments on commit 5b2a6b8

Please sign in to comment.