Skip to content

Commit

Permalink
Change STA plotting and order of products
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasmarke committed Oct 18, 2024
1 parent 491441b commit 8f21ffb
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 43 deletions.
4 changes: 2 additions & 2 deletions mwrpy/level2/write_lev2_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ def get_products(

else:
product_list = (
"lifted_index",
"k_index",
"ko_index",
"total_totals",
"k_index",
"lifted_index",
"showalter_index",
"cape",
)
Expand Down
74 changes: 55 additions & 19 deletions mwrpy/plots/generate_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1598,12 +1598,65 @@ def _plot_sta(ax, data_in: ma.MaskedArray, name: str, time: ndarray, nc_file: st
data0, time0 = data_in, time
plot_range = ATTRIBUTES[name].plot_range
assert plot_range is not None

rolling_mean = _calculate_rolling_mean(time0, data0, win=0.25)
time0 = _nan_time_gaps(time0)
vmin, vmax = plot_range
vmax = np.min([np.nanmax(data0) + 0.05, vmax])
vmin = np.max([np.nanmin(data0) - 0.05, vmin])
vmax = np.min([np.nanmax(rolling_mean) + 0.05, vmax])
vmin = np.max([np.nanmin(rolling_mean) - 0.05, vmin])
_set_ax(ax, vmax, ATTRIBUTES[name].ylabel, min_y=vmin)
_set_title(ax, name, nc_file, "")

limit_cape = [1500, 300, 1, 0]
limit_k_index = [35, 30, 1, 0]
limit_total_totals = [53, 48, 1, 0]
limit_lifted_index = [0, -3, 0, 1]
limit_showalter_index = [2, -2, 0, 1]
limit_ko_index = [6, 2, 0, 1]

probability = ["Low", "High"]
l_color = ["#3cb371", "#E64A23"]

if vmin < eval("limit_" + name)[0] < vmax:
ax.plot(
time,
np.ones(len(time)) * eval("limit_" + name)[0],
color=l_color[eval("limit_" + name)[2]],
)
ax.text(
0.5,
eval("limit_" + name)[0] + 0.025 * (vmax - vmin),
probability[eval("limit_" + name)[2]],
)
if vmin < eval("limit_" + name)[1] < vmax:
ax.plot(
time,
np.ones(len(time)) * eval("limit_" + name)[1],
color=l_color[eval("limit_" + name)[3]],
)
ax.text(
0.5,
eval("limit_" + name)[1] - 0.05 * (vmax - vmin),
probability[eval("limit_" + name)[3]],
)
if vmax < np.min(eval("limit_" + name)[:2]):
ax.text(0.5, vmax - 0.05 * (vmax - vmin), probability[eval("limit_" + name)[3]])
if vmin > np.max(eval("limit_" + name)[:2]):
ax.text(0.5, vmin + 0.05 * (vmax - vmin), probability[eval("limit_" + name)[2]])

ax.plot(
time0,
rolling_mean,
color="darkblue",
linewidth=4.0,
)
ax.plot(
time0,
rolling_mean,
color="lightblue",
linewidth=1.2,
)

flag_tmp = _calculate_rolling_mean(time, flag, win=1 / 60)
data_f = np.zeros((len(flag_tmp), 10), np.float32)
data_f[flag_tmp > 0, :] = 1.0
Expand Down Expand Up @@ -1635,20 +1688,3 @@ def _plot_sta(ax, data_in: ma.MaskedArray, name: str, time: ndarray, nc_file: st
(time_i, np.linspace(vmin, vmax, 10)),
nc_file,
)

ax.plot(time, data_in, ".", color="royalblue", markersize=1)
ax.axhline(linewidth=0.8, color="k")
rolling_mean = _calculate_rolling_mean(time0, data0)
time0 = _nan_time_gaps(time0)
ax.plot(
time0,
rolling_mean,
color="sienna",
linewidth=2.0,
)
ax.plot(
time0,
rolling_mean,
color="wheat",
linewidth=0.6,
)
21 changes: 11 additions & 10 deletions mwrpy/plots/plot_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class PlotMeta(NamedTuple):


_K = "K"
_JKG = "J kg$^{-1}$"
_KGM2 = "kg m$^{-2}$"
_GM2 = "g m$^{-2}$"
_KGM3 = "kg m$^{-3}$"
Expand Down Expand Up @@ -260,48 +261,48 @@ class PlotMeta(NamedTuple):
),
"lifted_index": PlotMeta(
name="Lifted index",
ylabel="",
plot_range=(0, 100),
ylabel=_K,
plot_range=(-100, 100),
plot_type="bar",
source="sta",
ele=(89.0, 91.0),
),
"ko_index": PlotMeta(
name="KO index",
ylabel="",
ylabel=_K,
plot_range=(-100, 100),
plot_type="bar",
source="sta",
ele=(89.0, 91.0),
),
"total_totals": PlotMeta(
name="Total totals",
ylabel="",
plot_range=(0, 100),
ylabel=_K,
plot_range=(-100, 100),
plot_type="bar",
source="sta",
ele=(89.0, 91.0),
),
"k_index": PlotMeta(
name="K index",
ylabel="",
plot_range=(0, 100),
ylabel=_K,
plot_range=(-100, 100),
plot_type="bar",
source="sta",
ele=(89.0, 91.0),
),
"showalter_index": PlotMeta(
name="Showalter index",
ylabel="",
ylabel=_K,
plot_range=(-100, 100),
plot_type="bar",
source="sta",
ele=(89.0, 91.0),
),
"cape": PlotMeta(
name="CAPE",
ylabel="",
plot_range=(-100, 1000),
ylabel=_JKG,
plot_range=(-5000, 5000),
plot_type="bar",
source="sta",
ele=(89.0, 91.0),
Expand Down
26 changes: 14 additions & 12 deletions mwrpy/process_mwrpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def main(args):
logging.info(f"Processing took {elapsed_time:.1f} seconds")
if args.command != "no-plot":
logging.info(f"Plotting {product} product, {args.site} {date}")
# try:
plot_product(product, date, args.site)
# except TypeError as err:
# logging.error(err)
try:
plot_product(product, date, args.site)
except TypeError as err:
logging.error(err)


def process_product(prod: str, date: datetime.date, site: str):
Expand Down Expand Up @@ -109,6 +109,8 @@ def process_product(prod: str, date: datetime.date, site: str):

def plot_product(prod: str, date, site: str):
filename = _get_filename(prod, date, site)
if not os.path.isfile(filename):
logging.warning("Nothing to plot for product " + prod)
output_dir = f"{os.path.dirname(filename)}/"

if os.path.isfile(filename) and prod[0] == "1":
Expand Down Expand Up @@ -155,12 +157,12 @@ def plot_product(prod: str, date, site: str):
if prod == "2I06":
f_names = list(
[
"lifted_index",
"ko_index",
"total_totals",
"cape",
"k_index",
"total_totals",
"lifted_index",
"showalter_index",
"cape",
"ko_index",
]
)
else:
Expand Down Expand Up @@ -189,12 +191,12 @@ def plot_product(prod: str, date, site: str):
)
)
f_names = [
"lifted_index",
"ko_index",
"total_totals",
"cape",
"k_index",
"total_totals",
"lifted_index",
"showalter_index",
"cape",
"ko_index",
]
if var_name == "stability":
keymap = {
Expand Down

0 comments on commit 8f21ffb

Please sign in to comment.