Skip to content
Merged
Changes from all commits
Commits
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
67 changes: 34 additions & 33 deletions scripts/exglobal_prep_ocean_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
to_timedelta,
YAMLFile
)
from gen_bufr2ioda_json import gen_bufr_json
# from gen_bufr2ioda_json import gen_bufr_json

logger = Logger()

Expand Down Expand Up @@ -55,35 +55,35 @@
os.makedirs(COMOUT_OBS)


def bufr2ioda(obtype, PDY, cyc, RUN, COMIN_OBS, COMOUT_OBS):
logger.info(f"Process {obtype} for {RUN}.{PDY}/{cyc} from {COMIN_OBS} to {COMIN_OBS}")

# Load configuration
config = {
'RUN': RUN,
'current_cycle': cdateDatetime,
'DMPDIR': COMIN_OBS,
'COM_OBS': COMIN_OBS,
}

json_output_file = os.path.join(COMIN_OBS, f"{obtype}_{datetime_to_YMDH(cdateDatetime)}.json")
filename = 'bufr2ioda_' + obtype + '.json'
template = os.path.join(JSON_TMPL_DIR, filename)

# Generate cycle specific json from TEMPLATE
gen_bufr_json(config, template, json_output_file)

bufr2iodapy = BUFR2IODA_PY_DIR + '/bufr2ioda_' + obtype + '.py'
logger.info(f"BUFR2IODA python scripts: {bufr2iodapy}")

try:
subprocess.run(['python', bufr2iodapy, '-c', json_output_file, '-v'])
logger.info(f"BUFR2IODA python API converter on obs space {obtype} ran successfully")
except subprocess.CalledProcessError as e:
logger.info(f"BUFR2IODA python API converter failed with error {e}, \
return code {e.returncode}")
return e.returncode

# def bufr2ioda(obtype, PDY, cyc, RUN, COMIN_OBS, COMOUT_OBS):
# logger.info(f"Process {obtype} for {RUN}.{PDY}/{cyc} from {COMIN_OBS} to {COMIN_OBS}")
#
# # Load configuration
# config = {
# 'RUN': RUN,
# 'current_cycle': cdateDatetime,
# 'DMPDIR': COMIN_OBS,
# 'COM_OBS': COMIN_OBS,
# }
#
# json_output_file = os.path.join(COMIN_OBS, f"{obtype}_{datetime_to_YMDH(cdateDatetime)}.json")
# filename = 'bufr2ioda_' + obtype + '.json'
# template = os.path.join(JSON_TMPL_DIR, filename)
#
# # Generate cycle specific json from TEMPLATE
# gen_bufr_json(config, template, json_output_file)
#
# bufr2iodapy = BUFR2IODA_PY_DIR + '/bufr2ioda_' + obtype + '.py'
# logger.info(f"BUFR2IODA python scripts: {bufr2iodapy}")
#
# try:
# subprocess.run(['python', bufr2iodapy, '-c', json_output_file, '-v'])
# logger.info(f"BUFR2IODA python API converter on obs space {obtype} ran successfully")
# except subprocess.CalledProcessError as e:
# logger.info(f"BUFR2IODA python API converter failed with error {e}, \
# return code {e.returncode}")
# return e.returncode
#

def run_netcdf_to_ioda(obsspace_to_convert):
name, iodaYamlFilename = obsspace_to_convert
Expand Down Expand Up @@ -144,9 +144,10 @@ def run_netcdf_to_ioda(obsspace_to_convert):
obsprepSpace['output file'] = outputFilename

if obsprepSpace['type'] == 'bufr':
bufr2ioda(obsprepSpaceName, PDY, cyc, RUN, COMIN_OBS, COMIN_OBS)
files_to_save.append([obsprepSpace['output file'],
os.path.join(COMOUT_OBS, obsprepSpace['output file'])])
logger.warning("bufr processing is not working yet")
# bufr2ioda(obsprepSpaceName, PDY, cyc, RUN, COMIN_OBS, COMIN_OBS)
# files_to_save.append([obsprepSpace['output file'],
# os.path.join(COMOUT_OBS, obsprepSpace['output file'])])
else:
iodaYamlFilename = obsprepSpaceName + '2ioda.yaml'
save_as_yaml(obsprepSpace, iodaYamlFilename)
Expand Down