diff --git a/sources/data-coupler/DataCouplerPreprocessor.py b/sources/data-coupler/DataCouplerPreprocessor.py index 855c906578f1434fd4385be026a8e5edc03de6dc..8df71ab94560f0d375a7c473205d95154e8f4a1d 100644 --- a/sources/data-coupler/DataCouplerPreprocessor.py +++ b/sources/data-coupler/DataCouplerPreprocessor.py @@ -20,27 +20,32 @@ def append_multiple_lines_to_file(file_path, lines_to_append): file.write(lines_to_append + '\n') -def add_field_to_namcouple(send_id, receive_id, timestepsec,send_grid_name, receive_grid): - lines_to_append = str(send_id) + " " + str(receive_id) + " 1 " + str(timestepsec) + " 1 rstas.nc EXPOUT \n" + \ - str(send_grid_name) + " " + str(receive_grid) + " LAG=0 \n" + \ - "P 0 P 0\n" + \ - "SCRIPR \n" + \ - "GAUSWGT LR SCALAR LATITUDE 1 9 2.0" +def add_field_to_namcouple(send_id, receive_id, timestepsec, send_grid, receive_grid): + # TODO add option for transformation and restart_file + if send_grid == receive_grid: + transfo = " LOCTRANS\n AVERAGE" + else: + transfo = "SCRIPR\n GAUSWGT LR SCALAR LATITUDE 1 9 2.0" - return lines_to_append + lines_to_append = """ + {send_id} {receive_id} 1 {timestepsec} 1 {restart_file} EXPOUT + {send_grid} {receive_grid} LAG=0 + P 0 P 0 + {transfo}""" + return lines_to_append.format(send_id=send_id, receive_id=receive_id, timestepsec=timestepsec, restart_file='rstas.nc', send_grid=send_grid, receive_grid=receive_grid, transfo=transfo) def create_empty_file(filename): try: with open(filename, 'w') as file: pass # The file is created but remains empty - print(f"Empty file '{filename}' created successfully.") + print(f"File '{filename}' created successfully.") except Exception as e: print(f"An error occurred: {e}") -def add_begin_to_namecouple(nfields,runtime): +def add_begin_to_namcouple(nfields, runtime, ModelNameSend, ModelNameReceive): lines_to_append = """# ================================================================================================= # General OASIS configuration # ================================================================================================= @@ -57,12 +62,12 @@ def add_begin_to_namecouple(nfields,runtime): $END # ------------------------------------------------------------------------------------------------- $STRINGS + # ================================================================================================= -# Fields send from AMIP to IFS -# ================================================================================================= -# --- AMIP forcing data --- [ifs amip]""" +# Fields send from {ModelNameSend} to {ModelNameReceive} +# =================================================================================================""" - return(lines_to_append.format(nfields=nfields,runtime=runtime)) + return(lines_to_append.format(nfields=nfields, runtime=runtime, ModelNameSend=ModelNameSend, ModelNameReceive=ModelNameReceive)) def add_end_to_namecouple(): @@ -129,12 +134,12 @@ if __name__ == '__main__': # Creating the namcouple file amd insert the read-in data from YAML file create_empty_file(namcouple_output) - lines=add_begin_to_namecouple(number_of_fields,RunLengthSec) + lines=add_begin_to_namcouple(number_of_fields, RunLengthSec, ModelNameSend, ModelNameReceive) append_multiple_lines_to_file(namcouple_output, lines) for v in OasisOutputVars_readin.keys() : lines = add_field_to_namcouple(OasisOutputVars_readin[v]['send_id'], OasisOutputVars_readin[v]['receive_id'], \ - TimeStepSec,OasisOutputVars_readin[v]['send_grid_name'], OasisOutputVars_readin[v]['receive_grid_name']) + TimeStepSec, OasisOutputVars_readin[v]['send_grid_name'], OasisOutputVars_readin[v]['receive_grid_name']) append_multiple_lines_to_file(namcouple_output, lines) lines = add_end_to_namecouple() diff --git a/tests/data/convert-ece4pyreader-grids.sh b/tests/data/convert-ece4pyreader-grids.sh index 58417d7b7fe2a220321624c3f34b78caa00551fd..d7f61bc39c974cef906c3b27ecda47e6e36b4c95 100755 --- a/tests/data/convert-ece4pyreader-grids.sh +++ b/tests/data/convert-ece4pyreader-grids.sh @@ -16,14 +16,11 @@ griddef_amip=grid-amip.txt # cdo griddes tosbcs_input4MIPs_SSTsAndSeaIce_CMIP_PC gridname_co2=CO2 griddef_co2=grid-co2_emis.txt # cdo griddes > grid-co2_emis.txt model_ifs=IFS_TOY -vars_ifs="A_SST A_Ice_frac" -[ -f namelist.co2box ] && CO2BOX=true || CO2BOX=false -[[ ${CO2_EMODE} == true ]] && vars_ifs+=" A_CO2_emis A_CO2_land A_CO2_ocean" +[$model_mode = "co2box" ] && CO2BOX=true || CO2BOX=false -vars_amip="AMIP_sst AMIP_sic" grids="AMIP L128" #B128 A128 R128 -[[ ${CO2_EMODE} == true ]] && grids+=" CO2_emis" +[[ ${CO2FLUX} == true ]] && grids+=" CO2_emis" # copy from runtime dir the following files grids.nc areas.nc masks.nc for gridname in ${grids} @@ -58,11 +55,11 @@ if [[ ${CO2BOX} == true ]]; then model_co2=CO2BOX [[ ${CO2_CMODE} == true ]] && vars_co2_co2box="CO2BOX_CO2_cconc CO2BOX_CO2_econc" [[ ${CO2_CMODE} == true ]] && vars_co2_ifs="A_CO2_cconc A_CO2_econc" - [[ ${CO2_EMODE} == true ]] && vars_co2="CO2BOX_CO2_emis" + [[ ${CO2FLUX} == true ]] && vars_co2="CO2BOX_CO2_emis" else model_amip=AMIPFORC model_co2=AMIPFORC - [[ ${CO2_EMODE} == true ]] && vars_co2="AMIP_CO2_emis" + [[ ${CO2FLUX} == true ]] && vars_co2="AMIP_CO2_emis" fi for v in $vars_ifs @@ -88,6 +85,3 @@ for v in $vars_co2_ifs do HDF5_DISABLE_VERSION_CHECK=1 cdo -O -f nc -r $taxis ${v}_${model_ifs}_??.nc ${v}.nc done - - - diff --git a/tests/data/template_conf_datacoupler_co2box.yaml b/tests/data/template_conf_datacoupler_co2box.yaml new file mode 100755 index 0000000000000000000000000000000000000000..2dc792879a9ddad5eb789f64bd8d6ff4302b20f9 --- /dev/null +++ b/tests/data/template_conf_datacoupler_co2box.yaml @@ -0,0 +1,33 @@ +cat << EOF +# YAML input file for DataCoupler, It will be ingested and turn to Experiment YAML file + +## Model Information +ModelNameSend : CO2BOX +ModelNameReceive : IFS_TOY +LogFileName : co2box.log + +## Run Information +RunLengthSec : ${leg_length_sec} +TimeStepSec : ${cpl_freq_amip_sec} +StartYear : ${leg_start_date_yyyymmdd:0:4} +StartMonth : ${leg_start_date_yyyymmdd:4:2} +StartDay : ${leg_start_date_yyyymmdd:6:2} +FixYear : ${ifs_cmip_fixyear} +GridInfo : 1 # GLOBAL grid + +## Coupling Information +FileInputVars: + CO2_cconc_monthly : { id: CO2_cconc_monthly, grid_name: GLOBAL, oasis_name: CO2BOX_CO2_cconc, file_pattern: mole-fraction-of-carbon-dioxide-in-air_input4MIPs_GHGConcentrations_CMIP_UoM-CMIP-1-2-0_gr1-GMNHSH_184901-201412.nc.mod, netcdf_variable: mole_fraction_of_carbon_dioxide_in_air, yref_min : 1849, yref_max: 2014, timestep: monthly, interpolate: true, scale_factor: 1, offset: 0, min:, max:, update: true, accum: true} + CO2_econc_monthly : { id: CO2_econc_monthly, grid_name: GLOBAL, oasis_name: CO2BOX_CO2_econc, file_pattern: mole-fraction-of-carbon-dioxide-in-air_input4MIPs_GHGConcentrations_CMIP_UoM-CMIP-1-2-0_gr1-GMNHSH_184901-201412.nc.mod, netcdf_variable: mole_fraction_of_carbon_dioxide_in_air, yref_min : 1849, yref_max: 2014, timestep: monthly, interpolate: true, scale_factor: 'co2_ppm_to_mass', offset: 0, min:, max:, update: false, accum: false} + CO2_em_monthly_GLOBAL : { id: CO2_em_monthly_GLOBAL, grid_name: GLOBAL, oasis_name: CO2BOX_CO2_econc, file_pattern: CO2-em-anthro_input4MIPs_emissions_CMIP_CEDS-2017-05-18_gn_200001-201412-global.nc, netcdf_variable: CO2_em_anthro, yref_min : 1750, yref_max: 2018, timestep: monthly, interpolate: false, scale_factor: 86400, offset: 0, min:, max:, update: true, accum: true} + CO2_land_monthly_GLOBAL : { id: CO2_land_monthly_GLOBAL, grid_name: GLOBAL, oasis_name: CO2BOX_CO2_econc, file_pattern: CO2-em-anthro_input4MIPs_emissions_CMIP_CEDS-2017-05-18_gn_200001-201412-global.nc, netcdf_variable: CO2_em_anthro, yref_min : 1750, yref_max: 2018, timestep: monthly, interpolate: false, scale_factor: 43200, offset: 0, min:, max:, update: true, accum: true} + CO2_ocean_monthly_GLOBAL : { id: CO2_ocean_monthly_GLOBAL, grid_name: GLOBAL, oasis_name: CO2BOX_CO2_econc, file_pattern: CO2-em-anthro_input4MIPs_emissions_CMIP_CEDS-2017-05-18_gn_200001-201412-global.nc, netcdf_variable: CO2_em_anthro, yref_min : 1750, yref_max: 2018, timestep: monthly, interpolate: false, scale_factor: 8640, offset: 0, min:, max:, update: true, accum: true} + +OasisOutputVars: + CO2BOX_CO2_cconc : { send_id: CO2BOX_CO2_cconc, receive_id: A_CO2_cconc, send_grid_name: GLOBAL, receive_grid_name: GLOBAL, timestep: 'daily', scale_factor: 1, offset: 0, reset: true } + CO2BOX_CO2_econc : { send_id: CO2BOX_CO2_econc, receive_id: A_CO2_econc, send_grid_name: GLOBAL, receive_grid_name: GLOBAL, timestep: 'daily', scale_factor: 'co2_mass_to_ppm', offset: 0, reset: false } + +LDebug : false + +EOF + diff --git a/tests/data/template_conf_datacoupler_co2.yaml b/tests/data/template_conf_datacoupler_co2flux.yaml similarity index 91% rename from tests/data/template_conf_datacoupler_co2.yaml rename to tests/data/template_conf_datacoupler_co2flux.yaml index 750011d01fce92fcebcb7e3e08f5fe62664c3cc2..dd29224ab1b25bd5adb0af2ba31819fcf8592054 100755 --- a/tests/data/template_conf_datacoupler_co2.yaml +++ b/tests/data/template_conf_datacoupler_co2flux.yaml @@ -1,12 +1,12 @@ cat << EOF # YAML input file for DataCoupler, It will be ingested and turn to Experiment YAML file + ## Model Information -OasisModel : IFS_TOY -OasisCPLNG : AMIPFORC -LogFileName : amip.log -YamlConfName : ${yaml_conf_name} -PartitionType : ApplePartition +ModelNameSend : AMIPFORC +ModelNameReceive : IFS_TOY +LogFileName : amip.log +YamlConfName : ${yaml_conf_file} ## Run Information RunLengthSec : ${leg_length_sec} @@ -15,7 +15,10 @@ StartYear : ${leg_start_date_yyyymmdd:0:4} StartMonth : ${leg_start_date_yyyymmdd:4:2} StartDay : ${leg_start_date_yyyymmdd:6:2} FixYear : ${ifs_cmip_fixyear} -GridInfo : TBD_VALUE +GridInfo : 88838 # number of grid cells : L080_NX = 35718 @ T159 resolution / L128_NX = 88838 @ T255 resolution / L256_NX = 348528 @ T511 resolution + + + ## Coupling Information FileInputVars: diff --git a/tests/data/template_conf_datacoupler_forcing.yaml b/tests/data/template_conf_datacoupler_forcing.yaml index 23e89c710c3721ed01ef3ba0b8b00f8e2d4743f8..2e0ab98ee7af41c2d4d98b197e253277178c0167 100755 --- a/tests/data/template_conf_datacoupler_forcing.yaml +++ b/tests/data/template_conf_datacoupler_forcing.yaml @@ -1,14 +1,11 @@ cat << EOF # YAML input file for DataCoupler, It will be ingested and turn to Experiment YAML file -# yaml metadata -type : 1 # DataCoupler is 1, ToyModel is 2 ## Model Information ModelNameSend : AMIPFORC ModelNameReceive : IFS_TOY LogFileName : amip.log -YamlConfName : ${yaml_conf_file} ## Run Information RunLengthSec : ${leg_length_sec} diff --git a/tests/launch_ece3_data_coupler_mn4.cmd b/tests/launch_ece3_data_coupler_mn4.cmd index 7a8948dee71e6f12fc650aa9e82189254fea3848..b5c4c4e75e772d8f763e7d5e7feba9f1fec07bd3 100644 --- a/tests/launch_ece3_data_coupler_mn4.cmd +++ b/tests/launch_ece3_data_coupler_mn4.cmd @@ -36,10 +36,13 @@ source ../sources/oasis3-mct/generated/python/init.sh #bash ./run_example.sh fortran forcing 4 2005-01-01 2005-03-01 0 128 true #bash ./run_example-t1279.sh python forcing 4 2010-01-01 2010-03-01 0 128 true -#bash ./run_example.sh datacoupler co2 4 2005-01-01 2005-03-01 0 128 true false template_conf_datacoupler_co2.yaml #bash ./run_example.sh co2box co2 4 2005-01-01 2005-03-01 0 128 true false +#AMIP + Forcing bash ./run_example.sh datacoupler forcing 4 2005-01-01 2005-03-01 0 128 true false template_conf_datacoupler_forcing.yaml +#AMIP + Forcing for co2flux +#bash ./run_example.sh datacoupler co2flux 4 2005-01-01 2005-03-01 0 128 true false template_conf_datacoupler_co2flux.yaml + #bash ./run_example.sh python co2 4 2005-01-01 2005-03-01 0 128 true #bash ./run_example.sh co2box co2 4 2005-01-01 2005-03-01 0 128 true #bash ./run_example.sh co2box co2 4 2005-01-01 2005-03-01 0 128 true false diff --git a/tests/run_example.sh b/tests/run_example.sh index 596a25982c8351a8087dec6442049de017ecd886..b04c75d7c346742ffabf64655e3f5925b8ccf25e 100755 --- a/tests/run_example.sh +++ b/tests/run_example.sh @@ -3,7 +3,7 @@ if [ $# -ne 10 ]; then echo 'Invalid args.' - echo 'Usage ./run_example.sh ' + echo 'Usage ./run_example.sh ' echo 'Try .bash ./run_example.sh datacoupler forcing 4 2005-01-01 2005-03-01 0 128 true false template_conf_datacoupler_forcing.yaml' exit 1 fi @@ -11,7 +11,7 @@ fi set -xuve model=$1 -amip_mode=$2 # forcing or primavera +model_mode=$2 # forcing, primavera or co2box # - Define number of processes to run each executable nproc_exe1=$3 nproc_exe2=1 # AMIP is always one process @@ -37,7 +37,7 @@ source_exe1=/../$srcdir/../sources/ece3-toy-model/toy_model.py if [ $model = fortran ]; then exe2='./amip-forcing' - if [ $amip_mode = forcing ]; then + if [ $model_mode = forcing ]; then source_exe2=$srcdir/../sources/amip-forcing/bin/amip-forcing else source_exe2=$srcdir/../sources/amip-primavera/bin/amip-forcing @@ -57,10 +57,10 @@ else fi CO2_CMODE=false -CO2_EMODE=false +CO2FLUX=false # - Define rundir -rundir=${srcdir}/work_${model}_${amip_mode}_${nproc_exe1}_${leg_start_date}_${leg_end_date}_${ifs_cmip_fixyear}_${ifs_grid}_${amip_interpolate} +rundir=${srcdir}/work_${model}_${model_mode}_${nproc_exe1}_${leg_start_date}_${leg_end_date}_${ifs_cmip_fixyear}_${ifs_grid}_${amip_interpolate} echo '*****************************************************************' @@ -82,30 +82,33 @@ mkdir -p $rundir ln -sf $datadir/ICMGGa22e+000000 $rundir/. ln -sf $datadir/*.txt $rundir/. # Get SST and SIC -if [ $amip_mode = forcing ] || [ $amip_mode = co2 ] || [ $model=datacoupler ]; then +if [ $model_mode = forcing ]; then ln -sf $datadir/forcing/siconcbcs*.nc $rundir/. ln -sf $datadir/forcing/tosbcs*.nc $rundir/. ln -sf $datadir/forcing/rmp_AMIP_to_L${ifs_grid}_GAUSWGT*.nc $rundir/. +elif [ $model_mode = primavera ]; then + ln -sf $datadir/$model_mode/HadI*.nc $rundir/. + ln -sf $datadir/$model_mode/rmp_PSIC_to_${ifs_grid}_GAUSWGT.nc $rundir/. + ln -sf $datadir/$model_mode/rmp_PSST_to_${ifs_grid}_GAUSWGT.nc $rundir/. +fi +if [ $model=datacoupler ]; then ln -sf $datadir/co2/CO2-em-anthro_*.nc $rundir/. ln -sf $datadir/co2/CO2-em-AIR-anthro_*.nc $rundir/. ln -sf $datadir/co2/mole-fraction-of-carbon-dioxide-in-air_*.nc* $rundir/. ln -sf $datadir/co2/rmp_CO2_emis_to_B${ifs_grid}_GAUSWGT*.nc $rundir/. -else - ln -sf $datadir/$amip_mode/HadI*.nc $rundir/. - ln -sf $datadir/$amip_mode/rmp_PSIC_to_${ifs_grid}_GAUSWGT.nc $rundir/. - ln -sf $datadir/$amip_mode/rmp_PSST_to_${ifs_grid}_GAUSWGT.nc $rundir/. fi # Get grids and masks if [ $model = fortran ] || [ $model = pythoncompat ]; then - cp -f $datadir/$amip_mode/masks.nc $rundir/. - cp -f $datadir/$amip_mode/grids.nc $rundir/. - cp -f $datadir/$amip_mode/areas.nc $rundir/. + cp -f $datadir/$model_mode/masks.nc $rundir/. + cp -f $datadir/$model_mode/grids.nc $rundir/. + cp -f $datadir/$model_mode/areas.nc $rundir/. else cp -f $datadir/grids-noamip.nc $rundir/grids.nc cp -f $datadir/masks-noamip.nc $rundir/masks.nc cp -f $datadir/areas-noamip.nc $rundir/areas.nc fi -cp -f $datadir/*.sh $rundir/. +#cp -f $datadir/*.sh $rundir/. +cp -f $datadir/convert-ece4pyreader-grids.sh $rundir/. cp -f $datadir/*.yaml $rundir/. ln -sf $source_exe1 $rundir/. ln -sf $source_exe2 $rundir/. @@ -119,22 +122,22 @@ cpl_freq_amip_sec=86400 # Always leg_start_date_yyyymmdd=$(date -u -d "${leg_start_date}" +%Y%m%d) if [ $model = fortran ] || [ $model = pythoncompat ]; then - if [ $amip_mode = forcing ]; then + if [ $model_mode = forcing ]; then . ./namelist.amip.sh > ./namelist.amip . ./namcouple.sh > ./namcouple - elif [ $amip_mode = primavera ]; then + elif [ $model_mode = primavera ]; then . ./namelist_primavera.amip.sh > ./namelist.amip . ./namcouple_primavera.sh > ./namcouple else - echo 'Error: for fortran or pythoncompat models, Only forcing or primavera is valid for amip_mode.' + echo 'Error: for fortran or pythoncompat models, Only forcing or primavera is valid for mode.' exit 9 fi else # Comleting the YAML template that user has provided and store it (yaml_conf_file) - # TODO: dynamically genarte YAML file name based on the exp. + # TODO: dynamically generate YAML file name based on the exp. #yaml_conf_file=$(grep -F "ModelNameReceive" "$yaml_conf_template" | awk '{print $3}')'_exp_conf.yaml' yaml_conf_file='DataCoupler_exp_conf.yaml' . ./$yaml_conf_template > $yaml_conf_file