def rebuild_models(self): """ Rebuild the true and initial models based on the current configuration.""" # Get the list of parameters required for the current physics parameter_names = self.physics_to_parameters_map[self.physics] # Get a list of properly scaled and cropped parameters arrays for each of those parameters parameter_arrays = [self._load_scaled_parameter_array(p) for p in parameter_names] # Velocity only, at the moment # Eventually all of this will need to be done for each model parameter vp = parameter_arrays[0] # Extract the depth coordinates of the grid points grid = self._mesh.mesh_coords() ZZ = grid[-1].reshape(vp.shape) # Copy the default values for the initial model style config = dict(self._initial_configs[self.initial_model_style]) # Override them with user provided values config.update(self.initial_config) # Construct initial velocity profile: if self.initial_model_style == 'constant': vp0 = np.ones(vp.shape)*config['velocity'] elif self.initial_model_style == 'smooth_width': vp0 = blur_image(vp, sigma=config['sigma'], mesh_deltas=self._mesh.deltas) elif self.initial_model_style == 'smooth_low_pass': vp0 = blur_image(vp, freq=config['freq'], mesh_deltas=self._mesh.deltas) elif self.initial_model_style == 'gradient': # construct the N-D depth trace shape, which is 1 in every dimension # except the depth direction sh = self._mesh.shape(as_grid=True) _shape_tuple = tuple([1]*(len(sh)-1) + [sh[-1]]) # Construct the shape of the padding, which is 0 padding in the depth # direction and n pixels in each other direction _pad_tuple = [(0, n-1) for n in sh] _pad_tuple[-1] = (0, 0) _pad_tuple = tuple(_pad_tuple) # If the water is to be fixed, the gradient is started at the # shallowest water-rock interaction. Otherwise, start at the top. if self.fix_water_layer and (self.water_properties[0] is not None): grid_sparse = self._mesh.mesh_coords(sparse=True) ZZZ = grid_sparse[-1].reshape(_shape_tuple) min_max_depth = self._find_min_max_water_depth() loc = np.where(ZZZ > min_max_depth) zprof = np.zeros(_shape_tuple) zprof[loc] = np.linspace(config['min'], config['max'], loc[0].size) else: zprof = np.linspace(config['min'], config['max'], self._mesh.z.n) zprof.shape = _shape_tuple # Pad out the gradient. vp0 = np.pad(zprof, _pad_tuple, 'edge') if self.fix_water_layer and (self.water_properties[0] is not None): # If the water layer is specified by depth, reset everything shallower if self.water_properties[0] == 'depth': loc = np.where(ZZ < self._find_min_max_water_depth()) vp0[loc] = vp[loc] # If the water mask is set, reset the masked values. elif self.water_properties[0] == 'mask': mask = self._load_scaled_parameter_array('water') self._water_mask = mask loc = np.where(mask != 0.0) vp0[loc] = vp[loc] # Construct final padded velocity profiles C = vp.reshape(self._mesh.shape()) C0 = vp0.reshape(self._mesh.shape()) self._true_model = C self._initial_model = C0
def rebuild_models(self): """ Rebuild the true and initial models based on the current configuration.""" sh = self._mesh.shape(as_grid=True) _shape_tuple = tuple([1]*(len(sh)-1) + [sh[-1]]) # ones in each dimension except for Z _pad_tuple = [(0,n-1) for n in sh] _pad_tuple[-1] = (0,0) _pad_tuple = tuple(_pad_tuple) # Construct true velocity profile vp = np.zeros(_shape_tuple) grid = self._mesh.mesh_coords(sparse=True) ZZ = grid[-1].reshape(_shape_tuple) total_filled = 0 for L in self.layers[::-1]: cutoff_depth = self.z_length - total_filled vp[ZZ <= cutoff_depth] = L.velocity total_filled += L.thickness # Construct initial velocity profile: if self.initial_model_style == 'constant': # initial_config = {'velocity': 3000.0} vp0 = np.ones(_shape_tuple)*self.initial_config['velocity'] elif self.initial_model_style == 'true': # initial_config = {}, set the initial model as the true model vp0 = vp.reshape(-1, ) vp0.shape = vp.shape elif self.initial_model_style == 'smooth': #initial_config = {'sigma':50.0, 'filtersize':8} vp0 = blur_image(vp.reshape(-1,), self.initial_config['filtersize'], self.initial_config['sigma'], mesh_deltas=(self._mesh.z.delta,)) vp0.shape = vp.shape elif self.initial_model_style == 'gradient': # initial_config = {} # collect the non-fixed layers for choosing the gradient bounds velocities = [L.velocity for L in self.layers if not L.fixed] cutoff_depth = 0 # find the first non-fixed layer to start the gradient at. for L in self.layers: if L.fixed: cutoff_depth += L.thickness else: break vp0 = vp.copy() loc = np.where(ZZ > cutoff_depth) vp0[loc] = np.linspace(min(velocities), max(velocities), loc[0].size) # Fix the fixed layers old_depth = 0 for L in self.layers: depth = old_depth + L.thickness if L.fixed: vp0[(ZZ >= old_depth) & (ZZ < depth)] = L.velocity old_depth = depth # Construct final padded velocity profiles C = np.pad(vp, _pad_tuple, 'edge').reshape(self._mesh.shape()) C0 = np.pad(vp0, _pad_tuple, 'edge').reshape(self._mesh.shape()) self._true_model = C self._initial_model = C0
def rebuild_models(self): """ Rebuild the true and initial models based on the current configuration.""" # Get the list of parameters required for the current physics parameter_names = self.physics_to_parameters_map[self.physics] # Get a list of properly scaled and cropped parameters arrays for each of those parameters parameter_arrays = [ self._load_scaled_parameter_array(p) for p in parameter_names ] # Velocity only, at the moment # Eventually all of this will need to be done for each model parameter vp = parameter_arrays[0] # Extract the depth coordinates of the grid points grid = self._mesh.mesh_coords() ZZ = grid[-1].reshape(vp.shape) # Copy the default values for the initial model style config = dict(self._initial_configs[self.initial_model_style]) # Override them with user provided values config.update(self.initial_config) # Construct initial velocity profile: if self.initial_model_style == 'constant': vp0 = np.ones(vp.shape) * config['velocity'] elif self.initial_model_style == 'smooth_width': vp0 = blur_image(vp, sigma=config['sigma'], mesh_deltas=self._mesh.deltas) elif self.initial_model_style == 'smooth_low_pass': vp0 = blur_image(vp, freq=config['freq'], mesh_deltas=self._mesh.deltas) elif self.initial_model_style == 'gradient': # construct the N-D depth trace shape, which is 1 in every dimension # except the depth direction sh = self._mesh.shape(as_grid=True) _shape_tuple = tuple([1] * (len(sh) - 1) + [sh[-1]]) # Construct the shape of the padding, which is 0 padding in the depth # direction and n pixels in each other direction _pad_tuple = [(0, n - 1) for n in sh] _pad_tuple[-1] = (0, 0) _pad_tuple = tuple(_pad_tuple) # If the water is to be fixed, the gradient is started at the # shallowest water-rock interaction. Otherwise, start at the top. if self.fix_water_layer and (self.water_properties[0] is not None): grid_sparse = self._mesh.mesh_coords(sparse=True) ZZZ = grid_sparse[-1].reshape(_shape_tuple) min_max_depth = self._find_min_max_water_depth() loc = np.where(ZZZ > min_max_depth) zprof = np.zeros(_shape_tuple) zprof[loc] = np.linspace(config['min'], config['max'], loc[0].size) else: zprof = np.linspace(config['min'], config['max'], self._mesh.z.n) zprof.shape = _shape_tuple # Pad out the gradient. vp0 = np.pad(zprof, _pad_tuple, 'edge') if self.fix_water_layer and (self.water_properties[0] is not None): # If the water layer is specified by depth, reset everything shallower if self.water_properties[0] == 'depth': loc = np.where(ZZ < self._find_min_max_water_depth()) vp0[loc] = vp[loc] # If the water mask is set, reset the masked values. elif self.water_properties[0] == 'mask': mask = self._load_scaled_parameter_array('water') self._water_mask = mask loc = np.where(mask != 0.0) vp0[loc] = vp[loc] # Construct final padded velocity profiles C = vp.reshape(self._mesh.shape()) C0 = vp0.reshape(self._mesh.shape()) self._true_model = C self._initial_model = C0
def rebuild_models(self): """ Rebuild the true and initial models based on the current configuration.""" sh = self._mesh.shape(as_grid=True) _shape_tuple = tuple([1]*(len(sh)-1) + [sh[-1]]) # ones in each dimension except for Z _pad_tuple = [(0,n-1) for n in sh] _pad_tuple[-1] = (0,0) _pad_tuple = tuple(_pad_tuple) # Construct true velocity profile vp = np.zeros(_shape_tuple) grid = self._mesh.mesh_coords(sparse=True) ZZ = grid[-1].reshape(_shape_tuple) total_filled = 0 for L in self.layers[::-1]: cutoff_depth = self.z_length - total_filled vp[ZZ <= cutoff_depth] = L.velocity total_filled += L.thickness # Construct initial velocity profile: if self.initial_model_style == 'constant': # initial_config = {'velocity': 3000.0} vp0 = np.ones(_shape_tuple)*self.initial_config['velocity'] elif self.initial_model_style == 'smooth': #initial_config = {'sigma':50.0, 'filtersize':8} vp0 = blur_image(vp.reshape(-1,), self.initial_config['filtersize'], self.initial_config['sigma'], mesh_deltas=(self._mesh.z.delta,)) vp0.shape = vp.shape elif self.initial_model_style == 'gradient': # initial_config = {} # collect the non-fixed layers for choosing the gradient bounds velocities = [L.velocity for L in self.layers if not L.fixed] cutoff_depth = 0 # find the first non-fixed layer to start the gradient at. for L in self.layers: if L.fixed: cutoff_depth += L.thickness else: break vp0 = vp.copy() loc = np.where(ZZ > cutoff_depth) vp0[loc] = np.linspace(min(velocities), max(velocities), loc[0].size) # Fix the fixed layers old_depth = 0 for L in self.layers: depth = old_depth + L.thickness if L.fixed: vp0[(ZZ >= old_depth) & (ZZ < depth)] = L.velocity old_depth = depth # Construct final padded velocity profiles C = np.pad(vp, _pad_tuple, 'edge').reshape(self._mesh.shape()) C0 = np.pad(vp0, _pad_tuple, 'edge').reshape(self._mesh.shape()) self._true_model = C self._initial_model = C0