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 IODA conversions to marine obs prep task ex-script #719

Merged
merged 20 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d8e0f8c
initial test rig for adding iodaconv to marine obs prep
AndrewEichmann-NOAA Nov 8, 2023
3c1538d
Merge branch 'develop' into feature/iodaconv
AndrewEichmann-NOAA Nov 9, 2023
f5e58be
some var name changes, etc.
AndrewEichmann-NOAA Nov 9, 2023
81c5159
create dynamic obs2ioda yaml, etc.
AndrewEichmann-NOAA Nov 9, 2023
26204a3
added ads_adt_3b, dedicated obs_list
AndrewEichmann-NOAA Nov 9, 2023
a88e3fc
add ice, change variable name
AndrewEichmann-NOAA Nov 9, 2023
ab28533
tweaks
AndrewEichmann-NOAA Nov 9, 2023
14996c6
adt ioda output file name changed
AndrewEichmann-NOAA Nov 13, 2023
95ff5d4
made window times dynamic
AndrewEichmann-NOAA Nov 13, 2023
126df70
logging tests
AndrewEichmann-NOAA Nov 14, 2023
4f5c3fc
more use of env vars
AndrewEichmann-NOAA Nov 14, 2023
c7fd438
Merge branch 'develop' into feature/iodaconv
AndrewEichmann-NOAA Nov 28, 2023
4fdc351
moved from bugfix/prepobs-ctest, getting different obs sources to work
AndrewEichmann-NOAA Nov 29, 2023
5f5de6f
cleanup of test obs sources
AndrewEichmann-NOAA Nov 29, 2023
c059d27
Merge branch 'develop' into feature/iodaconv
guillaumevernieres Nov 29, 2023
c42dcfa
corrected style issues, etc.
AndrewEichmann-NOAA Nov 29, 2023
fe95d02
Merge branch 'feature/iodaconv' of github.com:NOAA-EMC/GDASApp into f…
AndrewEichmann-NOAA Nov 29, 2023
191c5f3
corrected style issues, etc.
AndrewEichmann-NOAA Nov 29, 2023
b76d49f
Merge branch 'develop' into feature/iodaconv
AndrewEichmann-NOAA Nov 29, 2023
4ba02fd
Merge branch 'develop' into feature/iodaconv
AndrewEichmann-NOAA Nov 30, 2023
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
11 changes: 11 additions & 0 deletions parm/soca/obsproc/obs_list_obsproc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
observers:
- !INC ${OBS_YAML_DIR}/adt_all.yaml
- !INC ${OBS_YAML_DIR}/adt_j3.yaml
- !INC ${OBS_YAML_DIR}/adt_j2.yaml
#- !INC ${OBS_YAML_DIR}/salt_profile_fnmoc.yaml
- !INC ${OBS_YAML_DIR}/sss_smap.yaml
- !INC ${OBS_YAML_DIR}/sss_smos.yaml
- !INC ${OBS_YAML_DIR}/sst_noaa19_l3u.yaml
- !INC ${OBS_YAML_DIR}/icec_emc.yaml
- !INC ${OBS_YAML_DIR}/adt_3b_egm2008.yaml
- !INC ${OBS_YAML_DIR}/icec_amsr2_north.yaml
25 changes: 25 additions & 0 deletions parm/soca/obsproc/obsproc_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
observations:
- obs space:
name: sss_smap
obsproc subdir: SSS
obsproc regex: SMAP_L2B_SSS_NRT_?????_[AD]_????????T??????.h5
provider: SMAP
output file: sss_smap.ioda.nc
- obs space:
name: sss_smos
provider: SMOS
obsproc subdir: SSS
output file: sss_smos.ioda.nc
obsproc regex: SM_OPER_MIR_OSUDP2_????????T??????_????????T??????_700_001_1.nc
- obs space:
AndrewEichmann-NOAA marked this conversation as resolved.
Show resolved Hide resolved
name: adt_3b_egm2008
obsproc subdir: ADT
obsproc regex: rads_adt_3b_???????.nc
provider: RADS
output file: adt_all.nc4
- obs space:
name: icec_amsr2_north
provider: AMSR2
obsproc subdir: icec
output file: icec_amsr2_north_1.ioda.nc
obsproc regex: AMSR2-SEAICE-NH_v2r2_GW1_s???????????????_e???????????????_c???????????????.nc
25 changes: 25 additions & 0 deletions parm/soca/obsproc/obsproc_config_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
observations:
- obs space:
name: sss_smap
obsproc subdir: ''
obsproc regex: sss_smap_?.nc4
provider: SMAP
output file: sss_smap.ioda.nc
- obs space:
name: sss_smos
provider: SMOS
obsproc subdir: ''
output file: sss_smos.ioda.nc
obsproc regex: sss_smos_?.nc4
- obs space:
name: adt_3b_egm2008
obsproc subdir: ''
obsproc regex: rads_adt_??_???????.nc4
provider: RADS
output file: adt_all.nc4
- obs space:
name: icec_amsr2_north
provider: AMSR2
obsproc subdir: ''
output file: icec_amsr2_north.ioda.nc
obsproc regex: icec_amsr2_north_?.nc4
52 changes: 44 additions & 8 deletions scripts/exglobal_prep_ocean_obs.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,53 @@
#!/usr/bin/env python3
# exglobal_prep_ocean_obs.py
# Pepares observations for marine DA
from datetime import datetime, timedelta
import logging
import os
from wxflow import YAMLFile
import prep_marine_obs
import logging
import subprocess
from wxflow import YAMLFile, save_as_yaml

