def _test(self, points, centroids, lengths, widths, areas): fake_coords = numpy.array([[0]]) self.points = numpy.array(points, dtype=float) mesh = RectangularMesh(fake_coords, fake_coords, fake_coords) cell_center, cell_length, cell_width, cell_area \ = mesh.get_cell_dimensions() self.assertTrue(numpy.allclose(cell_length, lengths), '%s != %s' % (cell_length, lengths)) self.assertTrue(numpy.allclose(cell_width, widths), '%s != %s' % (cell_width, widths)) self.assertTrue(numpy.allclose(cell_area, areas), '%s != %s' % (cell_area, areas)) self.assertTrue(numpy.allclose(cell_center, centroids), '%s != %s' % (cell_center, centroids))
def __iter__(self): self.dstore.open() # if needed oq = self.dstore['oqparam'] grp_trt = self.dstore['csm_info'].grp_trt() recs = self.dstore['ruptures'][self.slice] for rec in recs: if self.rup_id is not None and self.rup_id != rec['serial']: continue evs = self.dstore['events'][rec['eidx1']:rec['eidx2']] grp_id = evs['grp_id'][0] if self.grp_id is not None and self.grp_id != grp_id: continue mesh = rec['points'].reshape(rec['sx'], rec['sy'], rec['sz']) rupture_cls, surface_cls, source_cls = BaseRupture.types[ rec['code']] rupture = object.__new__(rupture_cls) rupture.surface = object.__new__(surface_cls) # MISSING: case complex_fault_mesh_spacing != rupture_mesh_spacing if 'Complex' in surface_cls.__name__: mesh_spacing = oq.complex_fault_mesh_spacing else: mesh_spacing = oq.rupture_mesh_spacing rupture.source_typology = source_cls rupture.mag = rec['mag'] rupture.rake = rec['rake'] rupture.seed = rec['seed'] rupture.hypocenter = geo.Point(*rec['hypo']) rupture.occurrence_rate = rec['occurrence_rate'] rupture.tectonic_region_type = grp_trt[grp_id] pmfx = rec['pmfx'] if pmfx != -1: rupture.pmf = self.dstore['pmfs'][pmfx] if surface_cls is geo.PlanarSurface: rupture.surface = geo.PlanarSurface.from_array( mesh_spacing, rec['points']) elif surface_cls.__name__.endswith('MultiSurface'): rupture.surface.__init__([ geo.PlanarSurface.from_array(mesh_spacing, m1.flatten()) for m1 in mesh ]) else: # fault surface, strike and dip will be computed rupture.surface.strike = rupture.surface.dip = None m = mesh[0] rupture.surface.mesh = RectangularMesh(m['lon'], m['lat'], m['depth']) ebr = EBRupture(rupture, (), evs, rec['serial']) ebr.eidx1 = rec['eidx1'] ebr.eidx2 = rec['eidx2'] # not implemented: rupture_slip_direction yield ebr
def get_ruptures(dstore, grp_id): """ Extracts the ruptures of the given grp_id """ oq = dstore['oqparam'] trt = dstore['csm_info'].grp_trt()[grp_id] grp = 'grp-%02d' % grp_id events = dstore['events/' + grp] for rec in dstore['ruptures/' + grp]: mesh = rec['points'].reshape(rec['sx'], rec['sy'], rec['sz']) rupture_cls, surface_cls, source_cls = BaseRupture.types[rec['code']] rupture = object.__new__(rupture_cls) rupture.surface = object.__new__(surface_cls) # MISSING: test with complex_fault_mesh_spacing != rupture_mesh_spacing if 'Complex' in surface_cls.__name__: mesh_spacing = oq.complex_fault_mesh_spacing else: mesh_spacing = oq.rupture_mesh_spacing rupture.source_typology = source_cls rupture.mag = rec['mag'] rupture.rake = rec['rake'] rupture.seed = rec['seed'] rupture.hypocenter = geo.Point(*rec['hypo']) rupture.occurrence_rate = rec['occurrence_rate'] rupture.tectonic_region_type = trt pmfx = rec['pmfx'] if pmfx != -1: rupture.pmf = dstore['pmfs/' + grp][pmfx] if surface_cls is geo.PlanarSurface: rupture.surface = geo.PlanarSurface.from_array( mesh_spacing, rec['points']) elif surface_cls.__name__.endswith('MultiSurface'): rupture.surface.__init__([ geo.PlanarSurface.from_array(mesh_spacing, m1.flatten()) for m1 in mesh ]) else: # fault surface, strike and dip will be computed rupture.surface.strike = rupture.surface.dip = None m = mesh[0] rupture.surface.mesh = RectangularMesh(m['lon'], m['lat'], m['depth']) sids = dstore['sids'][rec['sidx']] evs = events[rec['eidx1']:rec['eidx2']] ebr = EBRupture(rupture, sids, evs, grp_id, rec['serial']) ebr.eidx1 = rec['eidx1'] ebr.eidx2 = rec['eidx2'] ebr.sidx = rec['sidx'] # not implemented: rupture_slip_direction yield ebr
def test_vertical_mesh(self): lons = numpy.array([[0, 0.5, 1, 2], [0, 0.5, 1, 2]], float) lats = numpy.array([[0, 0, 0, 0], [0, 0, 0, 0]], float) depths = numpy.array([[1, 1, 1, 1], [2, 2, 2, 2]], float) mesh = RectangularMesh(lons, lats, depths) target_mesh = Mesh.from_points_list( [Point(0.5, 0), Point(0.5, 1), Point(0.5, 5)]) dists = mesh.get_joyner_boore_distance(target_mesh) expected_dists = [ 0, Point(0.5, 1).distance(Point(0.5, 0)), Point(0.5, 5).distance(Point(0.5, 0)) ] aac(dists, expected_dists, atol=1)
def get_cdppvalue(self, target, buf=1.0, delta=0.01, space=2.): """ Get the directivity prediction value, centered DPP(cdpp) at a given site as described in Spudich et al. (2013), and this cdpp is used in Chiou and Young (2014) GMPE for near-fault directivity term prediction. :param target_site: A mesh object representing the location of the target sites. :param buf: A buffer distance in km to extend the mesh borders :param delta: The distance between two adjacent points in the mesh :param space: The tolerance for the distance of the sites (default 2 km) :returns: The centered directivity prediction value of Chiou and Young """ min_lon, max_lon, max_lat, min_lat = self.surface.get_bounding_box() min_lon -= buf max_lon += buf min_lat -= buf max_lat += buf lons = numpy.arange(min_lon, max_lon + delta, delta) # ex shape (233,) lats = numpy.arange(min_lat, max_lat + delta, delta) # ex shape (204,) mesh = RectangularMesh(*numpy.meshgrid(lons, lats)) mesh_rup = self.surface.get_min_distance(mesh).reshape(mesh.shape) # ex shape (204, 233) target_rup = self.surface.get_min_distance(target) # ex shape (2,) cdpp = numpy.zeros_like(target.lons) for i, (target_lon, target_lat) in enumerate(zip(target.lons, target.lats)): # indices around target_rup[i] around = (mesh_rup <= target_rup[i] + space) & ( mesh_rup >= target_rup[i] - space) dpp_target = self.get_dppvalue(Point(target_lon, target_lat)) dpp_mean = numpy.mean([ self.get_dppvalue(Point(lon, lat)) for lon, lat in zip(mesh.lons[around], mesh.lats[around]) ]) cdpp[i] = dpp_target - dpp_mean return cdpp
def get_rupture(dic, geom=None, trt=None): """ :param dic: a dictionary or a record :param geom: if any, an array with fields lon, lat, depth :returns: a rupture instance """ if not code2cls: code2cls.update(BaseRupture.init()) if geom is None: lons = dic['lons'] mesh = numpy.zeros((3, len(lons), len(lons[0])), F32) mesh[0] = dic['lons'] mesh[1] = dic['lats'] mesh[2] = dic['depths'] else: mesh = numpy.zeros((3, ) + geom.shape, F32) mesh[0] = geom['lon'] mesh[1] = geom['lat'] mesh[2] = geom['depth'] rupture_cls, surface_cls = code2cls[dic['code']] rupture = object.__new__(rupture_cls) rupture.rup_id = dic['serial'] rupture.surface = object.__new__(surface_cls) rupture.mag = dic['mag'] rupture.rake = dic['rake'] rupture.hypocenter = geo.Point(*dic['hypo']) rupture.occurrence_rate = dic['occurrence_rate'] rupture.tectonic_region_type = trt or dic['trt'] if surface_cls is geo.PlanarSurface: rupture.surface = geo.PlanarSurface.from_array(mesh[:, 0, :]) elif surface_cls is geo.MultiSurface: # mesh has shape (3, n, 4) rupture.surface.__init__([ geo.PlanarSurface.from_array(mesh[:, i, :]) for i in range(mesh.shape[1]) ]) elif surface_cls is geo.GriddedSurface: # fault surface, strike and dip will be computed rupture.surface.strike = rupture.surface.dip = None rupture.surface.mesh = Mesh(*mesh) else: # fault surface, strike and dip will be computed rupture.surface.strike = rupture.surface.dip = None rupture.surface.__init__(RectangularMesh(*mesh)) return rupture
def _get_rupture(rec, geom=None, trt=None): # rec: a dictionary or a record # geom: if any, an array of floats32 convertible into a mesh if not code2cls: code2cls.update(BaseRupture.init()) if geom is None: lons = rec['lons'] mesh = numpy.zeros((3, len(lons), len(lons[0])), F32) mesh[0] = rec['lons'] mesh[1] = rec['lats'] mesh[2] = rec['depths'] else: mesh = geom.reshape(rec['s1'], rec['s2'], 3).transpose(2, 0, 1) rupture_cls, surface_cls = code2cls[rec['code']] rupture = object.__new__(rupture_cls) rupture.rup_id = rec['serial'] rupture.surface = object.__new__(surface_cls) rupture.mag = rec['mag'] rupture.rake = rec['rake'] rupture.hypocenter = geo.Point(*rec['hypo']) rupture.occurrence_rate = rec['occurrence_rate'] try: rupture.probs_occur = rec['probs_occur'] except (KeyError, ValueError): # rec can be a numpy record pass rupture.tectonic_region_type = trt or rec['trt'] if surface_cls is geo.PlanarSurface: rupture.surface = geo.PlanarSurface.from_array( mesh[:, 0, :]) elif surface_cls is geo.MultiSurface: # mesh has shape (3, n, 4) rupture.surface.__init__([ geo.PlanarSurface.from_array(mesh[:, i, :]) for i in range(mesh.shape[1])]) elif surface_cls is geo.GriddedSurface: # fault surface, strike and dip will be computed rupture.surface.strike = rupture.surface.dip = None rupture.surface.mesh = Mesh(*mesh) else: # fault surface, strike and dip will be computed rupture.surface.strike = rupture.surface.dip = None rupture.surface.__init__(RectangularMesh(*mesh)) rupture.multiplicity = rec['n_occ'] return rupture
def test_version(self): # this test is sensitive to different versions of shapely/libgeos lons = numpy.array( [[-121.3956, -121.41050474, -121.42542273, -121.44035399, -121.45529855, -121.47025643], [-121.3956, -121.41050474, -121.42542273, -121.44035399, -121.45529855, -121.47025643]]) lats = numpy.array( [[36.8257, 36.85963772, 36.89357357, 36.92750756, 36.96143968, 36.99536993], [36.8257, 36.85963772, 36.89357357, 36.92750756, 36.96143968, 36.99536993]]) mesh = RectangularMesh(lons, lats) dist = mesh.get_joyner_boore_distance( Mesh.from_points_list([Point(-121.76, 37.23)])) dist_ubuntu_12_04 = 36.61260128 dist_ubuntu_14_04 = 36.61389245 self.assertTrue(numpy.allclose(dist, dist_ubuntu_12_04) or numpy.allclose(dist, dist_ubuntu_14_04))
def test_simple(self): lons = numpy.array([[0, 0.0089946277931563321], [0, 0.0089974527390248322]]) lats = numpy.array([[0, 0], [0, 0]], dtype=float) depths = numpy.array([[1, 0.99992150706475513], [3, 2.9999214824129012]]) mesh = RectangularMesh(lons, lats, depths) points, along_azimuth, updip, diag = mesh.triangulate() self.assertTrue( numpy.allclose(points, [[(6370, 0, 0), (6370, 1, 0)], [(6368, 0, 0), (6368, 1, 0)]])) self.assertTrue( numpy.allclose(along_azimuth, [[(0, 1, 0)], [(0, 1, 0)]])) self.assertTrue(numpy.allclose(updip, [ [(2, 0, 0)], [(2, 0, 0)], ])) self.assertTrue(numpy.allclose(diag, [[(2, 1, 0)]]))
def __iter__(self): with datastore.read(self.hdf5path) as dstore: rupgeoms = dstore['rupgeoms'] for rec in self.rup_array: mesh = numpy.zeros((3, rec['sy'], rec['sz']), F32) geom = rupgeoms[rec['gidx1']:rec['gidx2']].reshape( rec['sy'], rec['sz']) mesh[0] = geom['lon'] mesh[1] = geom['lat'] mesh[2] = geom['depth'] rupture_cls, surface_cls = self.code2cls[rec['code']] rupture = object.__new__(rupture_cls) rupture.serial = rec['serial'] rupture.surface = object.__new__(surface_cls) rupture.mag = rec['mag'] rupture.rake = rec['rake'] rupture.hypocenter = geo.Point(*rec['hypo']) rupture.occurrence_rate = rec['occurrence_rate'] rupture.tectonic_region_type = self.trt if surface_cls is geo.PlanarSurface: rupture.surface = geo.PlanarSurface.from_array(mesh[:, 0, :]) elif surface_cls is geo.MultiSurface: # mesh has shape (3, n, 4) rupture.surface.__init__([ geo.PlanarSurface.from_array(mesh[:, i, :]) for i in range(mesh.shape[1]) ]) elif surface_cls is geo.GriddedSurface: # fault surface, strike and dip will be computed rupture.surface.strike = rupture.surface.dip = None rupture.surface.mesh = Mesh(*mesh) else: # fault surface, strike and dip will be computed rupture.surface.strike = rupture.surface.dip = None rupture.surface.__init__(RectangularMesh(*mesh)) grp_id = rec['grp_id'] ebr = EBRupture(rupture, rec['srcidx'], grp_id, (), rec['n_occ'], self.samples) # not implemented: rupture_slip_direction yield ebr
def get_rupture_enclosing_polygon(self, dilation=0): """ Create instance of :class:`openquake.hazardlib.geo.surface.multi.MultiSurface` from all ruptures' surfaces and compute its bounding box. Calculate convex hull of bounding box, and return it dilated by ``dilation``. :param dilation: A buffer distance in km to extend the polygon borders to. :returns: Instance of :class:`openquake.hazardlib.geo.polygon.Polygon`. """ surfaces = [rup.surface for (rup, _) in self.data] multi_surf = MultiSurface(surfaces) west, east, north, south = multi_surf.get_bounding_box() mesh = RectangularMesh(numpy.array([[west, east], [west, east]]), numpy.array([[north, north], [south, south]]), None) poly = mesh.get_convex_hull() return poly if dilation == 0 else poly.dilate(dilation)
def _fix_right_hand(self): """ This method fixes the mesh used to represent the grid surface so that it complies with the right hand rule. """ found = False irow = 0 icol = 0 while not found: if np.all(np.isfinite(self.mesh.lons[irow:irow + 2, icol:icol + 2])): found = True else: icol += 1 if (icol + 1) >= self.mesh.lons.shape[1]: irow += 1 icol = 1 if (irow + 1) >= self.mesh.lons.shape[0]: break if found: azi_strike = azimuth(self.mesh.lons[irow, icol], self.mesh.lats[irow, icol], self.mesh.lons[irow + 1, icol], self.mesh.lats[irow + 1, icol]) azi_dip = azimuth(self.mesh.lons[irow, icol], self.mesh.lats[irow, icol], self.mesh.lons[irow, icol + 1], self.mesh.lats[irow, icol + 1]) if abs((azi_strike + 90) % 360 - azi_dip) < 10: tlo = np.fliplr(self.mesh.lons) tla = np.fliplr(self.mesh.lats) tde = np.fliplr(self.mesh.depths) mesh = RectangularMesh(tlo, tla, tde) self.mesh = mesh else: msg = 'Could not find a valid quadrilateral for strike calculation' raise ValueError(msg)
def test_simple(self): lons = numpy.array([numpy.arange(-1, 1.2, 0.2)] * 11) lats = lons.transpose() + 1 depths = lats + 10 mesh = RectangularMesh(lons, lats, depths) check = lambda lon, lat, depth, expected_distance, **kwargs: \ self.assertAlmostEqual( mesh.get_joyner_boore_distance( Mesh.from_points_list([Point(lon, lat, depth)]) )[0], expected_distance, **kwargs ) check(lon=0, lat=0.5, depth=0, expected_distance=0) check(lon=1, lat=1, depth=0, expected_distance=0) check(lon=0.6, lat=-1, depth=0, expected_distance=Point(0.6, -1).distance(Point(0.6, 0)), delta=0.1) check(lon=-0.8, lat=2.1, depth=10, expected_distance=Point(-0.8, 2.1).distance(Point(-0.8, 2)), delta=0.02) check(lon=0.75, lat=2.3, depth=3, expected_distance=Point(0.75, 2.3).distance(Point(0.75, 2)), delta=0.04)
def from_profiles(cls, profiles, profile_sd, edge_sd, idl=False, align=False): # TODO split this function into smaller components. """ This method creates a quadrilateral mesh from a set of profiles. The construction of the mesh is done trying to get quadrilaterals as much as possible close to a square. Nonetheless some distorsions are possible and admitted. :param list profiles: A list of :class:`openquake.hazardlib.geo.Line.line` instances :param float profile_sd: The desired sampling distance along the profiles [dd] CHECK :param edge_sd: The desired sampling distance along the edges [dd] CHECK :param idl: Boolean true if IDL :param align: A boolean used to decide if profiles should or should not be aligned at the top. :returns: A :class:`numpy.ndarray` instance with the coordinates of nodes of the mesh representing the fault surface. The cardinality of this array is: number of edges x number of profiles x 3. The coordinate of the point at [0, 0, :] is first point along the trace defined using the right-hand rule. [0, 0, :] [0, -1, :] Upper edge |--------------------| | V | Fault dipping toward the | | observer Lower edge |____________________| """ # Resample profiles using the resampling distance provided rprofiles = [] for prf in profiles: rprofiles.append(_resample_profile(prf, profile_sd)) # Set the reference profile i.e. the longest one ref_idx = None max_length = -1e10 for idx, prf in enumerate(rprofiles): length = prf.get_length() if length > max_length: max_length = length ref_idx = idx # Check that in each profile the points are equally spaced for pro in rprofiles: pnts = [(p.longitude, p.latitude, p.depth) for p in pro.points] pnts = np.array(pnts) # Check that the profile is not crossing the IDL and compute the # distance between consecutive points along the profile assert np.all(pnts[:, 0] <= 180) & np.all(pnts[:, 0] >= -180) dst = distance(pnts[:-1, 0], pnts[:-1, 1], pnts[:-1, 2], pnts[1:, 0], pnts[1:, 1], pnts[1:, 2]) # Check that all the distances are within a tolerance np.testing.assert_allclose(dst, profile_sd, rtol=1.) # Find the delta needed to align profiles if requested shift = np.zeros(len(rprofiles) - 1) if align is True: for i in range(0, len(rprofiles) - 1): shift[i] = profiles_depth_alignment(rprofiles[i], rprofiles[i + 1]) shift = np.array([0] + list(shift)) # Find the maximum back-shift ccsum = [shift[0]] for i in range(1, len(shift)): ccsum.append(shift[i] + ccsum[i - 1]) add = ccsum - min(ccsum) # Create resampled profiles. Now the profiles should be all aligned # from the top (if align option is True) rprof = [] maxnum = 0 for i, pro in enumerate(rprofiles): j = int(add[i]) coo = get_coords(pro, idl) tmp = [[np.nan, np.nan, np.nan] for a in range(0, j)] if len(tmp) > 0: points = tmp + coo else: points = coo rprof.append(points) maxnum = max(maxnum, len(rprof[-1])) # Now profiles will have the same number of samples (some of them can # be nan). This is needed to have an array to store the surface. for i, pro in enumerate(rprof): while len(pro) < maxnum: pro.append([np.nan, np.nan, np.nan]) rprof[i] = np.array(pro) # Create mesh the in the forward direction prfr = get_mesh(rprof, ref_idx, edge_sd, idl) # Create the mesh in the backward direction if ref_idx > 0: prfl = get_mesh_back(rprof, ref_idx, edge_sd, idl) else: prfl = [] prf = prfl + prfr msh = np.array(prf) # Convert from profiles to edges msh = msh.swapaxes(0, 1) msh = fix_mesh(msh) return cls(RectangularMesh(msh[:, :, 0], msh[:, :, 1], msh[:, :, 2]), profiles)
def test_even_rows_odd_columns_with_topo(self): lons = numpy.array([[20], [21]]) lats = numpy.array([[-1], [1]]) depths = numpy.array([[-1.1], [-1.3]]) mesh = RectangularMesh(lons, lats, depths=depths) self.assertEqual(mesh.get_middle_point(), Point(20.5, 0, -1.2))
def test_even_rows_even_columns_no_depths(self): lons = numpy.array([[10, 20], [10.002, 20.002]]) lats = numpy.array([[10, -10], [8, -8]]) mesh = RectangularMesh(lons, lats, depths=None) self.assertEqual(mesh.get_middle_point(), Point(15.001, 0))
def test_odd_rows_even_columns_with_topo(self): lons = numpy.array([[0, 20, 30, 90]]) lats = numpy.array([[30] * 4]) depths = numpy.array([[2, 1, -3, -5]]) mesh = RectangularMesh(lons, lats, depths=depths) self.assertEqual(mesh.get_middle_point(), Point(25, 30.094679, -1))
def test_even_rows_odd_columns_no_depths(self): lons = numpy.array([[-1, 0, 1, 2, 3], [-1.5, 0.5, 1.5, 2.5, 3.5]]) lats = numpy.array([[-0.01] * 5, [-0.015] * 5]) mesh = RectangularMesh(lons, lats, depths=None) self.assertEqual(mesh.get_middle_point(), Point(1.25, -0.0125, 0))
def test_odd_rows_even_columns_no_depths(self): lons = numpy.array([[10, 20, 30, 40]]) lats = numpy.array([[30] * 4]) mesh = RectangularMesh(lons, lats, depths=None) self.assertEqual(mesh.get_middle_point(), Point(25, 30.094679))
def test_odd_rows_odd_columns_with_topo(self): lons = numpy.array([numpy.arange(-1, 1.2, 0.2)] * 11) lats = lons.transpose() depths = lats - 1 mesh = RectangularMesh(lons, lats, depths) self.assertEqual(mesh.get_middle_point(), Point(0, 0, -1))
def test_odd_rows_odd_columns_no_depths(self): lons = numpy.array([numpy.arange(-1, 1.2, 0.2)] * 11) lats = lons.transpose() * 10 mesh = RectangularMesh(lons, lats, depths=None) self.assertEqual(mesh.get_middle_point(), Point(0, 0, 0))
def test_invalid_mesh(self): lons = numpy.array([[0.1]]) lats = numpy.array([[0.1]]) depths = numpy.array([[2.0]]) mesh = RectangularMesh(lons, lats, depths) self.assertRaises(AssertionError, mesh.get_mean_width)
def test_wrong_shape(self): with self.assertRaises(AssertionError): RectangularMesh(numpy.array([0, 1, 2]), numpy.array([0, 0, 0]), None) RectangularMesh(numpy.array([0, -1]), numpy.array([2, 10]), numpy.array([5, 44]))
def get_cdppvalue(self, target, buf=1.0, delta=0.01, space=2.): """ Get the directivity prediction value, centred DPP(cdpp) at a given site as described in Spudich et al. (2013), and this cdpp is used in Chiou and Young(2014) GMPE for near-fault directivity term prediction. :param target_site: A mesh object representing the location of the target sites. :param buf: A float vaule presents the buffer distance in km to extend the mesh borders to. :param delta: A float vaule presents the desired distance between two adjacent points in mesh :param space: A float vaule presents the tolerance for the same distance of the sites (default 2 km) :returns: A float value presents the centreed directivity predication value which used in Chioud and Young(2014) GMPE for directivity term """ min_lon, max_lon, max_lat, min_lat = self.surface.get_bounding_box() min_lon -= buf max_lon += buf min_lat -= buf max_lat += buf lons = numpy.arange(min_lon, max_lon + delta, delta) lats = numpy.arange(min_lat, max_lat + delta, delta) lons, lats = numpy.meshgrid(lons, lats) target_rup = self.surface.get_min_distance(target) mesh = RectangularMesh(lons=lons, lats=lats, depths=None) mesh_rup = self.surface.get_min_distance(mesh) target_lons = target.lons target_lats = target.lats cdpp = numpy.empty(len(target_lons)) for iloc, (target_lon, target_lat) in enumerate(zip(target_lons, target_lats)): cdpp_sites_lats = mesh.lats[(mesh_rup <= target_rup[iloc] + space) & (mesh_rup >= target_rup[iloc] - space)] cdpp_sites_lons = mesh.lons[(mesh_rup <= target_rup[iloc] + space) & (mesh_rup >= target_rup[iloc] - space)] dpp_sum = [] dpp_target = self.get_dppvalue(Point(target_lon, target_lat)) for lon, lat in zip(cdpp_sites_lons, cdpp_sites_lats): site = Point(lon, lat, 0.) dpp_one = self.get_dppvalue(site) dpp_sum.append(dpp_one) mean_dpp = numpy.mean(dpp_sum) cdpp[iloc] = dpp_target - mean_dpp return cdpp
def test_preserving_the_type(self): lons = lats = numpy.arange(100).reshape((10, 10)) mesh = RectangularMesh(lons, lats, depths=None) submesh = mesh[1:2, 3:4] self.assertIsInstance(submesh, RectangularMesh)