def estimate_relative_humidity(q,t_avg,lat,lon): ## estimates relative humidity using hypsometric equation for pressure, virtual temperature and ## average temperature import numpy as np from snowpack_functions import get_elev_for_lat_lon,import_gridcell_elevation #################### CONSTANTS ############################### Rd = 287.04 ## J kg^-1 K ^-1 p1 = 100000 ## Pa T0 = 273.15 ## reference temperature g = 9.81 ## m / s^2 ## need to get elevations for grid cells soil_file = '/raid9/gergel/agg_snowpack/soil_avail.txt' elev_corr_info = import_gridcell_elevation(soil_file) h = get_elev_for_lat_lon(elev_corr_info,lat,lon) ## Tv = T(1 + 0.61w) Tv = t_avg * (1 + 0.61*q) ## p = e ^ (-(((z_2 - z_1) * g)/ (Rd*Tv) - ln(p1))) hg = h * g RdTv = Rd * Tv p = np.exp(-((np.divide(hg,RdTv.air_temp_min)) - math.log(p1))) ## RH = 0.263*p*q[exp(17.67*T - T0)/(T - 29.65)]^-1 RH = 0.263*p*q * ((np.exp((17.67 * (t_avg - T0))/ (t_avg - 29.65)))**-1) return (RH)
def estimate_relative_humidity(q, t_avg, lat, lon): ## estimates relative humidity using hypsometric equation for pressure, virtual temperature and ## average temperature import numpy as np from snowpack_functions import get_elev_for_lat_lon, import_gridcell_elevation #################### CONSTANTS ############################### Rd = 287.04 ## J kg^-1 K ^-1 p1 = 100000 ## Pa T0 = 273.15 ## reference temperature g = 9.81 ## m / s^2 ## need to get elevations for grid cells soil_file = '/raid9/gergel/agg_snowpack/soil_avail.txt' elev_corr_info = import_gridcell_elevation(soil_file) h = get_elev_for_lat_lon(elev_corr_info, lat, lon) ## Tv = T(1 + 0.61w) Tv = t_avg * (1 + 0.61 * q) ## p = e ^ (-(((z_2 - z_1) * g)/ (Rd*Tv) - ln(p1))) hg = h * g RdTv = Rd * Tv p = np.exp(-((np.divide(hg, RdTv.air_temp_min)) - math.log(p1))) ## RH = 0.263*p*q[exp(17.67*T - T0)/(T - 29.65)]^-1 RH = 0.263 * p * q * ((np.exp( (17.67 * (t_avg - T0)) / (t_avg - 29.65)))**-1) return (RH)
import numpy as np import sys import os import math from snowpack_functions import import_gridcell_elevation,get_elev_for_lat_lon,lat_lon_adjust,unpack_netcdf_swe_month,mask_latlon,unpack_netcdf_file_var,historical_sum_swe import pandas as pd ## get command line arguments args = sys.argv[1:] basin = args[0] scenario = args[1] chunk = args[2] direc = '/raid9/gergel/agg_snowpack/goodleap/%s' %basin file_swe = 'SWE_ensavg_%s_%s.nc' %(scenario,basin) lats,lons,swe,datess = unpack_netcdf_file_var(direc,file_swe,"swe") soil_file = '/raid9/gergel/agg_snowpack/soil_avail.txt' elev_corr_info = import_gridcell_elevation(soil_file) ## step 1: load data sources ## PET: all three: NatVeg, Short, Tall ## AET: evaporation plus transpiration ## compare pet and aet from VIC (then see about computing aet using pm reference et) pet_agg = list() aet_agg = list() lats_inc = list() lons_inc = list() coms = list() elevs = list() ## function to be used to find center of mass def com_array(arr):
elev1=np.asarray(elev_1), elev2=np.asarray(elev_2), elev3=np.asarray(elev_3)) return (swe_1, swe_2, swe_3, elev_1, elev_2, elev_3) ################################################ BEGIN LOESS ANALYSIS ######################################### import numpy as np import sys from snowpack_functions import unpack_netcdf_file_var, import_gridcell_elevation ## get command line arguments args = sys.argv[1:] basin = args[0] scenario = args[1] soil_file = '/raid9/gergel/agg_snowpack/soil_avail.txt' elev_corr_info = import_gridcell_elevation(soil_file) direc = '/raid9/gergel/agg_snowpack/goodleap/%s' % basin file = 'SWE_ensavg_%s_%s.nc' % (scenario, basin) lats, lons, swe, datess = unpack_netcdf_file_var(direc, file, "swe") if (scenario == "historical"): swe_inc, elev_inc = swe_elevation_mean(lats, lons, swe, datess, elev_corr_info, basin, scenario) else: swe1, swe2, swe3, elev1, elev2, elev3 = swe_elevation_mean( lats, lons, swe, datess, elev_corr_info, basin, scenario) ##################### plot ############################ import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import os