Exemple #1
0
def quick_et(r_list: Volume_T) -> Radial:
    r"""
    Calculate echo tops

    Paramters
    ---------
    r_list: list of cinrad.datastruct.Radial

    Returns
    -------
    l2_obj: cinrad.datastruct.Grid
        echo tops
    """
    r_data, d, a, elev = _extract(r_list)
    i = r_list[0]
    et = echo_top(
        r_data.astype(np.double), d.astype(np.double), elev.astype(np.double), 0.0
    )
    l2_obj = Radial(
        np.ma.array(et, mask=(et < 2)),
        i.drange,
        0,
        i.reso,
        i.code,
        i.name,
        i.scantime,
        "ET",
        i.stp["lon"],
        i.stp["lat"],
        **i.scan_info
    )
    lon, lat = get_coordinate(d[0], a[:, 0], 0, i.stp["lon"], i.stp["lat"])
    l2_obj.add_geoc(lon, lat, np.zeros(lon.shape))
    return l2_obj
Exemple #2
0
def quick_vild(r_list: RList) -> Radial:
    r'''
    Calculate vertically integrated liquid density

    Paramters
    ---------
    r_list: list of cinrad.datastruct.Radial

    Returns
    -------
    l2_obj: cinrad.datastruct.Grid
        vertically integrated liquid density
    '''
    r_data, d, a, elev = _extract(r_list)
    i = r_list[0]
    vil = vert_integrated_liquid(r_data.astype(np.double),
                                 d.astype(np.double),
                                 elev.astype(np.double),
                                 density=True)
    vild = np.ma.masked_invalid(vil)
    l2_obj = Radial(np.ma.array(vild, mask=(vild <= 0.1)), i.drange, 0, i.reso,
                    i.code, i.name, i.scantime, 'VILD', i.stp['lon'],
                    i.stp['lat'], **i.scan_info)
    lon, lat = get_coordinate(d[0], a[:, 0], 0, i.stp['lon'], i.stp['lat'])
    l2_obj.add_geoc(lon, lat, np.zeros(lon.shape))
    return l2_obj
Exemple #3
0
def quick_vil(r_list: Volume_T) -> Radial:
    r"""
    Calculate vertically integrated liquid

    Paramters
    ---------
    r_list: list of cinrad.datastruct.Radial

    Returns
    -------
    l2_obj: cinrad.datastruct.Grid
        vertically integrated liquid
    """
    r_data, d, a, elev = _extract(r_list)
    i = r_list[0]
    vil = vert_integrated_liquid(
        r_data.astype(np.double), d.astype(np.double), elev.astype(np.double)
    )
    l2_obj = Radial(
        np.ma.array(vil, mask=(vil <= 0)),
        i.drange,
        0,
        i.reso,
        i.code,
        i.name,
        i.scantime,
        "VIL",
        i.stp["lon"],
        i.stp["lat"],
        **i.scan_info
    )
    lon, lat = get_coordinate(d[0], a[:, 0], 0, i.stp["lon"], i.stp["lat"])
    l2_obj.add_geoc(lon, lat, np.zeros(lon.shape))
    return l2_obj
Exemple #4
0
def max_potential_gust(r_list: Volume_T) -> Radial:
    r"""
    Estimate maximum potential descending gust by Stewart's formula

    Paramters
    ---------
    r_list: list of cinrad.datastruct.Radial

    Returns
    -------
    l2_obj: cinrad.datastruct.Grid
        Wind gust
    """
    r_data, d, a, elev = _extract(r_list)
    i = r_list[0]
    g = potential_maximum_gust_from_reflectivity(r_data, d, elev)
    l2_obj = Radial(
        np.ma.array(g, mask=(g <= 0)),
        i.drange,
        0,
        i.reso,
        i.code,
        i.name,
        i.scantime,
        "GUST",
        i.stp["lon"],
        i.stp["lat"],
        **i.scan_info
    )
    lon, lat = get_coordinate(d[0], a.T[0], 0, i.stp["lon"], i.stp["lat"])
    l2_obj.add_geoc(lon, lat, np.zeros(lon.shape))
    return l2_obj
Exemple #5
0
    def get_data(self, tilt:int, drange:Number_T, dtype:str) -> Radial:
        r'''
        Get radar data

        Parameters
        ----------
        tilt: int
            index of elevation angle
        drange: float
            radius of data
        dtype: str
            type of product (REF, VEL, etc.)

        Returns
        -------
        r_obj: cinrad.datastruct.Radial
        '''
        task = getattr(self, 'task_name', None)
        reso = self.Rreso if dtype == 'REF' else self.Vreso
        ret = self.get_raw(tilt, drange, dtype)
        shape = ret[0].shape[1] if isinstance(ret, tuple) else ret.shape[1]
        r_obj = Radial(ret, int(np.round(shape * reso)), self.elev, reso, self.code, self.name, self.scantime, dtype,
                       self.stationlon, self.stationlat, nyquist_velocity=self.nyquist_v[tilt], task=task)
        x, y, z, d, a = self.projection(reso)
        r_obj.add_geoc(x, y, z)
        r_obj.add_polarc(d, a)
        if self.radartype == 'CC':
            r_obj.a_reso = 512
        return r_obj
Exemple #6
0
    def get_data(self, tilt, drange, dtype):
        r'''
        Get radar raw data

        Parameters
        ----------
        tilt: int
            index of elevation angle
        drange: float
            radius of data
        dtype: str
            type of product (REF, VEL, etc.)

        Returns
        -------
        r_obj: cinrad.datastruct.Radial
        '''
        rf_flag = False
        self.tilt = tilt
        reso = self.Rreso if dtype == 'REF' else self.Vreso
        dmax = np.round(self.data[tilt][dtype][0].shape[0] * reso)
        if dmax < drange:
            warnings.warn('Requested data range exceed max range in this tilt')
        self.drange = drange
        self.elev = self.el[tilt]
        try:
            data = np.ma.array(self.data[tilt][dtype])
        except KeyError:
            raise RadarDecodeError('Invalid product name')
        length = data.shape[1] * reso
        cut = data.T[:int(np.round(drange / reso))]
        shape_diff = np.round(drange / reso) - cut.shape[0]
        append = np.zeros(
            (int(np.round(shape_diff)), cut.shape[1])) * np.ma.masked
        if dtype == 'VEL':
            try:
                rf = self.data[tilt]['RF']
            except KeyError:
                pass
            else:
                rf_flag = True
                rf = rf.T[:int(np.round(drange / reso))]
                rf = np.ma.vstack([rf, append])
        #r = np.ma.array(cut, mask=np.isnan(cut))
        r = np.ma.vstack([cut, append])
        if rf_flag:
            r.mask = np.logical_or(r.mask, ~rf.mask)
            ret = (r.T, rf.T)
        else:
            ret = r.T
        r_obj = Radial(ret, int(np.round(r.shape[0] * reso)), self.elev, reso,
                       self.code, self.name, self.scantime, dtype,
                       self.stationlon, self.stationlat)
        x, y, z, d, a = self.projection(reso)
        r_obj.add_geoc(x, y, z)
        r_obj.add_polarc(d, a)
        if self.radartype == 'CC':
            r_obj.a_reso = 512
        return r_obj
Exemple #7
0
    def get_data(
        self, tilt: int, drange: Number_T, dtype: str
    ) -> Union[Radial, Slice_]:
        r"""
        Get radar data

        Parameters
        ----------
        tilt: int
            index of elevation angle
        drange: float
            radius of data
        dtype: str
            type of product (REF, VEL, etc.)

        Returns
        -------
        r_obj: cinrad.datastruct.Radial
        """
        reso = self.scan_config[tilt].dop_reso / 1000
        ret = self.get_raw(tilt, drange, dtype)
        if self.scan_type == "PPI":
            shape = ret[0].shape[1] if isinstance(ret, tuple) else ret.shape[1]
            r_obj = Radial(
                ret,
                int(shape * reso),
                self.elev,
                reso,
                self.code,
                self.name,
                self.scantime,
                dtype,
                self.stationlon,
                self.stationlat,
                nyquist_velocity=self.scan_config[tilt].nyquist_spd,
                task=self.task_name,
            )
            x, y, z, d, a = self.projection(reso)
            r_obj.add_geoc(x, y, z)
            r_obj.add_polarc(d, a)
            return r_obj
        else:
            # Manual projection
            shape = ret[0].shape[1] if isinstance(ret, tuple) else ret.shape[1]
            dist = np.linspace(reso, self.drange, ret.shape[1])
            d, e = np.meshgrid(dist, self.aux[tilt]["elevation"])
            h = height(d, e, 0)
            rhi = Slice_(
                ret,
                d,
                h,
                self.scantime,
                self.code,
                self.name,
                dtype,
                azimuth=self.aux[tilt]["azimuth"][0],
            )
            return rhi
Exemple #8
0
    def get_data(self, tilt, drange, dtype):
        r'''
        Get radar raw data

        Parameters
        ----------
        tilt: int
            index of elevation angle
        drange: float
            radius of data
        dtype: str
            type of product (REF, VEL, etc.)

        Returns
        -------
        r_obj: cinrad.datastruct.Radial
        '''
        self.tilt = tilt
        self.drange = drange
        self.elev = self.el[tilt]
        try:
            raw = np.array(self.data[tilt][dtype])
        except KeyError:
            raise RadarDecodeError('Invalid product name')
        if raw.size == 0:
            warnings.warn('Empty data', RuntimeWarning)
        data = np.ma.array(raw, mask=(raw <= 5))
        reso = self.scan_config[tilt].dop_reso / 1000
        cut = data[:, :int(drange / reso)]
        shape_diff = np.round(drange / reso) - cut.shape[1]
        append = np.zeros((cut.shape[0], int(shape_diff))) * np.ma.masked
        if dtype == 'VEL':
            rf = np.ma.array(cut.data, mask=(cut.data != 1))
            rf = np.ma.hstack([rf, append])
        cut = np.ma.hstack([cut, append])
        scale, offset = self.aux[tilt][dtype]
        r = (cut - offset) / scale
        if dtype == 'VEL':
            ret = (r, rf)
        else:
            ret = r
        r_obj = Radial(ret, int(r.shape[1] * reso), self.elev, reso, self.code,
                       self.name, self.scantime, dtype, self.stationlon,
                       self.stationlat)
        x, y, z, d, a = self.projection(reso)
        r_obj.add_geoc(x, y, z)
        r_obj.add_polarc(d, a)
        return r_obj
Exemple #9
0
def max_potential_gust(r_list: RList) -> Radial:
    r'''
    Estimate maximum potential descending gust by Stewart's formula

    Paramters
    ---------
    r_list: list of cinrad.datastruct.Radial

    Returns
    -------
    l2_obj: cinrad.datastruct.Grid
        Wind gust
    '''
    r_data, d, a, elev = _extract(r_list)
    i = r_list[0]
    g = potential_maximum_gust_from_reflectivity(r_data, d, elev)
    l2_obj = Radial(np.ma.array(g, mask=(g <= 0)), i.drange, 0, 1, i.code,
                    i.name, i.scantime, 'GUST', i.stp['lon'], i.stp['lat'])
    lon, lat = get_coordinate(d[0], a.T[0], 0, i.stp['lon'], i.stp['lat'])
    l2_obj.add_geoc(lon, lat, np.zeros(lon.shape))
    return l2_obj
Exemple #10
0
def quick_vil(Rlist):
    r'''
    Calculate vertically integrated liquid

    Paramters
    ---------
    Rlist: list of cinrad.datastruct.Radial

    Returns
    -------
    l2_obj: cinrad.datastruct.Grid
        vertically integrated liquid
    '''
    r_data, d, a, elev = _extract(Rlist)
    i = Rlist[0]
    vil = vert_integrated_liquid(r_data, d, elev)
    l2_obj = Radial(np.ma.array(vil, mask=(vil <= 0)), i.drange, 0, 1, i.code,
                    i.name, i.scantime, 'VIL', i.stp['lon'], i.stp['lat'])
    lon, lat = get_coordinate(d[0], a.T[0], 0, i.stp['lon'], i.stp['lat'])
    l2_obj.add_geoc(lon, lat, np.zeros(lon.shape))
    return l2_obj
Exemple #11
0
def quick_et(Rlist):
    r'''
    Calculate echo tops

    Paramters
    ---------
    Rlist: list of cinrad.datastruct.Radial

    Returns
    -------
    l2_obj: cinrad.datastruct.Grid
        echo tops
    '''
    r_data, d, a, elev = _extract(Rlist)
    i = Rlist[0]
    et = echo_top(r_data, d, elev, 0)
    l2_obj = Radial(et, i.drange, 0, 1, i.code, i.name, i.scantime, 'ET',
                    i.stp['lon'], i.stp['lat'])
    lon, lat = get_coordinate(d[0], a.T[0], 0, i.stp['lon'], i.stp['lat'])
    l2_obj.add_geoc(lon, lat, np.zeros(lon.shape))
    return l2_obj
Exemple #12
0
def quick_et(r_list:RList) -> Radial:
    r'''
    Calculate echo tops

    Paramters
    ---------
    r_list: list of cinrad.datastruct.Radial

    Returns
    -------
    l2_obj: cinrad.datastruct.Grid
        echo tops
    '''
    r_data, d, a, elev = _extract(r_list)
    i = r_list[0]
    et = echo_top(r_data.astype(np.double), d.astype(np.double), elev.astype(np.double), 0.)
    l2_obj = Radial(np.ma.array(et, mask=(et < 2)), i.drange, 0, 1, i.code, i.name, i.scantime, 'ET',
                    i.stp['lon'], i.stp['lat'])
    lon, lat = get_coordinate(d[0], a[:, 0], 0, i.stp['lon'], i.stp['lat'])
    l2_obj.add_geoc(lon, lat, np.zeros(lon.shape))
    return l2_obj
Exemple #13
0
    def get_data(self, tilt, drange, dtype):
        r'''
        Get radar raw data

        Parameters
        ----------
        tilt: int
            index of elevation angle
        drange: float
            radius of data
        dtype: str
            type of product (REF, VEL, etc.)

        Returns
        -------
        r_obj: cinrad.datastruct.Radial
        '''
        self.tilt = tilt
        self.drange = drange
        self.elev = self.el[tilt]
        try:
            data = np.array(self.data[tilt][dtype])
        except KeyError:
            raise RadarDecodeError('Invalid product name')
        if data.size == 0:
            raise RadarDecodeError(
                'Current elevation does not contain this data.')
        reso = self.scanconfig[tilt]['radial_reso']
        length = data.shape[1] * reso
        cut = data[:, :int(drange / reso)]
        r = np.ma.array(cut, mask=np.isnan(cut))
        r_obj = Radial(r, int(r.shape[0] * reso), self.elev, reso, self.code,
                       self.name, self.scantime, dtype, self.stationlon,
                       self.stationlat)
        x, y, z, d, a = self.projection(reso)
        r_obj.add_geoc(x, y, z)
        r_obj.add_polarc(d, a)
        return r_obj
from metpy.io.nexrad import Level3File
from tkinter import filedialog
from metpy.plots import colortables

from cinrad.datastruct import Radial
from cinrad.projection import get_coordinate
from cinrad.visualize import ppi

