Beispiel #1
0
    def test_discrepancy_with_arange_catch_failure(self):

        ar = numpy.arange(self.start, self.end + self.dh / 2, self.dh)
        cr = cleaner_range(self.start, self.end, self.dh)

        self.assertRaises(AssertionError, numpy.testing.assert_array_equal, ar, cr)
        self.assertRaises(AssertionError, numpy.testing.assert_array_equal, ar, self.truth)
Beispiel #2
0
    def _build_bitmask_vec(self):
        """
        same as build mask but using vectorized calls to bin1d
        """
        # build bounding box of set of polygons based on origins
        nd_origins = numpy.array([poly.origin for poly in self.polygons])
        bbox = [(numpy.min(nd_origins[:, 0]), numpy.min(nd_origins[:, 1])),
                (numpy.max(nd_origins[:, 0]), numpy.max(nd_origins[:, 1]))]

        # get midpoints for hashing
        midpoints = numpy.array([poly.centroid() for poly in self.polygons])

        # set up grid over bounding box
        xs = cleaner_range(bbox[0][0], bbox[1][0], self.dh)
        ys = cleaner_range(bbox[0][1], bbox[1][1], self.dh)

        # set up mask array, 1 is index 0 is mask
        a = numpy.ones([len(ys), len(xs), 2])

        # set all indices to nan
        a[:, :, 1] = numpy.nan

        # bin1d returns the index of polygon within the cartesian grid
        idx = bin1d_vec(midpoints[:, 0], xs)
        idy = bin1d_vec(midpoints[:, 1], ys)

        for i in range(len(self.polygons)):
            a[idy[i], idx[i], 1] = int(i)
            # build mask in dim=0; here masked values are 1. see note below.
            if idx[i] >= 0 and idy[i] >= 0:
                if self.poly_mask is not None:
                    # note: csep1 gridded forecast file format convention states that a "1" indicates a valid cell, which is the opposite
                    # of the masking criterion
                    if self.poly_mask[i] == 1:
                        a[idy[i], idx[i], 0] = 0
                else:
                    a[idy[i], idx[i], 0] = 0

        return a, xs, ys
Beispiel #3
0
def global_region(dh=0.1, name="global", magnitudes=None):
    """ Creates a global region used for evaluating gridded forecasts on the global scale.

    The gridded region corresponds to the

    Args:
        dh:

    Returns:
        csep.utils.CartesianGrid2D:
    """
    # generate latitudes

    lons = cleaner_range(-180.0, 179.9, dh)
    lats = cleaner_range(-90, 89.9, dh)
    coords = itertools.product(lons, lats)
    region = CartesianGrid2D(
        [Polygon(bbox) for bbox in compute_vertices(coords, dh)],
        dh,
        name=name)
    if magnitudes is not None:
        region.magnitudes = magnitudes
    return region
Beispiel #4
0
    def test_discrepancy_with_direct_input(self):

        cr = cleaner_range(self.start, self.end, self.dh)
        numpy.testing.assert_array_equal(self.truth, cr)