def fit_bc(pF, theta, count=20, verbose=False): """Fits a Brooks-Corey retention curve into data pF: a sequence of pF values theta: an array of water contents """ theta_mean = np.mean(theta) ns_denom = np.sum((theta - theta_mean)**2) best_f = 1e12 for i in range(count): x0 = np.array((random.uniform(0.01, 1.0), random.uniform(1.0, 20), random.uniform(0.01, 1.0))) x_opt, f_opt, n_iter, n_eval, warn = opt.fmin(get_error_bc, x0=x0, args=(pF, theta), full_output=1, disp=0) if f_opt < best_f: if verbose: print "%i: x=%s f=%0.12g iter=%i, eval=%i" % ( i, x_opt, 1 - f_opt / ns_denom, n_iter, n_eval) bc = cmf.BrooksCoreyRetentionCurve(1., x_opt[0], x_opt[1], x_opt[2]) best_f = f_opt return bc, 1 - best_f / ns_denom
def soiltype(depth): """ Creates a retention curve for a depth below ground using an exponential Ksat decline :param depth: depth below ground in m :return: Retention curve """ return cmf.BrooksCoreyRetentionCurve(ksat=15 * np.exp(-depth), porosity=0.5, _b=5.5, theta_x=0.35)
def _create_cells(self,d_init_pot=0.3): """ Creates an object for each cell which consists of vertical layers Parameters ---------- d_init_pot : float, optional Delta in matric potential subtracted from the initial value (0.3 would subtract 0.3 from the standard value in each layer) [m]. The default is 0.3. Returns ------- None. """ for i in range(self.ncell): c: cmf.Cell = self.NewCell(i * self.length / self.ncell, 0, self.depth + (i-0) * self.slope_per_cell, self.length / self.ncell * self.width, True) if i: c.topology.AddNeighbor(self[i - 1], self.width) self.retention_curve = cmf.BrooksCoreyRetentionCurve(ksat=self.Ksat, porosity=self.porosity, _b=self.b, theta_x=0.20, psi_x=cmf.pF_to_waterhead(2.5)) list_z = list() for zi in np.arange(0,self.depth, self.dz): c.add_layer(zi+self.dz, self.retention_curve) list_z.append(zi+self.dz) c.install_connection(cmf.Richards) c.saturated_depth=self.depth-(self.init_z_interpol-self.bottom)[i] for ii,li in enumerate(c.layers): if list_z[ii] <= self.depth-(self.init_z_interpol-self.bottom)[i]: li.potential -= d_init_pot del list_z c.surfacewater.puddledepth = 0.001 c.surfacewater.nManning = self.mannings_n
def get_error_bc(params, pF, theta): bc = cmf.BrooksCoreyRetentionCurve(1, params[0], params[1], params[2]) model_wetness = bc.Wetness_pF(pF) err = np.sum((theta - params[0] * model_wetness)**2) return err
def soiltype(depth): return cmf.BrooksCoreyRetentionCurve(ksat=15*np.exp(-d), porosity=0.5, _b=5.5, theta_x=0.35)