예제 #1
0
def tempContingencyTable(forecasts, observations, start_date, end_date, temp="H", stations=None, shift=None, period=None):
    """
    tempContingencyTable()
    Purpose:    Produce a continuous contingency table containing all the temperature forecasts for the period.
    Parameters: forecasts [type=dictionary]
                    Dictionary mapping shift days (e.g. 'Tue_Aft' for Tuesday Afternoon) to their OWLShift objects.
                observations [type=dictionary]
                    Dictionary mapping observation points (e.g. 'OUN' for Norman) to their ASOS objects.
                start_date [type=string]
                    String containing the date of the start of the verification period (format is 'YYYYMMDD_HH:MM').
                end_date [type=string]
                    String containing the date of the end of the verification period (format is 'YYYYMMDD_HH:MM', same as in start_date).
                temp [type=string]
                    String telling whether the high or low temperature is being evaluated.  "H" for high and "L" for low.
                stations [type=list,tuple,string]
                    A station or list of stations to include in the contingency table.  Optional, defaults to KOUN if not given.
                shift [type=string]
                    The shift to verify (e.g. 'Tue_Aft' for Tuesday Afternoon).  Not implemented yet.
                period [type=string]
                    The period to verify (one of '1A', '1B', '2', '3', or '4').  Optional, defaults to '1A' if not given.
    Returns:    The completed contingency table as a ContinuousContingencyTable object.
    """
    temp_ct = ContinuousContingencyTable(np.array([]),np.array([]))
    if period is None:
        period = OWLShift._forecast_days[0]

    if stations is None:
        stations = observations.keys()
    elif type(stations) not in [ list, tuple ]:
        stations = [ stations ]

    for shift_name, shift_data in forecasts.iteritems():
        for stn in stations:
            if temp.upper()=="H":
                temp_fcasts = shift_data.getForecasts(period, start_date, end_date, "TMPH", verif_to_fcst[stn])
            else:
                temp_fcasts = shift_data.getForecasts(period, start_date, end_date, "TMPL", verif_to_fcst[stn])
            
            shift_start_times, shift_end_times = temp_fcasts[:2]
            if temp.upper()=="H":
                temp_obs = observations[stn].getHighTemps(shift_start_times,shift_end_times)
                high_idxs = np.nonzero(temp_obs > 150)
                if len(high_idxs[0]) > 0:
                    print shift_start_times[high_idxs],temp_obs[high_idxs]
            else:
                temp_obs = observations[stn].getLowTemps(shift_start_times,shift_end_times)
            temp_ct.addPairs(temp_fcasts[2],temp_obs)
            
    return temp_ct
예제 #2
0
def windContingencyTable(forecasts, observations, start_date, end_date, winds="max", stations=None, shift=None, period=None):
    """
    windContingencyTable()
    Purpose:    Produce a continuous contingency table containing all the wind forecasts for the period.
    Parameters: forecasts [type=dictionary]
                    Dictionary mapping shift days (e.g. 'Tue_Aft' for Tuesday Afternoon) to their OWLShift objects.
                observations [type=dictionary]
                    Dictionary mapping observation points (e.g. 'OUN' for Norman) to their ASOS objects.
                start_date [type=string]
                    String containing the date of the start of the verification period (format is 'YYYYMMDD_HH:MM').
                end_date [type=string]
                    String containing the date of the end of the verification period (format is 'YYYYMMDD_HH:MM', same as in start_date).
                winds [type=string]
                    String telling whether the high or low temperature is being evaluated.  "H" for high and "L" for low.
                stations [type=list,tuple,string]
                    A station or list of stations to include in the contingency table.  Optional, defaults to KOUN if not given.
                shift [type=string]
                    The shift to verify (e.g. 'Tue_Aft' for Tuesday Afternoon).  Not implemented yet.
                period [type=string]
                    The period to verify (one of '1A', '1B', '2', '3', or '4').  Optional, defaults to '1A' if not given.
    Returns:    The completed contingency table as a ContinuousContingencyTable object.
    """
    wind_ct = ContinuousContingencyTable(np.array([]),np.array([]))
    if period is None:
        period = OWLShift._forecast_days[0]

    if stations is None:
        stations = observations.keys()
    elif type(stations) not in [ list, tuple ]:
        stations = [ stations ]

    for shift_name, shift_data in forecasts.iteritems():
        for stn in stations:
            if stn == 'KHHW' or stn == 'HHW':
                pass
            else:
                if winds.upper()=="MAX":
                    wind_fcasts = shift_data.getForecasts(period, start_date, end_date, "WSHI", verif_to_fcst[stn])
                else:
                    wind_fcasts = shift_data.getForecasts(period, start_date, end_date, "WSLO", verif_to_fcst[stn])

                shift_start_times, shift_end_times = wind_fcasts[:2]
                if winds.upper()=="MAX":
                    wind_obs = observations[stn].getMaxWinds(shift_start_times,shift_end_times)
                else:
                    wind_obs = observations[stn].getMinWinds(shift_start_times,shift_end_times)
                wind_ct.addPairs(wind_fcasts[2],wind_obs)
    return wind_ct