Skip to content

Commit

Permalink
added netcdf4_classic to example script and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
veenstrajelmer committed Aug 23, 2024
1 parent f2a504f commit abb0d02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion ddlpy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ def dataframe_to_xarray(df: pd.DataFrame, drop_if_constant=[]):
The timestamps are converted to UTC since xarray does not support non-UTC timestamps.
These can be converted to different timezones after loading the netcdf and converting
to a pandas dataframe with df.index.tz_convert()
to a pandas dataframe with df.index.tz_convert().
When writing the dataset to disk with ds.to_netcdf() it is recommended to use
`format="NETCDF3_CLASSIC"` or `format="NETCDF4_CLASSIC"` since this automatically
converts variables of dtype <U to |S which saves a lot of disk space for DDL data.
"""

# create list of columns with duplicate info (often not constant), will be dropped
Expand Down
5 changes: 3 additions & 2 deletions docs/examples/retrieve_parallel_to_netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ def get_data(location, start_date, end_date, dir_output, overwrite=True):
ds = simplified.to_xarray()
ds = ds.assign_attrs(simplified.attrs)

# write to netcdf file
ds.to_netcdf(filename)
# write to netcdf file. NETCDF3_CLASSIC or NETCDF4_CLASSIC automatically converts
# variables of dtype <U to |S which saves a lot of disk space
ds.to_netcdf(filename, format="NETCDF4_CLASSIC")


if ( __name__ == "__main__" ):
Expand Down

0 comments on commit abb0d02

Please sign in to comment.