# Rainfall accumulation

**URL:** <https://openradar.discourse.group/t/rainfall-accumulation/102>\
**Category:** General\
**Created:** [November 21, 2022, 3:03pm UTC](https://openradar.discourse.group/t/rainfall-accumulation/102 "2022-11-21T15:03:28Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidmoranccm](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/davidmoranccm/32/42_2.png) [@davidmoranccm](https://openradar.discourse.group/u/davidmoranccm)\
**Post date:** [November 21, 2022, 3:03pm UTC](https://openradar.discourse.group/t/rainfall-accumulation/102/1 "2022-11-21T15:03:28Z")

</div>

I thought I posted here a few weeks ago, but couldn’t find a post from me when I went to look back for it. Apologies if I’ve missed it.

I have a problem I’m trying to help a colleague with and am comimg up short. He has two weeks’ worth of radar data from a site in Hawaii. From this data, he needs to know the total rainfall at a certain lat/lon within that two week period. I know Xarray is involved, but I’m still stuck on how to approach this.

Thanks,  
David

---

<div class="post-metadata">

**Author:** ![mgrover1](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/mgrover1/32/7_2.png) [@mgrover1](https://openradar.discourse.group/u/mgrover1)\
**Post date:** [November 21, 2022, 6:23pm UTC](https://openradar.discourse.group/t/rainfall-accumulation/102/2 "2022-11-21T18:23:42Z")

</div>

Thanks for asking this question @davidmoranccm - I would start by checking out the Xradar documentation

> **[xradar — xradar 0.0.9.dev7+g188b9c1 documentation](https://docs.openradarscience.org/projects/xradar/en/latest/index.html)**
>
> Top-level documentation for xradar, with links to the rest of the site.

This package will enable you to read in the data (what format is the dataset?)

Once you read in the data, you will either need to use one of the existing rainfall fields, or estimate the rainfall rate from reflectivity using some relationship.

---

<div class="post-metadata">

**Author:** ![mgrover1](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/mgrover1/32/7_2.png) [@mgrover1](https://openradar.discourse.group/u/mgrover1)\
**Post date:** [November 21, 2022, 6:35pm UTC](https://openradar.discourse.group/t/rainfall-accumulation/102/3 "2022-11-21T18:35:11Z")

</div>

If you are interested in using Py-ART for this, an example of calculating Quantitative Precipitation Estimation (QPE) from radar data was covered at the recent ERAD workshop

[https://openradarscience.org/erad2022/notebooks/pyart/exercice1\_swiss\_thunderstorm.html](https://openradarscience.org/erad2022/notebooks/pyart/exercice1_swiss_thunderstorm.html)

---

<div class="post-metadata">

**Author:** ![davidmoranccm](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/davidmoranccm/32/42_2.png) [@davidmoranccm](https://openradar.discourse.group/u/davidmoranccm)\
**Post date:** [November 21, 2022, 7:42pm UTC](https://openradar.discourse.group/t/rainfall-accumulation/102/4 "2022-11-21T19:42:34Z")

</div>

Thanks! I will check these out!

---

<div class="post-metadata">

**Author:** ![davidmoranccm](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/davidmoranccm/32/42_2.png) [@davidmoranccm](https://openradar.discourse.group/u/davidmoranccm)\
**Post date:** [November 23, 2022, 11:54am UTC](https://openradar.discourse.group/t/rainfall-accumulation/102/5 "2022-11-23T11:54:18Z")

</div>

OK, I feel stupid for asking, but I started installing Pyart and followed the instructions here: [The Python ARM Radar Toolkit - Py-ART — Py-ART 1.14.1.post1 documentation](https://arm-doe.github.io/pyart/#install). I grabbed a script off the Pyart website and when I ran it, I get:

Traceback (most recent call last):  
File “C:\Users\David\Desktop\plot\_nexrad\_data\_aws.py”, line 18, in   
import pyart  
ModuleNotFoundError: No module named ‘pyart’

Where could I have gone wrong?

Thanks!

---

<div class="post-metadata">

**Author:** ![mgrover1](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/mgrover1/32/7_2.png) [@mgrover1](https://openradar.discourse.group/u/mgrover1)\
**Post date:** [November 23, 2022, 2:00pm UTC](https://openradar.discourse.group/t/rainfall-accumulation/102/6 "2022-11-23T14:00:12Z")

</div>

There are no stupid questions! Did you activate your conda environment? What are you using to manage your environments?

---

<div class="post-metadata">

**Author:** ![davidmoranccm](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/davidmoranccm/32/42_2.png) [@davidmoranccm](https://openradar.discourse.group/u/davidmoranccm)\
**Post date:** [November 23, 2022, 2:31pm UTC](https://openradar.discourse.group/t/rainfall-accumulation/102/7 "2022-11-23T14:31:43Z")

</div>

I don’t think so; how do I do that? I’m using Anaconda.

---

<div class="post-metadata">

**Author:** ![mgrover1](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/mgrover1/32/7_2.png) [@mgrover1](https://openradar.discourse.group/u/mgrover1)\
**Post date:** [November 23, 2022, 2:37pm UTC](https://openradar.discourse.group/t/rainfall-accumulation/102/8 "2022-11-23T14:37:43Z")

</div>

I really like the description/videos from the NCAR Earth System Data Science site.

[https://ncar.github.io/esds/faq/#conda-environments](https://ncar.github.io/esds/faq/#conda-environments)

I would follow those videos/commands. Once you activate your environment

```bash
conda activate my-environment

```

You will need to install Py-ART

```auto
conda install -c conda-forge arm_pyart

```

Then, you can run

```auto
python -m my_script.py

```

The conda cheatsheet might help here too.

> **[conda-cheatsheet.pdf](https://docs.conda.io/projects/conda/en/stable/_downloads/843d9e0198f2a193a3484886fa28163c/conda-cheatsheet.pdf)**
>
> 337.46 KB

---

<div class="post-metadata">

**Author:** ![davidmoranccm](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/davidmoranccm/32/42_2.png) [@davidmoranccm](https://openradar.discourse.group/u/davidmoranccm)\
**Post date:** [December 9, 2022, 7:54pm UTC](https://openradar.discourse.group/t/rainfall-accumulation/102/9 "2022-12-09T19:54:49Z")

</div>

I finally had some time to work on my problem. Here’s a script I modified and the error I got. I’m not sure how to proceed. Thanks for all of the help; I really want to figure this out.

from **future** import print\_function  
import numpy as np  
import pyart  
import pyproj

def find\_x\_y\_displacement(radar, longitude, latitude):  
“”" Return the x and y displacement (in meters) from a radar location. “”"  
# longitude and latitude in degrees  
lat\_0 = radar.latitude[‘data’][0]  
lon\_0 = radar.longitude[‘data’][0]  
proj = pyproj.Proj(proj=‘aeqd’, lon\_0=lon\_0, lat\_0=lat\_0)  
return proj(longitude, latitude)

def find\_nearest\_gate(radar, longitude, latitude, altitude):  
“”" Return the indices of the nearest gate to a given point. “”"  
# longitude and latitude in degrees, altitude in meters  
gate\_x = radar.gate\_x[‘data’]  
gate\_y = radar.gate\_y[‘data’]  
gate\_z = radar.gate\_z[‘data’]

```
x_disp, y_disp = find_x_y_displacement(radar, longitude, latitude)
distances = np.sqrt(
    (gate_x-x_disp)**2. + (gate_y-y_disp)**2. + (gate_z-altitude)**2.)
return np.unravel_index(distances.argmin(), distances.shape)

```

def interpolate\_single\_point(radar, longitude, latitude, altitude):  
“”" Interpolate a single grid point at a given location. “”"  
x\_disp, y\_disp = find\_x\_y\_displacement(radar, longitude, latitude)  
grid = pyart.map.grid\_from\_radars(  
(radar,),  
gridding\_algo=‘map\_gates\_to\_grid’,  
grid\_shape=(1, 1, 1),  
grid\_limits=((altitude, 0), (y\_disp, 25000.0), (x\_disp, 25000.0)),  
fields=[‘reflectivity’])  
return grid

# read in the file

filename = ‘NWS\_NEXRAD\_NXL2DPBL\_PHMO\_20220626010000\_20220626015959\PHMO20220626\_010223\_V06.ar2v’  
radar = pyart.io.read\_nexrad\_archive(filename)

latitude = 21.3 # latitude (in degrees) to find reflectivity at or near  
longitude = 157.8 # longitude (in degrees) to find reflectivity at or near  
altitude = 1000 # altitude (in meters) to find reflectivity at or near

# find nearest gate

ray, gate = find\_nearest\_gate(radar, longitude, latitude, altitude)  
gate\_latitude = radar.gate\_latitude[‘data’][ray, gate]  
gate\_longitude = radar.gate\_longitude[‘data’][ray, gate]  
gate\_altitude = radar.gate\_altitude[‘data’][ray, gate]  
gate\_reflectivity = radar.fields[‘reflectivity’][‘data’][ray, gate]  
print(“-----------------------”)  
print(“Nearest gate:”)  
print(“Latitude:”, gate\_latitude)  
print(“Longitude:”, gate\_longitude)  
print(“Altitude:”, gate\_altitude)  
print(“Reflectivity:”, gate\_reflectivity)

# interpolate around gate

grid = interpolate\_single\_point(radar, longitude, latitude, altitude)  
pyart.core.get\_point\_longitude\_latitude(grid)  
pixel\_latitude = grid.axes[‘latitude’][‘data’][0, 0]  
pixel\_longitude = grid.axes[‘longitude’][‘data’][0, 0]  
pixel\_altitude = grid.axes[‘z\_disp’][‘data’][0]  
pixel\_reflectivity = grid.fields[‘reflectivity’][‘data’][0, 0]

print(“-----------------------”)  
print(“Interpolated pixel:”)  
print(“Latitude:”, pixel\_latitude)  
print(“Longitude:”, pixel\_longitude)  
print(“Altitude:”, pixel\_altitude)  
print(“Reflectivity:”, pixel\_reflectivity)

Traceback (most recent call last):  
File “…\test.py”, line 64, in   
pyart.core.get\_point\_longitude\_latitude(grid)  
AttributeError: module ‘pyart.core’ has no attribute ‘get\_point\_longitude\_latitude’

---

<div class="post-metadata">

**Author:** ![mgrover1](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/mgrover1/32/7_2.png) [@mgrover1](https://openradar.discourse.group/u/mgrover1)\
**Post date:** [December 9, 2022, 11:03pm UTC](https://openradar.discourse.group/t/rainfall-accumulation/102/10 "2022-12-09T23:03:07Z")

</div>

Which version of Py-ART are you running?

---

<div class="post-metadata">

**Author:** ![davidmoranccm](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/davidmoranccm/32/42_2.png) [@davidmoranccm](https://openradar.discourse.group/u/davidmoranccm)\
**Post date:** [December 10, 2022, 4:43am UTC](https://openradar.discourse.group/t/rainfall-accumulation/102/11 "2022-12-10T04:43:52Z")

</div>

If I’m looking at it right, 1.14.1.

![image001.png](https://global.discourse-cdn.com/free1/uploads/openradar/original/1X/42d8302ed33c0ff3fc527e5ac0c0b8c22cd061c9.png)
