def ode_littlerock(): filename = 'littlerock.nc' print 'reading file: %s\n' %(filename) nc_file = Dataset(filename) var_names = nc_file.variables.keys() print nc_file.ncattrs() print nc_file.units print nc_file.col_names sound_var = nc_file.variables[var_names[3]] press = sound_var[:,0] height = sound_var[:,1] temp = sound_var[:,2] dewpoint = sound_var[:,3] #height must have unique values newHeight= nudge(height) #Tenv and TdEnv interpolators return temp. in deg C, given height in m #Press interpolator returns pressure in hPa given height in m interpTenv = lambda zVals: np.interp(zVals, newHeight, temp) interpTdEnv = lambda zVals: np.interp(zVals, newHeight, dewpoint) interpPress = lambda zVals: np.interp(zVals, newHeight, press) p900_level = np.where(abs(900 - press) < 2.) p800_level = np.where(abs(800 - press) < 7.) thetaeVal=thetaep(dewpoint[p900_level] + c.Tc,temp[p900_level] + c.Tc,press[p900_level]*100.) height_800=height[p800_level] yinit = [0.5, height_800] #(intial velocity = 0.5 m/s, initial height in m) tinit = 0 tfin = 2500 dt = 10 #want to integrate F using ode45 (from MATLAB) equivalent integrator r = ode(F).set_integrator('dopri5') r.set_f_params(thetaeVal, interpTenv, interpTdEnv, interpPress) r.set_initial_value(yinit, tinit) y = np.array(yinit) t = np.array(tinit) #stop integration when the parcel changes direction, or time runs out while r.successful() and r.t < tfin and r.y[0] > 0: #find y at the next time step #(r.integrate(t) updates the fields r.y and r.t so that r.y = F(t) and r.t = t #where F is the function being integrated) r.integrate(r.t+dt) #keep track of y at each time step y = np.vstack((y, r.y)) t = np.vstack((t, r.t)) wvel = y[:,0] height = y[:,1] plt.figure(1) plt.plot(wvel, height) plt.xlabel('vertical velocity (m/s)') plt.ylabel('height about surface (m)') plt.show()
def call_nudge(event): if not artistConfigured and _gcodeThread.grbl.ready: _gcodeThread.grbl.setIncremental() nudge_window = nudge(tk, nudge_callback, nudge_closed) else: if not _gcodeThread.grbl.ready: print("please wait for plotter to be ready") else: print("nudge can only be called when in preview mode")
def answer_entrain(): filename = 'littlerock.nc' print 'reading file: %s\n' %(filename) nc_file = Dataset(filename) var_names = nc_file.variables.keys() print nc_file.ncattrs() print nc_file.units print nc_file.col_names sound_var = nc_file.variables[var_names[3]] press = sound_var[:,0] height = sound_var[:,1] temp = sound_var[:,2] dewpoint = sound_var[:,3] #height must have unique values envHeight= nudge(height) #Tenv and TdEnv interpolators return temp. in deg C, given height in m #Press interpolator returns pressure in hPa given height in m interpTenv = lambda zVals: np.interp(zVals, envHeight, temp) interpTdEnv = lambda zVals: np.interp(zVals, envHeight, dewpoint) interpPress = lambda zVals: np.interp(zVals, envHeight, press) p900_level = np.where(abs(900 - press) < 2.) p800_level = np.where(abs(800 - press) < 7.) thetaeVal=thetaep(dewpoint[p900_level] + c.Tc,temp[p900_level] + c.Tc,press[p900_level]*100.) height_800=height[p800_level] wTcloud = wsat(dewpoint[p900_level] + c.Tc, press[p900_level]*100.) entrain_rate = 2.e-4 winit = 0.5 #initial velocity (m/s) yinit = [winit, height_800, thetaeVal, wTcloud] tinit = 0 tfin = 2500 dt = 10 #want to integrate F using ode45 (from MATLAB) equivalent integrator r = ode(F).set_integrator('dopri5') r.set_f_params(entrain_rate, interpTenv, interpTdEnv, interpPress) r.set_initial_value(yinit, tinit) y = np.array(yinit) t = np.array(tinit) #stop tracking the parcel when the time runs out, or if the parcel stops moving/is desecnding while r.successful() and r.t < tfin and r.y[0] > 0: #find y at the next time step #(r.integrate(t) updates the fields r.y and r.t so that r.y = F(t) and r.t = t #where F is the function being integrated) r.integrate(r.t+dt) if r.y[0] <= 0: break #keep track of y at each time step y = np.vstack((y, r.y)) t = np.vstack((t, r.t)) wvel = y[:,0] cloud_height = y[:,1] thetae_cloud = y[:,2] wT_cloud = y[:,3] plt.figure(1) plt.plot(wvel, cloud_height) plt.xlabel('vertical velocity (m/s)') plt.ylabel('height above surface (m)') plt.gca().set_title('vertical velocity of a cloud parcel vs height,\ entrainment rate of %4.1e $s^{-1}$' %entrain_rate) Tcloud = np.zeros(cloud_height.size) wvCloud = np.zeros(cloud_height.size) wlCloud = np.zeros(cloud_height.size) for i in range(0, len(cloud_height)): the_press = interpPress(cloud_height[i])*100. Tcloud[i], wvCloud[i], wlCloud[i] = tinvert_thetae(thetae_cloud[i], wT_cloud[i], the_press) Tadia= np.zeros(cloud_height.size) wvAdia = np.zeros(cloud_height.size) wlAdia = np.zeros(cloud_height.size) for i in range(0, len(cloud_height)): the_press = interpPress(cloud_height[i])*100. Tadia[i], wvAdia[i], wlAdia[i] = tinvert_thetae(thetae_cloud[0], wT_cloud[0], the_press) plt.figure(2) TcloudHandle, = plt.plot(Tcloud - c.Tc, cloud_height, 'r-') TenvHandle, = plt.plot(temp, envHeight, 'g-') TadiaHandle, = plt.plot(Tadia - c.Tc, cloud_height, 'b-') plt.xlabel('temperature (deg C)') plt.ylabel('height above surface (m)') plt.gca().set_title('temp. of rising cloud parcel vs height,\ entrainment rate of %4.1e $s^{-1}$' %entrain_rate) plt.gca().legend([TcloudHandle, TenvHandle, TadiaHandle],['cloud', 'environment', 'moist adiabat']) plt.show()
#use 900 hPa sounding level for adiabat #array.argmin() finds the index of the min. value of array p900_level = np.abs(900 - press).argmin() thetaeVal=thetaep(dewpoint[p900_level] + c.Tc,temp[p900_level] + c.Tc,press[p900_level]*100.) pressVals,tempVals =calcAdiabat(press[p900_level]*100.,thetaeVal,200.e2) xTemp=convertTempToSkew(tempVals - c.Tc,pressVals*1.e-2,skew) p900_adiabat = plt.semilogy(xTemp,pressVals*1.e-2,'r-',linewidth=4) xleft=convertTempToSkew(-20,1.e3,skew) xright=convertTempToSkew(25.,1.e3,skew) # #interpolator fails if two pressure values are the same # newPress = nudge(press) #independent variable used to interpolate must be in increasing order #pVals must be in hPa interpTenv = lambda pVals: np.interp(pVals, newPress[::-1], temp[::-1]) interpTdenv = lambda pVals: np.interp(pVals, newPress[::-1], dewpoint[::-1]) interpDirec = lambda pVals: np.interp(pVals, newPress[::-1], direct[::-1]) interpSpeed = lambda pVals: np.interp(pVals, newPress[::-1], speed[::-1]) trytemp = interpTenv(pressVals*1.e-2) xTemp=convertTempToSkew(trytemp,pressVals*1.e-2,skew) plt.semilogy(xTemp,pressVals*1.e-2,'k.',markersize=6) labels = range(100, 1100, 100) ax2.set_yticks(labels) ax2.set_yticklabels(labels) ax2.set_ybound((200, 1000)) ax2.set_xbound((xleft, xright)) plt.gca().set_title('littlerock sounding, %s' %var_names[3])