示例#1
0
def computeMeanAndExtremeProfiles(pr_id,inputdir,quantile,computeP):
	omega_id = 'OMEGA'
	ts_id = 'TS'
	t_id = 'T'
	ps_id = 'PS'
	relhum_id = 'RELHUM'
	q_id = 'Q'
	# Extract all variables
	pr = getVar(pr_id,inputdir)
	omega = getVar(omega_id,inputdir)
	ts = getVar(ts_id,inputdir)
	t = getVar(t_id,inputdir)
	ps = getVar(ps_id,inputdir)
	relhum = getVar(relhum_id,inputdir)
	q = getVar(q_id,inputdir)
	# Compute means
	omega_m = computeMean(omega)
	ts_m = computeMean(ts)
	t_m = computeMean(t)
	ps_m = computeMean(ps)
	p_m = computeP(ps_m)
	relhum_m = computeMean(relhum)
	q_m = computeMean(q)
	rho_m = airDensity(t_m,p_m,q_m)
	w_m = np.divide(omega_m,-g*rho_m)
	profiles_m = (p_m,t_m,q_m,relhum_m,rho_m,omega_m,w_m)
	# Compute means for extreme quantile
	i_q = getIndicesOfExtremePercentile(pr,Q)
	omega_q = computeMeanAtTimeLatLonIndices(omega,i_q)
	ts_q = computeMeanAtTimeLatLonIndices(ts,i_q)
	t_q = computeMeanAtTimeLatLonIndices(t,i_q)
	ps_q = computeMeanAtTimeLatLonIndices(ps,i_q)
	p_q = computeP(ps_q)
	relhum_q = computeMeanAtTimeLatLonIndices(relhum,i_q)
	q_q = computeMeanAtTimeLatLonIndices(q,i_q)
	rho_q = airDensity(t_q,p_q,q_q)
	w_q = np.divide(omega_q,-g*rho_q)
	profiles_q = (p_q,t_q,q_q,relhum_q,rho_q,omega_q,w_q)
	# Return
	return profiles_m, profiles_q
		pressurf_values[i] = fh.variables[pressurf_id][:,lat_slice,:]

		fh.close()		# Close file

	##-- Compute hourly rho profile at each GCM point --##

		#- Compute the vertical pressure structure at each GCM point -#

	lev_file = 'lev_fx_CESM111-SPCAM20_allExperiments_r0i0p0.nc'
	computeP = getPressureCoordinateFunctionKeepDimensions(os.path.join(inputdir_fx,lev_file))
	pres_values = computeP(pressurf_values)			# Compute vertical structure
	pres_values = np.moveaxis(pres_values,-1,1)		# Reorder dimensions

		#- Compute rho -#

	rho_values = airDensity(temp_values,pres_values,spechum_values)

	##-- Write to output --##

	time[:] = time_values[:]
	date[:] = date_values[:]
	datesec[:] = datesec_values[:]
	rho[:] = rho_values[:]

	rootgrp.close()

	t1 = datetime.now()			# Stop chronometer
	print t1-t0

	sys.exit(0)
	# Iinitialize rank
	k = 0
	is_new_cell[0,:] = np.zeros((1,Nranks))
	# Loop over GCM points that match the percentile of interest
	for ilat,ilon in zip(*np.where(J_valid)):
		# Mark that we entered a new GCM cell
		is_new_cell[0,k] = 1
		# Get the CRM points that correspond to the convective event
		I_valid = np.array(I_vals[...,ilat,ilon] == 1,dtype=bool).squeeze()
		for itime,ix in zip(*np.where(I_valid)):
			# Compute and store CRM mass flux at current CRM point
			pressurf = pressurf_vals[itime,ilat,ilon]
			pres = computeP(pressurf)
			spechum = spechum_vals[itime,:,ilat,ilon]
			temp = temp_vals[itime,:,ilat,ilon]
			rho = airDensity(temp,pres,spechum)
			wspeed = w_vals[itime,...,ix,ilat,ilon].squeeze()
			pw = pw_vals[itime,...,ix,ilat,ilon].squeeze()
			omega = np.multiply(wspeed,-g*rho)
			omega_up = omega.copy()
			omega_dn = omega.copy()
			omega_up[omega >= 0] = 0
			omega_dn[omega <= 0] = 0
			crm_mf[0,k] = verticalPressureIntegral(pres,omega) / verticalPressureIntegral(pres)
			crm_mfup[0,k] = verticalPressureIntegral(pres,omega_up) / verticalPressureIntegral(pres)
			crm_mfdn[0,k] = verticalPressureIntegral(pres,omega_dn) / verticalPressureIntegral(pres)
			crm_mf_pw[0,k] = verticalPressureIntegralProduct(pres,omega,pw) / verticalPressureIntegral(pres,pw)
			crm_mfup_pw[0,k] = verticalPressureIntegralProduct(pres,omega_up,pw) / verticalPressureIntegral(pres,pw)
			crm_mfdn_pw[0,k] = verticalPressureIntegralProduct(pres,omega_dn,pw) / verticalPressureIntegral(pres,pw)
			crm_pw[0,k] = verticalPressureIntegral(pres,pw) / verticalPressureIntegral(pres)
			# increment current rank