Skip to content
Merged
Show file tree
Hide file tree
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 Nov 1, 2024
ee39a7e
Merge branch 'main' into cmor-snack-prep
ilaflott Nov 15, 2024
40129d5
wind back for a minute...
ilaflott Nov 15, 2024
5fb52ce
zonally averaged case AERmonZ / ta, aka CASE 4 now succeeds. objects …
ilaflott Nov 15, 2024
30adf0f
atmos_scalar data now works- case8! this case works with only time co…
ilaflott Nov 15, 2024
fe59511
landuse giving issues with gppLut-
ilaflott Nov 15, 2024
8672155
wow this LUmip file.... case9 is gonna be a fun one
ilaflott Nov 15, 2024
240c32e
fix json syntax mistake that thankfully does not seem to bother the c…
ilaflott Nov 18, 2024
4f53f89
point run_test_file_cases at ocean files... the land file will wait a…
ilaflott Nov 18, 2024
d43dfc3
now the exp_config_json file gets checked for the output field, and t…
ilaflott Nov 18, 2024
191aee9
slight clean up
ilaflott Nov 19, 2024
8608e74
correct name of original cmor_mixer author in tool-specifici doc
ilaflott Nov 19, 2024
c8b4dcb
add scratchwork script showing prototype land-data rewriting. small b…
ilaflott Nov 20, 2024
f69b577
i have a script that rewrite the land data in a compliant manner- can…
ilaflott Nov 21, 2024
70daee4
Merge branch 'main' into cmor-snack-prep
ilaflott Nov 27, 2024
0b769da
poke the test file cases script
ilaflott Dec 3, 2024
2d68649
adjust comment helpfulling re coord variable
ilaflott Dec 3, 2024
e7933c0
print cwd between tests, failures in cmor during its bulk routine may…
ilaflott Dec 3, 2024
a5dd1e7
add try-except-finally behavior to calling rewrite_netcdf_file_var, s…
ilaflott Dec 3, 2024
2681272
formally remove unneeded copy_nc function. replace iwth shutil. bette…
ilaflott Dec 3, 2024
ad73044
new subtool routine, fre cmor list.
ilaflott Dec 3, 2024
b9e43b4
actually add cmor_lister.py
ilaflott Dec 3, 2024
237402e
cmor lister updates, largely clean up of stdout text
ilaflott Dec 6, 2024
ec61ef0
break up reading bounds per each coordinate variable
ilaflott Dec 6, 2024
87eccbf
add notes regarding potential solution to lack of spherical lon/lat i…
ilaflott Dec 6, 2024
e4be3d7
rename scratchwork.py because i will likely need another scratchwork …
ilaflott Dec 6, 2024
4174f72
new function, from_dis_gimme_dis
ilaflott Dec 6, 2024
8805566
new prototype scripts for rewriting the ocean file with CMOR complian…
ilaflott Dec 9, 2024
6e2dfa3
dinking around with rewriting ocean file
ilaflott Dec 10, 2024
459efae
forget rewriting the whole ocean file- pretty sure all this needs is …
ilaflott Dec 10, 2024
920a361
... dun dun dun... another one bites the dust...
ilaflott Dec 10, 2024
83eaaa5
... annnnnnnd another one ones gone and another ones gone...
ilaflott Dec 10, 2024
1cac72b
LAST OCEAN case- not going down easy!
ilaflott Dec 10, 2024
0d5a490
remove now-irrelevant scratchwork files
ilaflott Dec 10, 2024
7b364e2
the code now finds everything it needs from the statics file and appe…
ilaflott Dec 12, 2024
781e654
push latest code
ilaflott Dec 19, 2024
60133de
Merge branch 'main' into cmor-snack-prep
ilaflott Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/tools/cmor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ background
~~~~~~~~~~

The bulk of this routine is housed in ``fre/cmor/cmor_mixer.py``, which is a rewritten version of
Sergey Malyshev's original ``CMORcommander.py`` script, utilized during GFDL's CMIP6 publishing run.
Sergey Nikonov's original ``CMORcommander.py`` script, utilized during GFDL's CMIP6 publishing run.
Copy link
Collaborator

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.


This code is dependent on two primary json configuration files- a MIP
variable table and another containing experiment (i.e. model) specific metdata (e.g. grid) to append
Expand Down
1 change: 1 addition & 0 deletions fre/cmor/__init__.py
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
120 changes: 120 additions & 0 deletions fre/cmor/cmor_lister.py
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()
Loading
Loading