def Es(T, method=None): """Computes saturated pressure in Pa given T in K, using the method: 1: Hyland-Wexler formulation, polynomial coeff (absolute norm) 2: Wexler formulation 3: Hyland-Wexler formulation, polynomial coeff (relative error norm) 4: classic Goff Gratch equation 5: 6.112*numpy.ma.exp(17.67*tempc/(tempc+243.5)) Default is method 1 Note: 1 and 2 use method 3 where T is not : 173.15 < T < 473.15 ref for 1, 2 and 3: Piotr Flatau and al., Journal of Applied Met., Vol 31, Dec 1992 ( http://ams.allenpress.com/perlserv/?request=get-document&doi=10.1175%2F1520-0450(1992)031%3C1507%3APFTSVP%3E2.0.CO%3B2&ct=1 ) """ if method is None: method = 1 if method == 1: ## Put in C x = T - 273.15 ## Water vapor c0 = 0.611220713E03 c1 = 0.443944344E02 c2 = 0.143195336E01 c3 = 0.263350515E-01 c4 = 0.310636053E-03 c5 = 0.185218710E-05 c6 = 0.103440324E-07 c7 = -0.468258100E-10 c8 = 0.466533033E-13 eswat = c0 + x * (c1 + x * (c2 + x * (c3 + x * (c4 + x * (c5 + x * (c6 + x * (c7 + x * c8))))))) ## ice c0 = .611153246E03 c1 = .503261230E02 c2 = .188595709E01 c3 = .422115970E-01 c4 = .620376691E-03 c5 = .616082536E-05 c6 = .405172828E-07 c7 = .161492905E-09 c8 = .297886454E-12 esice = c0 + x * (c1 + x * (c2 + x * (c3 + x * (c4 + x * (c5 + x * (c6 + x * (c7 + x * c8))))))) ## Combine es = MV2.where(MV2.less(T, 273.15), esice, eswat) ## Overwrite values outside valid range with method 2 mn, mx = genutil.minmax(T) if mn < 173.16 or mx > 473.15: es2 = Es(T, method=2) es = MV2.where(MV2.less(T, 173.16), es2, es) es = MV2.where(MV2.greater(T, 473.15), es2, es) elif method == 2: # over water g0 = -0.29912729E4 g1 = -0.60170128E4 g2 = 0.1887643854E2 g3 = -0.28354721E-1 g4 = 0.17838301E-4 g5 = -0.84150417E-9 g6 = 0.44412543E-12 g7 = 0.2858487E1 # over ice k0 = -0.58653696e4 k1 = 0.2224103300E2 k2 = 0.13749042E-1 k3 = -0.34031775E-4 k4 = 0.26967687E-7 k5 = 0.6918651 esice = (k0 + (k1 + k5 * MV2.log(T) + (k2 + (k3 + k4 * T) * T) * T) * T) / T # over ice eswat = (g0 + (g1 + (g2 + g7 * MV2.log(T) + (g3 + (g4 + (g5 + g6 * T) * T) * T) * T) * T) * T) / T**2 # over water es = MV2.where(MV2.less(T, 273.15), esice, eswat) es = MV2.exp(es) elif method == 3: ## Put in C x = T - 273.15 ## Water vapor c0 = 0.611213476E03 c1 = 0.444007856E02 c2 = 0.143064234E01 c3 = 0.264461437E-01 c4 = 0.305930558E-03 c5 = 0.196237241E-05 c6 = 0.892344772E-08 c7 = -0.373208410E-10 c8 = 0.209339997E-13 eswat = c0 + x * (c1 + x * (c2 + x * (c3 + x * (c4 + x * (c5 + x * (c6 + x * (c7 + x * c8))))))) ## ice c0 = .611123516E03 c1 = .503109514E02 c2 = .1888369801E01 c3 = .420547422E-01 c4 = .614396778E-03 c5 = .602780717E-05 c6 = .387940929E-07 c7 = .149436277E-09 c8 = .262655803E-12 esice = c0 + x * (c1 + x * (c2 + x * (c3 + x * (c4 + x * (c5 + x * (c6 + x * (c7 + x * c8))))))) ## Combine es = MV2.where(MV2.less(T, 273.15), esice, eswat) ## Overwrite values outside valid range with method 2 mn, mx = genutil.minmax(T) if mn < 173.16 or mx > 473.15: es2 = Es(T, method=2) es = MV2.where(MV2.less(T, 173.16), es2, es) es = MV2.where(MV2.greater(T, 473.15), es2, es) elif method == 4: est = 101324.6 #Pa Ts = 373.16 / T a = -7.90298 b = 5.02808 c = -1.3816E-7 d = 11.344 f = 8.1328E-3 h = -3.49149 maxexp = int(numpy.log10(numpy.finfo(numpy.float).max)) minexp = 1 - a es = a * (Ts - 1.) es = es + b * numpy.ma.log10(Ts) A = d * (1. - Ts) A = numpy.ma.masked_greater(A, maxexp) A = numpy.ma.masked_less(A, minexp) es = es + c * (numpy.ma.power(10, A) - 1.) A = h * (Ts - 1.) A = numpy.ma.masked_greater(A, maxexp) A = numpy.ma.masked_less(A, minexp) es = es + f * (numpy.ma.power(10, A) - 1.) es = est * numpy.ma.power(10, es) elif method == 5: tempc = T - 273.15 es = 611.2 * numpy.ma.exp(17.67 * tempc / (tempc + 243.5)) return es
def Es(T, method=None): """Computes saturated pressure in Pa given T in K, using the method: 1: Hyland-Wexler formulation, polynomial coeff (absolute norm) 2: Wexler formulation 3: Hyland-Wexler formulation, polynomial coeff (relative error norm) 4: classic Goff Gratch equation 5: 6.112*numpy.ma.exp(17.67*tempc/(tempc+243.5)) Default is method 1 Note: 1 and 2 use method 3 where T is not : 173.15 < T < 473.15 ref for 1, 2 and 3: Piotr Flatau and al., Journal of Applied Met., Vol 31, Dec 1992 ( http://ams.allenpress.com/perlserv/?request=get-document&\ doi=10.1175%2F1520-0450(1992)031%3C1507%3APFTSVP%3E2.0.CO%3B2&ct=1 ) """ if method is None: method = 1 if method == 1: # Put in C x = T - 273.15 # Water vapor c0 = 0.611220713e03 c1 = 0.443944344e02 c2 = 0.143195336e01 c3 = 0.263350515e-01 c4 = 0.310636053e-03 c5 = 0.185218710e-05 c6 = 0.103440324e-07 c7 = -0.468258100e-10 c8 = 0.466533033e-13 eswat = c0 + x * (c1 + x * (c2 + x * (c3 + x * (c4 + x * (c5 + x * (c6 + x * (c7 + x * c8))))))) # ice c0 = 0.611153246e03 c1 = 0.503261230e02 c2 = 0.188595709e01 c3 = 0.422115970e-01 c4 = 0.620376691e-03 c5 = 0.616082536e-05 c6 = 0.405172828e-07 c7 = 0.161492905e-09 c8 = 0.297886454e-12 esice = c0 + x * (c1 + x * (c2 + x * (c3 + x * (c4 + x * (c5 + x * (c6 + x * (c7 + x * c8))))))) # Combine es = MV2.where(MV2.less(T, 273.15), esice, eswat) # Overwrite values outside valid range with method 2 mn, mx = genutil.minmax(T) if mn < 173.16 or mx > 473.15: es2 = Es(T, method=2) es = MV2.where(MV2.less(T, 173.16), es2, es) es = MV2.where(MV2.greater(T, 473.15), es2, es) elif method == 2: # over water g0 = -0.29912729e4 g1 = -0.60170128e4 g2 = 0.1887643854e2 g3 = -0.28354721e-1 g4 = 0.17838301e-4 g5 = -0.84150417e-9 g6 = 0.44412543e-12 g7 = 0.2858487e1 # over ice k0 = -0.58653696e4 k1 = 0.2224103300e2 k2 = 0.13749042e-1 k3 = -0.34031775e-4 k4 = 0.26967687e-7 k5 = 0.6918651 esice = (k0 + (k1 + k5 * MV2.log(T) + (k2 + (k3 + k4 * T) * T) * T) * T) / T # over ice eswat = ( g0 + (g1 + (g2 + g7 * MV2.log(T) + (g3 + (g4 + (g5 + g6 * T) * T) * T) * T) * T) * T ) / T ** 2 # over water es = MV2.where(MV2.less(T, 273.15), esice, eswat) es = MV2.exp(es) elif method == 3: # Put in C x = T - 273.15 # Water vapor c0 = 0.611213476e03 c1 = 0.444007856e02 c2 = 0.143064234e01 c3 = 0.264461437e-01 c4 = 0.305930558e-03 c5 = 0.196237241e-05 c6 = 0.892344772e-08 c7 = -0.373208410e-10 c8 = 0.209339997e-13 eswat = c0 + x * (c1 + x * (c2 + x * (c3 + x * (c4 + x * (c5 + x * (c6 + x * (c7 + x * c8))))))) # ice c0 = 0.611123516e03 c1 = 0.503109514e02 c2 = 0.1888369801e01 c3 = 0.420547422e-01 c4 = 0.614396778e-03 c5 = 0.602780717e-05 c6 = 0.387940929e-07 c7 = 0.149436277e-09 c8 = 0.262655803e-12 esice = c0 + x * (c1 + x * (c2 + x * (c3 + x * (c4 + x * (c5 + x * (c6 + x * (c7 + x * c8))))))) # Combine es = MV2.where(MV2.less(T, 273.15), esice, eswat) # Overwrite values outside valid range with method 2 mn, mx = genutil.minmax(T) if mn < 173.16 or mx > 473.15: es2 = Es(T, method=2) es = MV2.where(MV2.less(T, 173.16), es2, es) es = MV2.where(MV2.greater(T, 473.15), es2, es) elif method == 4: est = 101324.6 # Pa Ts = 373.16 / T a = -7.90298 b = 5.02808 c = -1.3816e-7 d = 11.344 f = 8.1328e-3 h = -3.49149 maxexp = int(numpy.log10(numpy.finfo(numpy.float).max)) minexp = 1 - a es = a * (Ts - 1.0) es = es + b * numpy.ma.log10(Ts) A = d * (1.0 - Ts) A = numpy.ma.masked_greater(A, maxexp) A = numpy.ma.masked_less(A, minexp) es = es + c * (numpy.ma.power(10, A) - 1.0) A = h * (Ts - 1.0) A = numpy.ma.masked_greater(A, maxexp) A = numpy.ma.masked_less(A, minexp) es = es + f * (numpy.ma.power(10, A) - 1.0) es = est * numpy.ma.power(10, es) elif method == 5: tempc = T - 273.15 es = 611.2 * numpy.ma.exp(17.67 * tempc / (tempc + 243.5)) return es
def testAxisConvert(self): gm = vcs.create1d() gm.yaxisconvert = "log10" data = MV2.arange(10) data_pow = MV2.power(10, data) data_pow.id = "test" self.x.plot(data_pow, gm, bg=self.bg) self.checkImage("test_vcs_yaxisconvert_log10.png") self.x.clear() gm.flip = True gm.yaxisconvert = "linear" gm.xaxisconvert = "log10" self.x.plot(data_pow, gm, bg=self.bg) self.checkImage("test_vcs_xaxisconvert_log10_flip.png") self.x.clear() gm.flip = False gm.xaxisconvert = "linear" gm.yaxisconvert = "ln" data_exp = MV2.exp(data) data_exp.id = "test" self.x.plot(data_exp, gm, bg=self.bg) self.checkImage("test_vcs_yaxisconvert_ln.png") self.x.clear() gm.flip = False gm.xaxisconvert = "area_wt" gm.yaxisconvert = "linear" data2 = self.clt("clt", time=slice(0, 1), longitude=slice(23, 24), squeeze=1) self.x.plot(data2, gm, bg=self.bg) self.checkImage("test_vcs_xaxisconvert_areawt.png") self.x.clear() gm.flip = True gm.yaxisconvert = "area_wt" gm.xaxisconvert = "linear" self.x.plot(data2, gm, bg=self.bg) self.checkImage("test_vcs_yaxisconvert_areawt_flip.png") self.x.clear() gm.flip = False gm.xaxisconvert = "log10" gm.yaxisconvert = "ln" self.x.plot(data_pow, data_exp, gm, bg=self.bg) self.checkImage("test_vcs_axisconvert_log10_ln.png") self.x.clear() #gm.flip = True data2[:] = MV2.power(10, MV2.arange(1, data2.shape[0] + 1)) data2 = data2[:10] gm.xaxisconvert = "area_wt" gm.yaxisconvert = "log10" self.x.plot(data2, gm, bg=self.bg) self.checkImage("test_vcs_axisconvert_area_log10.png") self.x.clear() gm.flip = True gm.yaxisconvert = "area_wt" gm.xaxisconvert = "log10" self.x.plot(data2, gm, bg=self.bg) self.checkImage("test_vcs_axisconvert_area_log10_flip.png") self.x.clear() gm.flip = False gm.xaxisconvert = "area_wt" gm.yaxisconvert = "log10" data_axis = MV2.array(data2.getAxis(0)[:]) data_axis.id = "test" self.x.plot(data_axis, data2, gm, bg=self.bg) self.checkImage("test_vcs_axisconvert_area_log10_2arrays.png") with self.assertRaises(RuntimeError): self.x.clear() gm.flip = True self.x.plot(data_axis, data2, gm, bg=self.bg) self.x.clear() gm.flip = False gm.xaxisconvert = "area_wt" gm.yaxisconvert = "log10" gm.xticlabels1 = {-90: "90S", -80: "80S", -70: "70S", -60: "60S"} gm.xticlabels2 = {-85: "85S", -75: "75S", -65: "65S", -55: "55S"} mtics = {} def func(x): mtics[x] = "" map(func, range(-90, -40, 10)) gm.xmtics2 = mtics mtics = {} map(func, range(-85, -40, 10)) gm.xmtics1 = mtics gm.yticlabels1 = {100: "hun"} gm.yticlabels2 = {1000: "thou"} gm.ymtics1 = {10: "", 1000: ""} gm.ymtics2 = {10000: "", 1000: ""} gm.list() tmpl = vcs.createtemplate() for num in ["1", "2"]: for loc in ["x", "y"]: for attr in ["mintic", "tic"]: filled_attr = "{}{}{}".format(loc, attr, num) print("PRIO FOR ATT:", filled_attr) obj = getattr(tmpl, filled_attr) obj.priority = 1 obj.list() tmpl.xlabel1.priority = 1 tmpl.xlabel2.priority = 1 tmpl.ylabel1.priority = 1 tmpl.ylabel2.priority = 1 self.x.plot(data_axis, data2, gm, tmpl, bg=self.bg) self.checkImage("test_vcs_axisconvert_area_log10_user_labels.png")
from vacumm.misc.grid.masking import erode_coast from vacumm.misc.plot import savefigs, add_key import MV2, numpy as N, matplotlib.pyplot as P # Champs initial xx, yy = N.indices((50, 100), 'f') x0 = y0 = 25 dxy = 30 var = MV2.exp(-((xx - x0)**2 + (yy - y0)**2) / dxy**2) # Masques # - reference mask = var.filled() > .9 mask[:, 50:] = True mask[15:35, 65:85] = False # - variable var[:] = MV2.masked_greater(var, .8) var[:, 50:] = MV2.masked # Erode vare = erode_coast(var, mask) # Plots P.figure(figsize=(6, 9)) P.subplots_adjust(hspace=.2) P.subplot(311) P.pcolormesh(var.asma()) P.title('Original variable') add_key(1, color='w') P.subplot(312) P.pcolormesh(mask)
from vacumm.misc.grid.masking import erode_coast from vacumm.misc.plot import savefigs, add_key import MV2, numpy as N, matplotlib.pyplot as P # Champs initial xx, yy = N.indices((50, 100), 'f') x0 = y0 = 25 dxy = 30 var = MV2.exp(-((xx-x0)**2+(yy-y0)**2)/dxy**2) # Masques # - reference mask = var.filled()>.9 mask[:, 50:] = True mask[15:35, 65:85] = False # - variable var[:] = MV2.masked_greater(var, .8) var[:, 50:] = MV2.masked # Erode vare = erode_coast(var, mask) # Plots P.figure(figsize=(6, 9)) P.subplots_adjust(hspace=.2) P.subplot(311) P.pcolormesh(var.asma()) P.title('Original variable') ; add_key(1, color='w') P.subplot(312) P.pcolormesh(mask) P.title('Reference mask') ; add_key(2, color='w')