# Data quality and storing file

**URL:** <https://openradar.discourse.group/t/data-quality-and-storing-file/436>\
**Category:** General\
**Tags:** wradlib\
**Created:** [March 22, 2024, 11:28am UTC](https://openradar.discourse.group/t/data-quality-and-storing-file/436 "2024-03-22T11:28:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shridharIITM](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/shridhariitm/32/196_2.png) [@shridharIITM](https://openradar.discourse.group/u/shridharIITM)\
**Post date:** [March 22, 2024, 11:28am UTC](https://openradar.discourse.group/t/data-quality-and-storing-file/436/1 "2024-03-22T11:28:20Z")

</div>

Hi  
Wradlib version 2.0.3  
Python version 3.12.2  
I am using gabella filter on radar data using wradlib. I want to store the filtered data to store the output as cfradial so that it can be used in part easily but during writing file is showing error as below

Cell In[8], line 39  
xradar.io.export.to\_cfradial2(vol,fid\_write)

File ~\anaconda3\envs\wradlib\Lib\site-packages\xradar\io\export\cfradial2.py:85 in to\_cfradial2  
root.attrs[“history”] += f": xradar v{xradar\_version} CfRadial2 export"

KeyError: ‘history’

the code is as follows:  
import xarray as xr  
import wradlib as wrl  
import xradar  
import glob  
import matplotlib.pyplot as plt

def extract\_clutter(da, refl, cmap, wsize=3, thrsnorain=0, tr1=6.0, n\_p=6, tr2=1.3, rm\_nans=False):  
if refl in da.variables:  
da = da.assign({cmap: xr.apply\_ufunc(  
wrl.classify.filter\_gabella,  
da[refl],  
input\_core\_dims=[[“azimuth”, “range”]],  
output\_core\_dims=[[“azimuth”, “range”]],  
dask=“parallelized”,  
kwargs=dict(  
wsize=wsize,  
thrsnorain=thrsnorain,  
tr1=tr1,  
n\_p=n\_p,  
tr2=tr2,  
rm\_nans=rm\_nans,  
),  
)})  
return da

files = glob.glob(‘BHP\*.nc\*’)  
for ff in range(0,1):  
fname= files[ff]  
fid\_write = “test.nc”  
vol = xradar.io.open\_cfradial1\_datatree(fname)  
vol = vol.map\_over\_subtree(extract\_clutter, “reflectivity”, “CMAP”, wsize=3, thrsnorain=0.0, tr1=14, n\_p=2, tr2=1.5, rm\_nans=False)  
xradar.io.export.to\_cfradial2(vol,fid\_write)

I need help in storing volume data in cfradial format in such a way that it would be easier to handle using part.  
kindly have some suggestions.

---

<div class="post-metadata">

**Author:** ![jorahu](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/jorahu/32/19_2.png) [@jorahu](https://openradar.discourse.group/u/jorahu)\
**Post date:** [March 22, 2024, 1:12pm UTC](https://openradar.discourse.group/t/data-quality-and-storing-file/436/2 "2024-03-22T13:12:43Z")

</div>

Hey

If you read your file with:  
`vol = xradar.io.open_cfradial1_datatree(fname)`  
Check if your vol has “history” attribute, for example:  
`print(vol.history)`  
or  
`vol.root.attrs['history']` (As the Error message suggests)

If such attribute does not exist, you can manually define one with:  
`vol.root.attrs['history'] = 'None'`  
My file had ‘None’ there… I guess you can write here what you wish. But the export wants to add the xradar info there with `root.attrs[“history”] += f": xradar v{xradar_version} CfRadial2 export"`

---

<div class="post-metadata">

**Author:** ![shridharIITM](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/shridhariitm/32/196_2.png) [@shridharIITM](https://openradar.discourse.group/u/shridharIITM)\
**Post date:** [March 26, 2024, 6:46am UTC](https://openradar.discourse.group/t/data-quality-and-storing-file/436/3 "2024-03-26T06:46:14Z")

</div>

Thank you very much for your reply. your suggestion is working and the output is stored in cfradial but I am trying to read the stored cfradial radial file using pyart , the error is displaying as

File ~\anaconda3\envs\wradlib\Lib\site-packages\pyart\io\cfradial.py:150 in read\_cfradial  
time = \_ncvar\_to\_dict(ncvars[“time”])

I am using  
xradar.io.export.to\_cfradial2(vol,fid\_write, engine = “netcdf4” )  
to write cfradial file using Wradlib…

---

<div class="post-metadata">

**Author:** ![jorahu](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/jorahu/32/19_2.png) [@jorahu](https://openradar.discourse.group/u/jorahu)\
**Post date:** [March 26, 2024, 8:14am UTC](https://openradar.discourse.group/t/data-quality-and-storing-file/436/4 "2024-03-26T08:14:30Z")

</div>

I don’t use PyART myself, therefore I am not familiar with the import structure there. Maybe someone from PyART side can help here.

Just guessing here (never worked with cfradial format myself). You first import cfradial1 files and then export to cfradial2. Could there be any conflict there? Have you checked [this tutorial](https://docs.openradarscience.org/projects/xradar/en/stable/notebooks/CfRadial1_Model_Transformation.html)?

---

<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:** [March 26, 2024, 5:29pm UTC](https://openradar.discourse.group/t/data-quality-and-storing-file/436/5 "2024-03-26T17:29:58Z")

</div>

Py-ART only supports the reading of **cfradial1** , not **cfradial2** , my recommendation would be to read it back in with xradar, then use the Py-ART to xradar bridge, which is described in this example

[https://arm-doe.github.io/pyart/examples/xradar/plot\_xradar.html](https://arm-doe.github.io/pyart/examples/xradar/plot_xradar.html)

Thanks,

Max

---

<div class="post-metadata">

**Author:** ![shridharIITM](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/shridhariitm/32/196_2.png) [@shridharIITM](https://openradar.discourse.group/u/shridharIITM)\
**Post date:** [March 27, 2024, 7:43am UTC](https://openradar.discourse.group/t/data-quality-and-storing-file/436/6 "2024-03-27T07:43:59Z")

</div>

Thank you very much for your suggestion./. Now it is working…
