SHARE
TWEET

Untitled

a guest Oct 16th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import xarray as xr
  2. from glob import glob
  3.  
  4. paths = glob("/lsdf/kit/imk-tro/projects/MOD/Gruppe_Voigt/TRACMIP_ESGFCOPY/*/%s/%s*/%s/*/*/*/*/*/*"
  5.              % ("ECHAM63", "aquaControl", "mon"))
  6.                          
  7. for version in set([i.split("/")[-2] for i in paths]):
  8.  
  9.   ver_paths = [i for i in paths if version in i]
  10.  
  11.   merged = xr.open_dataset(ver_paths[0], chunks={})
  12.  
  13.   for path in ver_paths:
  14.    
  15.       # flatten height coordinate
  16.       ds = xr.open_dataset(path)
  17.       var = [i for i in ds.data_vars if "bnds" not in i][0]
  18.       if "height" in ds.coords:
  19.           ds[var].attrs["height"] = "%s %s" % (ds.height.values, ds.height.units)
  20.       merged[var] = ds[var].chunk({"time" : "auto"})
  21.  
  22.   # drop height from overall dataset
  23.   if "height" in merged.coords:
  24.       merged = merged.drop("height")
  25.  
  26.   # convert to zarr
  27.   merged.to_zarr("temp", mode="w", consolidated=True)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top