# set up logger
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S')

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

# set the window times
cdateDatetime = datetime.strptime(PDY + cyc, '%Y%m%d%H')
windowBeginDatetime = cdateDatetime - timedelta(hours=3)
windowEndDatetime = cdateDatetime + timedelta(hours=3)
windowBegin = windowBeginDatetime.strftime('%Y-%m-%dT%H:%M:%SZ')
windowEnd = windowEndDatetime.strftime('%Y-%m-%dT%H:%M:%SZ')

OCNOBS2IODAEXEC = os.getenv('OCNOBS2IODAEXEC')

OBS_YAML = os.getenv('OBS_YAML')
obsConfig = YAMLFile(OBS_YAML)

OBSPROC_YAML = os.getenv('OBSPROC_YAML')
obsprocConfig = YAMLFile(OBSPROC_YAML)

# TODO (AFE): needs more error handling (missing sources, missing files)
for observer in obsConfig['observers']:

obsSpaceName = observer['obs space']['name']
print(f"obsSpaceName: {obsSpaceName}")

for observation in obsprocConfig['observations']:

obsprocSpace = observation['obs space']
obsprocSpaceName = obsprocSpace['name']

if obsprocSpaceName == obsSpaceName:

matchingFiles = prep_marine_obs.obs_fetch(obsprocSpace)
obsprocSpace['input files'] = matchingFiles
obsprocSpace['window begin'] = windowBegin
obsprocSpace['window end'] = windowEnd

data = YAMLFile(OBS_YAML)
print(data)
iodaYamlFilename = obsprocSpaceName + '2ioda.yaml'
save_as_yaml(obsprocSpace, iodaYamlFilename)

for observer in data['observers']:
obs_source_name = observer['obs space']['name']
logging.info(f"obs_source_name: {obs_source_name}")
prep_marine_obs.obs_fetch(obs_source_name)
subprocess.run([OCNOBS2IODAEXEC, iodaYamlFilename], check=True)
14 changes: 11 additions & 3 deletions test/soca/gw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,22 @@ add_test(NAME test_gdasapp_soca_run_clean
# Create scratch for testing apps
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/test/soca/gw/apps_scratch)

# Create scratch for obs prep task
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/test/soca/gw/obsproc)

# Set up obsproc, based on test_gdasapp_util_prepdata
add_test(NAME test_gdasapp_soca_setup_obsproc
COMMAND ${PROJECT_SOURCE_DIR}/test/soca/gw/setup_obsproc.sh ${PROJECT_SOURCE_DIR}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/soca/gw/obsproc)

