Esempio n. 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
Esempio n. 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
Esempio n. 3
0
def main():
    """
    plots 2D domain map
    """

    lons = read_lon_lat(path_to_longitudes, subtract_360=True)
    lats = read_lon_lat(path_to_latitudes)

    cell_lat_lons = get_cell_lats_lons(path_to_infocell)
    cell_lons = []
    cell_lats = []
    for pair in cell_lat_lons:
        cell_lons.append(pair[0])
        cell_lats.append(pair[1])

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

    params = {
        "axes.labelsize": 14,
        "text.fontsize": 14,
        "legend.fontsize": 14,
        "xtick.labelsize": 16,
        "ytick.labelsize": 16,
        "figure.figsize": fig_size,
    }

    pylab.rcParams.update(params)

    lat_min = min(lats)
    lat_max = max(lats)

    lon_max = max(lons)
    lon_min = min(lons)

    print lon_min, lon_max
    print lat_min, lat_max

    m = Basemap(
        projection="npstere",
        resolution="i",
        lon_0=(lon_min + lon_max) / 2.0,
        lat_0=(lat_min + lat_max) / 2.0,
        boundinglat=40,
        lat_ts=60,
        llcrnrlon=lon_min,
        llcrnrlat=lat_min,
        urcrnrlon=lon_max,
        urcrnrlat=lat_max,
    )

    projected_lons, projected_lats = m(lons, lats)
    # m.scatter(projected_lons, projected_lats, color = "red", s = 0.1)

    projected_lons, projected_lats = m(cell_lons, cell_lats)
    m.scatter(projected_lons, projected_lats, color="green", s=45, marker="s")

    # show station positions
    manager = StationManager()
    manager.read_stations_from_files_rivdis()
    station_lons = []
    station_lats = []

    for station in manager.stations:
        station_lons.append(station.longitude)
        station_lats.append(station.latitude)

    print len(station_lons)

    projected_lons, projected_lats = m(station_lons, station_lats)
    m.scatter(projected_lons, projected_lats, color="red", s=45, marker="o")

    m.drawcoastlines()
    m.drawcountries()

    # m.fillcontinents(color='white',lake_color='blue', zorder=0)

    m.drawmeridians(np.arange(lon_min, lon_max, 10), labels=[0, 0, 0, 0])
    m.drawparallels(np.arange(lat_min, lat_max, 10), labels=[0, 0, 0, 0])

    y_min, y_max = plt.ylim()
    x_min, x_max = plt.xlim()

    plt.ylim(y_min, y_max / 2.0)
    plt.xlim(x_max / 4.0, 0.9 * x_max)

    plt.savefig("domain.png")