-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD: Adding a piechart function to distribution display module. (#828)
* ADD: Adding a piechart function to distribution display module. This new function uses act.utils.calculate_percentages to create a pie chart of percentages of user defined fields of a dataset. * STY: PEP8 fixes. * STY: More PEP8 fixes. * ENH: Suggested changes to doc and parameter usage. * STY: PEP8 fix.
- Loading branch information
Showing
5 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
Calculate and View Aerosol Percentages | ||
-------------------------------------- | ||
Calculate the percentages of different aerosols in a Aerosol | ||
Chemical Speciation (AOS) monitor dataset and view the percentages | ||
in a pie chart. | ||
Written: Zach Sherman | ||
""" | ||
|
||
from arm_test_data import DATASETS | ||
import matplotlib.pyplot as plt | ||
|
||
import act | ||
from act.io.arm import read_arm_netcdf | ||
|
||
# Read an ARM AOS dataset | ||
filename = DATASETS.fetch('sgpaosacsmE13.b2.20230420.000109.nc') | ||
ds = read_arm_netcdf(filename) | ||
|
||
# Let us print out the fields in the dataset and see what it contains. | ||
print(ds.data_vars.keys()) | ||
|
||
# Knowing what fields the dataset contains, let's create a list of fields | ||
# to use in the plot. | ||
|
||
fields = ['sulfate', 'ammonium', 'nitrate', 'chloride'] | ||
|
||
# We also want to provide some keyword arguments to avoid invalid data such | ||
# as negative values. | ||
threshold = 0.0 | ||
fill_value = 0.0 | ||
|
||
# Create a DistributionDisplay object to compare fields | ||
display = act.plotting.DistributionDisplay(ds) | ||
|
||
# We can set one of the slices to explode and give it a nice shadow. | ||
explode = (0, 0.1, 0, 0) | ||
shadow = True | ||
|
||
# Create a pie chart using the fields list. The percentages of the | ||
# fields will be calculated using act.utils.calculate_percentages. | ||
display.plot_pie_chart( | ||
fields, | ||
threshold=threshold, | ||
fill_value=fill_value, | ||
explode=explode, | ||
shadow=True, | ||
) | ||
plt.show() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters