how to convert gematronik.vol into netcdf???

503 views
Skip to first unread message

anjas man

unread,
Mar 5, 2017, 4:27:25 AM3/5/17
to wradlib-users
Dear Maik, Kai and admins....

After i running and plot vol data using this script below ,  I want to convert vol data from gematronik into netcdf...how to convert it?

Best regard
Anjasman
Indonesia

this script...succes to plot but I want to save it in netcdf format...
import wradlib as wrl
import numpy as np
import xmltodict
import matplotlib.pyplot as pl

from numpy.random import uniform, seed
from matplotlib.mlab import griddata
import matplotlib.pyplot as plt
import numpy as np

def dependencies_for_myprogram(): 
    import xmltodict

def ex_load_rainbow():
    filename = wrl.util.get_wradlib_data_file('rainbow/2013080100020900dBZ.vol')
    # load rainbow file contents to dict
    
    rbdict = wrl.io.read_Rainbow(filename)

    # which slice to select from volume scan
    slice = 0
    data=rbdict['volume']['scan']['slice'][slice]['slicedata']['rawdata']['data']

    # get azimuthal data
    azi = rbdict['volume']['scan']['slice'][slice]['slicedata']['rayinfo']['data']
    azidepth =  float(rbdict['volume']['scan']['slice'][slice]['slicedata']['rayinfo']['@depth'])
    azirange = float(rbdict['volume']['scan']['slice'][slice]['slicedata']['rayinfo']['@rays'])
    anglestep = float(rbdict['volume']['scan']['pargroup']['anglestep'])
    azi =  azi * azirange * anglestep / 2**azidepth

     # create range array
    stoprange = float(rbdict['volume']['scan']['pargroup']['stoprange'])
    rangestep = float(rbdict['volume']['scan']['slice'][slice]['rangestep'])
    r = np.arange(0,stoprange,rangestep)

    unit = rbdict['volume']['scan']['slice'][slice]['slicedata']['rawdata']['@type']
    time = rbdict['volume']['scan']['slice'][slice]['slicedata']['@time']
    date = rbdict['volume']['scan']['slice'][slice]['slicedata']['@date']
    lon = rbdict['volume']['sensorinfo']['lon']
    lat = rbdict['volume']['sensorinfo']['lat']
    sensortype = rbdict['volume']['sensorinfo']['@type']
    sensorname = rbdict['volume']['sensorinfo']['@name']

    cgax, caax, paax, pm = wrl.vis.plot_cg_ppi(data, r=r, az=azi, subplot=111)
    from mpl_toolkits.basemap import Basemap
    #cgax, caax, paax, pm = wrl.vis.plot_cg_ppi(data, r=r, az=azi, subplot=111)
    title = sensortype + ' ' + sensorname + ' ' + date + ' ' + time + '\n' + lon + 'E ' + lat + 'N'
    t = pl.title(title, fontsize=12)
    t.set_y(1.1)
    #cbar = pl.gcf().colorbar(pm, pad=0.075)
    #caax.set_xlabel('x_range [km]')
    #caax.set_ylabel('y_range [km]')
    #pl.text(1.0, 1.05, 'azimuth', transform=caax.transAxes, va='bottom',ha='right')
   # cbar.set_label('reflectivity [' + unit + ']')
    pl.tight_layout()
    pl.show()


if __name__ == '__main__':
    ex_load_rainbow()


    


    

    



Maik Heistermann

unread,
Mar 6, 2017, 3:33:44 AM3/6/17
to wradlib-users
Dear Anjasman,

there is no native wradlib function to export data into a netcdf file or directly convert other radar data file formats to netcdf. The reason is that the target netcdf depends on the data model you want to use, i. e. the way you want you data to be organised in terms of dimensions and metadata. While there are some conventions / data models for weather radar data (e.g. CfRadial), it is basically your decision.

The netCDF4 Python module conventiently supports you in writing netcdf4 files that are custom-tailored to your requirements. Once you have read the data - e.g. from a rainbow file - into numpy arrays or a dictionary that holds both the numpy arrays and the metadata, you can start to write the data / metadata into a netcdf4 file. The basic workflow is (just a suggestion, not tested):

import netCDF4 as nc

# Open a file for writing
foo = nc.Dataset('foo.nc', 'w')

# Create dimenesions
foo.createDimension("elevation", nelevs)
foo.createDimension("beam", nbeams)
foo.createDimension("range", nranges)

# Create variables
elevs = foo.createVariable('elevs', float, ('elevation'), zlib=True) azimuths = foo.createVariable('azimuths', float, ('beam'), zlib=True)
ranges = foo.createVariable('ranges', float, ('range'), zlib=True)
refl = foo.createVariable('reflectivity', float, ('elevation', 'beam', 'range'), zlib=True)

# Assign data
elevs = ... # numpy array with elevation angles
# ...and so on ...

# Write metadata e.g. as global attribute
foo.Conventions = 'my convention'
foo.title = 'my first netcdf from rainbow'
# ...and so on ...

# Close your file
foo.close()
 
See e.g. examples at http://salishsea-meopar-tools.readthedocs.io/en/latest/netcdf4, but there is plenty of other stuff on the web.

Maybe at some point, we'll be able to include a notebook with a minimal example into the wradlib docs. If you wish something like that, you could create an enhancement issue and see that it'll be upvoted.

Best,
Maik

anjas man

unread,
Mar 6, 2017, 6:21:21 AM3/6/17
to wradlib-users
hi Maik thankyou very much for script...i've try it and just get nc data 9 kb...i still confuse in assign data maik....

import netCDF4 as nc
    
    # Open a file for writing
    foo = nc.Dataset('D:/anjas/foo.nc', 'w')

    # Create dimenesions
    foo.createDimension("elevation", 10)
    foo.createDimension("beam", 10)
    foo.createDimension("range", 500)

    # Create variables
    elevs = foo.createVariable('elevs', float, ('elevation'), zlib=True)
    azimuths = foo.createVariable('azimuths', float, ('beam'), zlib=True)
    ranges = foo.createVariable('ranges', float, ('range'), zlib=True)
    refl = foo.createVariable('reflectivity', float, ('elevation', 'beam', 'range'), zlib=True)

    # Assign data
    elevs= data
    azimuth = azi
    ranges = r
    refl = data,azi,r 
Reply all
Reply to author
Forward
0 new messages