Skip to content

Commit

Permalink
Merge branch 'master' into cmor_3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mauzey1 committed Dec 19, 2018
2 parents ad7cbf5 + b78010e commit a5150d3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 19 deletions.
3 changes: 2 additions & 1 deletion Test/CMOR_input_example.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"#note": "explanation of what source_type is goes here",
"source_type": "AOGCM ISM AER",

"#note": "CMIP6 valid experiment_ids are found in CMIP6_CV.json",
Expand Down Expand Up @@ -67,7 +68,7 @@
"tracking_prefix": "hdl:21.14100",
"_history_template": "%s ;rewrote data to be consistent with <activity_id> for variable <variable_id> found in table <table_id>.",

"#output_path_template": "Template for output path directory using tables keys or global attributes",
"#output_path_template": "Template for output path directory using tables keys or global attributes, these should follow the relevant data reference syntax",
"output_path_template": "<mip_era><activity_id><institution_id><source_id><experiment_id><_member_id><table><variable_id><grid_label><version>",
"output_file_template": "<variable_id><table><source_id><experiment_id><_member_id><grid_label>",
}
50 changes: 32 additions & 18 deletions Test/test_doc.py
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()
25 changes: 25 additions & 0 deletions Test/test_python_CMIP6_CV_load_tables.py
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()

0 comments on commit a5150d3

Please sign in to comment.