name = filedialog.askopenfilename()
f = Level3File(name)
# Pull the data out of the file object
datadict = f.sym_block[0][0]
# Turn into an array, then mask
data = np.array(datadict['data']).astype(float)
data[data == 0] = np.nan
rf = np.ma.array(data, mask=(data != 1))
# Grab azimuths and calculate a range based on number of gates
az = np.deg2rad(datadict['start_az'] + [datadict['end_az'][-1]])
rng = np.linspace(0, f.max_range, data.shape[-1] + 1)
elev = f.metadata['el_angle']
slon, slat = f.lon, f.lat
scantime = f.metadata['msg_time']
lon, lat = get_coordinate(rng, az, elev, slon, slat)
threshold = f.thresholds
data = data * threshold[1] / 10 + threshold[0] / 10
v_obj = Radial([data, rf], int(f.max_range), elev, f.ij_to_km, f.siteID,
               f.siteID, scantime.strftime('%Y%m%d%H%M%S'), 'VEL', slon, slat)
v_obj.add_geoc(lon, lat, np.zeros(lon.shape))
norm2, v_cmap = colortables.get_with_range('NWS8bitVel', -64, 64)
fig = ppi.PPI(v_obj, coastline=True, norm=norm2, cmap=v_cmap, nlabel=17)
fig()
Exemple #15
0
    def get_data(self, tilt: int, drange: number_type, dtype: str) -> Radial:
        r'''
        Get radar raw data

        Parameters
        ----------
        tilt: int
            index of elevation angle
        drange: float
            radius of data
        dtype: str
            type of product (REF, VEL, etc.)

        Returns
        -------
        r_obj: cinrad.datastruct.Radial
        '''
        self.tilt = tilt if self.scan_type == 'PPI' else 0
        self.drange = drange
        if self.scan_type == 'RHI':
            max_range = self.scan_config[0].max_range1 / 1000
            if drange > max_range:
                drange = max_range
        self.elev = self.el[tilt]
        try:
            raw = np.array(self.data[tilt][dtype])
        except KeyError:
            raise RadarDecodeError('Invalid product name')
        if raw.size == 0:
            warnings.warn('Empty data', RuntimeWarning)
        data = np.ma.array(raw, mask=(raw <= 5))
        reso = self.scan_config[tilt].dop_reso / 1000
        cut = data[:, :int(drange / reso)]
        shape_diff = np.round(drange / reso) - cut.shape[1]
        append = np.zeros((cut.shape[0], int(shape_diff))) * np.ma.masked
        if dtype == 'VEL':
            rf = np.ma.array(cut.data, mask=(cut.data != 1))
            rf = np.ma.hstack([rf, append])
        cut = np.ma.hstack([cut, append])
        scale, offset = self.aux[tilt][dtype]
        r = (cut - offset) / scale
        if dtype in ['VEL', 'SW']:
            ret = (r, rf)
        else:
            ret = r
        if self.scan_type == 'PPI':
            r_obj = Radial(ret,
                           int(r.shape[1] * reso),
                           self.elev,
                           reso,
                           self.code,
                           self.name,
                           self.scantime,
                           dtype,
                           self.stationlon,
                           self.stationlat,
                           nyquist_velocity=self.scan_config[tilt].nyquist_spd)
            x, y, z, d, a = self.projection(reso)
            r_obj.add_geoc(x, y, z)
            r_obj.add_polarc(d, a)
            return r_obj
        else:
            # Manual projection
            dist = np.linspace(reso, self.drange, cut.shape[1])
            d, e = np.meshgrid(dist, self.aux[tilt]['elevation'])
            h = height(d, e, 0)
            rhi = Slice_(ret,
                         d,
                         h,
                         self.scantime,
                         self.code,
                         self.name,
                         dtype,
                         azimuth=self.aux[tilt]['azimuth'][0])
            return rhi