<jupyter_start><jupyter_text>Jan 31, 2017 class: Precipitation<jupyter_code># Import numerical tools
import numpy as np<jupyter_output><empty_output><jupyter_text>Here I will enter the weather data I downloaded for today.<jupyter_code>TnoonF = 61 #Temperature at noon (really 1pm) in Farenheit
TnightF = 54 #Temperature at 4am in Farenheit
RHnoon = 0.62 #Relative humidity at noon (really 1pm)
RHnight = 0.96 #Relative humidity at 4 am
Tdp_noonF = 48 #Dew point at noon (really 1pm) in Farenheit
Tdp_nightF = 40 #Dew point at 4 am, Farenheit<jupyter_output><empty_output><jupyter_text>Let's convert all of the Farenheit data to Celsius by creating a module (i.e., a function).<jupyter_code>def FtoC(TF):
    """
    Takes the temperature in Farenheit (TF) as input and returns it in Celsius (TC)
    """
    TC = (TF-32)*5/9
    return TC<jupyter_output><empty_output><jupyter_text>Now we'll apply that function to our temperature data in Farenheit<jupyter_code>TnoonC = FtoC(TnoonF)
TnightC = FtoC(TnightF)
Tdp_noonC = FtoC(Tdp_noonF)
Tdp_nightC = FtoC(Tdp_nightF)
print(TnoonC) #Just checking to make sure it looks reasonable--always a good idea!<jupyter_output>16.11111111111111<jupyter_text>What is today's pressure in Pa?<jupyter_code>Pinches = 30.12 #pressure in inches
Pmm = 30.12*25.4 #There are 25.4 mm in an inch
PPa = Pmm*133.322
print(PPa)<jupyter_output>101997.729456<jupyter_text>Now let's make a module for the Clausius-Clapeyron approximation.<jupyter_code>def CC_esat(TC):
    """
    Takes the temperature in Celsius (TC) as input and returns the 
    saturation vapor pressure in kPa
    """
    esat = 0.61078*np.exp(17.27*TC/(TC+237.3)) #the "e" function comes from the numpy library
    return esat<jupyter_output><empty_output><jupyter_text>Now we can feed this equation today's temperatures to calculate the saturation vapor pressure.<jupyter_code>esat_noon = CC_esat(TnoonC) #saturation vapor pressure at noon
esat_night = CC_esat(TnightC) #saturation vapor pressure at 4 am
print(esat_noon)
print(esat_night)<jupyter_output>1.83117137191
1.42320208583<jupyter_text>Let's now figure out actual vapor pressure from the relative humidity.<jupyter_code>ed_noon = esat_noon*RHnoon #in kPa
ed_night = esat_night*RHnight #in kPa
print(ed_noon)
print(ed_night)<jupyter_output>1.13532625058
1.3662740024<jupyter_text>Finally, let us convert the vapor pressures to mass in grams. Humidity in g/m3 is called the **absolute humidity.** We will do this using the ideal gas law, p=$\rho$RT. We need to solve this for the molar density and then convert it to a mass density.<jupyter_code>#First, let's enter some constants.
R = 8.314 #m3 Pa K−1 mol−1 We're going to need to do some more units conversions!
rho_noon = (ed_noon*1000)/(R*(TnoonC+273.15)) #now this is in moles/m^3
rho_night = (ed_night*1000)/(R*(TnightC+273.15))

#Now we will convert the molar densities to mass densities
MW_H2O = 18.01528 #grams of water per mole
m_noon = rho_noon*MW_H2O #grams per m^3
m_night = rho_night*MW_H2O
print(m_noon)
print(m_night)<jupyter_output>8.50475144674
10.3742594189<jupyter_text>Is the atmosphere at equilibrium with respect to water vapor content? Let's find out by solving for the actual vapor pressure from the dewpoint. Note that we can do this by plugging the dewpoint in to our saturation vapor pressure approximator above.<jupyter_code>ed_act_noon = CC_esat(Tdp_noonC) #in kPa
ed_act_night = CC_esat(Tdp_nightC) #in kPa
print(ed_act_noon)
print(ed_act_night)<jupyter_output>1.13943402461
0.839027797904
{'fraction_non_alphanumeric': 0.08657394266250355, 'fraction_numerical': 0.06443372126028953, 'mean_word_length': 5.776923076923077, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '517084', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1265, 'n_words': 393, 'path': 'ClausiusClapeyronModuleTutorial.ipynb', 'repo_name': 'LaurelOak/hydro-teaching-resources', 'size': '3523'}