{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Create a dataset to mimic ARM file formats\nExample shows how to create a dataset from an ARM DOD.\nThis will enable users to create files that mimic ARM\nfiles, making for easier use across the community.\n\nAuthor: Adam Theisen\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import act\n\n# Create an empty dataset using an ARM DOD\nds = act.io.arm.create_ds_from_arm_dod('vdis.b1', {'time': 1440}, scalar_fill_dim='time')\n\n# Print out the xarray dataset to see that it's empty\nprint(ds)\n\n# The user could populate this through a number of ways\n# and that's best left up to the user on how to do it.\n# If one has an existing dataset, a mapping of variable\n# names is sometimes the easiest way\n\n# Let's look at some variable attributes\n# These can be updated and it would be up to the\n# user to ensure these tests are being applied\n# and are appropriately set in the cooresponding QC variable\nprint(ds['num_drops'].attrs)\n\n# Next, let's print out the global attribuets\nprint(ds.attrs)\n\n# Add additional attributes or append to existing\n# if they are needed using a dictionary\natts = {\n 'command_line': 'python plot_create_arm_ds.py',\n 'process_version': '1.2.3',\n 'history': 'Processed with Jupyter Workbench',\n 'random': '1234253sdgfadf',\n}\nfor a in atts:\n if a in ds.attrs:\n ds.attrs[a] += atts[a]\n else:\n ds.attrs[a] = atts[a]\n # Print out the attribute\n print(a, ds.attrs[a])\n\n# Write data out to netcdf\nds.to_netcdf('./sgpvdisX1.b1.20230101.000000.nc')\n\n# If one wants to clean up the dataset to better match CF standards\n# the following can be done as well\nds.write.write_netcdf(cf_compliant=True, path='./sgpvdisX1.b1.20230101.000000.cf')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.14.3" } }, "nbformat": 4, "nbformat_minor": 0 }