def test_core_initialize_variogram_model(self): # Note the variogram_function argument is not a string in real life... self.assertRaises(ValueError, core.initialize_variogram_model, self.test_data[:, 0], self.test_data[:, 1], self.test_data[:, 2], 'linear', [0.0], 'linear', 6, False) self.assertRaises(ValueError, core.initialize_variogram_model, self.test_data[:, 0], self.test_data[:, 1], self.test_data[:, 2], 'spherical', [0.0], 'spherical', 6, False) x = np.array([1.0 + n / np.sqrt(2) for n in range(4)]) y = np.array([1.0 + n / np.sqrt(2) for n in range(4)]) z = np.arange(1.0, 5.0, 1.0) lags, semivariance, variogram_model_parameters = core.initialize_variogram_model( x, y, z, 'linear', [0.0, 0.0], 'linear', 6, False) self.assertTrue(np.allclose(lags, np.array([1.0, 2.0, 3.0]))) self.assertTrue(np.allclose(semivariance, np.array([0.5, 2.0, 4.5])))
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 __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 __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, 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, 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, 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'