-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python example of grid coordinates and updates to GitHub links #146
base: main
Are you sure you want to change the base?
Changes from all commits
f09d432
4615f73
97994d6
136b2b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import cmor | ||
import numpy | ||
import os | ||
|
||
|
||
var_data = numpy.random.random((3, 4, 2)) + 34. | ||
|
||
x = numpy.arange(4, dtype=float) | ||
x_bnds = numpy.array([[x_ - 0.5, x_ + 0.5] for x_ in x]) | ||
y = numpy.arange(3, dtype=float) | ||
y_bnds = numpy.array([[y_ - 0.5, y_ + 0.5] for y_ in y]) | ||
|
||
lat = numpy.array([10, 20, 30]).reshape((3, 1)) | ||
lat = numpy.tile(lat, (1, 4)) | ||
lon = numpy.array([0, 90, 180, 270]) | ||
lon = numpy.tile(lon, (3, 1)) | ||
lon_bnds = numpy.zeros((3, 4, 4)) | ||
lat_bnds = numpy.zeros((3, 4, 4)) | ||
|
||
for j in range(3): | ||
for i in range(4): | ||
lon_bnds[j, i, 0] = (lon[j, i] - 45) % 360 | ||
lon_bnds[j, i, 1] = lon[j, i] | ||
lon_bnds[j, i, 2] = (lon[j, i] + 45) % 360 | ||
lon_bnds[j, i, 3] = lon[j, i] | ||
lat_bnds[j, i, 0] = lat[j, i] | ||
lat_bnds[j, i, 1] = lat[j, i] - 5 | ||
lat_bnds[j, i, 2] = lat[j, i] | ||
lat_bnds[j, i, 3] = lat[j, i] + 5 | ||
|
||
time = numpy.array([0, 1]) | ||
time_bnds = numpy.array([0, 1, 2]) | ||
|
||
ipth = opth = 'Test' | ||
cmor.setup(inpath=ipth, | ||
set_verbosity=cmor.CMOR_NORMAL, | ||
netcdf_file_action=cmor.CMOR_REPLACE, | ||
exit_control=cmor.CMOR_EXIT_ON_MAJOR) | ||
cmor.dataset_json('CMOR_input_example.json') | ||
|
||
# First, load the grids table to set up x and y axes and the lat-long grid | ||
grid_table_id = cmor.load_table('CMIP6_grids.json') | ||
cmor.set_table(grid_table_id) | ||
|
||
y_axis_id = cmor.axis(table_entry='y_deg', | ||
units='degrees', | ||
coord_vals=y, | ||
cell_bounds=y_bnds) | ||
x_axis_id = cmor.axis(table_entry='x_deg', | ||
units='degrees', | ||
coord_vals=x, | ||
cell_bounds=x_bnds) | ||
|
||
grid_id = cmor.grid(axis_ids=[y_axis_id, x_axis_id], | ||
latitude=lat, | ||
longitude=lon, | ||
latitude_vertices=lat_bnds, | ||
longitude_vertices=lon_bnds) | ||
|
||
# Now, load the Omon table to set up the time axis and variable | ||
omon_table_id = cmor.load_table('CMIP6_Omon.json') | ||
cmor.set_table(omon_table_id) | ||
|
||
time_axis_id = cmor.axis(table_entry='time', | ||
units='months since 1980', | ||
coord_vals=time, | ||
cell_bounds=time_bnds) | ||
|
||
var_id = cmor.variable(table_entry='sos', | ||
units='0.001', | ||
axis_ids=[grid_id, time_axis_id]) | ||
|
||
cmor.write(var_id, var_data, 2) | ||
|
||
filename = cmor.close(var_id, file_name=True) | ||
print("Stored in:", filename) | ||
cmor.close() | ||
os.system("ncdump {}".format(filename)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,14 +54,14 @@ where: | |
|
||
PrePARE will verify that all attributes in the input file are present and conform to CMIP6 for publication into ESGF. We also recommand running the python program [cfchecker](https://pypi.python.org/pypi/cfchecker) created by the University of Reading in the UK to confirm that your file is CF-1 compliant. | ||
|
||
* In order to validate all CMIP6 required attributes by PrePARE, a [Controlled Vocabulary file](https://github.com/PCMDI/cmip6-cmor-tables/blob/master/Tables/CMIP6_CV.json) is read by the program where a JSON dictionnary called ["required_global_attributes"](https://github.com/PCMDI/cmip6-cmor-tables/blob/master/Tables/CMIP6_CV.json#L3) point to a list of strings. Each element of that list corresponds to a global attribute. | ||
* PrePARE can also use regular expressions to validate the value of the some global attributes. Here is an [example](https://github.com/PCMDI/cmip6-cmor-tables/blob/master/Tables/CMIP6_CV.json#L6343-L6344) used for variant_label. | ||
* In order to validate all CMIP6 required attributes by PrePARE, a [Controlled Vocabulary file](https://github.com/PCMDI/cmip6-cmor-tables/blob/main/Tables/CMIP6_CV.json) is read by the program where a JSON dictionnary called ["required_global_attributes"](https://github.com/PCMDI/cmip6-cmor-tables/blob/a46dcbf17ec5e11af23dc2d55107f5e52afbcade/Tables/CMIP6_CV.json#L3) point to a list of strings. Each element of that list corresponds to a global attribute. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. , a (extra space) |
||
* PrePARE can also use regular expressions to validate the value of the some global attributes. Here is an [example](https://github.com/PCMDI/cmip6-cmor-tables/blob/a46dcbf17ec5e11af23dc2d55107f5e52afbcade/Tables/CMIP6_CV.json#L11554-L11555) used for variant_label. | ||
|
||
* Institutions and institution_ids need to be registered into a list. PrePARE will only accept institutions which have been pre-registered for CMIP6 publication into ESGF. Click [here](https://github.com/PCMDI/cmip6-cmor-tables/blob/master/Tables/CMIP6_CV.json#L65) for the list of institutions. If you wish to register your institution write to the [cmor mailing list](mailto:[email protected]). | ||
* Institutions and institution_ids need to be registered into a list. PrePARE will only accept institutions which have been pre-registered for CMIP6 publication into ESGF. Click [here](https://github.com/PCMDI/cmip6-cmor-tables/blob/a46dcbf17ec5e11af23dc2d55107f5e52afbcade/Tables/CMIP6_CV.json#L74) for the list of institutions. If you wish to register your institution write to the [cmor mailing list](mailto:[email protected]). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Registering an institution will require engagement with the appropriate project_CVs repo, e.g. CMIP6Plus_CVs, CMIP7_CVs, input4MIPs_CVs, and obs4MIPs-cmor-tables (which will migrate to obs4MIPs_CVs once we have all the tables etc in place) |
||
|
||
* Source and Source ID also need to be registered for CMIP6 publication. Here is the [list](https://github.com/PCMDI/cmip6-cmor-tables/blob/master/Tables/CMIP6_CV.json#L93) of registered sources. | ||
* Source and Source ID also need to be registered for CMIP6 publication. Here is the [list](https://github.com/PCMDI/cmip6-cmor-tables/blob/a46dcbf17ec5e11af23dc2d55107f5e52afbcade/Tables/CMIP6_CV.json#L125) of registered sources. | ||
|
||
* Only experiments found in the Controlled Vocabulary files are accepted for CMIP6 publication. A list of [experiment_ids](https://github.com/PCMDI/cmip6-cmor-tables/blob/master/Tables/CMIP6_CV.json#L548) have been pre-defined including mandatory attributes. A warning will be displayed if one experiment attribute is missing or is not properly set by your program. | ||
* Only experiments found in the Controlled Vocabulary files are accepted for CMIP6 publication. A list of [experiment_ids](https://github.com/PCMDI/cmip6-cmor-tables/blob/a46dcbf17ec5e11af23dc2d55107f5e52afbcade/Tables/CMIP6_CV.json#L3708) have been pre-defined including mandatory attributes. A warning will be displayed if one experiment attribute is missing or is not properly set by your program. | ||
|
||
* grid and nominal_resolution are mandatory global attributes in CMIP6. PrePARE will make sure that these attributes are conformed to one of the following syntax: | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compression isn't controlled in the MIP tables - rather this would be the user input, no?
Note: CMOR3 Now output s NetCDF4 file by default (missing s)
..invoke d on demand.. (missing d)