-
Notifications
You must be signed in to change notification settings - Fork 21
Preparing fre cmor to snack
#243
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
37 commits
Select commit
Hold shift + click to select a range
689c065
Reapply "intermediate commit- new function to compar variable dimensi…
ilaflott ee39a7e
Merge branch 'main' into cmor-snack-prep
ilaflott 40129d5
wind back for a minute...
ilaflott 5fb52ce
zonally averaged case AERmonZ / ta, aka CASE 4 now succeeds. objects …
ilaflott 30adf0f
atmos_scalar data now works- case8! this case works with only time co…
ilaflott fe59511
landuse giving issues with gppLut-
ilaflott 8672155
wow this LUmip file.... case9 is gonna be a fun one
ilaflott 240c32e
fix json syntax mistake that thankfully does not seem to bother the c…
ilaflott 4f53f89
point run_test_file_cases at ocean files... the land file will wait a…
ilaflott d43dfc3
now the exp_config_json file gets checked for the output field, and t…
ilaflott 191aee9
slight clean up
ilaflott 8608e74
correct name of original cmor_mixer author in tool-specifici doc
ilaflott c8b4dcb
add scratchwork script showing prototype land-data rewriting. small b…
ilaflott f69b577
i have a script that rewrite the land data in a compliant manner- can…
ilaflott 70daee4
Merge branch 'main' into cmor-snack-prep
ilaflott 0b769da
poke the test file cases script
ilaflott 2d68649
adjust comment helpfulling re coord variable
ilaflott e7933c0
print cwd between tests, failures in cmor during its bulk routine may…
ilaflott a5dd1e7
add try-except-finally behavior to calling rewrite_netcdf_file_var, s…
ilaflott 2681272
formally remove unneeded copy_nc function. replace iwth shutil. bette…
ilaflott ad73044
new subtool routine, fre cmor list.
ilaflott b9e43b4
actually add cmor_lister.py
ilaflott 237402e
cmor lister updates, largely clean up of stdout text
ilaflott ec61ef0
break up reading bounds per each coordinate variable
ilaflott 87eccbf
add notes regarding potential solution to lack of spherical lon/lat i…
ilaflott e4be3d7
rename scratchwork.py because i will likely need another scratchwork …
ilaflott 4174f72
new function, from_dis_gimme_dis
ilaflott 8805566
new prototype scripts for rewriting the ocean file with CMOR complian…
ilaflott 6e2dfa3
dinking around with rewriting ocean file
ilaflott 459efae
forget rewriting the whole ocean file- pretty sure all this needs is …
ilaflott 920a361
... dun dun dun... another one bites the dust...
ilaflott 83eaaa5
... annnnnnnd another one ones gone and another ones gone...
ilaflott 1cac72b
LAST OCEAN case- not going down easy!
ilaflott 0d5a490
remove now-irrelevant scratchwork files
ilaflott 7b364e2
the code now finds everything it needs from the statics file and appe…
ilaflott 781e654
push latest code
ilaflott 60133de
Merge branch 'main' into cmor-snack-prep
ilaflott 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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| ''' for fre.cmor imports ''' | ||
| from .cmor_mixer import cmor_run_subtool | ||
| from .cmor_lister import cmor_list_subtool |
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,120 @@ | ||
| ''' fre cmor list | ||
| because ian got tired of typing things like the following in bash... | ||
|
|
||
| varname=sos; \ | ||
| table_files=$(ls fre/tests/test_files/cmip6-cmor-tables/Tables/CMIP6_*.json); \ | ||
| for table_file in $table_files; do \ | ||
| echo $table_file; \ | ||
| cat $table_file | grep -A 10 "\"$varname\""; \ | ||
| done; | ||
|
|
||
| ''' | ||
|
|
||
| #import os | ||
| import glob | ||
| import json | ||
| #import shutil | ||
| #import subprocess | ||
| from pathlib import Path | ||
|
|
||
| import click | ||
|
|
||
| DO_NOT_PRINT_LIST=[ 'comment', | ||
| 'ok_min_mean_abs', 'ok_max_mean_abs', | ||
| 'valid_min', 'valid_max' ] | ||
|
|
||
| def print_var_content( table_config_file = None, var_name = None): | ||
| ''' one variable printing routine- looks for info regarding var_name in table_config_file ''' | ||
| try: | ||
| proj_table_vars=json.load(table_config_file) | ||
| except Exception as exc: | ||
| raise Exception(f'problem getting proj_table_vars... WHY') | ||
|
|
||
| var_content = None | ||
| try: | ||
| var_content = proj_table_vars["variable_entry"].get(var_name) | ||
| except: | ||
| #print(f'(cmor_list_subtool) WARNING no "variable_entry" key. for {json_table_config}.' | ||
| # ' not the right json file probably. moving on!') | ||
| return | ||
|
|
||
| if var_content is None: | ||
| #print(f'(cmor_list_subtool) variable {var_name} not found in {Path(json_table_config).name}, moving on!') | ||
| return | ||
|
|
||
| table_name = None | ||
| try: | ||
| #print(f'(print_var_content) trying to get table_name from proj_table_vars...') | ||
| #print(f' table header is {proj_table_vars["Header"]}') | ||
| table_name = proj_table_vars["Header"].get('table_id').split(' ')[1] | ||
| #print(f' table_name = {table_name}') | ||
| except: | ||
| print(f'print_var_content) WARNING couldnt get header and table_name field') | ||
| pass | ||
|
|
||
| if table_name is not None: | ||
| print(f'(print_var_content) found {var_name} data in table {table_name}!') | ||
| else: | ||
| print(f'(print_var_content) found {var_name} data in table, but not its table_name!') | ||
|
|
||
| print(f' variable key: {var_name}') | ||
| for content in var_content: | ||
| if content in DO_NOT_PRINT_LIST: | ||
| continue | ||
| print(f' {content}: {var_content[content]}') | ||
| print('\n') | ||
|
|
||
| return | ||
|
|
||
| def cmor_list_subtool( json_var_list = None, json_table_config_dir = None, opt_var_name = None): | ||
| ''' | ||
| finds tables in the CMIP json config directory containing variable data of interest. prints it | ||
| out to screen, intended largely as a helper tool for cli users. | ||
| ''' | ||
| if not Path(json_table_config_dir).exists(): | ||
| raise OSError(f'(cmor_list_subtool) ERROR directory {json_table_config_dir} does not exist! exit.') | ||
|
|
||
| print(f'(cmor_list_subtool) attempting to find and open files in dir: \n {json_table_config_dir} ') | ||
| json_table_configs=glob.glob(f'{json_table_config_dir}/CMIP6_*.json') | ||
| if json_table_configs is None: | ||
| raise OSError(f'ERROR directory {json_table_config_dir} contains no JSON files, exit.') | ||
| else: | ||
| print(f'(cmor_list_subtool) found content in json_table_config_dir')#: {json_table_configs}') | ||
|
|
||
| var_list = None | ||
| if json_var_list is not None: | ||
| with open( json_var_list, "r", encoding = "utf-8") as var_list_file : | ||
| var_list=json.load(var_list_file) | ||
|
|
||
| if opt_var_name is None and var_list is None: | ||
| raise ValueError(f'(cmor_list_subtool) ERROR: no opt_var_name given but also no content in variable list!!! exit!') | ||
|
|
||
| if opt_var_name is not None: | ||
| print(f'(cmor_list_subtool) opt_var_name is not None: looking for only ONE variables worth of info!') | ||
| for json_table_config in json_table_configs: | ||
| #print(f'(cmor_list_subtool) attempting to open {json_table_config}') | ||
| with open( json_table_config, "r", encoding = "utf-8") as table_config_file: | ||
| print_var_content(table_config_file, opt_var_name) | ||
|
|
||
| elif var_list is not None: | ||
| print(f'(cmor_list_subtool) opt_var_name is None, and var_list is not None, looking for many variables worth of info!') | ||
| for var in var_list: | ||
| for json_table_config in json_table_configs: | ||
| #print(f'(cmor_list_subtool) attempting to open {json_table_config}') | ||
| with open( json_table_config, "r", encoding = "utf-8") as table_config_file: | ||
| #print(f' var = {var}, var_list[{var}]={var_list[var]}') | ||
| print_var_content(table_config_file, str(var_list[var])) | ||
| else: | ||
| print(f'(FATAL) this line should be unreachable!!!') | ||
|
|
||
| return | ||
|
|
||
|
|
||
| @click.command() | ||
| def _cmor_list_subtool( json_var_list = None, json_table_config_dir = None, opt_var_name = None): | ||
| ''' entry point to fre cmor run for click. see cmor_list_subtool for argument descriptions.''' | ||
| return cmor_list_subtool(json_var_list, json_table_config_dir, opt_var_name) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| cmor_list_subtool() |
Oops, something went wrong.
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.
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.
CMORcommander was a prototype rewrite of fremetar, which GFDL used for CMIP6 publishing.