コード例 #1
0
def main():
    model = LatLonHolder()
    station_manager = StationManager()
    station_manager.read_stations_from_files_rivdis()

    selected_stations = []
    ij_list = []

    composite_index = 0
    for longitude, latitude in zip( model.longitudes, model.latitudes ):
        the_station = station_manager.get_station_closest_to(longitude, latitude)
        if the_station != None:
            selected_stations.append(the_station)
            ix = model.get_ix(composite_index)
            iy = model.get_iy(composite_index)
            ij_list.append([ix, iy])
            
        composite_index += 1

    for station in selected_stations:
        print station.longitude, station.latitude, station.id
    print ij_list
コード例 #2
0
def plot_monthly_means_with_measurements(model_points):
    years = mdates.YearLocator(5, month=1, day=1)  # every year
    months = mdates.MonthLocator()  # every month
    yearsFmt = mdates.DateFormatter("%Y")

    plt.cla()

    ##holder of longitudes and latitudes of the model grid points
    holder = LatLonHolder()

    # Manager of the measurement data
    station_manager = StationManager()
    station_manager.read_stations_from_files_rivdis()
    station_manager.read_data_from_files_hydat()

    print station_manager.get_station_by_id("02NG005")

    measure_stations = []
    selected_model_points = []
    for model_point in model_points:
        lon, lat = holder.get_lon_lat(model_point.ix, model_point.iy)
        the_station = station_manager.get_station_closest_to(lon, lat)
        if the_station != None:
            measure_stations.append(the_station)
            model_point.set_longitude(lon)
            model_point.set_latitude(lat)
            selected_model_points.append(model_point)

    fig = plt.figure(figsize=(18, 18))

    num_cols = 2
    num_rows = len(selected_model_points) / num_cols
    if len(selected_model_points) % num_cols > 0:
        num_rows += 1

    inches_per_pt = 1.0 / 72.27  # Convert pt to inch
    golden_mean = (sqrt(5) - 1.0) / 2.0  # Aesthetic ratio
    fig_width = 100.0 * inches_per_pt  # width in inches
    fig_height = fig_width * golden_mean  # height in inches
    fig_size = [fig_width, 10 * fig_height]

    params = {
        "axes.labelsize": 14,
        "text.fontsize": 14,
        "font.size": 14,
        "legend.fontsize": 14,
        "xtick.labelsize": 14,
        "ytick.labelsize": 14,
    }

    print "fig_size = ", fig_size

    pylab.rcParams.update(params)

    assert len(selected_model_points) > 0
    model_dates = selected_model_points[0].get_monthly_dates_sorted()

    for i, model_point in enumerate(selected_model_points):
        ax = plt.subplot(num_rows, num_cols, i + 1)
        # plot model data
        values = model_point.get_monthly_means_sorted_by_date()
        ax.plot(model_dates, values, label="model")

        # plot measurement data
        values = measure_stations[i].get_values_for_dates(model_dates)
        ax.plot(model_dates, values, "-", label="measurements", lw=3)

        plt.title(model_point.__str__() + "\n" + measure_stations[i].__str__())

        # format the ticks
        ax.xaxis.set_major_locator(years)
        ax.xaxis.set_major_formatter(yearsFmt)

        ax.legend()
        # ax.xaxis.set_minor_locator(months)

    fig.subplots_adjust(wspace=0.4)
    # fig.autofmt_xdate()
    fig.savefig("comparison.png")

    pass