def read_variable_Ha(self): """Retourne l'amplitude de la réanalyse @return: un tableau en deux dimensions [y,x].""" data = self.reader.read_variable_Ha( self.map_mpi[self.rank]["src_global_x_overlap"].start, self.map_mpi[self.rank]["src_global_x_overlap"].stop, self.map_mpi[self.rank]["src_global_y_overlap"].start, self.map_mpi[self.rank]["src_global_y_overlap"].stop) if self.horizontal_resampling: data = resample_2d_to_grid(self.read_axis_x(type="source_global", with_overlap=True), self.read_axis_y(type="source_global", with_overlap=True), self.read_axis_x(type="target", with_overlap=True), self.read_axis_y(type="target", with_overlap=True), data, Coverage.HORIZONTAL_INTERPOLATION_METHOD) return data[self.map_mpi[self.rank]["dst_local_y"], self.map_mpi[self.rank]["dst_local_x"]]
def read_variable_2D_sea_binary_mask(self): """Retourne le masque terre/mer sur toute la couverture @return: un tableau en deux dimensions [y,x]. 0 = Terre 1 = Mer """ data = self.reader.read_variable_2D_sea_binary_mask( self.map_mpi[self.rank]["src_global_x_overlap"].start, self.map_mpi[self.rank]["src_global_x_overlap"].stop, self.map_mpi[self.rank]["src_global_y_overlap"].start, self.map_mpi[self.rank]["src_global_y_overlap"].stop) if self.horizontal_resampling: data = resample_2d_to_grid(self.read_axis_x(type="source_global", with_overlap=True), self.read_axis_y(type="source_global", with_overlap=True), self.read_axis_x(type="target", with_overlap=True), self.read_axis_y(type="target", with_overlap=True), data, Coverage.HORIZONTAL_INTERPOLATION_METHOD) return data[self.map_mpi[self.rank]["dst_local_y"],self.map_mpi[self.rank]["dst_local_x"]]
def read_variable_sea_water_temperature_at_time_and_depth(self, time, depth): """Retourne la salinité à la date souhaitée et au niveau souhaité sur toute la couverture horizontale. @type time: datetime ou l'index @param time: date souhaitée @type depth: profondeur en mètre (float) ou index (integer) @param depth: profondeur souhaitée. Si le z est un entier, on considère qu'il s'agit de l'index, si c'est un flottant on considère qu'il s'agit d'une profondeur @return: un tableau en deux dimensions [y,x].""" index_t = self.find_time_index(time); tmp = self.find_level_index(depth); vert_coord = tmp[0] indexes_z = tmp[1] xmax = self.get_x_size(type="source", with_overlap=True) ymax = self.get_y_size(type="source", with_overlap=True) z_axis = self.read_axis_z(type="source", with_horizontal_overlap=True) layers = np.zeros([np.shape(indexes_z)[0], ymax, xmax]) layers[::] = np.NAN data = np.zeros([ymax, xmax]) data[:] = np.NAN targetDepth = [depth] mask_t = self.reader.read_variable_2D_sea_binary_mask( self.map_mpi[self.rank]["src_global_x_overlap"].start, self.map_mpi[self.rank]["src_global_x_overlap"].stop, self.map_mpi[self.rank]["src_global_y_overlap"].start, self.map_mpi[self.rank]["src_global_y_overlap"].stop) for z in range(0, len(indexes_z)): layers[z] = self.reader.read_variable_sea_water_temperature_at_time_and_depth( self.map_mpi[self.rank]["src_global_t"].start + index_t, indexes_z[z], self.map_mpi[self.rank]["src_global_x_overlap"].start, self.map_mpi[self.rank]["src_global_x_overlap"].stop, self.map_mpi[self.rank]["src_global_y_overlap"].start, self.map_mpi[self.rank]["src_global_y_overlap"].stop) idx = np.where(vert_coord != None) for index in range(np.shape(idx)[1]): x = idx[1][index] y = idx[0][index] if mask_t[y,x] == 1: if len(vert_coord[y, x]) == 1: # Il n'y a qu'une seule couche de sélectionner donc pas d'interpolation possible # On retrouve l'index de la layer array = np.asarray(indexes_z) index_layer = (np.abs(array - vert_coord[y, x][0])).argmin() data[y, x] = layers[index_layer, y, x] elif len(vert_coord[y, x]) > 1: candidateValues = np.zeros([len(vert_coord[y, x])]) candidateDepths = np.zeros([len(vert_coord[y, x])]) for z in range(0, len(vert_coord[y, x])): # On retrouve l'index de la layer array = np.asarray(indexes_z) index_layer = (np.abs(array - vert_coord[y, x][z])).argmin() if self.is_sigma_coordinate(type="source"): candidateDepths[z] = z_axis[index_layer, y, x] else: candidateDepths[z] = z_axis[index_layer] candidateValues[z] = layers[index_layer, y, x] data[y, x] = vertical_interpolation(candidateDepths, targetDepth, candidateValues, LevelCoverage.VERTICAL_INTERPOLATION_METHOD) if self.horizontal_resampling: data = resample_2d_to_grid(self.read_axis_x(type="source_global", with_overlap=True), self.read_axis_y(type="source_global", with_overlap=True), self.read_axis_x(type="target", with_overlap=True), self.read_axis_y(type="target", with_overlap=True), data, Coverage.HORIZONTAL_INTERPOLATION_METHOD) return data[self.map_mpi[self.rank]["dst_local_y"], self.map_mpi[self.rank]["dst_local_x"]]