Menu

Remap WRF files to interpolate wrfinput from wrfout files

Help
2023-04-28
2024-01-10
  • Paul MAUGER

    Paul MAUGER - 2023-04-28

    Hello to the community,

    I'm new to NCO and willing to remap a wrfout files in order to create an interpolated (ratio = 3) wrfinput file (1 timestep, 2D/3D variables). I looked up the forum and the User Guide but was not able to find answers to my questions.

    1. How to create a mapfile from a wrfout.nc as input (coarse) and a wrfinput.nc (fine) ?
    2. Then, if I understand correctly the User Guide, I shoud type something like : remap -i wrfout.nc -m map_fl -o wrfinput_remapped.nc ; is it correct ?
    3. Do NCO/remap handles staggered grid (as WRF has XLAT, XLON for T° and XLAT_U, XLON_U for U/V...) ? Because CDO can't with WRF files.

    I read these threads 1,2,3 but didn't find any help.

    I would really appreciate your help as I'm struggling finding my way out in the User Guide/on the internet.

    Thanks'

     

    Last edit: Paul MAUGER 2023-04-28
    • Charlie Zender

      Charlie Zender - 2023-04-28

      You might want to read the first sections of this https://acme-climate.atlassian.net/wiki/spaces/DOC/pages/754286611/Regridding+E3SM+Data+with+ncremap
      I suggest you try to construct the appropriate command for your use case based on those instructions.

       
      👍
      1
      • Paul MAUGER

        Paul MAUGER - 2023-04-28

        Hello,

        Thank you. I tried the Prototypical Regridding III: Infer Grid-file from Data-file, please see hereunder :

        pmauger@datarmor2:/home3/datawork/pmauger/CONFIGS/TEST_WRFINPUT_FROM_CYR> l
        total 75M
        -rwxrwxrwx 1 pmauger droos 7.8M Apr 28 01:48 wrfinput_d01_2005_01
        -rwxrwxrwx 1 pmauger droos 7.0M Apr 28 01:48 wrfinput_d02_2005_01
        -rwxrwxrwx 1 pmauger droos  60M Apr 28 05:42 wrfinput_origin.nc
        -rwxr-xr-x 1 pmauger droos 399K Apr 28 22:03 geo_em.d01.nc
        -rwxr-xr-x 1 pmauger droos 405K Apr 28 22:03 geo_em.d02.nc
        pmauger@datarmor2:/home3/datawork/pmauger/CONFIGS/TEST_WRFINPUT_FROM_CYR> ncremap -s wrfinput_origin.nc -d wrfinput_d01_2005_01 -m map_d01.nc
        ncks: ERROR nco_grd_nfr() reports an identified grid variable (XLAT with rank 3 and/or XLONG with rank 3) has rank greater than two---grid variables currently must have rank 1 or 2.
        HINT: If grid variables do not vary in time, then temporally average them (with, e.g., ncwa -a time in.nc out.nc) prior to inferring grid
        ncremap: ERROR Failed to infer destination grid. Debug this:
        ncks -O --no_tmp_fl --hdr_pad=10000 --gaa remap_script=ncremap --gaa remap_hostname=datarmor2.ice.ifremer.fr --gaa remap_version=4.9.2 --rgr infer --rgr hnt_dst="/tmp/ncremap_tmp_hnt_dst.txt.pid11951"     --rgr scrip="/tmp/ncremap_tmp_grd_dst.nc.pid11951" "wrfinput_d01_2005_01" "/tmp/ncremap_tmp_out.nc.pid11951"
        pmauger@datarmor2:/home3/datawork/pmauger/CONFIGS/TEST_WRFINPUT_FROM_CYR> ncks -O --no_tmp_fl --hdr_pad=10000 --gaa remap_script=ncremap --gaa remap_hostname=datarmor2.ice.ifremer.fr --gaa remap_version=4.9.2 --rgr infer --rgr hnt_dst="/tmp/ncremap_tmp_hnt_dst.txt.pid11951"     --rgr scrip="/tmp/ncremap_tmp_grd_dst.nc.pid11951" "wrfinput_d01_2005_01" "/tmp/ncremap_tmp_out.nc.pid11951"
        ncks: ERROR nco_grd_nfr() reports an identified grid variable (XLAT with rank 3 and/or XLONG with rank 3) has rank greater than two---grid variables currently must have rank 1 or 2.
        HINT: If grid variables do not vary in time, then temporally average them (with, e.g., ncwa -a time in.nc out.nc) prior to inferring grid
        pmauger@datarmor2:/home3/datawork/pmauger/CONFIGS/TEST_WRFINPUT_FROM_CYR> ncwa -a Time wrfinput_d01_2005_01 wrfinput_d01_2005_01.timeavg
        pmauger@datarmor2:/home3/datawork/pmauger/CONFIGS/TEST_WRFINPUT_FROM_CYR> ncwa -a Time wrfinput_origin.nc wrfinput_origin.timeavg
        pmauger@datarmor2:/home3/datawork/pmauger/CONFIGS/TEST_WRFINPUT_FROM_CYR> l
        total 131M
        -rwxrwxrwx 1 pmauger droos 7.8M Apr 28 01:48 wrfinput_d01_2005_01
        -rwxrwxrwx 1 pmauger droos 7.0M Apr 28 01:48 wrfinput_d02_2005_01
        -rwxrwxrwx 1 pmauger droos  60M Apr 28 05:42 wrfinput_origin.nc
        -rwxr-xr-x 1 pmauger droos 399K Apr 28 22:03 geo_em.d01.nc
        -rwxr-xr-x 1 pmauger droos 405K Apr 28 22:03 geo_em.d02.nc
        -rw-r--r-- 1 pmauger droos 7.7M Apr 28 22:07 wrfinput_d01_2005_01.timeavg
        -rw-r--r-- 1 pmauger droos  60M Apr 28 22:08 wrfinput_origin.timeavg
        pmauger@datarmor2:/home3/datawork/pmauger/CONFIGS/TEST_WRFINPUT_FROM_CYR> ncremap -s wrfinput_origin.timeavg -d wrfinput_d01_2005_01.timeavg -m map_d01.nc
        Grid(src): wrfinput_origin.timeavg
        Grid(dst): /tmp/ncremap_tmp_grd_dst.nc.pid12721
        nco_err_exit(): ERROR Short NCO-generated message (usually name of function that triggered error): nco_inq_dimid()
        nco_err_exit(): ERROR Error code is -46. Translation into English with nc_strerror(-46) is "NetCDF: Invalid dimension ID or name"
        ncremap: ERROR Failed to generate map-file. Debug this:
        ncks -O --dmm_in_mk --thr_nbr=2 --no_tmp_fl --hdr_pad=10000 --gaa remap_script=ncremap --gaa remap_hostname=datarmor2.ice.ifremer.fr --gaa remap_version=4.9.2 --grd_src="wrfinput_origin.timeavg" --grd_dst="/tmp/ncremap_tmp_grd_dst.nc.pid12721" --map="map_d01.nc"  "/tmp/ncremap_tmp_dmm.nc.pid12721" "/tmp/ncremap_tmp_out.nc.pid12721" > /dev/null
        pmauger@datarmor2:/home3/datawork/pmauger/CONFIGS/TEST_WRFINPUT_FROM_CYR> ncks -O --dmm_in_mk --thr_nbr=2 --no_tmp_fl --hdr_pad=10000 --gaa remap_script=ncremap --gaa remap_hostname=datarmor2.ice.ifremer.fr --gaa remap_version=4.9.2 --grd_src="wrfinput_origin.timeavg" --grd_dst="/tmp/ncremap_tmp_grd_dst.nc.pid12721" --map="map_d01.nc"  "/tmp/ncremap_tmp_dmm.nc.pid12721" "/tmp/ncremap_tmp_out.nc.pid12721" > /dev/null
        nco_err_exit(): ERROR Short NCO-generated message (usually name of function that triggered error): nco_inq_dimid()
        nco_err_exit(): ERROR Error code is -46. Translation into English with nc_strerror(-46) is "NetCDF: Invalid dimension ID or name"
        

        I looked the page up for trace of "WRF" or Weather Reasearch & Forecast" but didn't find any. I attached 3 geogrid files from WPS (WRF), "Cyr" being the original grid I'm looking to interpolate from. I also tried with geo_em.Cyr.nc and geo_em.d01.nc without any success ; even Time averaged files.

        Have you any idea how I can get ncremap to work with my files ?

        May I ask what is the problem with WRF files ? I'm constantly facing failure with usual weather/climate toolkits (like CDO). Is this all about CF Convention ?

         

        Last edit: Paul MAUGER 2023-04-29
        • Charlie Zender

          Charlie Zender - 2023-04-28

          Thank your for reading the docs. You're making progress...
          This command is incorrect because is supposed to specify the source grid-file and instead you give it the source data file to be regridded:

          ncremap -s wrfinput_origin.timeavg -d wrfinput_d01_2005_01.timeavg -m map_d01.nc
          

          Try:

          ncremap -d wrfinput_d01_2005_01.timeavg -m map_d01.nc wrfinput_origin.timeavg out.nc
          
           
          👍
          1
    • wang yueya

      wang yueya - 2024-01-10

      hello, I just wondering if you are using this wrfinput files to drive wrf again. I would like to use such wrfout files as the initial and boundary conditions. If so, may i know how to process the wrfbdy file? thanks !!

       
  • Paul MAUGER

    Paul MAUGER - 2023-04-29

    Hello,

    Thanks for your encouragement. I obviously misunderstood what I read. Nevertheless, I tried your command and I got no error... BUT : the out.nc file is corrupted ; see images attached.
    Please see the original files I'm working with : https://drive.google.com/drive/folders/19dBokRXJxAENWBuKY9ZO0RTT65cDUcpc?usp=share_link

     

    Last edit: Paul MAUGER 2023-04-29
    • Charlie Zender

      Charlie Zender - 2023-04-29

      This appears to work for me. First I time-average the grid variables. Then I supply a 1x1 destination grid for the regridder. The regridder infers the source grid from the input file,
      regrids it into foo.nc and saves the resulting mapfile as map.nc.

      ncwa -a Time wrfinput_origin.nc wrfinput_origin_t.nc 
      ncremap -v PSFC,TSK -g /Users/zender/data/grids/cmip6_180x360_scrip.20181001.nc /Users/zender/Downloads/wrfinput_origin_t.nc ~/foo.nc
      
       
      • Paul MAUGER

        Paul MAUGER - 2023-05-02

        Hello,
        Thanks for your answer. However, I'm looking to regrid wrfinput_origin.nc to the dimensions of wrfinput_d01_2005-01 without having any preprocessed grid file. Typing the exaxt command you advised unfortunately led to an invalid out.nc.
        Would you mind trying with both source and destination grid files as I did ? Did I get the command wrong ? I would like to understand what went wrong and, moreover, I really need this remapped file for my initial conditions to fit my boundary conditions.
        Thanks for your help which is much appreciated.

         
        • Charlie Zender

          Charlie Zender - 2023-05-03

          This input file appears to be corrupt:

          zender@spectral:~/Downloads$ ncdump -h wrfinput_d01_2005_01
          ncdump: wrfinput_d01_2005_01: NetCDF: Unknown file format
          
           
  • Paul MAUGER

    Paul MAUGER - 2023-05-04

    My bad, sorry. I don't understand what happened (and still happens) when I transfer from the super-computer to my own computer : 2 files out of 3 seem to be corrupted in the while.

    (base) pmauger@Laptop-STS0009:~/Documents/DATA_CYRIL/TEST> nch wrfinput_d01_2005_01 | head -n 5
    ncdump: wrfinput_d01_2005_01: NetCDF: Unknown file format
    (base) pmauger@Laptop-STS0009:~/Documents/DATA_CYRIL/TEST> nch wrfinput_d01_2005_01.origin | head -n 5
    netcdf wrfinput_d01_2005_01 {
    dimensions:
        Time = UNLIMITED ; // (1 currently)
        DateStrLen = 19 ;
        west_east = 120 ;
    (base) pmauger@Laptop-STS0009:~/Documents/DATA_CYRIL/TEST> nch wrfinput_d02_2005_01 | head -n 5
    ncdump: wrfinput_d02_2005_01: NetCDF: Unknown file format
    

    The 3 files though are looking good on the super-computer, I tested each of them before and after sending them to my laptop.

    pmauger@datarmor3:/home3/scratch/pmauger/eftp/TEST> nch wrfinput_d02_2005_01 | head -n 5
    netcdf wrfinput_d02_2005_01 {
    dimensions:
        Time = UNLIMITED ; // (1 currently)
        DateStrLen = 19 ;
        west_east = 120 ;
    pmauger@datarmor3:/home3/scratch/pmauger/eftp/TEST> nch wrfinput_d01_2005_01.origin | head -n 5
    netcdf wrfinput_d01_2005_01 {
    dimensions:
        Time = UNLIMITED ; // (1 currently)
        DateStrLen = 19 ;
        west_east = 120 ;
    pmauger@datarmor3:/home3/scratch/pmauger/eftp/TEST> nch wrfinput_d01_2005_01 | head -n 5
    netcdf wrfinput_d01_2005_01 {
    dimensions:
        Time = UNLIMITED ; // (1 currently)
        DateStrLen = 19 ;
        west_east = 120 ;
    

    Would you mind test with the new wrfinput_d01_2005-01.origin file I just uploaded (same link to the drive as above) ?

    Ncview and ncdump ran well with this one on my PC. It's got the same grid as the other wrfinput which is corrupted, so this is OK to use as destination grid file.

    Thanks

     
  • Charlie Zender

    Charlie Zender - 2023-05-05
    ncwa -a Time wrfinput_d01_2005_01.origin wrfinput_d01_2005_01.origin_t
    ncwa -a Time wrfinput_origin.nc wrfinput_origin_t.nc
    ncremap -d wrfinput_d01_2005_01.origin_t -m map.nc wrfinput_origin_t.nc ~/foo.nc
    
     
    • Paul MAUGER

      Paul MAUGER - 2023-05-10

      I really don't understand why it doesn't work for me. I keep getting corrupted files. Also I miss some variables, as U and V.

      I checked each file at each step (after ncks -d Time,0 ... and ncwa -a Time ...).

      pmauger@datarmor1:/home3/scratch/pmauger/eftp> clc
      total 326M
      drwxrwxrwx 2 pmauger droos 4.0K May 10 04:09 .
      drwxrwxrwx 5 pmauger droos 4.0K Apr 25 11:20 ..
      -rwxr-xr-x 1 pmauger droos 7.8M May 10 04:06 wrfinput_d01
      -rwxr-xr-x 1 pmauger droos 7.0M May 10 04:06 wrfinput_d02
      -rw-r-xr-- 1 pmauger droos 312M May 10 01:47 wrfout_cyril
      
      pmauger@datarmor1:/home3/scratch/pmauger/eftp> nctime wrfinput_d01 | tms
        "2005-01-01_06:00:00" ;
      
      pmauger@datarmor1:/home3/scratch/pmauger/eftp> nctime wrfinput_d02 | tms
        "2005-01-01_06:00:00" ;
      
      pmauger@datarmor1:/home3/scratch/pmauger/eftp> nctime wrfout_cyril | tms
        "2005-01-01_06:00:00",
        "2005-01-01_12:00:00",
        "2005-01-01_18:00:00",
        "2005-01-02_00:00:00" ;
      
      pmauger@datarmor1:/home3/scratch/pmauger/eftp> ncks -d Time,0 -v Times,XLAT,XLONG,LU_INDEX,ZNU,ZNW,VAR_SSO,U,V,W,PH,PHB,T,MU,MUB,P,PB,FNM,FNP,RDNW,RDN,DNW,DN,CFN,CFN1,Q2,T2,TH2,PSFC,U10,V10,RDX,RDY,RESM,ZETATOP,CF1,CF2,CF3,QVAPOR,QCLOUD,QRAIN,QICE,QSNOW,QGRAUP,SHDMAX,SHDMIN,SNOALB,SH2O,SMCREL,SEAICE,IVGTYP,ISLTYP,VEGFRA,SNOW,SNOWH,CANWAT,VAR,MAPFAC_M,MAPFAC_U,MAPFAC_V,MAPFAC_MX,MAPFAC_MY,MAPFAC_UX,MAPFAC_UY,MAPFAC_VX,MF_VX_INV,MAPFAC_VY,F,E,SINALPHA,COSALPHA,HGT,TSK,P_TOP,T00,P00,TLP,TISO,TLP_STRAT,P_STRAT,XLAT_U,XLONG_U,XLAT_V,XLONG_V,CLAT,TMN,XLAND,SR,SAVE_TOPO_FROM_REAL,LANDMASK,LAKEMASK,SST wrfout_cyril wrfout_cyr_1ts
      
      pmauger@datarmor1:/home3/scratch/pmauger/eftp> nctime wrfout_cyr_1ts | tms
        "2005-01-01_06:00:00" ;
      
      pmauger@datarmor1:/home3/scratch/pmauger/eftp> ncwa -a Time wrfout_cyr_1ts wrfout_cyr_1ts_ta
      pmauger@datarmor1:/home3/scratch/pmauger/eftp> nctime wrfout_cyr_1ts_ta | tms
       Times = "2005-01-01_06:00:00" ;
      
      pmauger@datarmor1:/home3/scratch/pmauger/eftp> ls -l *ta*
      -rw-r--r-- 1 pmauger droos  7985551 May 10 04:22 wrfinput_d01_ta
      -rw-r--r-- 1 pmauger droos 61892323 May 10 04:17 wrfout_cyr_1ts_ta
      
      pmauger@datarmor1:/home3/scratch/pmauger/eftp> ncremap -d wrfinput_d01_ta -m map.d01 wrfout_cyr_1ts_ta wrfinput_d01_remap
      Input #00: /home3/scratch/pmauger/eftp/wrfout_cyr_1ts_ta
      Grid(src): /tmp/ncremap_tmp_grd_src.nc.pid38005
      Grid(dst): /tmp/ncremap_tmp_grd_dst.nc.pid38005
      Map/Wgt  : map.d01
      

      Please see screenshots attached below.

      If this can be of any help :

      pmauger@datarmor1:/home3/scratch/pmauger/eftp> ncremap --version
      ncremap, the NCO regridder and grid, map, and weight-generator, version 4.9.2 "Delirium"
      Copyright (C) 2016--present Charlie Zender
      This program is part of NCO, the netCDF Operators
      NCO is free software and comes with a BIG FAT KISS and ABSOLUTELY NO WARRANTY
      You may redistribute and/or modify NCO under the terms of the
      3-Clause BSD License with exceptions described in the LICENSE file
      BSD: https://opensource.org/licenses/BSD-3-Clause
      LICENSE: https://github.com/nco/nco/tree/master/LICENSE
      Config: ncremap script located in directory /home/datawork-wave/NETCDF2019/INTEL/bin
      Config: NCO binaries located in directory /home/datawork-wave/NETCDF2019/INTEL/bin, linked to netCDF library version 4.7.3
      Config: No hardcoded machine-dependent path/module overrides. (If desired, turn-on NCO hardcoded paths at supported national labs with "export NCO_PATH_OVERRIDE=Yes").
      Config: External (non-NCO) program availability:
      Config: ESMF weight-generation command ESMF_RegridWeightGen not found
      Config: MOAB-Tempest weight-generation command mbtempest not found
      Config: MPAS depth coordinate addition command add_depth.py not found
      Config: TempestRemap weight-generation command GenerateOfflineMap not found
      
       

      Last edit: Paul MAUGER 2023-05-10
      • Charlie Zender

        Charlie Zender - 2023-05-10

        I lack the resources to investigate in any greater detail. However, I notice your NCO is > 3 years old. I suggest you upgrade in case the issues you encountered have been mitigated by features or bugfixes since 2021. Good luck, CZ

         
  • Paul MAUGER

    Paul MAUGER - 2023-05-16

    Hello,

    I've got some help and succeeded at regridding WRF's NetCDF. Please find below the procedure to be used :

    1) Split coarse and fine files to T, U and V grids :

    T grid :

    ncks -v CANWAT,CLAT,COSALPHA,E,F,HGT,ISLTYP,IVGTYP,LAKEMASK,LANDMASK,LU_INDEX,MAPFAC_M,MAPFAC_MX,MAPFAC_MY,MU,MUB,P,PB,PH,PHB,PSFC,Q2,QCLOUD,QGRAUP,QICE,QRAIN,QSNOW,QVAPOR,SEAICE,SH2O,SHDMAX,SHDMIN,SINALPHA,SMCREL,SNOALB,SNOW,SNOWH,SR,SST,T,T2,TH2,TMN,TSK,U10,V10,VAR,VAR_SSO,VEGFRA,W,XLAND,XLAT,XLONG coarse_in.nc coarse_out_T.nc
    
    ncks -v CANWAT,CLAT,COSALPHA,E,F,HGT,ISLTYP,IVGTYP,LAKEMASK,LANDMASK,LU_INDEX,MAPFAC_M,MAPFAC_MX,MAPFAC_MY,MU,MUB,P,PB,PH,PHB,PSFC,Q2,QCLOUD,QGRAUP,QICE,QRAIN,QSNOW,QVAPOR,SEAICE,SH2O,SHDMAX,SHDMIN,SINALPHA,SMCREL,SNOALB,SNOW,SNOWH,SR,SST,T,T2,TH2,TMN,TSK,U10,V10,VAR,VAR_SSO,VEGFRA,W,XLAND,XLAT,XLONG fine_in.nc fine_out_T.nc
    

    U grid :

    ncks -v U,MAPFAC_U,MAPFAC_UX,MAPFAC_UY,XLAT_U,XLONG_U coarse_in.nc coarse_out_U.nc
    
    **ncks -v MAPFAC_U,MAPFAC_UX,MAPFAC_UY,XLAT_U,XLONG_U fine_in.nc fine_out_U.nc
    

    V grid :

    ncks -v V,MAPFAC_V,MAPFAC_VX,MF_VX_INV,MAPFAC_VY,XLAT_V,XLONG_V coarse_in.nc coarse_out_V.nc
    
    ncks -v V,MAPFAC_V,MAPFAC_VX,MF_VX_INV,MAPFAC_VY,XLAT_V,XLONG_V fine_in.nc fine_out_V.nc
    

    2) Remap each of the new coarse grids to fine grids :

    cdo griddes fine_in_T.nc > grid_T.txt 
    cdo remapbil,grid_T.txt coarse_out_T.nc fine_out_T_remap.nc
    
    cdo griddes fine_in_U.nc > grid_U.txt 
    cdo remapbil,grid_U.txt coarse_out_U.nc fine_out_U_remap.nc
    
    cdo griddes fine_in_V.nc > grid_V.txt 
    cdo remapbil,grid_V.txt coarse_out_V.nc fine_out_V_remap.nc
    

    3) Concatenate T, U and V remapped fine grids together :

    cp fine_out_T_remap.nc fine_out_all_remap.nc
    ncks -A fine_out_U_remap.nc fine_out_all_remap.nc
    ncks -A fine_out_V_remap.nc fine_out_all_remap.nc
    

    4) Add times :

    ncrename -d time,Time fine_out_all_remap.nc
    ncks -A -v Times fine_in.nc fine_out_all_remap.nc
    
     

    Last edit: Paul MAUGER 2023-05-16
    • Charlie Zender

      Charlie Zender - 2023-05-17

      Thanks for posting your solution!

       
  • Paul MAUGER

    Paul MAUGER - 2023-06-08

    Update for complete wrfinput/wrfout processing (compliant with WRF3.6.1 : variables list has been updated since)

    I had some trouble with my previous script version. Some variables on the W staggered grid that I has separated from the unstaggered grid woudn't be accepted by NCO (PH, PHB, SH2O, W).
    I corrected the problem by suppressing the division of wrfinput_ and wrfout_ into T,U,V axes instead of T,U,V,W. Then only SH2O wouldn't be accepted by NCO (edit : layers number problem : 3 vs 4). This is why, hereunder, I tested each variable one by one the end of the code. I have to optimize this part.

    # DEFINE INPUTS
    
    # USUALLY $1 = wrfinput_d0*
    # USUALLY $2 = wrfout_*
    
    # SELECT FIRST TIMESTEP FROM WRFOUT
    
        ncks -O -d Time,0 $2 wrfout
    
    # WRFOUT (1 timestep) ACCORDING TO T,U,V,W
    
    ncks -v Times,MU,MUB,P,P00,PB,PH,PHB,PSFC,P_STRAT,Q2,QCLOUD,QGRAUP,QICE,QRAIN,QSNOW,QVAPOR,SST,T,T00,T2,TH2,TSK,U10,V10,W wrfout wrfout_T
    ncks -v Times,U wrfout wrfout_U
    ncks -v Times,V wrfout wrfout_V
    
    #  ACCORDING TO T,U,V,W
    
    cp $1 wrfin
    
    ncks -v Times,ALBBCK,CANWAT,CF1,CF2,CF3,CFN,CFN1,CLAT,COSALPHA,DN,DNW,DTBC,DTS,DTSEPS,E,F,FCX,FNDALBSI,FNDICEDEPTH,FNDSNOWH,FNDSNOWSI,FNDSOILW,FNM,FNP,FRC_URB2D,GCX,HGT,ISLTYP,IVGTYP,LAI,LAKE_DEPTH,LAKE_DEPTH_FLAG,LAKEFLAG,LAKEMASK,LANDMASK,LU_INDEX,MAPFAC_M,MAPFAC_MX,MAPFAC_MY,P_HYD,P_TOP,QV_BASE,RDN,RDNW,RDX,RDY,RESM,SAVE_TOPO_FROM_REAL,SEAICE,SHDMAX,SHDMIN,SINALPHA,SNOALB,SNOW,SNOWC,SNOWH,SR,STEP_NUMBER,T_BASE,T_INIT,TISO,TLP,TLP_STRAT,TMN,TOPOSLPX,TOPOSLPY,U_BASE,U_FRAME,UOCE,VAR,VAR_SSO,V_BASE,VEGFRA,V_FRAME,VOCE,XLAND,XLAT,XLONG,Z_BASE,ZETATOP,ZNU,CPLMASK,DZS,LANDUSEF,SMCREL,SMOIS,SOILCBOT,SOILCTOP,TSLB,ZNW,ZS wrfin wrfin_T
    ncks -v Times,MAPFAC_U,MAPFAC_UX,MAPFAC_UY,XLAT_U,XLONG_U wrfin wrfin_U
    ncks -v Times,MAPFAC_V,MAPFAC_VX,MAPFAC_VY,MF_VX_INV,XLAT_V,XLONG_V wrfin wrfin_V
    
    # GRID DESCRIPTION
    
    cdo griddes wrfin_T > grid_T.txt 
    cdo griddes wrfin_U > grid_U.txt 
    cdo griddes wrfin_V > grid_V.txt
    
    # REMAP (BILINEAR)
    
    cdo remapbil,grid_T.txt wrfout_T wrfout_T_remap
    cdo remapbil,grid_U.txt wrfout_U wrfout_U_remap
    cdo remapbil,grid_V.txt wrfout_V wrfout_V_remap
    
    # CONCATENATE ALL SUB-FILES
    
    cp wrfout_T_remap wrfout_remap
    
    ncks -A wrfout_U_remap wrfout_remap
    ncks -A wrfout_V_remap wrfout_remap
    
    # REPLACE TIME VARIABLE TYPE AND TIME COORDINATE BY WRFIN
    
    ncrename -d Times,Time wrfout_remap
    ncks -O -s 'Times=char(Times)' wrfout_remap wrfout_remap
    ncks -O -x -v Times wrfout_remap wrfout_remap
    ncks -A -v Times wrfin wrfout_remap
    
    # CHANGE XLAT* & XLONG* ATTRIBUTES
    
    ncks -C -x -v XLONG,XLAT,XLONG_U,XLAT_U,XLONG_V,XLAT_V wrfout_remap wrfout_remap_xlonglat_ok
    ncks -A -v XLONG,XLAT,XLONG_U,XLAT_U,XLONG_V,XLAT_V,HGT wrfin wrfout_remap_xlonglat_ok
    
    # APPEND ALL REMAPPED VARIABLES TO WRFINPUT (to be optimized)
    
    #cp wrfin control_0 # FOR TESTS
    
    ncks -A -C -v MU wrfout_remap_xlonglat_ok wrfin 
    ncks -A -C -v MUB wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v P wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v P00 wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v PB wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v PSFC wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v P_STRAT wrfout_remap_xlonglat_ok wrfin
    
    #cp wrfin control_P # IDEM
    
    ncks -A -C -v Q2 wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v QCLOUD wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v QGRAUP wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v QICE wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v QRAIN wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v QSNOW wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v QVAPOR wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v SST wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v T wrfout_remap_xlonglat_ok wrfin
    
    #cp wrfin control_SST_T # IDEM
    
    ncks -A -C -v T00 wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v T2 wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v TH2 wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v TSK wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v U10 wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v V10 wrfout_remap_xlonglat_ok wrfin
    
    #cp wrfin control_UV10 # IDEM
    
    ncks -A -C -v U wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v V wrfout_remap_xlonglat_ok wrfin
    
    #cp wrfin control_UV # IDEM
    
    ncks -A -C -v PH wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v PHB wrfout_remap_xlonglat_ok wrfin
    ncks -A -C -v W wrfout_remap_xlonglat_ok wrfin
    
    # RENAME PROPERLY ACCORDING TO INPUT FILE
    
    name="$(basename -- $1)"
    cp wrfin $name
    
    # CLEAN
    
    rm -rf grid* wrfout_* wrfin_* *pid* wrfin wrfinput
    
    # TIME COUNTER ENDS
    
    end=$(date +%s)
    echo "Elapsed Time: $(($end-$start)) seconds"
    
     

    Last edit: Paul MAUGER 2023-06-09
    • Charlie Zender

      Charlie Zender - 2023-06-13

      Again, thanks for posting your detailed solution.

       

Log in to post a comment.

MongoDB Logo MongoDB