-
Notifications
You must be signed in to change notification settings - Fork 6
Python example of grid coordinates and updates to GitHub links #146
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f09d432
Change branch name from 'master' to 'main' for links to cmor and cmip…
mauzey1 4615f73
Use permalinks when linking to specific parts of CMIP6_CV.json
mauzey1 97994d6
Add Python example for using grid coordinates
mauzey1 136b2b4
Update PDF
mauzey1 5e94991
Fix typos
mauzey1 8bd5f76
Update index.md
mauzey1 87b8c11
Update PDF
mauzey1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,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)) |
This file contains hidden or 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 |
---|---|---|
|
@@ -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 dictionary called ["required_global_attributes"](https://github.com/PCMDI/cmip6-cmor-tables/blob/a46dcbf17ec5e11af23dc2d55107f5e52afbcade/Tables/CMIP6_CV.json#L3) points 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/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]). | ||
|
||
* 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: | ||
|
||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.