1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
from __future__ import print_function
import cmor
import numpy
ipth = "Test"
cmor.setup(inpath=ipth,
set_verbosity=cmor.CMOR_NORMAL,
netcdf_file_action=cmor.CMOR_REPLACE,
logfile=None)
cmor.dataset(
outpath=ipth,
experiment_id="lgm",
institution="PCMDI",
source="PCMDI",
calendar="standard",
model_id="pcmdi-09a", forcing="forcing")
cmor.load_table("Tables/CMIP6_Omon.json")
nlat = 90
dlat = 180 / nlat
nlon = 180
dlon = 360. / nlon
nlev = 5
lats = numpy.arange(-90 + dlat / 2., 90, dlat)
blats = numpy.arange(-90, 90 + dlat, dlat)
lons = numpy.arange(0 + dlon / 2., 360., dlon)
blons = numpy.arange(0, 360. + dlon, dlon)
ntime = 12
data = numpy.random.random((ntime, nlat, nlev, nlon)) * 5 + 273.
itim = cmor.axis(
table_entry='time', coord_vals=numpy.arange(
0, ntime, 1), units='month since 2008', cell_bounds=numpy.arange(
0, ntime + 1, 1))
ilat = cmor.axis(
table_entry='latitude',
coord_vals=lats,
units='degrees_north',
cell_bounds=blats)
ilon = cmor.axis(
table_entry='longitude',
coord_vals=lons,
units='degrees_east',
cell_bounds=blons)
ilev = cmor.axis(table_entry='depth_coord',
length=5,
cell_bounds=numpy.arange(-12000,
0,
2000),
coord_vals=numpy.arange(-10000,
0,
2000),
units="m")
iv = cmor.variable(
table_entry='thetao', axis_ids=numpy.array(
(itim, ilat, ilev, ilon)), units='K')
cmor.write(iv, data)
f1 = cmor.close(iv, file_name=True)
print(f1)
|