# Ingest a New Grid Unrecognized grids can be decoded by EDEX simply by dropping `*.grib` or `*.grib2` files into `/awips2/edex/data/manual/` !!! note "This page explains how to ingest `.grib2` products. To view information about `.grib` products, [please see this page](../new-grid-grib1-old)." To add support for a new grid, two edits must be made: * **Geospatial projection** must be defined in a [***grid navigation file***](#create-grid-projection-file) * **Grid name**, **center**, **subcenter**, and **process ID** must be defined in a [***model definition file***](#create-model-definition) If the parameters in the grib file haven't been previously specified, another change *may* be needed as well: * **Center**, **subcenter**, **discipline**, **category**, and possibly **parameter ID** information may need to be defined in a [***table***](#adding-a-table) --- ## Ingest an Unsupported Grid ### Download Test Data Download an example grib2 file (make sure the extension is `.grib2` or the [EDEX distribution file](../data-distribution-files/#editing-an-edex-data-distribution-file) may not recognize it), and then copy to the manual ingest point `/awips2/edex/data/manual/`: wget https://downloads.unidata.ucar.edu/awips2/current/files/CPTI_00.50_20180502-000144.grib2 -O cpti.grib2 cp cpti.grib2 /awips2/edex/data/manual/ ### Check Grib Logs Confirm that the grib file decodes in the grib log file. Look in the current log file (/awips2/edex/logs/edex-ingestGrib-[YYYYMMDD].log) for the following: INFO [Ingest.GribDecode] /awips2/edex/data/manual/cpti.grib2 processed in: 0.1200 (sec) Latency: 21.8080 (sec) INFO [Ingest.GribDecode] /awips2/edex/data/manual/cpti.grib2 processed in: 0.1180 (sec) Latency: 21.8140 (sec) INFO [Ingest.GribDecode] /awips2/edex/data/manual/cpti.grib2 processed in: 0.4230 (sec) Latency: 21.8360 (sec) INFO [Ingest.GribDecode] /awips2/edex/data/manual/cpti.grib2 processed in: 0.2240 (sec) Latency: 21.9140 (sec) ... !!! warning "This step will fail for our example because the parameter is not yet defined. The error will look like:"
INFO  2020-07-20 20:34:17,710 2565 [GribPersist-1] GridDao: EDEX - Discarding record due to missing or unknown parameter mapping: /grid/2018-05-02_00:01:44.0_(0)/GribModel:161:0:97/null/null/403/Missing/FH/500.0/-999999.0
INFO  2020-07-20 20:34:17,710 2566 [GribPersist-1] Ingest: EDEX: Ingest - grib2:: /awips2/edex/data/manual/CPTI_00.50_20180502-000144.grib2 processed in: 2.3550 (sec)
INFO  2020-07-20 20:34:17,827 2567 [Ingest.GribDecode-6] grib: EDEX - No parameter information for center[161], subcenter[0], tableName[4.2.209.3], parameter value[61]
In order to successfully ingest the example file, you must [**define the appropriate table**](#adding-a-table). ### Check HDF5 Data Check that the hdf5 data directory exists for our unnamed grid ls -latr /awips2/edex/data/hdf5/grid/GribModel:161:0:97 Though the grib file has been decoded, it has been given a generic name with its **center, subcenter, and process IDs** (161, 0, 97, respectively). --- ## Determine Grid Projection When a grid is ingested a record is added to the `grid_coverage` table with its navigation information: psql metadata metadata=> select nx,ny,dx,dy,majoraxis,minoraxis,la1,lo1,lov,latin1,latin2,spacingunit,lad,la2,latin,lo2,firstgridpointcorner from gridcoverage where id=(select distinct(location_id) from grid_info where datasetid='GribModel:161:0:97'); nx | ny | dx | dy | majoraxis | minoraxis | la1 | lo1 | lov | latin1 | latin2 | spacingunit | lad | la2 | latin | lo2 | firstgridpointcorner -----+-----+-------+-------+-----------+-----------+-----------+-----+-----+--------+--------+-------------+-----+-----+-------+-----+---------------------- 600 | 640 | 0.005 | 0.005 | | | 40.799999 | 261 | | | | degree | | | | | UpperLeft (1 row) Compare with the projection info returned by wgrib2 on the original file (look at the bolded sections below and make sure they match up with the corresponding entries returned from the database above):
wgrib2 -grid -nxny cpti.grib2
1:0:grid_template=0:winds(N/S):
	lat-lon grid:(600 x 640) units 1e-06 input WE:NS output WE:SN res 48
	lat 40.799999 to 37.599999 by 0.005000
	lon 260.999999 to 263.999999 by 0.005000 #points=384000:(600 x 640)
  ...
Notice that our grib2 file has a **Lat/lon Grid** projection, that starts in the **UpperLeft** corner (as defined by input West to East, North to South). Where: * **nx** is **600** * **ny** is **640** * **dx** is **0.005** * **dy** is **0.005** * **la1** is **40.799999** * **lo1** is **261** We will need these values for the next step. !!! note "**There is a tolerance of +/- 0.1 degrees** to keep in mind when defining your coverage (la1 and lo1) area." --- ## Create Grid Projection File ### Projection Types !!! note "You may not have information for every tag listed, for example it's not required for the latLonGridCoverage to have spacingUnit, la2, lo2." Grid projection files are stored in `/awips2/edex/data/utility/common_static/base/grib/grids/` and there are four grid coverage types available: 1. **lambertConformalGridCoverage** (example: `RUCIcing.xml`) 305 Regional - CONUS (Lambert Conformal) 16.322 -125.955 LowerLeft 151 113 40.63525 40.63525 km 6356775.0 6378160.0 -95.0 25.0 25.0 2. **polarStereoGridCoverage** (example `seaice_south1_grid.xml`) 405 Sea Ice south 690X710 13km grid -36.866 139.806 LowerLeft 690 710 12.7 12.7 km 6371229.0 6371229.0 100.0 3. **latLonGridCoverage** (example `UkmetHR-SHemisphere.xml`) 864162002 UKMet HiRes combined - Southern Hemisphere Longitude range 71.25E - 70.416E -89.721 71.25 LowerLeft 864 162 0.833 0.556 degree -0.278 70.416 4. **mercatorGridCoverage** (example `gridNBM_PR.xml`) NBM_PR National Blend Grid over Puerto Rico - (1.25 km) 16.9775 -68.0278 LowerLeft 339 225 1.25 1.25 19.3750032477232 -63.984399999999994 20 km 6371200 6371200 ### Creating a New Projection File Copy an existing xml file with the same grid projection type (in this case **latLonGridCoverage**) to a new file `cpti.xml`: cd /awips2/edex/data/utility/common_static/base/grib/grids/ cp MRMS-1km-CONUS.xml cpti.xml And edit the new `cpti.xml` to define the projection values using the [output from wgrib2 or the database](#determine-grid-projection) (example provided): vi cpti.xml 600640 Small domain for CPTI products 40.799999 261 UpperLeft 600 640 0.005 0.005 degree !!! note "Notice the `600640` tag was created by using the number of grid points (600 and 640). This name can be anything as long as it is unique and will be used to match against in the model definition." --- ## Create Model Definition Model definition XML files are found in **/awips2/edex/data/utility/common_static/base/grib/models/**. Since our grib2 file has a center of 161 (NOAA) we will edit the **gribModels_NOAA-161.xml** file. cd /awips2/edex/data/utility/common_static/base/grib/models/ vi gribModels_NOAA-161.xml In ``, under the `<-- Subcenter 0 -->` comment, add an entry: CPTI
161
0 600640 97
Save the model file and restart edex: sudo service edex_camel restart ingestGrib Now if you drop `cpti.grib2` into the manual endpoint again, it should ingest without any persistence errors. --- ## Adding a Table If you ingest a piece of data and the parameter appears as unknown in the metadata database, ensure that the correct parameter tables are in place for the center/subcenter. The tables are located in **/awips2/edex/data/utility/common_static/base/grib/tables/**. They are then broken into subdirectories using the following structure: **/[Center]/[Subcenter]/4.2.[Discipine].[Category].table**. !!! note "There are also default parameters that all grib products may access located in this directory: **/awips2/edex/data/utility/common_static/base/grib/tables/-1/-1/**" If you are using a grib2 file, then you can use either the log output or the `-center`, `-subcenter`, and `-full_name` options on `wgrib2` to get the center, subcenter, discipline, category, and parameter information: The table would be found in the directory structure using this file's center and subcenter. ### Finding Center The center can be found by either: * Running the following command: wgrib2 -center cpti.grib2 1:0:center=US NOAA Office of Oceanic and Atmospheric Research ... And then looking up the corresponding value for "US NOAA Office of Oceanic and Atmospheric Research" at [**this website**](https://www.nco.ncep.noaa.gov/pmb/docs/on388/table0.html), where it happens to be **161**. **OR:** * Running the following command:
wgrib2 -varX cpti.grib2
1:0:var209_255_1_161_3_61
...
Where the 4th argument after "var" is the center id, in this case **161**. ### Finding Subcenter To get the subcenter, simply run:
wgrib2 -subcenter cpti.grib2
  1:0:subcenter=0
...
The subcenter of this file is **0**. Based on the center and subcenter, the corresponding directory is: /awips2/edex/data/utility/common_static/base/grib/tables/161/0/ ### Finding Discipline and Category To find the exact table, we need the discipline and category:
wgrib2 -full_name cpti.grib2
	1:0:var209_3_61.500_m_above_mean_sea_level
  ...
In this case the **discipline is 209** and **category is 3**, so the corresponding table is: 4.2.209.3.table ### Corresponding Table The full path to the corresponding table would be: /awips2/edex/data/utility/common_static/base/grib/tables/161/0/4.2.209.3.table The parameter ID was also listed in that output as **61**. Make sure that specific parameter information is defined in the table:
...
56:56:Reflectivity at -20C:dBZ:ReflectivityM20C
57:57:Reflectivity At Lowest Altitude (RALA):dBZ:ReflectivityAtLowestAltitude
58:58:Merged Reflectivity At Lowest Altitude (RALA):dBZ:MergedReflectivityAtLowestAltitude
59:59:CPTI 80mph+:%:CPTI80mph
61:61:CPTI 110mph+:%:CPTI110mph
You will have to restart ingestGrib for the changes to take place: sudo service edex_camel restart ingestGrib Now you can try [re-ingesting the grib2 file](#download-test-data). --- ## Creating Menu Items After you have confirmed that the grid was ingested with the given name, you can [edit the D2D product menus to display the new grid](../cave/d2d-edit-menus.md). --- ## Implementing a Production Process The [ingest method](#download-test-data) mentioned earlier is strictly meant to only be used during testing and development of ingesting new grid data. The reasoning is because the manual end point is very inefficent during its ingest. It creates copies of the data file and uses more resources than you'd want in a production process. Once you are satisfied with the data ingest and display in CAVE, then we highly recommend you implement a production process for ingest that does not involve the manual directory (`/awips2/edex/data/manual/`). The recommended way is to make use of a Python script we distribute with AWIPS (EDEX). This script is called `notifyAWIPS2-unidata.py` and located in th `/awips2/ldm/dev/` directory. If you are already using a script to manually gather the data, then adding an additional call like the one below, should ingest your data to EDEX in an efficient manner: ``` /awips2/ldm/dev/notifyAWIPS2-unidata.py [path-to-new-grib-file] ``` !!! note "Make sure the python script is executable. To do this you may have to run `chmod +x /awips2/ldm/dev/notifyAWIPS2-unidata.py`" --- ## Using wgrib2 Mentioned in this page are a few command parameters for `wgrib2` such as `-grid`, `varX`, `-center`, `-subcenter`, and `-full_name`. A complete [list of all available parameters can be found here](https://www.cpc.ncep.noaa.gov/products/wesley/wgrib2/long_cmd_list.html). --- ## Troubleshooting Grib Ingest * Make sure the latitude and longitude entries in your coverage specification file match those of your ingested raw grib file. There is a tolerance of +/- 0.1 degree to keep in mind when defining your coverage area. * If some of the information is unknown, using a grib utility application such as *wgrib* and *wgrib2* can be useful in determining the information that must be added to correctly process a new grib file. * If you are experiencing `Segmentation fault` errors when running wgrib2, it may be best to install the latest version using the following command: yum install wgrib2 And then you may either need to change where `wgrib2` points to, or use `/bin/wgrib2` to run the recently downloaded version.