Skip to content

Commit

Permalink
ADD: Adding an example of the calculated_percentages function.
Browse files Browse the repository at this point in the history
  • Loading branch information
zssherman committed Mar 28, 2024
1 parent 06fcfed commit 937a9bb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/utils/plot_calculated_percentages.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 937a9bb

Please sign in to comment.