# AMET v1.4 error

**URL:** <https://forum.cmascenter.org/t/amet-v1-4-error/1144>\
**Category:** AMET\
**Created:** [November 25, 2019, 7:17pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144 "2019-11-25T19:17:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgurer](https://avatars.discourse-cdn.com/v4/letter/k/f04885/32.png) [@kgurer](https://forum.cmascenter.org/u/kgurer)\
**Post date:** [November 25, 2019, 7:17pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/1 "2019-11-25T19:17:11Z")

</div>

Hello,

I have been using AMET v1.4 to compare MPAS “global” model results against observations without any problem. However, when I try to compare MPAS “limited area” model results, then I get an error:

“Mapping MADIS obs sites to MPAS grid  
Error in cwgt[sitenum, 1] \<- (XP \* (YB - YC) + YP \* (XC - XB) + XB \* YC - :  
replacement has length zero”

I tried to track down the error and found out that the eror occurs in function “mpas\_site\_map”. However, I cannot locate this function (I assume it is somewhere in one of the R scripts, but cannot find it) and hence cannot continue debugging. First I thought that limited area domain must have to do with this, but when I compare WRF “limited area” model results against observations, I don’t have any problem, either. So, I am not sure what is happening. Output seems to suggests that, based on some location finding algorithm, the analysis script is trying to co-locate the site on the model domain. But without locating this function, I cannot move forward with this error. Can you help me to solve this error?

I cut and pasted the full output below for your review. Thank you for your help.

With regards,

Kemal.

-------------- beginning of output ------------------

Date/Time START  
Mon Nov 25 11:14:12 PST 2019  
Loading required package: RMySQL  
Loading required package: DBI  
Loading required package: date  
Loading required package: ncdf4  
Read Model Variables  
passed 1  
Matching MPAS output file with observations: /share/mmb01/ST/MPAS/2016/limited.area/output.files/history.2016-07-18\_00.00.00.nc  
passed 2  
Creating new database if it does not exist: CREATE DATABASE IF NOT EXISTS amet\_test ;  
Database Action: An AMET \*\* stations \*\* table exists in database amet\_test . Will use this existing table.  
Database Action: An AMET \*\* project\_log \*\* table exists in database amet\_test . Will not re-create this existing table.  
Database Action: mpas\_2016\_test\_surface AMET table exists. Will add new model-obs pairs to this existing table.  
Reading MPAS Model Output File: /share/mmb01/ST/MPAS/2016/limited.area/output.files/history.2016-07-18\_00.00.00.nc  
Read latCell  
Read lonCell  
Read latVertex  
Read lonVertex  
Read time  
Read t2m  
Read q2  
Read u10  
Read v10  
Read swdnb  
Read surface\_pressure  
passed 3  
MPAS time period skipped because initial model time  
passed 4  
Opening MADIS metar for time: 20160718 00:00:00  
/aa/kgurer/AMET-1.4/obs/MET/point/metar/netcdf/20160718\_0000  
passed 5  
Mapping MADIS obs sites to MPAS grid  
Error in cwgt[sitenum, 1] \<- (XP \* (YB - YC) + YP \* (XC - XB) + XB \* YC - :  
replacement has length zero  
Calls: mpas\_site\_map  
Execution halted  
Date/Time END  
Mon Nov 25 11:14:14 PST 2019

--------------- end of output ----------------------

---

<div class="post-metadata">

**Author:** ![cjcoats](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@cjcoats](https://forum.cmascenter.org/u/cjcoats)\
**Post date:** [November 26, 2019, 7:21pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/2 "2019-11-26T19:21:18Z")

</div>

Not what you’re asking, but there is a possible “hack” work-around: use M3Tools program _mpastom3_ ([https://www.cmascenter.org/ioapi/documentation/all\_versions/html/MPASTOM3.html](https://www.cmascenter.org/ioapi/documentation/all_versions/html/MPASTOM3.html) to interpolate the data from the MPAS-grid file to a (preferably high resolution) gridded I/O API file, and then use _AMET_ on that…

---

<div class="post-metadata">

**Author:** ![kgurer](https://avatars.discourse-cdn.com/v4/letter/k/f04885/32.png) [@kgurer](https://forum.cmascenter.org/u/kgurer)\
**Post date:** [November 26, 2019, 9:46pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/3 "2019-11-26T21:46:01Z")

</div>

Hello cjcoats,

Thank you for your kind reply. I appreciate that. It is great to hear that there is a work-around for this problem, which I will certainly try. Having said that, we still need to find out if there is a bug in AMET code. I had not tried with AMET 1.3 version before when I was writing my question, but then I tried yesterday with the previous version and sure enough version 1.3 also gives the same error. Since I don’t have problem with WRF limited area model comparisons with observations and I can plot 3 km resolution MPAS limited area model results without any problem, I am guessing there is a small error in AMET code in finding the location of observation point over the limited area MPAS domain. SInce I cannot find the “mpas\_site\_map” function, I got stuck. Just to clarify, I change “only” the path of model output from global MPAS model outputs to the path for the limited area domain MPAS model output (nothing else changes in AMET script) and then the error comes up.

Again, thank you very much for your kind input.

Kemal.

---

<div class="post-metadata">

**Author:** ![rgilliam](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.cmascenter.org/rgilliam/32/65_2.png) [@rgilliam](https://forum.cmascenter.org/u/rgilliam)\
**Post date:** [November 27, 2019, 11:49am UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/4 "2019-11-27T11:49:07Z")

</div>

Kemal,

That function is here: $AMETBASE/R\_db\_code/MET\_site.mapping.R

With that said, I suspect the error is related to the limited area MPAS. At the time of development there was no such option in MPAS. The function is based on the full global MPAS. We have no limited area domains, so would be greatful for a one day MPAS output for testing. Without even looking at the code, I suspect this is occurring when and observation is outside of the limited area domain and a calculation results in zero or NA. It’s likely a 10 min fix that involves catching the NA’s and skipping to the next side like the WRF side of things when an ob is outside of the domain. As it stands now, the assumptions is that all sides reside in the global domain.

Going to ping you via email for an FTP to get a sample output.

---

<div class="post-metadata">

**Author:** ![Catalyst2682](https://avatars.discourse-cdn.com/v4/letter/c/a6a055/32.png) [@Catalyst2682](https://forum.cmascenter.org/u/Catalyst2682)\
**Post date:** [November 27, 2019, 1:19pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/5 "2019-11-27T13:19:07Z")

</div>

Dear @rgilliam,

I’m trying to install AMET1.4. I’ve installed all other required software. I installed R (3.6.1) but couldn’t find the package **stats** in it. I only found **stats19** , **statsr** , **statsguru** , **statsExpressions** , **STAT** and others. Which one should I install for the AMET to work properly? Also, the **wgrib** software couldn’t be downloaded successfully on the link you provided. Is there an alternative to it?

Thanks and regards,

Catalyst

---

<div class="post-metadata">

**Author:** ![wyat.appel](https://avatars.discourse-cdn.com/v4/letter/w/3d9bf3/32.png) [@wyat.appel](https://forum.cmascenter.org/u/wyat.appel)\
**Post date:** [November 27, 2019, 1:41pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/6 "2019-11-27T13:41:23Z")

</div>

Hi Catalyst,

Are you trying to find the package stat or stats? Unless I’m mistaken, AMET requires the package stats and not stat.

Also, did you attempt to install the stat(s) R library separately from your base R install? Some of the libraries needed by AMET will need to be downloaded separately from the base R install.

[https://www.rdocumentation.org/packages/stats/versions/3.6.1](https://www.rdocumentation.org/packages/stats/versions/3.6.1)

Wyat

---

<div class="post-metadata">

**Author:** ![Catalyst2682](https://avatars.discourse-cdn.com/v4/letter/c/a6a055/32.png) [@Catalyst2682](https://forum.cmascenter.org/u/Catalyst2682)\
**Post date:** [November 27, 2019, 2:46pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/7 "2019-11-27T14:46:45Z")

</div>

Dear @wyat.appel,

Below is the response I got while trying to install **stats** :

Warning messages:  
1: package ‘stats’ is not available (for R version 3.6.1)  
2: package ‘stats’ is a base package, and should not be updated

Other AMET required packages have been installed.

Catalyst

---

<div class="post-metadata">

**Author:** ![wyat.appel](https://avatars.discourse-cdn.com/v4/letter/w/3d9bf3/32.png) [@wyat.appel](https://forum.cmascenter.org/u/wyat.appel)\
**Post date:** [November 27, 2019, 3:48pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/8 "2019-11-27T15:48:32Z")

</div>

Interesting. So, in your R 3.6.1 session, if you type

require(stats)

Is the response that there is no package called ‘stats’?

---

<div class="post-metadata">

**Author:** ![Catalyst2682](https://avatars.discourse-cdn.com/v4/letter/c/a6a055/32.png) [@Catalyst2682](https://forum.cmascenter.org/u/Catalyst2682)\
**Post date:** [November 27, 2019, 4:00pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/9 "2019-11-27T16:00:58Z")

</div>

@wyat.appel,

I typed:  
require(stats)  
and the cursor moved to the next line. I think it’s preinstalled. Am I right, please?

Thanks

Catalyst

---

<div class="post-metadata">

**Author:** ![wyat.appel](https://avatars.discourse-cdn.com/v4/letter/w/3d9bf3/32.png) [@wyat.appel](https://forum.cmascenter.org/u/wyat.appel)\
**Post date:** [November 27, 2019, 4:19pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/10 "2019-11-27T16:19:17Z")

</div>

Yes, that indicates that the stats package is installed and I think was actually already loaded and available in your R session (as R did not respond that it was loading the required package as it would with other packages). Since it’s in the base R installation, R likely pre-loads that package when you start an R session.

Hopefully you won’t run into any further issues with R.

Wyat

---

<div class="post-metadata">

**Author:** ![Catalyst2682](https://avatars.discourse-cdn.com/v4/letter/c/a6a055/32.png) [@Catalyst2682](https://forum.cmascenter.org/u/Catalyst2682)\
**Post date:** [November 27, 2019, 4:42pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/11 "2019-11-27T16:42:22Z")

</div>

Dear @wyat.appel

Thanks for your prompt and useful responses. Please, how do I get **wgrib** downloaded? @kgurer

Best regards,

Catalyst

---

<div class="post-metadata">

**Author:** ![kgurer](https://avatars.discourse-cdn.com/v4/letter/k/f04885/32.png) [@kgurer](https://forum.cmascenter.org/u/kgurer)\
**Post date:** [November 27, 2019, 4:57pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/12 "2019-11-27T16:57:09Z")

</div>

Hello Robert,

I must be blind. We have a label for it: “looker-blind”. One looks at it but cannot see it, like you open the fridge, the food that you are looking for is in front of you but you cannot see it. I searched the function in all R scripts and F files. I either mistyped the search script, so I couldn’t find; or it found it but I didn’t see it. In any case, thank you for pointing to the script where the function is.

I solved the problem. As I suspected, when a station lat/lon is outside of the model domain, closest MPAS vertex to each station becomes null (cind[sitenum,2] and cind[sitenum,3]) and hence XB, XC, YB, YC points become null and the calculation stops with zero length in cwgt. I calculated minlat, maxlat, minlon and maxlon before station do-loop and put a multiple conditional if statement within the station do-loop and allowed the script to continue running only if station lat/lon is within the domain, then it worked. Here are the lines that I added:

Before do-loop:

minlat = min(slat)  
maxlat = max(slat)  
minlon = min(slon)  
maxlon = max(slon)

Within the do-loop, right after site index “inds”:

if(slat[inds]\>=minlat && slat[inds]\<=maxlat && slon[inds]\>=minlon && slon[inds]\<=maxlon){ next }

AMET is working now. However, since the script is determining whether that station is within the domain and number of lat/lon vertices are quite large, script is taking a long time (still short enough) to move forward. If we can create a list of acceptable stations from the stations falling into the model domain before the do-loop, we can totally avoid this determination and script will run faster.

Thank you very much for the solution and pointing me the right script. I still cannot believe that I missed it. I apologize taking your time.

With regards and happy Thanksgiving.

Kemal.

---

<div class="post-metadata">

**Author:** ![rgilliam](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.cmascenter.org/rgilliam/32/65_2.png) [@rgilliam](https://forum.cmascenter.org/u/rgilliam)\
**Post date:** [November 27, 2019, 6:09pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/13 "2019-11-27T18:09:40Z")

</div>

Well done sir. I will get a fix in our official archive asap.

Need to apologize about the latency in my response. Wyat and I just found that the CMAS forum emails are being put in my clutter directory for some strange reason.

And I messed up and did not send you the password to the FTP. If you could still upload a sample output, it would be appreciated. Will send you the password in a private email.

Rob

---

<div class="post-metadata">

**Author:** ![kgurer](https://avatars.discourse-cdn.com/v4/letter/k/f04885/32.png) [@kgurer](https://forum.cmascenter.org/u/kgurer)\
**Post date:** [November 27, 2019, 6:26pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/14 "2019-11-27T18:26:11Z")

</div>

Hi Robert,

No problem. Just send me an email to my work email with the login credentials and I will upload the files. In the meantime, I sent you an email directly with  
the files that I provided using our ftp server. If you cannot download the files from our ftp site, I will upload the files to [scienceftp2.epa.gov](http://scienceftp2.epa.gov). Please let me know.

Kemal.

![image001.jpg](https://canada1.discourse-cdn.com/flex027/uploads/cmas/original/1X/f464dd1c7c382c015b3fc53eebe1cd1aadffee61.jpeg)

---

<div class="post-metadata">

**Author:** ![Catalyst2682](https://avatars.discourse-cdn.com/v4/letter/c/a6a055/32.png) [@Catalyst2682](https://forum.cmascenter.org/u/Catalyst2682)\
**Post date:** [November 29, 2019, 5:07pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/15 "2019-11-29T17:07:23Z")

</div>

@kgurer @wyat.appel @rgilliam

The **wgrib** software couldn’t be downloaded successfully on the link you provided. Is there an alternative to it?

Also, I want your guide on **amet-config.R script** , I don’t know if I am correct like this or how should the directory paths be:

amet\_base \<- Sys.getenv(’/home/catalyst/Desktop/Build\_WRF/LIBRARIES/AMET-master’)  
mysql\_server \<- “localhost” ## Name of MYSQL server  
amet\_login \<- “ametsecure” ## AMET Root login for MYSQL serve  
amet\_pass \<- “1234526” ## AMET Root password for MYSQL server  
maxrec \<- -1 ## Set MySQL maximum records for queries (-1 for no maximum)

Bldoverlay\_exe\_config \<- paste(amet\_base,"/home/catalyst/Desktop/Build\_WRF/LIBRARIES/AMET-master/tools\_src/bldoverlay/src/bldoverlay\_v53.exe",sep="")  
EXEC\_sitex\_daily\_config \<- paste(amet\_base,"/home/catalyst/Desktop/Build\_WRF/LIBRARIES/AMET-master/tools\_src/sitecmp\_dailyo3/sitecmp\_dailyo3\_v53.exe",sep="")  
EXEC\_sitex\_config \<- paste(amet\_base,"/home/catalyst/Desktop/Build\_WRF/LIBRARIES/AMET-master/tools\_src/sitecmp/src/sitecmp\_v53.exe",sep="")

Thanks and regards,

Catalyst

---

<div class="post-metadata">

**Author:** ![cjcoats](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@cjcoats](https://forum.cmascenter.org/u/cjcoats)\
**Post date:** [November 30, 2019, 3:02pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/16 "2019-11-30T15:02:32Z")

</div>

Try the _wgrib_ home page: [https://www.cpc.ncep.noaa.gov/products/wesley/wgrib.html](https://www.cpc.ncep.noaa.gov/products/wesley/wgrib.html)

---

<div class="post-metadata">

**Author:** ![Catalyst2682](https://avatars.discourse-cdn.com/v4/letter/c/a6a055/32.png) [@Catalyst2682](https://forum.cmascenter.org/u/Catalyst2682)\
**Post date:** [November 30, 2019, 3:03pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/17 "2019-11-30T15:03:46Z")

</div>

I have tried this site several times to no avail. @cjcoats

---

<div class="post-metadata">

**Author:** ![cjcoats](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@cjcoats](https://forum.cmascenter.org/u/cjcoats)\
**Post date:** [November 30, 2019, 3:26pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/18 "2019-11-30T15:26:42Z")

</div>

[wgrib.c.txt](https://forum.cmascenter.org/uploads/short-url/bnwuso8l2069xUgeEkrgbd3gy1D.txt) (607.6 KB)

Works for me (and I had tested it before I replied earlier). See attachment for proof.

---

<div class="post-metadata">

**Author:** ![Catalyst2682](https://avatars.discourse-cdn.com/v4/letter/c/a6a055/32.png) [@Catalyst2682](https://forum.cmascenter.org/u/Catalyst2682)\
**Post date:** [November 30, 2019, 3:31pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/19 "2019-11-30T15:31:19Z")

</div>

@cjcoats,

I couldn’t download **wgrib.tar** on the site. It fails on every attempt I make.

---

<div class="post-metadata">

**Author:** ![cjcoats](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@cjcoats](https://forum.cmascenter.org/u/cjcoats)\
**Post date:** [November 30, 2019, 4:34pm UTC](https://forum.cmascenter.org/t/amet-v1-4-error/1144/20 "2019-11-30T16:34:33Z")

</div>

So download and compile the C source code.

[Next page](https://forum.cmascenter.org/t/amet-v1-4-error/1144.md?page=2)
