def unrotated_inner_border(self): return rotations.get_border_latlng_list( min_lat=self.min_latitude + self.boundary_width_in_degree, max_lat=self.max_latitude - self.boundary_width_in_degree, min_lng=self.min_longitude + self.boundary_width_in_degree, max_lng=self.max_longitude - self.boundary_width_in_degree, number_of_points_per_side=50)
def border(self): return rotations.get_border_latlng_list( min_lat=self.min_latitude, max_lat=self.max_latitude, min_lng=self.min_longitude, max_lng=self.max_longitude, number_of_points_per_side=50, rotation_axis=self.rotation_axis, rotation_angle_in_degree=self.rotation_angle_in_degree)
def unrotated_border(self): return rotations.get_border_latlng_list( min_lat=self.min_latitude, max_lat=self.max_latitude, min_lng=self.min_longitude, max_lng=self.max_longitude, number_of_points_per_side=50)
def unrotated_border(self): return rotations.get_border_latlng_list(min_lat=self.min_latitude, max_lat=self.max_latitude, min_lng=self.min_longitude, max_lng=self.max_longitude, number_of_points_per_side=50)
def plot_depth_slice(self, component, depth_in_km): """ Plots a depth slice. :param component: The component to plot. :type component: basestring :param depth_in_km: The depth in km to plot. If the exact depth does not exists, the nearest neighbour will be plotted. :type depth_in_km: integer or float """ lat_bounds = [rotations.colat2lat(_i) for _i in self.setup["physical_boundaries_x"][::-1]] lng_bounds = self.setup["physical_boundaries_y"] depth_bounds = [6371 - _i / 1000.0 for _i in self.setup["physical_boundaries_z"]] data = self.parsed_components[component] available_depths = np.linspace(*depth_bounds, num=data.shape[2]) depth_index = np.argmin(np.abs(available_depths - depth_in_km)) actual_depth = available_depths[depth_index] lngs = self._get_collocation_points_along_axis( lng_bounds[0], lng_bounds[1], data.shape[1]) lats = self._get_collocation_points_along_axis( lat_bounds[0], lat_bounds[1], data.shape[0]) lon, lat = np.meshgrid(lngs, lats) if self.rotation_axis and self.rotation_angle_in_degree: lon_shape = lon.shape lat_shape = lat.shape lon.shape = lon.size lat.shape = lat.size lat, lon = rotations.rotate_lat_lon(lat, lon, self.rotation_axis, self.rotation_angle_in_degree) lon.shape = lon_shape lat.shape = lat_shape # Get the center of the map. lon_0 = lon.min() + lon.ptp() / 2.0 lat_0 = lat.min() + lat.ptp() / 2.0 plt.figure(0) # Attempt to zoom into the region of interest. max_extend = max(lon.ptp(), lat.ptp()) extend_used = max_extend / 180.0 if extend_used < 0.5: # Calculate approximate width and height in meters. width = lon.ptp() height = lat.ptp() width *= 110000 * 1.1 height *= 110000 * 1.1 # Lambert azimuthal equal area projection. Equal area projections # are useful for interpreting features and this particular one also # does not distort features a lot on regional scales. m = Basemap(projection='laea', resolution="l", width=width, height=height, lat_0=lat_0, lon_0=lon_0) else: m = Basemap(projection='ortho', lon_0=lon_0, lat_0=lat_0, resolution="c") m.drawcoastlines() m.fillcontinents("0.9", zorder=0) m.drawmapboundary(fill_color="white") m.drawparallels(np.arange(-80.0, 80.0, 10.0), labels=[1, 0, 0, 0]) m.drawmeridians(np.arange(-170.0, 170.0, 10.0), labels=[0, 0, 0, 1]) m.drawcountries() x, y = m(lon, lat) depth_data = data[::-1, :, depth_index] vmin, vmax = depth_data.min(), depth_data.max() vmedian = np.median(depth_data) offset = max(abs(vmax - vmedian), abs(vmedian - vmin)) if vmax - vmin == 0: offset = 0.01 vmin = vmedian - offset vmax = vmedian + offset im = m.pcolormesh(x, y, depth_data, cmap=tomo_colormap, vmin=vmin, vmax=vmax) # Add colorbar and potentially unit. cm = m.colorbar(im, "right", size="3%", pad='2%') if component in UNIT_DICT: cm.set_label(UNIT_DICT[component], fontsize="x-large", rotation=0) plt.suptitle("Depth slice of %s at %i km" % ( component, int(round(actual_depth))), size="large") border = rotations.get_border_latlng_list( rotations.colat2lat(self.setup["physical_boundaries_x"][0]), rotations.colat2lat(self.setup["physical_boundaries_x"][1]), self.setup["physical_boundaries_y"][0], self.setup["physical_boundaries_y"][1], rotation_axis=self.rotation_axis, rotation_angle_in_degree=self.rotation_angle_in_degree) border = np.array(border) lats = border[:, 0] lngs = border[:, 1] lngs, lats = m(lngs, lats) m.plot(lngs, lats, color="black", lw=2, path_effects=[ PathEffects.withStroke(linewidth=4, foreground="white")]) def _on_button_press(event): if event.button != 1 or not event.inaxes: return lon, lat = m(event.xdata, event.ydata, inverse=True) # Convert to colat to ease indexing. colat = rotations.lat2colat(lat) x_range = (self.setup["physical_boundaries_x"][1] - self.setup["physical_boundaries_x"][0]) x_frac = (colat - self.setup["physical_boundaries_x"][0]) / x_range x_index = int(((self.setup["boundaries_x"][1] - self.setup["boundaries_x"][0]) * x_frac) + self.setup["boundaries_x"][0]) y_range = (self.setup["physical_boundaries_y"][1] - self.setup["physical_boundaries_y"][0]) y_frac = (lon - self.setup["physical_boundaries_y"][0]) / y_range y_index = int(((self.setup["boundaries_y"][1] - self.setup["boundaries_y"][0]) * y_frac) + self.setup["boundaries_y"][0]) plt.figure(1, figsize=(3, 8)) depths = available_depths values = data[x_index, y_index, :] plt.plot(values, depths) plt.grid() plt.ylim(depths[-1], depths[0]) plt.show() plt.close() plt.figure(0) plt.gcf().canvas.mpl_connect('button_press_event', _on_button_press) plt.show()