# Table of Contents

# Lesson S2 - Regridding GLDAS v2.1 Forcing Data to the WRF-Hydro Domain¶

## Overview¶

In this lesson, we will cover regridding GLDAS v2.1 forcing data to a WRF-Hydro domain using the ESMF regridding functions within the NCAR Command Language (NCL).

### Software and conventions¶

The easiest way to run these lessons is via the wrfhydro/costarica-training Docker container, which has all software dependencies and data pre-installed.

For a complete description of the software environment used for this training please see Getting started.

You may either execute commands by running each cell of this notebook. Alternatively, you may open a terminal in Jupyter Lab by selecting `New -> Terminal` in your `Home` tab of Jupyter Lab and input the commands manually if you prefer. You can also use your own terminal by logging into the container with the command `docker exec -it wrf-hydro-training bash`

All paths used in this lesson assume that the lesson materials are located under your home directory in a folder named `wrf-hydro-training`. If your materials are located in another directory, you will not be able to run the commands in this notebook inside Jupyter and will need to type them manually in your terminal session.

## Required scripts and datasets¶

### Regridding scripts¶

Scripts and documentation to regrid GLDAS v2.1 forcing data can be downloaded from the WRF-Hydro website at https://ral.ucar.edu/projects/wrf_hydro/regridding-scripts.

### Data sources¶

For this training, test data has already been included.

NOTE: These data are a small temporal subset intended to be used for instructional purposes only

If you would like to acquire other data, GLDAS v2.1 forcing data can be retrieved from a NASA data server at https://hydro1.gesdisc.eosdis.nasa.gov/data/GLDAS/GLDAS_NOAH025_3H.2.1/.

See the following site for information on how to access data: https://disc.gsfc.nasa.gov/data-access

See the following instructions for how to download data files using wget: https://disc.gsfc.nasa.gov/information/howto?title=How%20to%20Download%20Data%20Files%20from%20HTTPS%20Service%20with%20wget

## Creating the directory structure¶

The NCL regridding scripts require a very specific directory structure, which is outlined below:

    |
    input_files
        |_GLDAS_NOAH025_3H.*.nc4 - All GLDAS input forcing data
    |_GLDAS2WRFHydro_generate_weights.ncl - NCL script for generating weight file
    |_GLDAS2WRFHydro_regrid.ncl - NCL script for regridding

In this section, we will create this directory structure

Step 1: Explore the contents of the GLDAS regridding package provided with this tutorial Note: These files are identical to those distributed with the GLDAS regridding package on the WRF-Hydro webpage. They are unpacked for you in the following directory.

In [1]:

    %%bash
    ls ~/wrf-hydro-training/regridding

    GLDAS2WRFHydro_generate_weights.ncl
    GLDAS2WRFHydro_regrid.ncl
    README.txt
    geo_em.d01.nc
    input_files

Step 2: Create an input_files directory to hold the forcing data and move the data to it.

