Beispiel #1
0
 def test_issequence(self):
     self.assertTrue(util.issequence([0, 1, 2]))
     self.assertFalse(util.issequence(1))
     self.assertFalse(util.issequence('str'))
Beispiel #2
0
 def test_issequence(self):
     assert util.issequence([0, 1, 2])
     assert not util.issequence(1)
     assert not util.issequence("str")
Beispiel #3
0
def volcoords_from_polar_irregular(sitecoords, elevs, azimuths,
                                   ranges, proj=None):
    """Create Cartesian coordinates for polar volumes with irregular \
    sweep specifications

    Parameters
    ----------
    sitecoords : sequence of three floats indicating the radar position
        (longitude in decimal degrees, latitude in decimal degrees,
        height a.s.l. in meters)
    elevs : sequence of elevation angles
    azimuths : sequence of azimuth angles
    ranges : sequence of ranges
    proj : object
        GDAL OSR Spatial Reference Object describing projection

    Returns
    -------
    output : :class:`numpy:numpy.ndarray`
        (num volume bins, 3)

    """
    # check structure: Are azimuth angles and range bins the same for each
    # elevation angle?
    oneaz4all = True
    onerange4all = True
    #   check elevs array, first: must be one-dimensional
    try:
        elevs = np.array(elevs)
    except Exception:
        print("Could not create an array from argument <elevs>.")
        print("The following exception was raised:")
        raise
    assert (elevs.ndim == 1) and (elevs.dtype != np.dtype("object")), \
        "Argument <elevs> in wradlib.volcoords_from_polar must be a 1-D array."
    # now: is there one azimuths array for all elevation angles
    # or one for each?
    try:
        azimuths = np.array(azimuths)
    except Exception:
        print("Could not create an array from argument <azimuths>.")
        print("The following exception was raised:")
        raise
    if len(azimuths) == len(elevs):
        # are the items of <azimuths> arrays themselves?
        isseq = [util.issequence(elem) for elem in azimuths]
        assert not ((False in isseq) and (True in isseq)), \
            "Argument <azimuths> contains both iterable " \
            "and non-iterable items."
        if True in isseq:
            # we expect one azimuth array for each elevation angle
            oneaz4all = False
    # now: is there one ranges array for all elevation angles or one for each?
    try:
        ranges = np.array(ranges)
    except Exception:
        print("Could not create an array from argument <ranges>.")
        print("The following exception was raised:")
        raise
    if len(ranges) == len(elevs):
        # are the items of <azimuths> arrays themselves?
        isseq = [util.issequence(elem) for elem in ranges]
        assert not ((False in isseq) and (True in isseq)), \
            "Argument <azimuths> contains both iterable " \
            "and non-iterable items."
        if True in isseq:
            # we expect one azimuth array for each elevation angle
            onerange4all = False
    if oneaz4all and onerange4all:
        # this is the simple way
        return volcoords_from_polar(sitecoords, elevs, azimuths, ranges, proj)
    # No simply way, so we need to construct the coordinates arrays for
    # each elevation angle
    # but first adapt input arrays to this task
    if onerange4all:
        ranges = np.array([ranges for i in range(len(elevs))])
    if oneaz4all:
        azimuths = np.array([azimuths for i in range(len(elevs))])
    # and second create the corresponding polar volume grid
    el = np.array([])
    az = np.array([])
    r = np.array([])
    for i, elev in enumerate(elevs):
        az_tmp, r_tmp = np.meshgrid(azimuths[i], ranges[i])
        el = np.append(el, np.repeat(elev, len(azimuths[i]) * len(ranges[i])))
        az = np.append(az, az_tmp.ravel())
        r = np.append(r, r_tmp.ravel())
    # get projected coordinates
    coords = georef.spherical_to_proj(r, az, el, sitecoords, proj=proj)
    coords = coords.reshape(-1, 3)

    return coords
Beispiel #4
0
 def test_issequence(self):
     self.assertTrue(util.issequence([0, 1, 2]))
     self.assertFalse(util.issequence(1))
     self.assertFalse(util.issequence('str'))