Skip to content

Commit

Permalink
initial changes for bufr conversion refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewEichmann-NOAA committed Oct 17, 2024
1 parent 404dfab commit 33862a8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
10 changes: 10 additions & 0 deletions parm/ioda/bufr2ioda/bufr2ioda_insitu_profile_argo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cycle_datetime: '{{ current_cycle | to_YMDH }}'
cycle_type: '{{ RUN }}'
data_description: 6-hrly in situ ARGO profiles
data_format: subpfl
data_provider: U.S. NOAA
data_type: argo
dump_directory: '{{ DMPDIR }}'
ioda_directory: '{{ COM_OBS }}'
source: NCEP data tank
subsets: SUBPFL
24 changes: 24 additions & 0 deletions parm/ioda/bufr2ioda/j2y.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import json
import yaml
import argparse

def convert_json_to_yaml(input_file, output_file):
# Load the JSON data from the input file
with open(input_file, 'r') as json_file:
json_data = json.load(json_file)

# Convert and save as YAML in the output file
with open(output_file, 'w') as yaml_file:
yaml.dump(json_data, yaml_file, default_flow_style=False)

if __name__ == '__main__':
# Set up argument parser
parser = argparse.ArgumentParser(description='Convert JSON to YAML.')
parser.add_argument('input_file', help='Path to the input JSON file')
parser.add_argument('output_file', help='Path to the output YAML file')

args = parser.parse_args()

# Perform the conversion
convert_json_to_yaml(args.input_file, args.output_file)

19 changes: 12 additions & 7 deletions ush/soca/prep_ocean_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from wxflow import (chdir,
FileHandler,
logit,
parse_j2yaml,
save_as_yaml,
Task,
YAMLFile)
Expand Down Expand Up @@ -91,7 +92,8 @@ def initialize(self):
raise FileNotFoundError

JSON_TMPL_DIR = self.task_config.JSON_TMPL_DIR
BUFR2IODA_PY_DIR = self.task_config.BUFR2IODA_PY_DIR
# BUFR2IODA_PY_DIR = self.task_config.BUFR2IODA_PY_DIR
BUFR2IODA_PY_DIR = os.path.join(self.task_config.HOMEgfs, 'sorc/gdas.cd/ush/ioda/bufr2ioda/marine/b2i')

COMIN_OBS = self.task_config.COMIN_OBS
COMOUT_OBS = self.task_config['COMOUT_OBS']
Expand Down Expand Up @@ -150,19 +152,22 @@ def initialize(self):
# set up the config file for conversion to IODA for bufr and
# netcdf files respectively
if obsprep_space['type'] == 'bufr':
gen_bufr_json_config = {'RUN': RUN,
gen_bufr_yaml_config = {'RUN': RUN,
'current_cycle': cdate,
'DMPDIR': COMIN_OBS,
'COM_OBS': COMIN_OBS}
json_config_file = os.path.join(COMIN_OBS,
f"{obtype}_{cdatestr}.json")
obsprep_space['conversion config file'] = json_config_file
yaml_config_file = os.path.join(COMIN_OBS,
f"{obtype}_{cdatestr}.yaml")
obsprep_space['conversion config file'] = yaml_config_file
bufr2iodapy = BUFR2IODA_PY_DIR + '/bufr2ioda_' + obtype + '.py'
obsprep_space['bufr2ioda converter'] = bufr2iodapy
tmpl_filename = 'bufr2ioda_' + obtype + '.json'
tmpl_filename = 'bufr2ioda_' + obtype + '.yaml'
template = os.path.join(JSON_TMPL_DIR, tmpl_filename)

try:
gen_bufr_json(gen_bufr_json_config, template, json_config_file)
# gen_bufr_json(gen_bufr_json_config, template, yaml_config_file)
myyaml = parse_j2yaml(template, gen_bufr_yaml_config, yaml_config_file)
myyaml.save(yaml_config_file)
except Exception as e:
logger.warning(f"An exeception {e} occured while trying to run gen_bufr_json")
logger.warning(f"obtype {obtype} will be skipped")
Expand Down

0 comments on commit 33862a8

Please sign in to comment.