Пример #1
0
def mapmaker(domain, **kwargs):
    if kwargs.get('map_bbox', None) is not None:
        map_bbox = kwargs['map_bbox']
    else:
        map_bbox = None

    if domain == 'terrestrial':
        if map_bbox is not None:
            try:
                # Convert to a native-typed bounding box
                from tracktable.domain.terrestrial import BoundingBox, BasePoint
                min_corner = BasePoint(map_bbox[0], map_bbox[1])
                max_corner = BasePoint(map_bbox[2], map_bbox[3])
                bbox = BoundingBox(min_corner, max_corner)
                kwargs['map_bbox'] = bbox
            except TypeError: # it's already a bbox
                pass
        return terrestrial_map(**kwargs)
    elif domain == 'cartesian' or domain == 'cartesian2d':
        if map_bbox is not None:
            try:
                # Convert to a native-typed bounding box
                from tracktable.domain.cartesian2d import BoundingBox, BasePoint
                min_corner = BasePoint(map_bbox[0], map_bbox[1])
                max_corner = BasePoint(map_bbox[2], map_bbox[3])
                bbox = BoundingBox(min_corner, max_corner)
                kwargs['map_bbox'] = bbox
            except TypeError: # it's already a bbox
                pass

        return cartesian_map(**kwargs)
Пример #2
0
def render_histogram(mymap,
                     domain,
                     point_source,
                     bounding_box,
                     bin_size=2,
                     color_map='gist_gray',
                     scale_type='linear',
                     zorder=8):
    """Compile all the points in a source into a 2D histogram, then render
    that histogram onto an already-prepared map."""

    if scale_type.lower() == 'linear':
        scale = matplotlib.colors.Normalize()
    elif scale_type.lower() in ['log', 'logarithmic']:
        scale = matplotlib.colors.LogNorm()
    else:
        raise ValueError(
            "ERROR: Unknown scale type '{}'.  Legal values are 'linear', 'log' and 'logarithmic'."
            .format(scale_type))

    if domain == 'terrestrial':
        # Deduce bounding box from map.  Whatever the user requested
        # has already been figured out there.
        from tracktable.domain.terrestrial import BasePoint, BoundingBox
        min_corner = BasePoint(mymap.llcrnrlon, mymap.llcrnrlat)
        max_corner = BasePoint(mymap.urcrnrlon, mymap.urcrnrlat)
        bounding_box = BoundingBox(min_corner, max_corner)

        return histogram2d.render_histogram(map_projection=mymap,
                                            point_source=point_source,
                                            bounding_box=bounding_box,
                                            bin_size=bin_size,
                                            colormap=color_map,
                                            colorscale=scale,
                                            zorder=zorder)
    elif domain == 'cartesian2d':
        # TODO: Bounding box should have been attached to map projection.
        print("DEBUG: Data bounds: {}".format(bounding_box))
        return histogram2d.render_histogram(mymap,
                                            point_source=point_source,
                                            bounding_box=bounding_box,
                                            bin_size=bin_size,
                                            colormap=color_map,
                                            colorscale=scale,
                                            zorder=zorder)
    else:
        raise AttributeError(
            'Domain {} does not yet have histogram support.'.format(domain))
Пример #3
0
def generate_points(howmany):
    points = []

    for i in range(howmany):
        longitude = (10 * howmany % 360) - 180
        latitude = (5 * howmany % 180) - 90

        points.append(BasePoint(longitude, latitude))

    return points
Пример #4
0
def test_geographic_histogram(outfilename):
    min_corner = BasePoint(-180, -23.4378)
    max_corner = BasePoint(180, 23.4378)
    bbox = BoundingBox(min_corner, max_corner)
    num_points = 100000

    points_in_tropics = random_box_uniform(min_corner, max_corner, num_points)

   
    pyplot.figure()
    pyplot.subplot(111, aspect='equal')

    mymap = mapmaker(domain='terrestrial', map_name='region:world')

    histogram2d.render_histogram(map_projection=mymap,
                                 point_source=points_in_tropics,
                                 bounding_box=bbox,
                                 bin_size=0.5,
                                 colormap='gist_heat',
                                 colorscale=matplotlib.colors.LogNorm())
    pyplot.savefig(outfilename, figsize=(4, 4), dpi=150)
    return True
