def test_boundaries_types(self): bird = tectonics.PeterBird2003() boundaries = bird.get_boundaries() for boundary in boundaries: if (boundary.name1, boundary.kind, boundary.name2) == ( 'PS', '/', 'PA'): tt = boundary.split_types() assert len(tt) == 1 assert tt[0][0] == 'SUB' if (boundary.name1, boundary.kind, boundary.name2) == ( 'AS', '-', 'AT'): lastpoint = None for typ, part in boundary.split_types(): if lastpoint is not None: assert_allclose(lastpoint, part[0, :]) lastpoint = part[:, -1] lastpoint = None types = [] for typ, part in boundary.split_types( [['OSR'], ['SUB'], ['OTF', 'OCB', 'CTF', 'CCB', 'CRB']]): if lastpoint is not None: assert_allclose(lastpoint, part[0, :]) lastpoint = part[:, -1] types.append(typ) assert types == [['OSR'], ['CTF', 'CRB']] boundary.split_types()
def test_plates(self): bird = tectonics.PeterBird2003() plates = bird.get_plates() assert len(plates) == 52 point = num.array([-25., 135.], dtype=num.float) for plate in plates: plate.max_interpoint_distance() assert (plate.name == 'AU') == plate.contains_point(point) lats = num.linspace(-20., -10., 20) lons = num.linspace(-80., -70., 20) lats2 = num.repeat(lats, lons.size) lons2 = num.tile(lons, lats.size) points = num.vstack((lats2, lons2)).T full_names = [] for plate in plates: if num.any(plate.contains_points(points)): full_names.append(bird.full_name(plate.name)) assert full_names == [ 'South American Plate', 'Nazca Plate', 'Altiplano Plate']
def draw_plates(self): from pyrocko.dataset import tectonics neast = 20 nnorth = max(1, int(round(num.round(self._hreg/self._wreg * neast)))) norths = num.linspace(-self._hreg*0.5, self._hreg*0.5, nnorth) easts = num.linspace(-self._wreg*0.5, self._wreg*0.5, neast) norths2 = num.repeat(norths, neast) easts2 = num.tile(easts, nnorth) lats, lons = od.ne_to_latlon( self.lat, self.lon, norths2, easts2) bird = tectonics.PeterBird2003() plates = bird.get_plates() color_plates = gmtpy.color('aluminium5') color_velocities = gmtpy.color('skyblue1') color_velocities_lab = gmtpy.color(darken(gmtpy.color_tup('skyblue1'))) points = num.vstack((lats, lons)).T used = [] for plate in plates: mask = plate.contains_points(points) if num.any(mask): used.append((plate, mask)) if len(used) > 1: candi_fixed = {} label_data = [] for plate, mask in used: mean_north = num.mean(norths2[mask]) mean_east = num.mean(easts2[mask]) iorder = num.argsort(num.sqrt( (norths2[mask] - mean_north)**2 + (easts2[mask] - mean_east)**2)) lat_candis = lats[mask][iorder] lon_candis = lons[mask][iorder] candi_fixed[plate.name] = lat_candis.size label_data.append(( lat_candis, lon_candis, plate, color_plates)) boundaries = bird.get_boundaries() size = 2 psxy_kwargs = [] for boundary in boundaries: if num.any(points_in_region(boundary.points, self._wesn)): for typ, part in boundary.split_types( [['SUB'], ['OSR', 'OTF', 'OCB', 'CTF', 'CCB', 'CRB']]): lats, lons = part.T kwargs = {} if typ[0] == 'SUB': if boundary.kind == '\\': kwargs['S'] = 'f%g/%gp+t+r' % ( 0.45*size, 3.*size) elif boundary.kind == '/': kwargs['S'] = 'f%g/%gp+t+l' % ( 0.45*size, 3.*size) kwargs['G'] = color_plates kwargs['in_columns'] = (lons, lats) kwargs['W'] = '%gp,%s' % (size, color_plates), psxy_kwargs.append(kwargs) if boundary.kind == '\\': if boundary.name2 in candi_fixed: candi_fixed[boundary.name2] += neast*nnorth elif boundary.kind == '/': if boundary.name1 in candi_fixed: candi_fixed[boundary.name1] += neast*nnorth candi_fixed = [name for name in sorted( list(candi_fixed.keys()), key=lambda name: -candi_fixed[name])] candi_fixed.append(None) gsrm = tectonics.GSRM1() for name in candi_fixed: if name not in gsrm.plate_names() \ and name not in gsrm.plate_alt_names(): continue lats, lons, vnorth, veast, vnorth_err, veast_err, corr = \ gsrm.get_velocities(name, region=self._wesn) fixed_plate_name = name self.gmt.psvelo( in_columns=( lons, lats, veast, vnorth, veast_err, vnorth_err, corr), W='0.25p,%s' % color_velocities, A='9p+e+g%s' % color_velocities, S='e0.2p/0.95/10', *self.jxyr) for _ in range(len(lons) // 50 + 1): ii = random.randint(0, len(lons)-1) v = math.sqrt(vnorth[ii]**2 + veast[ii]**2) self.add_label( lats[ii], lons[ii], '%.0f' % v, font_size=0.7*self.gmt.label_font_size(), style=dict( G=color_velocities_lab)) break for (lat_candis, lon_candis, plate, color) in label_data: full_name = bird.full_name(plate.name) if plate.name == fixed_plate_name: full_name = '@_' + full_name + '@_' self.add_area_label( lat_candis, lon_candis, full_name, color=color, font='3') for kwargs in psxy_kwargs: self.gmt.psxy(*self.jxyr, **kwargs)
def test_boundaries(self): bird = tectonics.PeterBird2003() boundaries = bird.get_boundaries() assert len(boundaries) == 229