Skip to content

Commit

Permalink
ENH: updated feature detection function and example (#1487)
Browse files Browse the repository at this point in the history
* Rename functions and variables to remove "convective-stratiform"

We want to make this function more generic so it can be used on a wide variety of fields and not just to detect convective and stratiform elements. I renamed most of the functions and some of the variables to reflect this and hopefully make it easier to use.

* Add new reference

* Incorporate binary closing option to functions

* Add author to functions

* Slight reformat for linting

* More linting formatting

* Add alternate option for getting under/over estimate field

* Create plot_feature_detection.py

* Delete plot_convective_stratiform.py

* Update echo_class.py

* Update plot_feature_detection.py

* Update plot_feature_detection.py

* Update test_echo_class.py

* Keep original function and add warning

* Revert "Delete plot_convective_stratiform.py"

This reverts commit 2bff81a.

* Update __init__.py

* Update echo_class.py

* Update dictionary keys

* Update plot_convective_stratiform.py

* Fix issues

* Update plot_convective_stratiform.py
  • Loading branch information
lauratomkins authored Nov 14, 2023
1 parent bb1fe24 commit 35aaff2
Show file tree
Hide file tree
Showing 7 changed files with 1,328 additions and 322 deletions.
42 changes: 24 additions & 18 deletions examples/retrieve/plot_convective_stratiform.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@

# add to grid object
# mask zero values (no surface echo)
convsf_masked = np.ma.masked_equal(convsf_dict["convsf"]["data"], 0)
convsf_masked = np.ma.masked_equal(convsf_dict["feature_detection"]["data"], 0)
# mask 3 values (weak echo)
convsf_masked = np.ma.masked_equal(convsf_masked, 3)
# add dimension to array to add to grid object
convsf_dict["convsf"]["data"] = convsf_masked[None, :, :]
convsf_dict["feature_detection"]["data"] = convsf_masked
# add field
grid.add_field("convsf", convsf_dict["convsf"], replace_existing=True)
grid.add_field("convsf", convsf_dict["feature_detection"], replace_existing=True)

# create plot using GridMapDisplay
# plot variables
Expand Down Expand Up @@ -195,23 +195,23 @@
# ``estimate_flag=False``), but we recommend keeping it turned on.

# mask weak echo and no surface echo
convsf_masked = np.ma.masked_equal(convsf_dict["convsf"]["data"], 0)
convsf_masked = np.ma.masked_equal(convsf_dict["feature_detection"]["data"], 0)
convsf_masked = np.ma.masked_equal(convsf_masked, 3)
convsf_dict["convsf"]["data"] = convsf_masked
convsf_dict["feature_detection"]["data"] = convsf_masked
# underest.
convsf_masked = np.ma.masked_equal(convsf_dict["convsf_under"]["data"], 0)
convsf_masked = np.ma.masked_equal(convsf_dict["feature_under"]["data"], 0)
convsf_masked = np.ma.masked_equal(convsf_masked, 3)
convsf_dict["convsf_under"]["data"] = convsf_masked
convsf_dict["feature_under"]["data"] = convsf_masked
# overest.
convsf_masked = np.ma.masked_equal(convsf_dict["convsf_over"]["data"], 0)
convsf_masked = np.ma.masked_equal(convsf_dict["feature_over"]["data"], 0)
convsf_masked = np.ma.masked_equal(convsf_masked, 3)
convsf_dict["convsf_over"]["data"] = convsf_masked
convsf_dict["feature_over"]["data"] = convsf_masked

# Plot each estimation
plt.figure(figsize=(10, 4))
ax1 = plt.subplot(131)
ax1.pcolormesh(
convsf_dict["convsf"]["data"][0, :, :],
convsf_dict["feature_detection"]["data"][0, :, :],
vmin=0,
vmax=2,
cmap=plt.get_cmap("viridis", 3),
Expand All @@ -220,13 +220,19 @@
ax1.set_aspect("equal")
ax2 = plt.subplot(132)
ax2.pcolormesh(
convsf_dict["convsf_under"]["data"], vmin=0, vmax=2, cmap=plt.get_cmap("viridis", 3)
convsf_dict["feature_under"]["data"][0, :, :],
vmin=0,
vmax=2,
cmap=plt.get_cmap("viridis", 3),
)
ax2.set_title("Underestimate")
ax2.set_aspect("equal")
ax3 = plt.subplot(133)
ax3.pcolormesh(
convsf_dict["convsf_over"]["data"], vmin=0, vmax=2, cmap=plt.get_cmap("viridis", 3)
convsf_dict["feature_over"]["data"][0, :, :],
vmin=0,
vmax=2,
cmap=plt.get_cmap("viridis", 3),
)
ax3.set_title("Overestimate")
ax3.set_aspect("equal")
Expand Down Expand Up @@ -274,13 +280,13 @@

# add to grid object
# mask zero values (no surface echo)
convsf_masked = np.ma.masked_equal(convsf_dict["convsf"]["data"], 0)
convsf_masked = np.ma.masked_equal(convsf_dict["feature_detection"]["data"], 0)
# mask 3 values (weak echo)
convsf_masked = np.ma.masked_equal(convsf_masked, 3)
# add dimension to array to add to grid object
convsf_dict["convsf"]["data"] = convsf_masked[None, :, :]
convsf_dict["feature_detection"]["data"] = convsf_masked
# add field
grid.add_field("convsf", convsf_dict["convsf"], replace_existing=True)
grid.add_field("convsf", convsf_dict["feature_detection"], replace_existing=True)

# create plot using GridMapDisplay
# plot variables
Expand Down Expand Up @@ -393,13 +399,13 @@

# add to grid object
# mask zero values (no surface echo)
convsf_masked = np.ma.masked_equal(convsf_dict["convsf"]["data"], 0)
convsf_masked = np.ma.masked_equal(convsf_dict["feature_detection"]["data"], 0)
# mask 3 values (weak echo)
convsf_masked = np.ma.masked_equal(convsf_masked, 3)
# add dimension to array to add to grid object
convsf_dict["convsf"]["data"] = convsf_masked[None, :, :]
convsf_dict["feature_detection"]["data"] = convsf_masked
# add field
grid.add_field("convsf", convsf_dict["convsf"], replace_existing=True)
grid.add_field("convsf", convsf_dict["feature_detection"], replace_existing=True)

# create plot using GridMapDisplay
# plot variables
Expand Down
Loading

0 comments on commit 35aaff2

Please sign in to comment.