Пример #5
0
def terrestrial_map(map_name,
                    draw_coastlines=True,
                    draw_countries=True,
                    draw_states=True,
                    draw_lonlat=True,
                    land_color='#101010',
                    sea_color='#000000',
                    lonlat_spacing=10,
                    lonlat_color='#A0A0A0',
                    lonlat_linewidth=0.2,
                    lonlat_zorder=4,
                    coastline_color='#808080',
                    coastline_linewidth=1,
                    coastline_zorder=3,
                    country_color='#606060',
                    country_linewidth=0.5,
                    country_zorder=2,
                    state_color='#404040',
                    state_linewidth=0.3,
                    state_zorder=1,
                    draw_largest_cities=None,
                    draw_cities_larger_than=None,
                    city_label_size=12,
                    city_dot_size=2,
                    city_dot_color='white',
                    city_label_color='white',
                    border_resolution='i',
                    map_bbox=None,
                    map_projection=None,
                    map_scale_length=None,
                    region_size=None,
                    axes=None,
                    **kwargs):

    """Create and decorate a map

    Call the Basemap toolkit to create a map of some predefined area,
    up to and including the entire world.  The map will be decorated
    with some subset of coastlines, country borders, state/province
    borders and cities.

    Args:
      map_name:            Region name (one of the choices in
                           render.maps.available_maps()) or 'airport:XXX' or 'custom'
      draw_coastlines:     Whether or not to draw coastlines on the map
      draw_countries:      Whether or not to draw country borders on the map
      draw_states:         Whether or not to draw US/Canada state borders
      draw_lonlat:         Whether or not to draw longitude/latitude lines
      land_color:          Color name or hex string for land area
      sea_color:           Color name or hex string for sea area
      lonlat_spacing:      Distance in degrees between lon/lat lines
      lonlat_color:        Color name or hex string for longitude/latitude lines
      lonlat_linewidth:    Width (in point) for lon/lat lines
      lonlat_zorder:       Image layer for coastlines
      coastline_color:     Color name or hex string for coastlines
      coastline_linewidth: Width (in points) of coastlines
      coastline_zorder:    Image layer for coastlines
      country_color:       Color name or hex string for coastlines
      country_linewidth:   Width (in points) of coastlines
      country_zorder:      Image layer for coastlines
      state_color:         Color name or hex string for coastlines
      state_linewidth:     Width (in points) of coastlines
      state_zorder:        Image layer for coastlines
      draw_largest_cities: Draw the N largest cities on the map
      draw_cities_larger_than: Draw cities with populations greater than N
      city_label_size:     Size (in points) for city name labels
      city_dot_size:       Size (in points) for city markers
      city_dot_color:      Color name or hex string for city markers
      city_label_color:    Color name or hex string for city names
      border_resolution:   'c', 'i', 'h' or 'f' (in increasing order of complexity)
      axes:                Matplotlib axes to render into
      map_bbox:            Bounding box for custom map extent
      region_size:         Size of region depicted around an airport (km width x km height)
      map_projection:      Matplotlib string for map projection
      map_scale_length:    Length of map scale indicator (in km)

    Raises:
      KeyError: unknown map name

    Returns:
      (basemap, artist_list): Basemap instance and a list of Matplotlib artists that were rendered
    """

    if map_name == "custom":
        (mymap, artists) = maps.draw_custom_map(bounding_box=map_bbox,
                                                projection=map_projection,
                                                resolution=border_resolution,
                                                axes=axes)
    else:
        (mymap, artists) = draw_basemap(map_name,
                                        resolution=border_resolution,
                                        region_size=region_size,
                                        axes=axes
                                        )

    artists.extend(maps.fill_continents(mymap,
                                        land_color=land_color,
                                        sea_color=sea_color,
                                        zorder=0))
    if draw_coastlines:
        artists.extend(maps.draw_coastlines(mymap,
                                            linewidth=coastline_linewidth,
                                            color=coastline_color,
                                            zorder=coastline_zorder))

    if draw_countries:
        artists.extend(maps.draw_countries(mymap,
                                           linewidth=country_linewidth,
                                           color=country_color,
                                           zorder=country_zorder))

    if draw_states:
        artists.extend(maps.draw_states(mymap,
                                        linewidth=state_linewidth,
                                        color=state_color,
                                        zorder=state_zorder))

    if draw_lonlat:
        artists.extend(maps.draw_lonlat(mymap,
                                        spacing=lonlat_spacing,
                                        color=lonlat_color,
                                        linewidth=lonlat_linewidth,
                                        zorder=lonlat_zorder))

    if draw_largest_cities is not None:
        artists.extend(maps.draw_largest_cities(mymap,
                                                draw_largest_cities,
                                                dot_color=city_dot_color,
                                                dot_size=city_dot_size,
                                                label_color=city_label_color,
                                                label_size=city_label_size))

    if draw_cities_larger_than is not None:
        artists.extend(maps.draw_cities_larger_than(mymap,
                                                    draw_cities_larger_than,
                                                    dot_color=city_dot_color,
                                                    dot_size=city_dot_size,
                                                    label_color=city_label_color,
                                                    label_size=city_label_size))

    if map_scale_length is not None:
        artists.extend(maps.draw_scale(mymap,
                                       map_scale_length,
                                       label_color=city_label_color,
                                       label_size=city_label_size))

    from tracktable.domain.terrestrial import BoundingBox, BasePoint
    mymap.bbox = BoundingBox(
        BasePoint(mymap.llcrnrlon, mymap.llcrnrlat),
        BasePoint(mymap.urcrnrlon, mymap.urcrnrlat)
        )
    return (mymap, artists)