Skip to content

Commit

Permalink
Merge branch 'develop' into feature/faster-better-recentering
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumevernieres committed Sep 8, 2023
2 parents 176130e + 0073a5f commit 90c20b4
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 87 deletions.
2 changes: 1 addition & 1 deletion parm/ioda/bufr2ioda/bufr2ioda_satwind_amv_goes.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"data_format" : "bufr_d",
"data_type" : "satwnd",
"cycle_type" : "{{ DUMP }}",
"cycle_type" : "{{ RUN }}",
"cycle_datetime" : "{{ current_cycle | to_YMDH }}",
"dump_directory" : "{{ DMPDIR }}",
"ioda_directory" : "{{ COM_OBS }}",
Expand Down
1 change: 1 addition & 0 deletions ush/ioda/bufr2ioda/bufr2ioda_satwind_amv_goes.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import argparse
import numpy as np
import numpy.ma as ma
Expand Down
8 changes: 1 addition & 7 deletions ush/ioda/bufr2ioda/gen_bufr2ioda_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import argparse
import json
import os
from wxflow import Logger, parse_j2yaml, cast_strdict_as_dtypedict
from wxflow import add_to_datetime, to_timedelta
from wxflow import Logger, parse_j2yaml

# Initialize root logger
logger = Logger('gen_bufr2ioda_json.py', level='INFO', colored_log=True)
Expand All @@ -29,9 +28,4 @@ def gen_bufr_json(config, template, output):
parser.add_argument('-t', '--template', type=str, help='Input JSON template', required=True)
parser.add_argument('-o', '--output', type=str, help='Output JSON file', required=True)
args = parser.parse_args()
# get the config from your environment
config = cast_strdict_as_dtypedict(os.environ)
# we need to add in current cycle from PDYcyc
config['current_cycle'] = add_to_datetime(config['PDY'], to_timedelta(f"{config['cyc']}H"))
# call the parsing function
gen_bufr_json(config, args.template, args.output)
63 changes: 63 additions & 0 deletions ush/ioda/bufr2ioda/run_bufr2ioda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python3
import argparse
import os
from pathlib import Path
from gen_bufr2ioda_json import gen_bufr_json
from wxflow import (Logger, Executable, cast_as_dtype, logit,
to_datetime, datetime_to_YMDH, Task, rm_p)

# Initialize root logger
logger = Logger('run_bufr2ioda.py', level='INFO', colored_log=True)


@logit(logger)
def bufr2ioda(current_cycle, RUN, DMPDIR, config_template_dir, COM_OBS):
logger.info(f"Process {current_cycle} {RUN} from {DMPDIR} to {COM_OBS} using {config_template_dir}")

# Get gdasapp root directory
DIR_ROOT = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../.."))
USH_IODA = os.path.join(DIR_ROOT, "ush", "ioda", "bufr2ioda")

# Create output directory if it doesn't exist
os.makedirs(COM_OBS, exist_ok=True)

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

# Specify observation types to be processed by a script
BUFR_py = ["satwind_amv_goes"]

for obtype in BUFR_py:
logger.info(f"Convert {obtype}...")
json_output_file = os.path.join(COM_OBS, f"{obtype}_{datetime_to_YMDH(current_cycle)}.json")
filename = 'bufr2ioda_' + obtype + '.json'
template = os.path.join(config_template_dir, filename)
gen_bufr_json(config, template, json_output_file)

# Use the converter script for the ob type
bufr2iodapy = USH_IODA + '/bufr2ioda_' + obtype + ".py"
cmd = Executable(bufr2iodapy)
cmd.add_default_arg('-c')
cmd.add_default_arg(json_output_file)
logger.info(f"Executing {cmd}")
cmd()

# Check if the converter was successful
if os.path.exists(json_output_file):
rm_p(json_output_file)


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Convert bufr dump file to ioda format')
parser.add_argument('current_cycle', help='current cycle to process', type=lambda dd: to_datetime(dd))
parser.add_argument('RUN', type=str, help='dump to process, either gdas or gdas')
parser.add_argument('DMPDIR', type=Path, help='path to bufr dump files')
parser.add_argument('config_template_dir', type=Path, help='path to templates')
parser.add_argument('COM_OBS', type=Path, help='path to output ioda format dump files')
args = parser.parse_args()
bufr2ioda(args.current_cycle, args.RUN, args.DMPDIR, args.config_template_dir, args.COM_OBS)
79 changes: 0 additions & 79 deletions ush/ioda/bufr2ioda/run_bufr2ioda.sh

This file was deleted.

0 comments on commit 90c20b4

Please sign in to comment.