Пример #1
0
 def _get_section(self, stp: Tuple[float, float], enp: Tuple[float, float],
                  spacing: int) -> Slice_:
     r_sec = list()
     h_sec = list()
     for x, y, h, r in zip(self.x, self.y, self.h, self.r):
         d_x = DataArray(r, [('lat', y), ('lon', x)])
         d_h = DataArray(h, [('lat', y), ('lon', x)])
         x_new = DataArray(np.linspace(stp[0], enp[0], spacing), dims='z')
         y_new = DataArray(np.linspace(stp[1], enp[1], spacing), dims='z')
         r_section = d_x.interp(lon=x_new, lat=y_new)
         h_section = d_h.interp(lon=x_new, lat=y_new)
         r_sec.append(r_section)
         h_sec.append(h_section)
     r = np.asarray(r_sec)
     h = np.asarray(h_sec)
     r[np.isnan(r)] = 0
     x = np.linspace(0, 1, spacing) * np.ones(r.shape[0])[:, np.newaxis]
     stp_s = '{}N, {}E'.format(stp[1], stp[0])
     enp_s = '{}N, {}E'.format(enp[1], enp[0])
     sl = Slice_(r,
                 x,
                 h,
                 self.rl[0].scantime,
                 self.rl[0].code,
                 self.rl[0].name,
                 self.rl[0].dtype,
                 stp_s=stp_s,
                 enp_s=enp_s,
                 stp=stp,
                 enp=enp)
     return sl
Пример #2
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
Пример #3
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