Skip to content
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

Add BUFR2IODA python API converter to prepoceanobs task #914

Merged
merged 46 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b4522a2
Add BUFR2IODA python API converter to prepoceanobs
ShastriPaturi Feb 8, 2024
8419802
fix coding norm
ShastriPaturi Feb 8, 2024
7ef2abf
fix coding norm
ShastriPaturi Feb 8, 2024
536d9c2
fix coding norm
ShastriPaturi Feb 8, 2024
02fe4e6
cleaned up obsprep_config.yaml: added type, removed output_file
ShastriPaturi Feb 13, 2024
30eeae7
copy BUFR IODA output to ROTDIR
ShastriPaturi Feb 14, 2024
75ffc6f
updated BUFR IODA output filename
ShastriPaturi Feb 14, 2024
7623bd9
all the monthly and fixed and drifting buoys added
ShastriPaturi Feb 16, 2024
f6b93da
ObsSpace yamls: all the monthly and fixed and drifting buoys added
ShastriPaturi Feb 16, 2024
a528afd
resolve conflict
ShastriPaturi Feb 16, 2024
d7d657f
arranged modules alphabetically
ShastriPaturi Feb 20, 2024
e522587
fix coding norm
ShastriPaturi Feb 20, 2024
b644cc1
module import update
ShastriPaturi Feb 21, 2024
1dba075
module import update+1
ShastriPaturi Feb 21, 2024
60ecb97
module import update+2
ShastriPaturi Feb 21, 2024
2da25c8
module import update+3
ShastriPaturi Feb 21, 2024
b5ab1e8
module import update+4
ShastriPaturi Feb 21, 2024
8dfc869
module import update+5
ShastriPaturi Feb 21, 2024
c512774
Merge branch 'develop' into feature/marine_addBUFR2IODAconverter
ShastriPaturi Feb 21, 2024
1a24a91
fix prep obs failure
ShastriPaturi Feb 26, 2024
47a051f
Merge branch 'develop' into feature/marine_addBUFR2IODAconverter
ShastriPaturi Feb 26, 2024
5a8c588
update insitu yamls
ShastriPaturi Feb 28, 2024
25c22eb
Merge branch 'develop' into feature/marine_addBUFR2IODAconverter
ShastriPaturi Feb 28, 2024
b00a74d
Merge branch 'develop' into feature/marine_addBUFR2IODAconverter
ShastriPaturi Feb 28, 2024
0161478
Merge branch 'develop' into feature/marine_addBUFR2IODAconverter
ShastriPaturi Feb 29, 2024
309aa9a
Merge branch 'develop' into feature/marine_addBUFR2IODAconverter
ShastriPaturi Feb 29, 2024
a418180
Fixed typo
ShastriPaturi Feb 29, 2024
4300340
Merge branch 'feature/marine_addBUFR2IODAconverter' of https://github…
ShastriPaturi Feb 29, 2024
4852fcd
Merge branch 'develop' into feature/marine_addBUFR2IODAconverter
ShastriPaturi Mar 1, 2024
57d849e
Merge branch 'develop' into feature/marine_addBUFR2IODAconverter
ShastriPaturi Mar 1, 2024
10ad109
Merge branch 'develop' into feature/marine_addBUFR2IODAconverter
ShastriPaturi Mar 4, 2024
bf077ab
copy daily insitu subsampled
ShastriPaturi Mar 4, 2024
466d433
Add json files for situ surface
ShastriPaturi Mar 4, 2024
b4e64a0
Merge branch 'develop' into feature/marine_addBUFR2IODAconverter
guillaumevernieres Mar 13, 2024
d87fc0f
Merge branch 'develop' into feature/marine_addBUFR2IODAconverter
guillaumevernieres Mar 19, 2024
4f57720
Merge branch 'develop' into feature/marine_addBUFR2IODAconverter
AndrewEichmann-NOAA Mar 25, 2024
e6b3e38
Update obsprep_config.yaml
ShastriPaturi Mar 25, 2024
c92feef
monthly insitu
ShastriPaturi Mar 25, 2024
b237995
Merge branch 'feature/marine_addBUFR2IODAconverter' of https://github…
ShastriPaturi Mar 25, 2024
12a0903
monthly insitu json
ShastriPaturi Mar 25, 2024
8d946ae
monthly insitu json: altkob
ShastriPaturi Mar 25, 2024
e64c9e4
Merge branch 'develop' into feature/marine_addBUFR2IODAconverter
AndrewEichmann-NOAA Mar 26, 2024
98682c2
make obs prep ctest work without new jjob
AndrewEichmann-NOAA Mar 26, 2024
4be9a35
Merge branch 'develop' into feature/marine_addBUFR2IODAconverter
CoryMartin-NOAA Mar 28, 2024
302c328
yaml tidy
guillaumevernieres Mar 28, 2024
118a30b
Merge branch 'develop' into feature/marine_addBUFR2IODAconverter
guillaumevernieres Mar 28, 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
12 changes: 12 additions & 0 deletions parm/ioda/bufr2ioda/bufr2ioda_insitu_profile_bathy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"data_format" : "bathy",
"subsets" : "BATHY",
"source" : "NCEP data tank",
"data_type" : "bathy",
"cycle_type" : "{{ RUN }}",
"cycle_datetime" : "{{ current_cycle | to_YMDH }}",
"dump_directory" : "{{ DMPDIR }}",
"ioda_directory" : "{{ COM_OBS }}",
"data_description" : "6-hrly in situ Bathythermal profiles",
"data_provider" : "U.S. NOAA"
}
12 changes: 12 additions & 0 deletions parm/ioda/bufr2ioda/bufr2ioda_insitu_profile_tesac.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"data_format" : "tesac",
"subsets" : "TESAC",
"source" : "NCEP data tank",
"data_type" : "tesac",
"cycle_type" : "{{ RUN }}",
"cycle_datetime" : "{{ current_cycle | to_YMDH }}",
"dump_directory" : "{{ DMPDIR }}",
"ioda_directory" : "{{ COM_OBS }}",
"data_description" : "6-hrly in situ TESAC profiles",
"data_provider" : "U.S. NOAA"
}
12 changes: 12 additions & 0 deletions parm/ioda/bufr2ioda/bufr2ioda_insitu_surface_trkob.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"data_format" : "trkob",
"subsets" : "TRACKOB",
"source" : "NCEP data tank",
"data_type" : "trackob",
"cycle_type" : "{{ RUN }}",
"cycle_datetime" : "{{ current_cycle | to_YMDH }}",
"dump_directory" : "{{ DMPDIR }}",
"ioda_directory" : "{{ COM_OBS }}",
"data_description" : "6-hrly in situ TRACKOB surface",
"data_provider" : "U.S. NOAA"
}
12 changes: 6 additions & 6 deletions parm/soca/obsprep/obsprep_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,17 @@ observations:
name: insitu_profile_bathy
provider: GTS
dmpdir subdir: atmos
output file: '*.bathy_profile.ioda.nc'
dmpdir regex: 'bathy.*.dcom_subsampled'
output file: 'bathy_profile.ioda.nc'
ShastriPaturi marked this conversation as resolved.
Show resolved Hide resolved
dmpdir regex: 'gdas.*.bathy.*.bufr_d'
- obs space:
name: insitu_profile_tesac
provider: GTS
dmpdir subdir: atmos
output file: '*.tesac_profile.ioda.nc'
dmpdir regex: 'tesac.*.dcom_subsampled'
output file: 'tesac_profile.ioda.nc'
dmpdir regex: 'gdas.*.tesac.*.bufr_d'
- obs space:
name: insitu_surface_trkob
provider: GTS
dmpdir subdir: atmos
output file: '*.trkob_surface.ioda.nc'
dmpdir regex: 'trkob.*.dcom_subsampled'
output file: 'trkob_surface.ioda.nc'
dmpdir regex: 'gdas.*.trkob.*.bufr_d'
48 changes: 43 additions & 5 deletions scripts/exglobal_prep_ocean_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
from datetime import datetime, timedelta
from multiprocessing import Process
import os
from pathlib import Path
import subprocess
from soca import prep_marine_obs
from wxflow import YAMLFile, save_as_yaml, FileHandler, Logger
from wxflow import add_to_datetime, to_timedelta, datetime_to_YMDH
ShastriPaturi marked this conversation as resolved.
Show resolved Hide resolved
from gen_bufr2ioda_json import gen_bufr_json
ShastriPaturi marked this conversation as resolved.
Show resolved Hide resolved

