def __init__(self, x, y, z, val, variogram_model='linear', variogram_parameters=None, variogram_function=None, nlags=6, weight=False, anisotropy_scaling_y=1.0, anisotropy_scaling_z=1.0, anisotropy_angle_x=0.0, anisotropy_angle_y=0.0, anisotropy_angle_z=0.0, verbose=False, enable_plotting=False): # Code assumes 1D input arrays. Ensures that any extraneous dimensions # don't get in the way. Copies are created to avoid any problems with # referencing the original passed arguments. self.X_ORIG = np.atleast_1d(np.squeeze(np.array(x, copy=True))) self.Y_ORIG = np.atleast_1d(np.squeeze(np.array(y, copy=True))) self.Z_ORIG = np.atleast_1d(np.squeeze(np.array(z, copy=True))) self.VALUES = np.atleast_1d(np.squeeze(np.array(val, copy=True))) self.verbose = verbose self.enable_plotting = enable_plotting if self.enable_plotting and self.verbose: print "Plotting Enabled\n" self.XCENTER = (np.amax(self.X_ORIG) + np.amin(self.X_ORIG)) / 2.0 self.YCENTER = (np.amax(self.Y_ORIG) + np.amin(self.Y_ORIG)) / 2.0 self.ZCENTER = (np.amax(self.Z_ORIG) + np.amin(self.Z_ORIG)) / 2.0 self.anisotropy_scaling_y = anisotropy_scaling_y self.anisotropy_scaling_z = anisotropy_scaling_z self.anisotropy_angle_x = anisotropy_angle_x self.anisotropy_angle_y = anisotropy_angle_y self.anisotropy_angle_z = anisotropy_angle_z if self.verbose: print "Adjusting data for anisotropy..." self.X_ADJUSTED, self.Y_ADJUSTED, self.Z_ADJUSTED = \ core.adjust_for_anisotropy_3d(np.copy(self.X_ORIG), np.copy(self.Y_ORIG), np.copy(self.Z_ORIG), self.XCENTER, self.YCENTER, self.ZCENTER, self.anisotropy_scaling_y, self.anisotropy_scaling_z, self.anisotropy_angle_x, self.anisotropy_angle_y, self.anisotropy_angle_z) self.variogram_model = variogram_model if self.variogram_model not in self.variogram_dict.keys( ) and self.variogram_model != 'custom': raise ValueError( "Specified variogram model '%s' is not supported." % variogram_model) elif self.variogram_model == 'custom': if variogram_function is None or not callable(variogram_function): raise ValueError( "Must specify callable function for custom variogram model." ) else: self.variogram_function = variogram_function else: self.variogram_function = self.variogram_dict[self.variogram_model] if self.verbose: print "Initializing variogram model..." self.lags, self.semivariance, self.variogram_model_parameters = \ core.initialize_variogram_model_3d(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z_ADJUSTED, self.VALUES, self.variogram_model, variogram_parameters, self.variogram_function, nlags, weight) if self.verbose: if self.variogram_model == 'linear': print "Using '%s' Variogram Model" % 'linear' print "Slope:", self.variogram_model_parameters[0] print "Nugget:", self.variogram_model_parameters[1], '\n' elif self.variogram_model == 'power': print "Using '%s' Variogram Model" % 'power' print "Scale:", self.variogram_model_parameters[0] print "Exponent:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' elif self.variogram_model == 'custom': print "Using Custom Variogram Model" else: print "Using '%s' Variogram Model" % self.variogram_model print "Sill:", self.variogram_model_parameters[0] print "Range:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' if self.enable_plotting: self.display_variogram_model() if self.verbose: print "Calculating statistics on variogram model fit..." self.delta, self.sigma, self.epsilon = core.find_statistics_3d( self.X_ADJUSTED, self.Y_ADJUSTED, self.Z_ADJUSTED, self.VALUES, self.variogram_function, self.variogram_model_parameters) self.Q1 = core.calcQ1(self.epsilon) self.Q2 = core.calcQ2(self.epsilon) self.cR = core.calc_cR(self.Q2, self.sigma) if self.verbose: print "Q1 =", self.Q1 print "Q2 =", self.Q2 print "cR =", self.cR, '\n'
def update_variogram_model(self, variogram_model, variogram_parameters=None, variogram_function=None, nlags=6, weight=False, anisotropy_scaling_y=1.0, anisotropy_scaling_z=1.0, anisotropy_angle_x=0.0, anisotropy_angle_y=0.0, anisotropy_angle_z=0.0): """Allows user to update variogram type and/or variogram model parameters.""" if anisotropy_scaling_y != self.anisotropy_scaling_y or anisotropy_scaling_z != self.anisotropy_scaling_z or \ anisotropy_angle_x != self.anisotropy_angle_x or anisotropy_angle_y != self.anisotropy_angle_y or \ anisotropy_angle_z != self.anisotropy_angle_z: if self.verbose: print "Adjusting data for anisotropy..." self.anisotropy_scaling_y = anisotropy_scaling_y self.anisotropy_scaling_z = anisotropy_scaling_z self.anisotropy_angle_x = anisotropy_angle_x self.anisotropy_angle_y = anisotropy_angle_y self.anisotropy_angle_z = anisotropy_angle_z self.X_ADJUSTED, self.Y_ADJUSTED, self.Z_ADJUSTED = \ core.adjust_for_anisotropy_3d(np.copy(self.X_ORIG), np.copy(self.Y_ORIG), np.copy(self.Z_ORIG), self.XCENTER, self.YCENTER, self.ZCENTER, self.anisotropy_scaling_y, self.anisotropy_scaling_z, self.anisotropy_angle_x, self.anisotropy_angle_y, self.anisotropy_angle_z) self.variogram_model = variogram_model if self.variogram_model not in self.variogram_dict.keys( ) and self.variogram_model != 'custom': raise ValueError( "Specified variogram model '%s' is not supported." % variogram_model) elif self.variogram_model == 'custom': if variogram_function is None or not callable(variogram_function): raise ValueError( "Must specify callable function for custom variogram model." ) else: self.variogram_function = variogram_function else: self.variogram_function = self.variogram_dict[self.variogram_model] if self.verbose: print "Updating variogram mode..." self.lags, self.semivariance, self.variogram_model_parameters = \ core.initialize_variogram_model_3d(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z_ADJUSTED, self.VALUES, self.variogram_model, variogram_parameters, self.variogram_function, nlags, weight) if self.verbose: if self.variogram_model == 'linear': print "Using '%s' Variogram Model" % 'linear' print "Slope:", self.variogram_model_parameters[0] print "Nugget:", self.variogram_model_parameters[1], '\n' elif self.variogram_model == 'power': print "Using '%s' Variogram Model" % 'power' print "Scale:", self.variogram_model_parameters[0] print "Exponent:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' elif self.variogram_model == 'custom': print "Using Custom Variogram Model" else: print "Using '%s' Variogram Model" % self.variogram_model print "Sill:", self.variogram_model_parameters[0] print "Range:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' if self.enable_plotting: self.display_variogram_model() if self.verbose: print "Calculating statistics on variogram model fit..." self.delta, self.sigma, self.epsilon = core.find_statistics_3d( self.X_ADJUSTED, self.Y_ADJUSTED, self.Z_ADJUSTED, self.VALUES, self.variogram_function, self.variogram_model_parameters) self.Q1 = core.calcQ1(self.epsilon) self.Q2 = core.calcQ2(self.epsilon) self.cR = core.calc_cR(self.Q2, self.sigma) if self.verbose: print "Q1 =", self.Q1 print "Q2 =", self.Q2 print "cR =", self.cR, '\n'
def __init__(self, x, y, z, variogram_model='linear', variogram_parameters=None, variogram_function=None, nlags=6, weight=False, anisotropy_scaling=1.0, anisotropy_angle=0.0, verbose=False, enable_plotting=False, enable_statistics=False): # Code assumes 1D input arrays. Ensures that any extraneous dimensions # don't get in the way. Copies are created to avoid any problems with # referencing the original passed arguments. self.X_ORIG = np.atleast_1d(np.squeeze(np.array(x, copy=True))) self.Y_ORIG = np.atleast_1d(np.squeeze(np.array(y, copy=True))) self.Z = np.atleast_1d(np.squeeze(np.array(z, copy=True))) self.verbose = verbose self.enable_plotting = enable_plotting if self.enable_plotting and self.verbose: print "Plotting Enabled\n" self.XCENTER = (np.amax(self.X_ORIG) + np.amin(self.X_ORIG))/2.0 self.YCENTER = (np.amax(self.Y_ORIG) + np.amin(self.Y_ORIG))/2.0 self.anisotropy_scaling = anisotropy_scaling self.anisotropy_angle = anisotropy_angle if self.verbose: print "Adjusting data for anisotropy..." self.X_ADJUSTED, self.Y_ADJUSTED = \ core.adjust_for_anisotropy(np.copy(self.X_ORIG), np.copy(self.Y_ORIG), self.XCENTER, self.YCENTER, self.anisotropy_scaling, self.anisotropy_angle) self.variogram_model = variogram_model if self.variogram_model not in self.variogram_dict.keys() and self.variogram_model != 'custom': raise ValueError("Specified variogram model '%s' is not supported." % variogram_model) elif self.variogram_model == 'custom': if variogram_function is None or not callable(variogram_function): raise ValueError("Must specify callable function for custom variogram model.") else: self.variogram_function = variogram_function else: self.variogram_function = self.variogram_dict[self.variogram_model] if self.verbose: print "Initializing variogram model..." self.lags, self.semivariance, self.variogram_model_parameters = \ core.initialize_variogram_model(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z, self.variogram_model, variogram_parameters, self.variogram_function, nlags, weight) if self.verbose: if self.variogram_model == 'linear': print "Using '%s' Variogram Model" % 'linear' print "Slope:", self.variogram_model_parameters[0] print "Nugget:", self.variogram_model_parameters[1], '\n' elif self.variogram_model == 'power': print "Using '%s' Variogram Model" % 'power' print "Scale:", self.variogram_model_parameters[0] print "Exponent:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' elif self.variogram_model == 'custom': print "Using Custom Variogram Model" else: print "Using '%s' Variogram Model" % self.variogram_model print "Sill:", self.variogram_model_parameters[0] print "Range:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' if self.enable_plotting: self.display_variogram_model() if self.verbose: print "Calculating statistics on variogram model fit..." if enable_statistics: self.delta, self.sigma, self.epsilon = core.find_statistics(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z, self.variogram_function, self.variogram_model_parameters) self.Q1 = core.calcQ1(self.epsilon) self.Q2 = core.calcQ2(self.epsilon) self.cR = core.calc_cR(self.Q2, self.sigma) if self.verbose: print "Q1 =", self.Q1 print "Q2 =", self.Q2 print "cR =", self.cR, '\n' else: self.delta, self.sigma, self.epsilon, self.Q1, self.Q2, self.cR = [None]*6
def update_variogram_model(self, variogram_model, variogram_parameters=None, variogram_function=None, nlags=6, weight=False, anisotropy_scaling=1.0, anisotropy_angle=0.0): """Allows user to update variogram type and/or variogram model parameters.""" if anisotropy_scaling != self.anisotropy_scaling or \ anisotropy_angle != self.anisotropy_angle: if self.verbose: print "Adjusting data for anisotropy..." self.anisotropy_scaling = anisotropy_scaling self.anisotropy_angle = anisotropy_angle self.X_ADJUSTED, self.Y_ADJUSTED = \ core.adjust_for_anisotropy(np.copy(self.X_ORIG), np.copy(self.Y_ORIG), self.XCENTER, self.YCENTER, self.anisotropy_scaling, self.anisotropy_angle) self.variogram_model = variogram_model if self.variogram_model not in self.variogram_dict.keys() and self.variogram_model != 'custom': raise ValueError("Specified variogram model '%s' is not supported." % variogram_model) elif self.variogram_model == 'custom': if variogram_function is None or not callable(variogram_function): raise ValueError("Must specify callable function for custom variogram model.") else: self.variogram_function = variogram_function else: self.variogram_function = self.variogram_dict[self.variogram_model] if self.verbose: print "Updating variogram mode..." self.lags, self.semivariance, self.variogram_model_parameters = \ core.initialize_variogram_model(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z, self.variogram_model, variogram_parameters, self.variogram_function, nlags, weight) if self.verbose: if self.variogram_model == 'linear': print "Using '%s' Variogram Model" % 'linear' print "Slope:", self.variogram_model_parameters[0] print "Nugget:", self.variogram_model_parameters[1], '\n' elif self.variogram_model == 'power': print "Using '%s' Variogram Model" % 'power' print "Scale:", self.variogram_model_parameters[0] print "Exponent:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' elif self.variogram_model == 'custom': print "Using Custom Variogram Model" else: print "Using '%s' Variogram Model" % self.variogram_model print "Sill:", self.variogram_model_parameters[0] print "Range:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' if self.enable_plotting: self.display_variogram_model() if self.verbose: print "Calculating statistics on variogram model fit..." self.delta, self.sigma, self.epsilon = core.find_statistics(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z, self.variogram_function, self.variogram_model_parameters) self.Q1 = core.calcQ1(self.epsilon) self.Q2 = core.calcQ2(self.epsilon) self.cR = core.calc_cR(self.Q2, self.sigma) if self.verbose: print "Q1 =", self.Q1 print "Q2 =", self.Q2 print "cR =", self.cR, '\n'
def update_variogram_model(self, variogram_model, variogram_parameters=None, nlags=6, anisotropy_scaling=1.0, anisotropy_angle=0.0): """Allows user to update variogram type and/or variogram model parameters.""" if anisotropy_scaling != self.anisotropy_scaling or \ anisotropy_angle != self.anisotropy_angle: if self.verbose: print "Adjusting data for anisotropy..." self.anisotropy_scaling = anisotropy_scaling self.anisotropy_angle = anisotropy_angle self.X_ADJUSTED, self.Y_ADJUSTED = \ core.adjust_for_anisotropy(np.copy(self.X_ORIG), np.copy(self.Y_ORIG), self.XCENTER, self.YCENTER, self.anisotropy_scaling, self.anisotropy_angle) self.variogram_model = variogram_model if self.variogram_model == 'linear': self.variogram_function = variogram_models.linear_variogram_model if self.variogram_model == 'power': self.variogram_function = variogram_models.power_variogram_model if self.variogram_model == 'gaussian': self.variogram_function = variogram_models.gaussian_variogram_model if self.variogram_model == 'spherical': self.variogram_function = variogram_models.spherical_variogram_model if self.variogram_model == 'exponential': self.variogram_function = variogram_models.exponential_variogram_model if self.verbose: print "Updating variogram mode..." self.lags, self.semivariance, self.variogram_model_parameters = \ core.initialize_variogram_model(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z, self.variogram_model, variogram_parameters, self.variogram_function, nlags) if self.verbose: if self.variogram_model == 'linear': print "Using '%s' Variogram Model" % 'linear' print "Slope:", self.variogram_model_parameters[0] print "Nugget:", self.variogram_model_parameters[1], '\n' elif self.variogram_model == 'power': print "Using '%s' Variogram Model" % 'power' print "Scale:", self.variogram_model_parameters[0] print "Exponent:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' else: print "Using '%s' Variogram Model" % self.variogram_model print "Sill:", self.variogram_model_parameters[0] print "Range:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' if self.enable_plotting: self.display_variogram_model() if self.verbose: print "Calculating statistics on variogram model fit..." self.delta, self.sigma, self.epsilon = core.find_statistics(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z, self.variogram_function, self.variogram_model_parameters) self.Q1 = core.calcQ1(self.epsilon) self.Q2 = core.calcQ2(self.epsilon) self.cR = core.calc_cR(self.Q2, self.sigma) if self.verbose: print "Q1 =", self.Q1 print "Q2 =", self.Q2 print "cR =", self.cR, '\n'
def __init__(self, x, y, z, val, variogram_model='linear', variogram_parameters=None, variogram_function=None, nlags=6, weight=False, anisotropy_scaling_y=1.0, anisotropy_scaling_z=1.0, anisotropy_angle_x=0.0, anisotropy_angle_y=0.0, anisotropy_angle_z=0.0, drift_terms=None, specified_drift=None, functional_drift=None, verbose=False, enable_plotting=False): # Deal with mutable default argument if drift_terms is None: drift_terms = [] if specified_drift is None: specified_drift = [] if functional_drift is None: functional_drift = [] # Code assumes 1D input arrays. Ensures that any extraneous dimensions # don't get in the way. Copies are created to avoid any problems with # referencing the original passed arguments. self.X_ORIG = np.atleast_1d(np.squeeze(np.array(x, copy=True))) self.Y_ORIG = np.atleast_1d(np.squeeze(np.array(y, copy=True))) self.Z_ORIG = np.atleast_1d(np.squeeze(np.array(z, copy=True))) self.VALUES = np.atleast_1d(np.squeeze(np.array(val, copy=True))) self.verbose = verbose self.enable_plotting = enable_plotting if self.enable_plotting and self.verbose: print "Plotting Enabled\n" self.XCENTER = (np.amax(self.X_ORIG) + np.amin(self.X_ORIG))/2.0 self.YCENTER = (np.amax(self.Y_ORIG) + np.amin(self.Y_ORIG))/2.0 self.ZCENTER = (np.amax(self.Z_ORIG) + np.amin(self.Z_ORIG))/2.0 self.anisotropy_scaling_y = anisotropy_scaling_y self.anisotropy_scaling_z = anisotropy_scaling_z self.anisotropy_angle_x = anisotropy_angle_x self.anisotropy_angle_y = anisotropy_angle_y self.anisotropy_angle_z = anisotropy_angle_z if self.verbose: print "Adjusting data for anisotropy..." self.X_ADJUSTED, self.Y_ADJUSTED, self.Z_ADJUSTED = \ core.adjust_for_anisotropy_3d(np.copy(self.X_ORIG), np.copy(self.Y_ORIG), np.copy(self.Z_ORIG), self.XCENTER, self.YCENTER, self.ZCENTER, self.anisotropy_scaling_y, self.anisotropy_scaling_z, self.anisotropy_angle_x, self.anisotropy_angle_y, self.anisotropy_angle_z) self.variogram_model = variogram_model if self.variogram_model not in self.variogram_dict.keys() and self.variogram_model != 'custom': raise ValueError("Specified variogram model '%s' is not supported." % variogram_model) elif self.variogram_model == 'custom': if variogram_function is None or not callable(variogram_function): raise ValueError("Must specify callable function for custom variogram model.") else: self.variogram_function = variogram_function else: self.variogram_function = self.variogram_dict[self.variogram_model] if self.verbose: print "Initializing variogram model..." self.lags, self.semivariance, self.variogram_model_parameters = \ core.initialize_variogram_model_3d(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z_ADJUSTED, self.VALUES, self.variogram_model, variogram_parameters, self.variogram_function, nlags, weight) if self.verbose: if self.variogram_model == 'linear': print "Using '%s' Variogram Model" % 'linear' print "Slope:", self.variogram_model_parameters[0] print "Nugget:", self.variogram_model_parameters[1], '\n' elif self.variogram_model == 'power': print "Using '%s' Variogram Model" % 'power' print "Scale:", self.variogram_model_parameters[0] print "Exponent:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' elif self.variogram_model == 'custom': print "Using Custom Variogram Model" else: print "Using '%s' Variogram Model" % self.variogram_model print "Sill:", self.variogram_model_parameters[0] print "Range:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' if self.enable_plotting: self.display_variogram_model() if self.verbose: print "Calculating statistics on variogram model fit..." self.delta, self.sigma, self.epsilon = core.find_statistics_3d(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z_ADJUSTED, self.VALUES, self.variogram_function, self.variogram_model_parameters) self.Q1 = core.calcQ1(self.epsilon) self.Q2 = core.calcQ2(self.epsilon) self.cR = core.calc_cR(self.Q2, self.sigma) if self.verbose: print "Q1 =", self.Q1 print "Q2 =", self.Q2 print "cR =", self.cR, '\n' if self.verbose: print "Initializing drift terms..." # Note that the regional linear drift values will be based on the adjusted coordinate system. # Really, it doesn't actually matter which coordinate system is used here. if 'regional_linear' in drift_terms: self.regional_linear_drift = True if self.verbose: print "Implementing regional linear drift." else: self.regional_linear_drift = False if 'specified' in drift_terms: if type(specified_drift) is not list: raise TypeError("Arrays for specified drift terms must be encapsulated in a list.") if len(specified_drift) == 0: raise ValueError("Must provide at least one drift-value array when using the " "'specified' drift capability.") self.specified_drift = True self.specified_drift_data_arrays = [] for term in specified_drift: specified = np.squeeze(np.array(term, copy=True)) if specified.size != self.X_ORIG.size: raise ValueError("Must specify the drift values for each data point when using the " "'specified' drift capability.") self.specified_drift_data_arrays.append(specified) else: self.specified_drift = False # The provided callable functions will be evaluated using the adjusted coordinates. if 'functional' in drift_terms: if type(functional_drift) is not list: raise TypeError("Callables for functional drift terms must be encapsulated in a list.") if len(functional_drift) == 0: raise ValueError("Must provide at least one callable object when using the " "'functional' drift capability.") self.functional_drift = True self.functional_drift_terms = functional_drift else: self.functional_drift = False
def __init__(self, x, y, z, variogram_model='linear', variogram_parameters=None, nlags=6, anisotropy_scaling=1.0, anisotropy_angle=0.0, verbose=False, enable_plotting=False): # Code assumes 1D input arrays. Ensures that this is the case. self.X_ORIG = np.array(x).flatten() self.Y_ORIG = np.array(y).flatten() self.Z = np.array(z).flatten() self.verbose = verbose self.enable_plotting = enable_plotting if self.enable_plotting and self.verbose: print "Plotting Enabled\n" self.XCENTER = (np.amax(self.X_ORIG) + np.amin(self.X_ORIG))/2.0 self.YCENTER = (np.amax(self.Y_ORIG) + np.amin(self.Y_ORIG))/2.0 self.anisotropy_scaling = anisotropy_scaling self.anisotropy_angle = anisotropy_angle if self.verbose: print "Adjusting data for anisotropy..." self.X_ADJUSTED, self.Y_ADJUSTED = \ core.adjust_for_anisotropy(np.copy(self.X_ORIG), np.copy(self.Y_ORIG), self.XCENTER, self.YCENTER, self.anisotropy_scaling, self.anisotropy_angle) self.variogram_model = variogram_model if self.variogram_model == 'linear': self.variogram_function = variogram_models.linear_variogram_model if self.variogram_model == 'power': self.variogram_function = variogram_models.power_variogram_model if self.variogram_model == 'gaussian': self.variogram_function = variogram_models.gaussian_variogram_model if self.variogram_model == 'spherical': self.variogram_function = variogram_models.spherical_variogram_model if self.variogram_model == 'exponential': self.variogram_function = variogram_models.exponential_variogram_model if self.verbose: print "Initializing variogram model..." self.lags, self.semivariance, self.variogram_model_parameters = \ core.initialize_variogram_model(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z, self.variogram_model, variogram_parameters, self.variogram_function, nlags) if self.verbose: if self.variogram_model == 'linear': print "Using '%s' Variogram Model" % 'linear' print "Slope:", self.variogram_model_parameters[0] print "Nugget:", self.variogram_model_parameters[1], '\n' elif self.variogram_model == 'power': print "Using '%s' Variogram Model" % 'power' print "Scale:", self.variogram_model_parameters[0] print "Exponent:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' else: print "Using '%s' Variogram Model" % self.variogram_model print "Sill:", self.variogram_model_parameters[0] print "Range:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' if self.enable_plotting: self.display_variogram_model() if self.verbose: print "Calculating statistics on variogram model fit..." self.delta, self.sigma, self.epsilon = core.find_statistics(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z, self.variogram_function, self.variogram_model_parameters) self.Q1 = core.calcQ1(self.epsilon) self.Q2 = core.calcQ2(self.epsilon) self.cR = core.calc_cR(self.Q2, self.sigma) if self.verbose: print "Q1 =", self.Q1 print "Q2 =", self.Q2 print "cR =", self.cR, '\n'
def __init__(self, x, y, z, variogram_model='linear', variogram_parameters=None, nlags=6, anisotropy_scaling=1.0, anisotropy_angle=0.0, drift_terms=[None], point_drift=None, external_drift=None, external_drift_x=None, external_drift_y=None, external_drift_xspacing=None, external_drift_yspacing=None, verbose=False, enable_plotting=False): # Code assumes 1D input arrays. Ensures that this is the case. self.X_ORIG = np.array(x).flatten() self.Y_ORIG = np.array(y).flatten() self.Z = np.array(z).flatten() self.verbose = verbose self.enable_plotting = enable_plotting if self.enable_plotting and self.verbose: print "Plotting Enabled\n" self.XCENTER = (np.amax(self.X_ORIG) + np.amin(self.X_ORIG))/2.0 self.YCENTER = (np.amax(self.Y_ORIG) + np.amin(self.Y_ORIG))/2.0 self.anisotropy_scaling = anisotropy_scaling self.anisotropy_angle = anisotropy_angle if self.verbose: print "Adjusting data for anisotropy..." self.X_ADJUSTED, self.Y_ADJUSTED = \ core.adjust_for_anisotropy(np.copy(self.X_ORIG), np.copy(self.Y_ORIG), self.XCENTER, self.YCENTER, self.anisotropy_scaling, self.anisotropy_angle) self.variogram_model = variogram_model if self.variogram_model == 'linear': self.variogram_function = variogram_models.linear_variogram_model if self.variogram_model == 'power': self.variogram_function = variogram_models.power_variogram_model if self.variogram_model == 'gaussian': self.variogram_function = variogram_models.gaussian_variogram_model if self.variogram_model == 'spherical': self.variogram_function = variogram_models.spherical_variogram_model if self.variogram_model == 'exponential': self.variogram_function = variogram_models.exponential_variogram_model if self.verbose: print "Initializing variogram model..." self.lags, self.semivariance, self.variogram_model_parameters = \ core.initialize_variogram_model(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z, self.variogram_model, variogram_parameters, self.variogram_function, nlags) if self.verbose: if self.variogram_model == 'linear': print "Using '%s' Variogram Model" % 'linear' print "Slope:", self.variogram_model_parameters[0] print "Nugget:", self.variogram_model_parameters[1], '\n' elif self.variogram_model == 'power': print "Using '%s' Variogram Model" % 'power' print "Scale:", self.variogram_model_parameters[0] print "Exponent:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' else: print "Using '%s' Variogram Model" % self.variogram_model print "Sill:", self.variogram_model_parameters[0] print "Range:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2] if self.enable_plotting: self.display_variogram_model() if self.verbose: print "Calculating statistics on variogram model fit..." self.delta, self.sigma, self.epsilon = core.find_statistics(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z, self.variogram_function, self.variogram_model_parameters) self.Q1 = core.calcQ1(self.epsilon) self.Q2 = core.calcQ2(self.epsilon) self.cR = core.calc_cR(self.Q2, self.sigma) if self.verbose: print "Q1 =", self.Q1 print "Q2 =", self.Q2 print "cR =", self.cR, '\n' if self.verbose: print "Initializing drift terms..." if 'regional_linear' in drift_terms: self.regional_linear_drift = True if self.verbose: print "Implementing regional linear drift." else: self.regional_linear_drift = False if 'external_Z' in drift_terms: if external_drift is None: raise ValueError("Must specify external Z drift terms.") if external_drift_x is None or external_drift_y is None: raise ValueError("Must specify coordinates of external Z drift terms.") self.external_Z_drift = True self.external_Z_array = np.array(external_drift) self.external_Z_array_x = np.array(external_drift_x).flatten() self.external_Z_array_y = np.array(external_drift_y).flatten() if np.unique(self.external_Z_array_x[1:] - self.external_Z_array_x[:-1]).size != 1: if external_drift_xspacing is None: raise ValueError("X-coordinate spacing is not constant. " "Must provide X-coordinate grid size.") else: self.external_Z_array_x_spacing = np.array(external_drift_xspacing).flatten() else: self.external_Z_array_x_spacing = np.zeros(self.external_Z_array_x.shape) self.external_Z_array_x_spacing.fill( np.unique(self.external_Z_array_x[1:] - self.external_Z_array_x[:-1])[0]) if np.unique(self.external_Z_array_y[1:] - self.external_Z_array_y[:-1]).size != 1: if external_drift_yspacing is None: raise ValueError("Y-coordinate spacing is not constant. " "Must provide Y-coordinate grid size.") else: self.external_Z_array_y_spacing = np.array(external_drift_yspacing).flatten() else: self.external_Z_array_y_spacing = np.zeros(self.external_Z_array_y.shape) self.external_Z_array_y_spacing.fill( np.unique(self.external_Z_array_y[1:] - self.external_Z_array_y[:-1])[0]) self.z_scalars = self._calculate_data_point_zscalars(self.X_ORIG, self.Y_ORIG) if self.verbose: print "Implementing external Z drift." else: self.external_Z_drift = False if 'point_log' in drift_terms: if point_drift is None: raise ValueError("Must specify location(s) and strength(s) of point drift terms.") self.point_log_drift = True self.point_log_array = np.atleast_2d(np.array(point_drift)) if self.verbose: print "Implementing external point-logarithmic drift; " \ "number of points =", self.point_log_array.shape[0], '\n' else: self.point_log_drift = False
def __init__(self, x, y, z, val, variogram_model='linear', variogram_parameters=None, variogram_function=None, nlags=6, weight=False, anisotropy_scaling_y=1.0, anisotropy_scaling_z=1.0, anisotropy_angle_x=0.0, anisotropy_angle_y=0.0, anisotropy_angle_z=0.0, drift_terms=None, specified_drift=None, functional_drift=None, verbose=False, enable_plotting=False): # Deal with mutable default argument if drift_terms is None: drift_terms = [] if specified_drift is None: specified_drift = [] if functional_drift is None: functional_drift = [] # Code assumes 1D input arrays. Ensures that any extraneous dimensions # don't get in the way. Copies are created to avoid any problems with # referencing the original passed arguments. self.X_ORIG = np.atleast_1d(np.squeeze(np.array(x, copy=True))) self.Y_ORIG = np.atleast_1d(np.squeeze(np.array(y, copy=True))) self.Z_ORIG = np.atleast_1d(np.squeeze(np.array(z, copy=True))) self.VALUES = np.atleast_1d(np.squeeze(np.array(val, copy=True))) self.verbose = verbose self.enable_plotting = enable_plotting if self.enable_plotting and self.verbose: print "Plotting Enabled\n" self.XCENTER = (np.amax(self.X_ORIG) + np.amin(self.X_ORIG)) / 2.0 self.YCENTER = (np.amax(self.Y_ORIG) + np.amin(self.Y_ORIG)) / 2.0 self.ZCENTER = (np.amax(self.Z_ORIG) + np.amin(self.Z_ORIG)) / 2.0 self.anisotropy_scaling_y = anisotropy_scaling_y self.anisotropy_scaling_z = anisotropy_scaling_z self.anisotropy_angle_x = anisotropy_angle_x self.anisotropy_angle_y = anisotropy_angle_y self.anisotropy_angle_z = anisotropy_angle_z if self.verbose: print "Adjusting data for anisotropy..." self.X_ADJUSTED, self.Y_ADJUSTED, self.Z_ADJUSTED = \ core.adjust_for_anisotropy_3d(np.copy(self.X_ORIG), np.copy(self.Y_ORIG), np.copy(self.Z_ORIG), self.XCENTER, self.YCENTER, self.ZCENTER, self.anisotropy_scaling_y, self.anisotropy_scaling_z, self.anisotropy_angle_x, self.anisotropy_angle_y, self.anisotropy_angle_z) self.variogram_model = variogram_model if self.variogram_model not in self.variogram_dict.keys( ) and self.variogram_model != 'custom': raise ValueError( "Specified variogram model '%s' is not supported." % variogram_model) elif self.variogram_model == 'custom': if variogram_function is None or not callable(variogram_function): raise ValueError( "Must specify callable function for custom variogram model." ) else: self.variogram_function = variogram_function else: self.variogram_function = self.variogram_dict[self.variogram_model] if self.verbose: print "Initializing variogram model..." self.lags, self.semivariance, self.variogram_model_parameters = \ core.initialize_variogram_model_3d(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z_ADJUSTED, self.VALUES, self.variogram_model, variogram_parameters, self.variogram_function, nlags, weight) if self.verbose: if self.variogram_model == 'linear': print "Using '%s' Variogram Model" % 'linear' print "Slope:", self.variogram_model_parameters[0] print "Nugget:", self.variogram_model_parameters[1], '\n' elif self.variogram_model == 'power': print "Using '%s' Variogram Model" % 'power' print "Scale:", self.variogram_model_parameters[0] print "Exponent:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' elif self.variogram_model == 'custom': print "Using Custom Variogram Model" else: print "Using '%s' Variogram Model" % self.variogram_model print "Sill:", self.variogram_model_parameters[0] print "Range:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' if self.enable_plotting: self.display_variogram_model() if self.verbose: print "Calculating statistics on variogram model fit..." self.delta, self.sigma, self.epsilon = core.find_statistics_3d( self.X_ADJUSTED, self.Y_ADJUSTED, self.Z_ADJUSTED, self.VALUES, self.variogram_function, self.variogram_model_parameters) self.Q1 = core.calcQ1(self.epsilon) self.Q2 = core.calcQ2(self.epsilon) self.cR = core.calc_cR(self.Q2, self.sigma) if self.verbose: print "Q1 =", self.Q1 print "Q2 =", self.Q2 print "cR =", self.cR, '\n' if self.verbose: print "Initializing drift terms..." # Note that the regional linear drift values will be based on the adjusted coordinate system. # Really, it doesn't actually matter which coordinate system is used here. if 'regional_linear' in drift_terms: self.regional_linear_drift = True if self.verbose: print "Implementing regional linear drift." else: self.regional_linear_drift = False if 'specified' in drift_terms: if type(specified_drift) is not list: raise TypeError( "Arrays for specified drift terms must be encapsulated in a list." ) if len(specified_drift) == 0: raise ValueError( "Must provide at least one drift-value array when using the " "'specified' drift capability.") self.specified_drift = True self.specified_drift_data_arrays = [] for term in specified_drift: specified = np.squeeze(np.array(term, copy=True)) if specified.size != self.X_ORIG.size: raise ValueError( "Must specify the drift values for each data point when using the " "'specified' drift capability.") self.specified_drift_data_arrays.append(specified) else: self.specified_drift = False # The provided callable functions will be evaluated using the adjusted coordinates. if 'functional' in drift_terms: if type(functional_drift) is not list: raise TypeError( "Callables for functional drift terms must be encapsulated in a list." ) if len(functional_drift) == 0: raise ValueError( "Must provide at least one callable object when using the " "'functional' drift capability.") self.functional_drift = True self.functional_drift_terms = functional_drift else: self.functional_drift = False
def update_variogram_model(self, variogram_model, variogram_parameters=None, nlags=6, weight=False, anisotropy_scaling=1.0, anisotropy_angle=0.0): """Allows user to update variogram type and/or variogram model parameters.""" if anisotropy_scaling != self.anisotropy_scaling or \ anisotropy_angle != self.anisotropy_angle: if self.verbose: print "Adjusting data for anisotropy..." self.anisotropy_scaling = anisotropy_scaling self.anisotropy_angle = anisotropy_angle self.X_ADJUSTED, self.Y_ADJUSTED = \ core.adjust_for_anisotropy(np.copy(self.X_ORIG), np.copy(self.Y_ORIG), self.XCENTER, self.YCENTER, self.anisotropy_scaling, self.anisotropy_angle) self.variogram_model = variogram_model if self.variogram_model == 'linear': self.variogram_function = variogram_models.linear_variogram_model elif self.variogram_model == 'power': self.variogram_function = variogram_models.power_variogram_model elif self.variogram_model == 'gaussian': self.variogram_function = variogram_models.gaussian_variogram_model elif self.variogram_model == 'spherical': self.variogram_function = variogram_models.spherical_variogram_model elif self.variogram_model == 'exponential': self.variogram_function = variogram_models.exponential_variogram_model else: raise ValueError( "Specified variogram model '%s' is not supported." % variogram_model) if self.verbose: print "Updating variogram mode..." self.lags, self.semivariance, self.variogram_model_parameters = \ core.initialize_variogram_model(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z, self.variogram_model, variogram_parameters, self.variogram_function, nlags, weight) if self.verbose: if self.variogram_model == 'linear': print "Using '%s' Variogram Model" % 'linear' print "Slope:", self.variogram_model_parameters[0] print "Nugget:", self.variogram_model_parameters[1], '\n' elif self.variogram_model == 'power': print "Using '%s' Variogram Model" % 'power' print "Scale:", self.variogram_model_parameters[0] print "Exponent:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' else: print "Using '%s' Variogram Model" % self.variogram_model print "Sill:", self.variogram_model_parameters[0] print "Range:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' if self.enable_plotting: self.display_variogram_model() if self.verbose: print "Calculating statistics on variogram model fit..." self.delta, self.sigma, self.epsilon = core.find_statistics( self.X_ADJUSTED, self.Y_ADJUSTED, self.Z, self.variogram_function, self.variogram_model_parameters) self.Q1 = core.calcQ1(self.epsilon) self.Q2 = core.calcQ2(self.epsilon) self.cR = core.calc_cR(self.Q2, self.sigma) if self.verbose: print "Q1 =", self.Q1 print "Q2 =", self.Q2 print "cR =", self.cR, '\n'
def __init__(self, x, y, z, variogram_model='linear', variogram_parameters=None, nlags=6, weight=False, anisotropy_scaling=1.0, anisotropy_angle=0.0, verbose=False, enable_plotting=False): # Code assumes 1D input arrays. Ensures that this is the case. # Copies are created to avoid any problems with referencing # the original passed arguments. self.X_ORIG = np.array(x, copy=True).flatten() self.Y_ORIG = np.array(y, copy=True).flatten() self.Z = np.array(z, copy=True).flatten() self.verbose = verbose self.enable_plotting = enable_plotting if self.enable_plotting and self.verbose: print "Plotting Enabled\n" self.XCENTER = (np.amax(self.X_ORIG) + np.amin(self.X_ORIG)) / 2.0 self.YCENTER = (np.amax(self.Y_ORIG) + np.amin(self.Y_ORIG)) / 2.0 self.anisotropy_scaling = anisotropy_scaling self.anisotropy_angle = anisotropy_angle if self.verbose: print "Adjusting data for anisotropy..." self.X_ADJUSTED, self.Y_ADJUSTED = \ core.adjust_for_anisotropy(np.copy(self.X_ORIG), np.copy(self.Y_ORIG), self.XCENTER, self.YCENTER, self.anisotropy_scaling, self.anisotropy_angle) self.variogram_model = variogram_model if self.variogram_model == 'linear': self.variogram_function = variogram_models.linear_variogram_model elif self.variogram_model == 'power': self.variogram_function = variogram_models.power_variogram_model elif self.variogram_model == 'gaussian': self.variogram_function = variogram_models.gaussian_variogram_model elif self.variogram_model == 'spherical': self.variogram_function = variogram_models.spherical_variogram_model elif self.variogram_model == 'exponential': self.variogram_function = variogram_models.exponential_variogram_model else: raise ValueError( "Specified variogram model '%s' is not supported." % variogram_model) if self.verbose: print "Initializing variogram model..." self.lags, self.semivariance, self.variogram_model_parameters = \ core.initialize_variogram_model(self.X_ADJUSTED, self.Y_ADJUSTED, self.Z, self.variogram_model, variogram_parameters, self.variogram_function, nlags, weight) if self.verbose: if self.variogram_model == 'linear': print "Using '%s' Variogram Model" % 'linear' print "Slope:", self.variogram_model_parameters[0] print "Nugget:", self.variogram_model_parameters[1], '\n' elif self.variogram_model == 'power': print "Using '%s' Variogram Model" % 'power' print "Scale:", self.variogram_model_parameters[0] print "Exponent:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' else: print "Using '%s' Variogram Model" % self.variogram_model print "Sill:", self.variogram_model_parameters[0] print "Range:", self.variogram_model_parameters[1] print "Nugget:", self.variogram_model_parameters[2], '\n' if self.enable_plotting: self.display_variogram_model() if self.verbose: print "Calculating statistics on variogram model fit..." self.delta, self.sigma, self.epsilon = core.find_statistics( self.X_ADJUSTED, self.Y_ADJUSTED, self.Z, self.variogram_function, self.variogram_model_parameters) self.Q1 = core.calcQ1(self.epsilon) self.Q2 = core.calcQ2(self.epsilon) self.cR = core.calc_cR(self.Q2, self.sigma) if self.verbose: print "Q1 =", self.Q1 print "Q2 =", self.Q2 print "cR =", self.cR, '\n'