def show_view(self, figure_name='regatta_view', show=False): view = self.get_view() uwind = view[0, :, :] vwind = view[1, :, :] mask = view[2, :, :] print(view.shape) fig = plt(figure_name) # ax = fig.gca() fig.subplot(1, 3, 1) fig.imshow(np.squeeze(uwind)) fig.title('u wind (m.s-1)') fig.subplot(1, 3, 2) fig.imshow(np.squeeze(vwind)) fig.title('v wind (m.s-1)') fig.subplot(1, 3, 3) fig.imshow(np.squeeze(mask)) fig.title('mask') save_fig(figure_name=figure_name)
def plot(self, plot_weather=False, save=False, show=True, track=None, figure_name='regatta_plot'): if track is not None: self.track = track ax = plt(figure_name, figsize=special_parameters.plt_default_size).gca() # draw land if plot_weather: # current simulation timestamp t_idx = self.numpy_grib.physical_time_to_idx(self.start_timestamp + self.timedelta) self.numpy_grib.print_wind(show=False, save=False, idx=t_idx, ax=ax) else: self.numpy_grib.print_mask(show=False, save=False, figure_name=figure_name, ax=ax) # current position y_position, x_position = project(latitude=self.position[1], longitude=self.position[0], grib=self.numpy_grib) y_position = self.numpy_grib.latitudes.shape[0] - y_position ax.plot(x_position, y_position, 's', markersize=4, color="blue") # target y_target, x_target = project(latitude=self.target[1], longitude=self.target[0], grib=self.numpy_grib) y_target = self.numpy_grib.latitudes.shape[0] - y_target ax.plot(x_target, y_target, 'bo', markersize=6, color="green") # track X, Y = [], [] for lat, lon in zip(self.track[:, 1], self.track[:, 0]): y, x = project(lat, lon, self.numpy_grib) X.append(x) Y.append(self.numpy_grib.latitudes.shape[0] - y) ax.plot(X, Y, '-', color="red") ax.set_xlabel('Longitude') ax.set_ylabel('Latitude') ax.set_title('Offshore Regatta (at ' + str(self.start_timestamp + self.timedelta) + ')', y=1, fontsize=12) save_fig(figure_name=figure_name)
from datascience.visu.patch import pplot_patch import numpy as np # with option --more idx=12 to change the index from the command line... from engine.logging import print_info from engine.parameters.special_parameters import get_parameters # load the idx + 1 first elements idx = get_parameters('idx', 0) train, _, _ = occurrence_loader(EnvironmentalIGNDataset, source='full_ign', id_name='X_key', label_name='glc19SpId', validation_size=0, test_size=0, limit=idx + 1) patch, _ = train[idx] patch = [l.int() for l in patch] patch = patch[:-3] + [np.transpose(np.stack(patch[-3:], axis=0), (1, 2, 0))] print_info('Printing patch at ' + str(train.dataset[idx])) pplot_patch(patch, header=train.named_dimensions) save_fig()
def plot_on_map(activations, map_ids, n_cols=1, n_rows=1, figsize=4, log_scale=False, mean_size=1, selected=tuple(), legend=None, output="activations", style="grey", exp_scale=False, cmap=None, alpha=None, bad_alpha=1., font_size=12, color_text='black', color_tick='black'): if log_scale: print_info("apply log...") activations = activations + 1.0 activations = np.log(activations) elif exp_scale: print_info("apply exp...") p = np.full(activations.shape, 1.2) activations = np.power(p, activations) print_info("construct array activation map...") pos = [] max_x = 0 max_y = 0 for id_ in map_ids: x, y = id_.split("_") x, y = int(x), int(y) pos.append((x, y)) if x > max_x: max_x = x if y > max_y: max_y = y size = max(max_x + 1, max_y + 1) while size % mean_size != 0: size += 1 nb = n_cols * n_rows act_map = np.ndarray((nb, size, size)) act_map[:] = np.nan print_info("select neurons to print...") if len(selected) > 0: list_select = selected else: list_select = random.sample(list(range(activations.shape[1])), nb) print_info("fill activation map array...") for k, act in enumerate(activations): for idx, j in enumerate(list_select): x, y = pos[k][0], pos[k][1] act_map[idx, x, y] = act[j] """ fig, axs = plt.subplots(n_rows, n_cols, sharex='col', sharey='row', figsize=(n_cols*figsize*1.2, n_rows*figsize)) fig.subplots_adjust(wspace=0.5) plt.tight_layout(pad=1.5) print_info("make figure...") for j in range(nb): if mean_size != 1: height, width = act_map[j].shape act_map_j = np.ma.average(np.split(np.ma.average(np.split(act_map[j], width // mean_size, axis=1), axis=2), height // mean_size, axis=1), axis=2) else: act_map_j = act_map[j] masked_array = np.ma.array(act_map_j, mask=np.isnan(act_map_j)) cmap = matplotlib.cm.inferno cmap.set_bad('grey', 1.) im = axs[j // n_cols, j % n_cols].imshow(masked_array, cmap=cmap, interpolation='none') axs[j // n_cols, j % n_cols].set_title(str(list_select[j])) divider = make_axes_locatable(axs[j // n_cols, j % n_cols]) cax = divider.append_axes("right", size="5%", pad=0.05) fig.colorbar(im, cax=cax) """ font = {'family': 'normal', 'weight': 'bold', 'size': font_size} matplotlib.rc('font', **font) if legend is None: legend = list(map(str, list_select)) mplt.rcParams['text.color'] = color_text mplt.rcParams['axes.labelcolor'] = color_tick mplt.rcParams['xtick.color'] = color_tick mplt.rcParams['ytick.color'] = color_tick plt(output, figsize=(n_cols * figsize * 1.2, n_rows * figsize)) fig = get_figure(output) fig.subplots_adjust(wspace=0.05) print_info("make figure...") for j in range(nb): if mean_size != 1: height, width = act_map[j].shape act_map_j = np.nanmean(np.split(np.nanmean(np.split(act_map[j], width // mean_size, axis=1), axis=2), height // mean_size, axis=1), axis=2) else: act_map_j = act_map[j] print(act_map_j[2, 572]) masked_array = np.ma.array(act_map_j, mask=np.isnan(act_map_j)) if cmap is None: if style == "grey": cmap = matplotlib.cm.inferno cmap.set_bad('grey', bad_alpha) elif style == "white": cmap = matplotlib.cm.inferno cmap.set_bad('white', bad_alpha) ax = plt(output).subplot(n_rows, n_cols, j + 1) ax.set_facecolor((0, 0, 0, 0)) im = plt(output).imshow(masked_array, cmap=cmap, interpolation='none', alpha=alpha) plt(output).title(legend[j]) divider = make_axes_locatable(ax) cax = divider.append_axes("right", size="5%", pad=0.05) plt(output).colorbar(im, cax=cax) fig.tight_layout(pad=0.05) fig.patch.set_alpha(0.0) save_fig(figure_name=output, extension='png')
from datascience.visu.util import save_fig from datascience.visu.patch import pplot pplot(latitude=48.848530, longitude=1.93953, source='glc18', resolution=0.6, nb_cols=7, alpha=0.), save_fig(extension='png')
kappa = 0.015 kappa_k = kappa var_x_delta = 1. lambda_jk = 1. w_0 = 1. result = eta / (b * 2) * (var_x_delta / lambda_jk) w_t = np.log(kappa * omega * kappa_k * t + np.exp(kappa * omega * w_0)) w_t /= (kappa * omega + (kappa**2) * kappa_k * (omega**2) * t + np.exp(kappa * omega * w_0)) result *= w_t**2 result *= (1 - np.exp(-2 * lambda_jk * eta * t)) return result for width in [16 * i for i in range(2, 5)]: ax.plot(x, f(x, width), label='$\\omega$=%ld' % width) ax.legend() save_fig('sde_omega') ax = plt('sde_eta_b').gca() x = np.linspace(0, 3500, 5000) for batch_size in np.linspace(64, 512, 8): ax.plot(x, f(x, b=batch_size), label='$\\eta$/B=%.4lf' % (0.1 / float(batch_size))) ax.legend() save_fig('sde_eta_b')