# Test JGDAS_GLOBAL_OCEAN_ANALYSIS_*
set(jjob_list "JGDAS_GLOBAL_OCEAN_ANALYSIS_PREP"
set(jjob_list "JGLOBAL_PREP_OCEAN_OBS"
"JGDAS_GLOBAL_OCEAN_ANALYSIS_PREP"
"JGDAS_GLOBAL_OCEAN_ANALYSIS_BMAT"
"JGDAS_GLOBAL_OCEAN_ANALYSIS_RUN"
"JGDAS_GLOBAL_OCEAN_ANALYSIS_CHKPT"
"JGDAS_GLOBAL_OCEAN_ANALYSIS_POST"
"JGDAS_GLOBAL_OCEAN_ANALYSIS_VRFY"
"JGLOBAL_PREP_OCEAN_OBS")
"JGDAS_GLOBAL_OCEAN_ANALYSIS_VRFY")

set(setup "")
foreach(jjob ${jjob_list})
Expand Down
4 changes: 3 additions & 1 deletion test/soca/gw/run_jjobs.yaml.test
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ setup_expt config:
NICAS_RESOL: 1
NICAS_GRID_SIZE: 150
prepoceanobs:
SOCA_OBS_LIST: @HOMEgfs@/sorc/gdas.cd/parm/soca/obs/obs_list_small.yaml
SOCA_OBS_LIST: @HOMEgfs@/sorc/gdas.cd/parm/soca/obsproc/obs_list_obsproc.yaml
OBSPROC_CONFIG: @HOMEgfs@/sorc/gdas.cd/parm/soca/obsproc/obsproc_config_test.yaml
DMPDIR: @HOMEgfs@/sorc/gdas.cd/build/test/soca/gw/obsproc

job options:
account: da-cpu
Expand Down
17 changes: 17 additions & 0 deletions test/soca/gw/setup_obsproc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -ex

project_source_dir=$1

# working directory should be ${PROJECT_BINARY_DIR}/test/soca/gw/obsproc, set in ctest command
test_dmpdir="gdas.20180415/12"

rm -rf ${test_dmpdir}
mkdir -p ${test_dmpdir}

cd ${test_dmpdir}

${project_source_dir}/utils/test/prepdata.sh ${project_source_dir}/utils/test/



27 changes: 12 additions & 15 deletions ush/soca/prep_marine_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,29 @@
}

ShastriPaturi marked this conversation as resolved.
Show resolved Hide resolved

def obs_fetch(obs_source_name):
def obs_fetch(obsprocSpace):

try:
obs_source = obs_dict[obs_source_name]
except KeyError:
print(f'WARNING: no obs source {obs_source_name} defined, skipping')
return

subdir = obs_source[0]
filepattern = obs_source[1]
subdir = obsprocSpace['obsproc subdir']
filepattern = obsprocSpace['obsproc regex']

datadir = os.path.join(cycdir, subdir)
# TODO: check the existence of this
print('datadir:', datadir)
matching_files = []
matchingFiles = []

for root, _, files in os.walk(datadir):
for filename in fnmatch.filter(files, filepattern):
matching_files.append((root, filename))
matchingFiles.append(filename)

obs_cpy = []
for obs_src in matching_files:
obs_path = os.path.join(obs_src[0], obs_src[1])
obs_dst = os.path.join(COMIN_OBS, obs_src[1])
for obs_src in matchingFiles:
obs_path = os.path.join(datadir, obs_src)
obs_dst = os.path.join(COMIN_OBS, obs_src)
obs_cpy.append([obs_path, obs_dst])

print(obs_cpy)
print(f"obs_cpy: {obs_cpy}")
print(f"matchingFiles: {matchingFiles}")

FileHandler({'copy': obs_cpy}).sync()

return matchingFiles
6 changes: 6 additions & 0 deletions ush/soca/run_jjobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ def fixconfigs(self):
'STMP': self.stmp,
'ROTDIR': self.rotdir,
'EXPDIRS': self.expdirs}

# needed for this ctest at least until R2D2 goes away
if 'JGLOBAL_PREP_OCEAN_OBS' in self.config['jjobs']:
dmpdir = self.config['setup_expt config']['prepoceanobs']['DMPDIR']
var2replace['DMPDIR'] = dmpdir

with open(configbase, 'r') as f:
newconfigbase = f.read()
for key, value in var2replace.items():
Expand Down
4 changes: 4 additions & 0 deletions utils/test/prepdata.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash
# called for test_gdasapp_util_prepdata, and by
# test/soca/gw/setup_obsproc.sh for test_gdasapp_soca_setup_obsproc


set -e

cdl2nc4() {
Expand Down
Loading