Exemple #1
0
    def __init__(self, region, sp_res, shapefile=None):

        self.country = region

        self.shp = Shape(region, shapefile=shapefile)

        # countries that cross the international dateline (maybe more!)
        if region in ['NZ', 'RS', 'US']:
            lonmin, lonmax = dateline_country(region)
        else:
            lonmin, lonmax = _minmaxcoord(self.shp.bbox[0], self.shp.bbox[2],
                                         sp_res)

        latmin, latmax = _minmaxcoord(self.shp.bbox[1], self.shp.bbox[3],
                                     sp_res)

        if region in ['NZ', 'US', 'RS']:
            lons1 = np.arange(lonmin, 180, sp_res)
            lons2 = (np.arange(-180, lonmax + sp_res, sp_res))
            lons = np.empty(len(lons1) + len(lons2))
            lons[0:len(lons1)] = lons1[:]
            lons[len(lons1):] = lons2[:]
        else:
            lons = np.arange(lonmin, lonmax + sp_res, sp_res)

        lats = np.arange(latmin, latmax + sp_res, sp_res)

        lon_new, lat_new = _remove_blank_frame(region, lons, lats, shapefile)

        lon, lat = np.meshgrid(lon_new, lat_new)

        shape = (lon.shape[1], lon.shape[0])

        super(ShapeGrid, self).__init__(lon.flatten(), lat.flatten(),
                                        shape=shape)
    def test_dateline_country(self):
        lon_min1 = [165.87, 173.18333333333334, 19.633333333333333]
        lon_max1 = [-175.83333333333334, -66.98353057222222, -169.065]

        for ind, region in enumerate(self.region[0:-1]):
            lon_min, lon_max = imf.dateline_country(region)

            assert lon_min == lon_min1[ind]
            assert lon_max == lon_max1[ind]