Created
May 19, 2021 12:44
-
-
Save nmathewa/61522659bc21c5406129b80d2449ef54 to your computer and use it in GitHub Desktop.
netcdf using xarray
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Created on Wed May 19 17:55:14 2021 | |
@author: mathew | |
""" | |
import xarray as xr | |
import numpy as np | |
# making a random spatial dataset | |
# 12 time-step and 30x30 grid points | |
vals = np.random.rand(12,30,30) | |
time = np.arange(12) | |
lats = np.linspace(10,20,30) | |
lon = np.linspace(70,80,30) | |
# creating xarray dataset | |
dset = xr.Dataset({ | |
"values" : (["time","lon","lat"],vals),}, | |
coords = {"time":(["time",],time), | |
"lon":(["lon",],lon), | |
"lat":(["lat",],lats)}) | |
dset.to_netcdf("file.nc") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment