NCAR / ctsm_python_gallery

A place to put sample workflows and tools that use ctsm model output
Apache License 2.0
18 stars 28 forks source link

concatenating monthly history files #32

Closed wwieder closed 3 years ago

wwieder commented 4 years ago

We need to develop a script that handles concatenating a variable (or variables) from monthly history files for looking at results before they've been converted to single variable time series.

wwieder commented 4 years ago

from @djk2120

Would something like this work? (might be too slow??)

import glob path = .../*.h0.*.nc da = xr.open_mfdataset(glob.glob(path),combine='by_coords')

I used the glob module, because it seems to handle wildcards better than xarray itself.

andersy005 commented 4 years ago

da = xr.open_mfdataset(glob.glob(path),combine='by_coords')

glob.glob() can return bizarre ordering (the sortedness of glob.glob's output is platform-dependent). Because of this, you may end up with a time coordinate that is not monotonic after the concatenation step. To be safe, you probably want to sort the output of glob.glob():

da = xr.open_mfdataset(sorted(glob.glob(path)),combine='by_coords')
samsrabin commented 3 years ago

This is now handled by import_ds().