In [2]:

    %%bash
    mkdir -p mkdir ~/wrf-hydro-training/output/lessonS2/input_files
    cp ~/wrf-hydro-training/regridding/input_files/*.nc4 \
    ~/wrf-hydro-training/output/lessonS2/input_files

Step 3: View the contents of the input_files directory files

In [3]:

    %%bash
    ls ~/wrf-hydro-training/output/lessonS2/input_files | head -10

    GLDAS_NOAH025_3H.A20000101.0300.021.nc4
    GLDAS_NOAH025_3H.A20000101.0600.021.nc4
    GLDAS_NOAH025_3H.A20000101.0900.021.nc4
    GLDAS_NOAH025_3H.A20000101.1200.021.nc4
    GLDAS_NOAH025_3H.A20000101.1500.021.nc4
    GLDAS_NOAH025_3H.A20000101.1800.021.nc4
    GLDAS_NOAH025_3H.A20000101.2100.021.nc4

Step 4: Copy over the NCL regridding scripts

In [4]:

    %%bash
    cp ~/wrf-hydro-training/regridding/*.ncl \
    ~/wrf-hydro-training/output/lessonS2/

Step 5: Check that your directory structure is correct

In [5]:

    %%bash
    ls ~/wrf-hydro-training/output/lessonS2/

    GLDAS2WRFHydro_generate_weights.ncl
    GLDAS2WRFHydro_regrid.ncl
    input_files

Our directory structure is established, now we can begin the regridding process.

## Creating the regridding weight file¶

The weight files are netCDF files which specify interpolation weights between the source coordinate data grids and destination coordinate data grids.

We will use the script GLDAS2WRFHydro_generate_weights.ncl to generate the weight file. This script takes a geogrid file and a single GLDAS forcing .nc4 file as inputs and returns a weight file.

Step 1: Creating the regridding weight file We will use the GLDAS2WRFHydro_generate_weights.ncl script to create the weight file

Recall that we created a geogrid file in Lesson S1. We will use this geogrid file as input to the regridding script along with a single GLDAS forcing file. We will run the NCL scripts from our output directory because outputs are written to the current working directory

In [6]:

    %%bash
    cd ~/wrf-hydro-training/output/lessonS2
    ncl 'interp_opt="bilinear"' \
        'srcGridName="./input_files/GLDAS_NOAH025_3H.A20000101.0300.021.nc4"' \
        'dstGridName="~/wrf-hydro-training/example_case/Gridded/DOMAIN/geo_em.d01.nc"' \
        GLDAS2WRFHydro_generate_weights.ncl

     Copyright (C) 1995-2017 - All Rights Reserved
     University Corporation for Atmospheric Research
     NCAR Command Language Version 6.4.0
     The use of this software is governed by a License Agreement.
     See http://www.ncl.ucar.edu/ for more details.
    (0)	=====> CPU Elapsed Time: rectilinear_to_SCRIP: 0.63 seconds <=====
    (0)	=====> CPU Elapsed Time: curvilinear_to_SCRIP: 0 seconds <=====
    (0)	ESMF_regrid_gen_weights: number of processors used: 1
    (0)	--------------------------------------------------
    (0)	ESMF_regrid_gen_weights: the following command is about to be executed on the system:
    (0)	'ESMF_RegridWeightGen --source SCRIP_GLDAS_bilinear.nc --destination SCRIP_WRFHydro_bilinear.nc --weight ./GLDAS2WRFHydro_weight_bilinear.nc --method bilinear --dst_regional -i'
    (0)	--------------------------------------------------
    (0)	ESMF_regrid_gen_weights: output from 'ESMF_RegridWeightGen':
    (0)	      Starting weight generation with these inputs:
    (1)	        Source File: SCRIP_GLDAS_bilinear.nc
    (2)	        Destination File: SCRIP_WRFHydro_bilinear.nc
    (3)	        Weight File: ./GLDAS2WRFHydro_weight_bilinear.nc
    (4)	        Source File is in SCRIP format
    (5)	        Source Grid is a global grid
    (6)	        Source Grid is a logically rectangular grid
    (7)	        Destination File is in SCRIP format
    (8)	        Destination Grid is a regional grid
    (9)	        Destination Grid is a logically rectangular grid
    (10)	        Regrid Method: bilinear
    (11)	        Pole option: ALL
    (12)	        Ignore unmapped destination points
    (13)	        Norm Type: dstarea
    (14)
    (15)	      Completed weight generation successfully.
    (16)
    (0)	--------------------------------------------------
    (0)	ESMF_regrid_gen_weights: 'ESMF_RegridWeightGen' was successful.
    (0)	=====> CPU Elapsed Time: ESMF_regrid_gen_weights: 0.00999999 seconds <=====

In [7]:

    %%bash
    ls ~/wrf-hydro-training/output/lessonS2

    GLDAS2WRFHydro_generate_weights.ncl
    GLDAS2WRFHydro_regrid.ncl
    GLDAS2WRFHydro_weight_bilinear.nc
    PET0.RegridWeightGen.Log
    SCRIP_GLDAS_bilinear.nc
    SCRIP_WRFHydro_bilinear.nc
    input_files

We have two new files: The SCRIP_GLDAS_bilinear.nc describes the GLDAS grids and the SCRIP_WRFHydro_bilinear.nc describes the WRF-Hydro grid from the geogrid file.

## Regridding the forcing data using the weight file¶

In this section we will regrid our forcing data using the weight file generated in the previous section.

Step 2: Run the GLDAS2WRFHydro_regrid.ncl regridding script

The GLDAS2WRFHydro_regrid.ncl script takes 2 arguments, the path to the geogrid file and the path to GLDAS forcing data. NOTE: Wildcards can be used in the path to the forcing data to regrid multiple files.

The GLDAS2WRFHydro_regrid.ncl regridding script produces a large amount of standard output so we will pipe the output to a log file.

In [8]:

    %%bash
    cd ~/wrf-hydro-training/output/lessonS2
    ncl 'srcFileName="GLDAS_NOAH025_3H.*.nc4"' \
    'dstGridName="~/wrf-hydro-training/example_case/Gridded/DOMAIN/geo_em.d01.nc"' \
    GLDAS2WRFHydro_regrid.ncl &> regrid.log

Step 3: View the contents of the output_files directory The GLDAS2WRFHydro_regrid.ncl regridding script will create a directory called output_files in the parent directory. Let's view the contents of the directory.

In [9]:

    %%bash
    ls ~/wrf-hydro-training/output/lessonS2/output_files

    2000010103.LDASIN_DOMAIN1
    2000010106.LDASIN_DOMAIN1
    2000010109.LDASIN_DOMAIN1
    2000010112.LDASIN_DOMAIN1
    2000010115.LDASIN_DOMAIN1
    2000010118.LDASIN_DOMAIN1
    2000010121.LDASIN_DOMAIN1

In [ ]: