From 937a9bb17ba585f8d6fc3d81d9193ff929f7b520 Mon Sep 17 00:00:00 2001 From: zssherman Date: Thu, 28 Mar 2024 10:11:57 -0500 Subject: [PATCH] ADD: Adding an example of the calculated_percentages function. --- examples/utils/plot_calculated_percentages.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/utils/plot_calculated_percentages.py diff --git a/examples/utils/plot_calculated_percentages.py b/examples/utils/plot_calculated_percentages.py new file mode 100644 index 0000000000..0024f9edbb --- /dev/null +++ b/examples/utils/plot_calculated_percentages.py @@ -0,0 +1,33 @@ +""" +Calculate and plot aerosol percentanges. +---------------------------------------- + +Example on how to plot a Pie Chart of the composition of aerosols in a volume of air by +obtaining percentanges of each aerosol from the dataset. + +Author: Zach Sherman +""" + +from arm_test_data import DATASETS +import matplotlib.pyplot as plt + +import act + +# Read in the data. +ds = act.io.read_arm_netcdf(DATASETS.fetch("sgpaosacsmE13.b2.20230420.000109.nc")) + +# Calculate percentages using selected fields. +fields = ['sulfate', 'ammonium', 'nitrate', 'chloride'] +time_slice = ('2023-04-20T17:38:20.000000000', '2023-04-20T20:29:47.000000000') +threshold = 0.0 +percentages = act.utils.calculate_percentages(ds, fields, time_slice=time_slice, threshold=0.0) + +# Get values for the pie chart. +labels = percentages.keys() +sizes = [percentages[i] for i in percentages.keys()] + +# Plot the figure +fig, ax = plt.subplots() +ax.pie(sizes, labels=labels, autopct='%1.1f%%') +plt.show() +ds.close()