Skip to content

Commit

Permalink
Dod example (#640)
Browse files Browse the repository at this point in the history
* BUG: Bug fix for when it's not a standard ARM file

* ENH:  Updating to be more robust

* ADD: Adding new example on how to create datasets based on ARM DODs and modify attributes

* ENH: PEP8 issue
  • Loading branch information
AdamTheisen authored Mar 17, 2023
1 parent 2be17ec commit c082d3f
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions examples/io/plot_create_arm_ds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
Create a dataset to mimic ARM file formats
------------------------------------------
Example shows how to create a dataset from an ARM DOD.
This will enable users to create files that mimic ARM
files, making for easier use across the community.
Author: Adam Theisen
"""

import act

# Create an empty dataset using an ARM DOD
ds = act.io.armfiles.create_ds_from_arm_dod('vdis.b1', {'time': 1440}, scalar_fill_dim='time')

# Print out the xarray dataset to see that it's empty
print(ds)

# The user could populate this through a number of ways
# and that's best left up to the user on how to do it.
# If one has an existing dataset, a mapping of variable
# names is sometimes the easiest way

# Let's look at some variable attributes
# These can be updated and it would be up to the
# user to ensure these tests are being applied
# and are appropriately set in the cooresponding QC variable
print(ds['num_drops'].attrs)

# Next, let's print out the global attribuets
print(ds.attrs)

# Add additional attributes or append to existing
# if they are needed using a dictionary
atts = {
'command_line': 'python plot_create_arm_ds.py',
'process_version': '1.2.3',
'history': 'Processed with Jupyter Workbench',
'random': '1234253sdgfadf'
}
for a in atts:
if a in ds.attrs:
ds.attrs[a] += atts[a]
else:
ds.attrs[a] = atts[a]
# Print out the attribute
print(a, ds.attrs[a])

# Write data out to netcdf
ds.to_netcdf('./sgpvdisX1.b1.20230101.000000.nc')

# If one wants to clean up the dataset to better match CF standards
# the following can be done as well
ds.write.write_netcdf(cf_compliant=True, path='./sgpvdisX1.b1.20230101.000000.cf')

0 comments on commit c082d3f

Please sign in to comment.