logger = Logger()

cyc = os.getenv('cyc')
PDY = os.getenv('PDY')
RUN = os.getenv('RUN')
COMIN_OBS = os.getenv('COMIN_OBS')

# Set the window times
cdateDatetime = datetime.strptime(PDY + cyc, '%Y%m%d%H')
Expand All @@ -29,12 +34,49 @@

OBSPREP_YAML = os.getenv('OBSPREP_YAML')

# BUFR2IODA json and python scripts
JSON_TMPL_DIR = os.getenv('JSON_TMPL_DIR')
BUFR2IODA_PY_DIR = os.getenv('BUFR2IODA_PY_DIR')

if os.path.exists(OBSPREP_YAML):
obsprepConfig = YAMLFile(OBSPREP_YAML)
else:
logger.critical(f"OBSPREP_YAML file {OBSPREP_YAML} does not exist")
raise FileNotFoundError

if not os.path.exists(COMOUT_OBS):
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 {COMOUT_OBS}")

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

json_output_file = os.path.join(COMOUT_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 @@ -94,9 +136,8 @@ def run_netcdf_to_ioda(obsspace_to_convert):
outputFilename = f"gdas.t{cyc}z.{obs_space_name}.{PDY}{cyc}.nc4"
ShastriPaturi marked this conversation as resolved.
Show resolved Hide resolved
obsprepSpace['output file'] = outputFilename

# Skip in situ IODA conversion for now
if obsprepSpaceName.split('_')[0] == 'insitu':
ShastriPaturi marked this conversation as resolved.
Show resolved Hide resolved
logger.info("Skipping insitu conversion for now")
bufr2ioda(obsprepSpaceName, PDY, cyc, RUN, COMIN_OBS, COMOUT_OBS)
else:
iodaYamlFilename = obsprepSpaceName + '2ioda.yaml'
save_as_yaml(obsprepSpace, iodaYamlFilename)
Expand All @@ -122,7 +163,4 @@ def run_netcdf_to_ioda(obsspace_to_convert):
for process in processes:
process.join()

if not os.path.exists(COMOUT_OBS):
os.makedirs(COMOUT_OBS)

FileHandler({'copy': files_to_save}).sync()
5 changes: 3 additions & 2 deletions test/soca/gw/setup_obsprep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ for PDY in "${PDYs[@]}"; do
done
else
# Copy subsampled monthly in situ BUFR
# Example filename: tesac.201804.dcom_subsampled
# Example filename: tesac.201804.dcom_subsampled have been copied as
# gdas.t00z.tesac.tm00.bufr_d (the original filename)
# TODO: SP to replace these with daily and monthly subsampled with proper dates
fullsubdir="$PDYdir/$cyc/atmos"
mkdir -p "$fullsubdir"
for file in "$testdatadir_bufr/*.${PDY:0:6}.dcom_subsampled"; do
for file in "$testdatadir_bufr/*.bufr_d"; do
cp -p $file $fullsubdir
done
fi
Expand Down
Loading
Loading