Example #1
0
def run_calcs(station, logfile, plots = False, diagnostics = False):
    '''
    Run the humidity calculations and add the attributes to the station file

    :param object station: station object
    :param file logfile: logfile to store outputs
    :param boolean diagnostics: output diagnostic information
    :param boolean plots: make a plot

    :returns: station - updated with humidity variables
    '''

    temperatures = utils.apply_flags_to_mask(station, "temperatures")
    dewpoints = utils.apply_flags_to_mask(station, "dewpoints")
   
    # adjust from sea-level to station-level
    station_pressure = get_station_level_pressure(station)
    

    e_v = utils.set_MetVar_attributes("vapor_pressure", "Vapor pressure calculated w.r.t water", "water_vapor_pressure", "hPa", temperatures.mdi, np.dtype('float64'))
    e_s = utils.set_MetVar_attributes("saturation_vapor_pressure", "Saturation vapor pressure calculated w.r.t. water", "water_vapor_pressure", "hPa", temperatures.mdi, np.dtype('float64'))
    Tw = utils.set_MetVar_attributes("wet_bulb_temperature", "Wet bulb temperatures nearest to reporting hour", "wet_bulb_temperature", "C", temperatures.mdi, np.dtype('float64'))
    q = utils.set_MetVar_attributes("specific_humidity", "Specific humidity", "specific_humidity", "g/kg", temperatures.mdi, np.dtype('float64'))
    rh = utils.set_MetVar_attributes("relative_humidity", "Relative humidity", "relative_humidity", "%rh", temperatures.mdi, np.dtype('float64'))


    # sort the vapour pressures and wet-bulb --> ice or water?
    e_v.data, e_s.data, Tw.data = fix_wrt_ice_or_water(temperatures.data, dewpoints.data, station_pressure)

    
    # get relative and specific humidity
    q.data = calculate_q(e_v.data, station_pressure)
    rh.data = calculate_rh(e_v.data, e_s.data)
    
    if plots or diagnostics:
        print "Humidity variables calculated, setting attributes\n"
    else:
        logfile.write("Humidity variables calculated, setting attributes\n")

    setattr(station, "vapour_pressure", e_v)
    setattr(station, "saturation_vapour_pressure", e_s)
    setattr(station, "wetbulb_temperature", Tw)
    setattr(station, "specific_humidity", q)
    setattr(station, "relative_humidity", rh)

    station = utils.append_history(station, "Humidity Calculations")

    return station # run_calcs
Example #2
0
def get_station_level_pressure(station):
    '''
    Convert from sea level pressure back to station level
    List, R. J.: Smithsonian Meteorological Tables, Vol. 114, 6th Edn.,
    Smithsonian Institution, Washington DC, 268 pp., 1963.

    :param object station: station object
    
    :returns: station level pressure (hPa)
    '''

    slp = utils.apply_flags_to_mask(station, "slp")
    temperatures = utils.apply_flags_to_mask(station, "temperatures")

    t_in_kelvin = temperatures.data + 273.15

    elevation = station.elev

    pressure = slp.data * np.ma.power(t_in_kelvin / (t_in_kelvin + 0.0065 * elevation), 5.625)

    return pressure # get_station_level_pressure