-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into cmor_3.4.0
- Loading branch information
Showing
3 changed files
with
59 additions
and
19 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
import cmor | ||
|
||
cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE_4) | ||
cmor.setup( | ||
# inpath has to point to the CMOR | ||
# tables path (CMIP6, input4MIPs or otherwise) | ||
inpath='Tables', | ||
netcdf_file_action=cmor.CMOR_REPLACE_4 | ||
) | ||
|
||
cmor.dataset_json("Test/CMOR_input_example.json") | ||
|
||
table = 'CMIP6_Amon.json' | ||
cmor.dataset_json("Test/CMOR_input_example.json") | ||
|
||
# Loading this test table overwrites the normal CF checks on valid variable values. | ||
# This is perfect for testing but shouldn't be done when writing real data. | ||
table='CMIP6_Amon.json' | ||
cmor.load_table(table) | ||
|
||
itime = cmor.axis(table_entry='time', | ||
units='days since 2000-01-01 00:00:00', | ||
coord_vals=[15, ], | ||
cell_bounds=[0, 30]) | ||
ilat = cmor.axis(table_entry='latitude', | ||
units='degrees_north', | ||
coord_vals=[0], | ||
cell_bounds=[-1, 1]) | ||
ilon = cmor.axis(table_entry='longitude', | ||
units='degrees_east', | ||
coord_vals=[90], | ||
cell_bounds=[89, 91]) | ||
|
||
axis_ids = [itime, ilat, ilon] | ||
# here is where you add your axes | ||
itime = cmor.axis(table_entry= 'time', | ||
units= 'days since 2000-01-01 00:00:00', | ||
coord_vals= [15,], | ||
cell_bounds= [0, 30]) | ||
ilat = cmor.axis(table_entry= 'latitude', | ||
units= 'degrees_north', | ||
coord_vals= [0], | ||
cell_bounds= [-1, 1]) | ||
ilon = cmor.axis(table_entry= 'longitude', | ||
units= 'degrees_east', | ||
coord_vals= [90], | ||
cell_bounds= [89, 91]) | ||
|
||
axis_ids = [itime,ilat,ilon] | ||
|
||
# here we create a variable with appropriate name, units and axes | ||
varid = cmor.variable('ts', 'K', axis_ids) | ||
|
||
# then we can write the variable along with the data | ||
cmor.write(varid, [273]) | ||
|
||
# finally we close the file and print where it was saved | ||
outfile = cmor.close(varid, file_name=True) | ||
print "File written: ", outfile | ||
print("File written to: {}".format(outfile)) | ||
cmor.close() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from __future__ import print_function | ||
import cmor | ||
import glob | ||
import unittest | ||
|
||
|
||
|
||
def run(): | ||
unittest.main() | ||
|
||
class TestLoadTables(unittest.TestCase): | ||
def testLoadTables(self): | ||
tables = glob.glob("Tables/CMIP6*json") | ||
for table in tables: | ||
if "formula_terms" in table: | ||
continue | ||
cmor.setup(inpath='Tables', netcdf_file_action=cmor.CMOR_REPLACE) | ||
cmor.dataset_json("Test/CMOR_input_example.json") | ||
print("Loading table:", table) | ||
ierr = cmor.load_table(table) | ||
self.assertEqual(ierr, 0) | ||
cmor.close() | ||
|
||
if __name__ == '__main__': | ||
run() |