def thetaes(T, p): """ thetaes(T, p) Calculates the pseudo equivalent potential temperature of an air parcel. Parameters - - - - - - T : float Temperature (K). p : float Pressure (Pa). Returns - - - - thetaep : float Pseudo equivalent potential temperature (K). Notes - - - It should be noted that the pseudo equivalent potential temperature (thetaep) of an air parcel is not a conserved variable. References - - - - - - Emanuel 4.7.9 p. 132 Examples - - - - - >>> thetaes(300., 8.e4) 412.97362667593831 """ c = constants(); # The parcel is saturated - prohibit supersaturation with Td > T. Tlcl = T; wv = wsat(T, p); thetaval = theta(T, p, wv); power = 0.2854 * (1 - 0.28 * wv); thetaep = thetaval * np.exp(wv * (1 + 0.81 * wv) * \ (3376. / Tlcl - 2.54)) # # peg this at 450 so rootfinder won't blow up # if thetaep > 450.: thetaep = 450; return thetaep
def thetaes(T, p): """ thetaes(T, p) Calculates the pseudo equivalent potential temperature of an air parcel. Parameters - - - - - - T : float Temperature (K). p : float Pressure (Pa). Returns - - - - thetaep : float Pseudo equivalent potential temperature (K). Notes - - - It should be noted that the pseudo equivalent potential temperature (thetaep) of an air parcel is not a conserved variable. References - - - - - - Emanuel 4.7.9 p. 132 Examples - - - - - >>> thetaes(300., 8.e4) 412.97362667593831 """ c = constants() # The parcel is saturated - prohibit supersaturation with Td > T. Tlcl = T wv = wsat(T, p) thetaval = theta(T, p, wv) power = 0.2854 * (1 - 0.28 * wv) thetaep = thetaval * np.exp(wv * (1 + 0.81 * wv) * \ (3376. / Tlcl - 2.54))\ #if thetaep > 550: # thetaep = 550 return thetaep
def thetaep(Td, T, p): """ thetaep(Td, T, p) Calculates the pseudo equivalent potential temperature of a parcel. Parameters - - - - - - Td : float Dewpoint temperature (K). T : float Temperature (K). p : float Pressure (Pa). Returns - - - - thetaepOut : float Pseudo equivalent potential temperature (K). Notes - - - Note that the pseudo equivalent potential temperature of an air parcel is not a conserved variable. References - - - - - - Emanuel 4.7.9 p. 132 Examples - - - - - >>> thetaep(280., 300., 8.e4) # Parcel is unsaturated. 344.99830738253371 >>> thetaep(300., 280., 8.e4) # Parcel is saturated. 321.5302927767795 """ c = constants() if Td < T: #parcel is unsaturated [Tlcl, plcl] = LCLfind(Td, T, p) wv = wsat(Td, p) else: #parcel is saturated -- prohibit supersaturation with Td > T Tlcl = T wv = wsat(T, p) # $$$ disp('inside theate') # $$$ [Td,T,wv] thetaval = theta(T, p, wv) power = 0.2854 * (1 - 0.28 * wv) thetaep = thetaval * np.exp(wv * (1 + 0.81 * wv) \ * (3376. / Tlcl - 2.54)) # # peg this at 450 so rootfinder won't blow up # #thetaepOut = thetaep #if(thetaepOut > 450.): # thetaepOut = 450; return thetaep
from theta import theta def generate(n: int) -> str: stdin = f'{n} 2000000000\n' stdin += ' '.join([str(x) for x in range(1000000000, 2000000000, 2000000000 // n)]) return stdin test = theta( r'C:\Users\Steven\Google Drive\School\University of Alberta\Y1\CMPUT 275 Introduction to Tangible Computing II\Weekly Exercises\Interview Questions\3 Pair Hunt\pair_hunt.cpp', generate, 2, 250000, 20, 1 ) test.run()
import pylab import numpy as np data = gD.TrainingDataSet('data.csv', ',') data.printData() X=list() Y=list() for item in data.getData(): x=item.getX() y=item.getY() X.append(x[1]) Y.append(y) print(x,y) theta = th.theta(dimension=2) theta.printData() ex1 = data.getExample(0) index = 0 print("Linear hypothesis value:\n{}".format(hL.hypothesisLinearTrain(theta, ex1))) print("Simple cost for hypothesis:\n{}".format(hL.cost(theta, ex1))) print("Number of examples:\n{}".format(data.getNumberOfExamples())) print("Total cost for hypothesis:\n{}".format(hL.costFunction(theta, data))) print("Cost function derivative for index {0}:\n{1}\ ".format(index, hL.costFunctionDerivative(theta, data, index))) theta = grad.gradientDescentLinear(theta, data, 0.01)
from theta import theta def generate(n: int) -> str: return str(n) test = theta('quadratic.cpp', generate, 2, 1000, 10, 1) test.run()
def convecSkew(figNum): """ Usage: convecSkew(figNum) Input: figNum = integer Takes any integer, creates figure(figNum), and plots a skewT logp thermodiagram. Output: skew=30. """ c = constants(); plt.figure(figNum); plt.clf(); yplot = range(1000,190,-10) xplot = range(-300,-139) pvals = np.size(yplot) tvals = np.size(xplot) temp = np.zeros([pvals, tvals]); theTheta = np.zeros([pvals, tvals]); ws = np.zeros([pvals, tvals]); theThetae = np.zeros([pvals, tvals]); skew = 30; #skewness factor (deg C) # lay down a reference grid that labels xplot,yplot points # in the new (skewT-lnP) coordinate system . # Each value of the temp matrix holds the actual (data) # temperature label (in deg C) of the xplot, yplot coordinate. # pairs. The transformation is given by W&H 3.56, p. 78. Note # that there is a sign difference, because rather than # taking y= -log(P) like W&H, I take y= +log(P) and # then reverse the y axis for i in yplot: for j in xplot: # Note that we don't have to transform the y # coordinate, as it is still pressure. iInd = yplot.index(i) jInd = xplot.index(j) temp[iInd, jInd] = convertSkewToTemp(j, i, skew); Tk = c.Tc + temp[iInd, jInd]; pressPa = i * 100.; theTheta[iInd, jInd] = theta(Tk, pressPa); ws[iInd, jInd] = wsat(Tk, pressPa); theThetae[iInd, jInd] = thetaes(Tk, pressPa); # # Contour the temperature matrix. # # First, make sure that all plotted lines are solid. mpl.rcParams['contour.negative_linestyle'] = 'solid' tempLabels = range(-40, 50, 10); output1 = plt.contour(xplot, yplot, temp, tempLabels, \ colors='k') # # Customize the plot # plt.setp(plt.gca(), yscale='log') locs = np.array(range(100, 1100, 100)) labels = locs plt.yticks(locs, labels) # Conventionally labels semilog graph. plt.setp(plt.gca(), ybound=(200, 1000)) plt.setp(plt.getp(plt.gca(), 'xticklabels'), fontweight='bold') plt.setp(plt.getp(plt.gca(),'yticklabels'), fontweight='bold') plt.grid(True) plt.setp(plt.gca().get_xgridlines(), visible=False) plt.hold(True); thetaLabels = range(200, 380, 10); output2 = plt.contour(xplot, yplot, theTheta, thetaLabels, \ colors='b'); wsLabels = range(6, 24, 2); output3 = plt.contour(xplot, yplot, (ws * 1.e3), wsLabels, \ colors='g'); thetaeLabels = range(250, 380, 10); output4 = plt.contour(xplot, yplot, theThetae, thetaeLabels, \ colors='r'); # Transform the temperature,dewpoint from data coords to # plotting coords. plt.title('skew T - lnp chart'); plt.ylabel('pressure (hPa)'); plt.xlabel('temperature (deg C)'); # # Crop image to a more usable size # TempTickLabels = range(5, 35, 5); TempTickCoords = TempTickLabels; skewTickCoords = convertTempToSkew(TempTickCoords, 1.e3, skew); plt.xticks(skewTickCoords, TempTickLabels) skewLimits = convertTempToSkew([5, 30], 1.e3, skew); plt.axis([skewLimits[0], skewLimits[1], 600, 1.e3]); # # Create line labels # fntsz = 9 # Handle for 'fontsize' of the line label. ovrlp = 1 # Handle for 'inline'. Any integer other than 0 # creates a white space around the label. plt.clabel(output1, inline=ovrlp, fmt='%1d', fontsize=fntsz); plt.clabel(output2, inline=ovrlp, fmt='%1d', fontsize=fntsz); plt.clabel(output3, inline=ovrlp, fmt='%1d', fontsize=fntsz); plt.clabel(output4, inline=ovrlp, fmt='%1d', fontsize=fntsz); # # Flip the y axis # plt.setp(plt.gca(), ylim=plt.gca().get_ylim()[::-1]) return skew
def thetaep(Td, T, p): """ thetaep(Td, T, p) Calculates the pseudo equivalent potential temperature of a parcel. Parameters - - - - - - Td : float Dewpoint temperature (K). T : float Temperature (K). p : float Pressure (Pa). Returns - - - - thetaepOut : float Pseudo equivalent potential temperature (K). Notes - - - Note that the pseudo equivalent potential temperature of an air parcel is not a conserved variable. References - - - - - - Emanuel 4.7.9 p. 132 Examples - - - - - >>> thetaep(280., 300., 8.e4) # Parcel is unsaturated. 344.99830738253371 >>> thetaep(300., 280., 8.e4) # Parcel is saturated. 321.5302927767795 """ c = constants(); if Td < T: #parcel is unsaturated [Tlcl, plcl] = LCLfind(Td, T, p); wv = wsat(Td, p); else: #parcel is saturated -- prohibit supersaturation with Td > T Tlcl = T; wv = wsat(T, p); # $$$ disp('inside theate') # $$$ [Td,T,wv] thetaval = theta(T, p, wv); power = 0.2854 * (1 - 0.28 * wv); thetaep = thetaval * np.exp(wv * (1 + 0.81 * wv) \ * (3376. / Tlcl - 2.54)); # # peg this at 450 so rootfinder won't blow up # if(thetaepOut > 450.): thetaepOut = 450; return thetaepOut