Ejemplo n.º 1
0
def test_vega_heat_map():
    vega = vega_heatmap(1900, 1410,
                        [-73.998427, 40.730309, -73.954348, 40.780816], 10.0,
                        "EPSG:3857").build()
    vega_dict = json.loads(vega)
    assert vega_dict["width"] == 1900
    assert vega_dict["height"] == 1410
    assert vega_dict["marks"][0]["encode"]["enter"]["bounding_box"]["value"][
        0] == -73.998427
    assert vega_dict["marks"][0]["encode"]["enter"]["bounding_box"]["value"][
        1] == 40.730309
    assert vega_dict["marks"][0]["encode"]["enter"]["bounding_box"]["value"][
        2] == -73.954348
    assert vega_dict["marks"][0]["encode"]["enter"]["bounding_box"]["value"][
        3] == 40.780816
    assert vega_dict["marks"][0]["encode"]["enter"]["map_zoom_level"][
        "value"] == 10.0
    assert vega_dict["marks"][0]["encode"]["enter"]["coordinate_system"][
        "value"] == "EPSG:3857"
    assert vega_dict["marks"][0]["encode"]["enter"]["aggregation_type"][
        "value"] == "sum"

    vega = vega_heatmap(1900, 1410,
                        [-73.998427, 40.730309, -73.954348, 40.780816],
                        10.0).build()
    vega_dict = json.loads(vega)
    assert vega_dict["marks"][0]["encode"]["enter"]["coordinate_system"][
        "value"] == "EPSG:4326"
Ejemplo n.º 2
0
def draw_heat_map(spark):
    start_time = time.time()
    df = spark.read.format("csv").option("header", True).option(
        "delimiter", ","
    ).schema(
        "VendorID string, tpep_pickup_datetime timestamp, tpep_dropoff_datetime timestamp, passenger_count long, trip_distance double, pickup_longitude double, pickup_latitude double, dropoff_longitude double, dropoff_latitude double, fare_amount double, tip_amount double, total_amount double, buildingid_pickup long, buildingid_dropoff long, buildingtext_pickup string, buildingtext_dropoff string"
    ).load("file:///tmp/0_5M_nyc_taxi_and_building.csv").cache()
    df.createOrReplaceTempView("nyc_taxi")

    register_funcs(spark)
    res = spark.sql(
        "select ST_Point(pickup_longitude, pickup_latitude) as point, passenger_count as w from nyc_taxi where ST_Within(ST_Point(pickup_longitude, pickup_latitude),  ST_GeomFromText('POLYGON ((-73.998427 40.730309, -73.954348 40.730309, -73.954348 40.780816 ,-73.998427 40.780816, -73.998427 40.730309))'))"
    )

    res.show()

    vega = vega_heatmap(1024, 896,
                        [-73.998427, 40.730309, -73.954348, 40.780816], 10.0,
                        'EPSG:4326')
    res = heatmap(vega, res)
    save_png(res, '/tmp/heatmap.png')

    spark.sql("show tables").show()
    spark.catalog.dropGlobalTempView("nyc_taxi")
    print("--- %s seconds ---" % (time.time() - start_time))
Ejemplo n.º 3
0
def test_heat_map():
    x_data = []
    y_data = []
    c_data = []

    x_data.append(-73.96524)
    x_data.append(-73.96118)
    x_data.append(-73.97324)
    x_data.append(-73.98456)

    y_data.append(40.73747)
    y_data.append(40.74507)
    y_data.append(40.75890)
    y_data.append(40.77654)

    c_data.append(10)
    c_data.append(20)
    c_data.append(30)
    c_data.append(40)

    arr_x = pandas.Series(x_data)
    arr_y = pandas.Series(y_data)
    arr_c = pandas.Series(c_data)
    points = arctern.ST_Point(arr_x, arr_y)

    vega = vega_heatmap(
        1024,
        896,
        bounding_box=[-73.998427, 40.730309, -73.954348, 40.780816],
        map_zoom_level=13.0,
        coordinate_system='EPSG:4326')
    heat_map1 = arctern.heat_map_layer(vega, points, arr_c)

    save_png(heat_map1, "/tmp/test_heat_map1.png")
Ejemplo n.º 4
0
def heatmap(ax,
            points,
            weights,
            bounding_box,
            map_zoom_level=None,
            coordinate_system='EPSG:3857',
            aggregation_type='max',
            **extra_contextily_params):
    """
    :type ax: AxesSubplot
    :param ax: Matplotlib axes object on which to add the basemap.

    :type points: Series(dtype: object)
    :param points: Points in WKB form
    :type bounding_box: (float, float, float, float)
    :param bounding_box: The bounding rectangle, as a [left, upper, right, lower]-tuple.
                                             value should be of :coordinate_system:
    :type coordinate_system: str
    :param coordinate_system: either 'EPSG:4326' or 'EPSG:3857'
    :type extra_contextily_params: dict
    :param extra_contextily_params: extra parameters for contextily.add_basemap.
                                                                    See https://contextily.readthedocs.io/en/latest/reference.html
    """
    from matplotlib import pyplot as plt
    import contextily as cx
    bbox = _transform_bbox(bounding_box, coordinate_system, 'epsg:3857')
    w, h = _get_recom_size(bbox[2] - bbox[0], bbox[3] - bbox[1])
    if map_zoom_level is None:
        map_zoom_level = _calc_zoom(bounding_box, coordinate_system)
    vega = vega_heatmap(w,
                        h,
                        bounding_box=bounding_box,
                        map_zoom_level=map_zoom_level,
                        aggregation_type=aggregation_type,
                        coordinate_system=coordinate_system)
    hexstr = arctern.heat_map_layer(vega, points, weights)
    f = io.BytesIO(base64.b64decode(hexstr))

    img = plt.imread(f)
    ax.set(xlim=(bbox[0], bbox[2]), ylim=(bbox[1], bbox[3]))
    cx.add_basemap(ax, **extra_contextily_params)
    ax.imshow(img,
              alpha=img[:, :, 3],
              extent=(bbox[0], bbox[2], bbox[1], bbox[3]))
Ejemplo n.º 5
0
def test_heat_map():
    x_data = []
    y_data = []
    c_data = []

    for i in range(0, 5):
        x_data.append(i + 50)
        y_data.append(i + 50)
        c_data.append(i + 50)

    arr_x = pandas.Series(x_data)
    arr_y = pandas.Series(y_data)
    points = arctern.ST_Point(arr_x, arr_y)
    arr_c = pandas.Series(y_data)

    vega = vega_heatmap(1024, 896, [-73.998427, 40.730309, -73.954348, 40.780816], 10.0, 'EPSG:4326')
    heat_map1 = arctern.heat_map(vega, points, arr_c)

    save_png(heat_map1, "/tmp/test_heat_map1.png")
Ejemplo n.º 6
0
def draw_heat_map(spark):
    df = spark.read.format("csv").option("header", True).option(
        "delimiter", ","
    ).schema(
        "VendorID string, tpep_pickup_datetime timestamp, tpep_dropoff_datetime timestamp, passenger_count long, trip_distance double, pickup_longitude double, pickup_latitude double, dropoff_longitude double, dropoff_latitude double, fare_amount double, tip_amount double, total_amount double, buildingid_pickup long, buildingid_dropoff long, buildingtext_pickup string, buildingtext_dropoff string"
    ).load(data_path).cache()
    df.show(20, False)
    df.createOrReplaceTempView("nyc_taxi")

    register_funcs(spark)
    res = spark.sql(
        "select ST_Point(pickup_longitude, pickup_latitude) as point, passenger_count as w from nyc_taxi where ST_Within(ST_Point(pickup_longitude, pickup_latitude),  'POLYGON ((-73.998427 40.730309, -73.954348 40.730309, -73.954348 40.780816 ,-73.998427 40.780816, -73.998427 40.730309))')"
    )

    vega = vega_heatmap(1024, 896, 10.0,
                        [-73.998427, 40.730309, -73.954348, 40.780816],
                        'EPSG:4326')
    res = heatmap(res, vega)
    save_png(res, '/tmp/heatmap.png')

    spark.sql("show tables").show()
    spark.catalog.dropGlobalTempView("nyc_taxi")
Ejemplo n.º 7
0
def test_heat_map():
    x_data = []
    y_data = []
    c_data = []

    for i in range(0, 5):
        x_data.append(i + 50)
        y_data.append(i + 50)
        c_data.append(i + 50)

    arr_x = pandas.Series(x_data)
    arr_y = pandas.Series(y_data)
    arr_c = pandas.Series(y_data)

    vega_heat_map = vega_heatmap(
        1024, 896, 10.0, [-73.998427, 40.730309, -73.954348, 40.780816],
        'EPSG:4326')
    vega_json = vega_heat_map.build()

    heat_map1 = arctern.heat_map(arr_x, arr_y, arr_c,
                                 vega_json.encode('utf-8'))
    save_png(heat_map1, "/tmp/test_heat_map1.png")
Ejemplo n.º 8
0
def heatmap(ax,
            points,
            weights,
            bounding_box,
            map_zoom_level=None,
            coordinate_system='EPSG:3857',
            aggregation_type='max',
            **extra_contextily_params):
    """
    Plot heatmap in matplotlibs

    :type ax: AxesSubplot
    :param ax: Matplotlib axes object on which to add the basemap.

    :type points: GeoSeries
    :param points: Sequence of Points

    :type weights: Series(dtype: float|int64)
    :param weights: Weights of point intensity

    :type bounding_box: list
    :param bounding_box: Specify the bounding rectangle [west, south, east, north].

    :type map_zoom_level: int
    :param map_zoom_level: Zoom level of heatmap. Default as auto.

    :type coordinate_system: str
    :param coordinate_system: Coordinate Reference System of the geometry objects.
                              Must be SRID formed, e.g. 'EPSG:4326' or 'EPSG:3857'
                              Default as 'EPSG:3857'

    :type aggregation_type: str
    :param aggregation_type: Aggregation type of data processing. Default as 'max'

    :type extra_contextily_params: dict
    :param extra_contextily_params: Extra parameters will be passed to contextily.add_basemap.
                                    See https://contextily.readthedocs.io/en/latest/reference.html for details

    :example:
    >>> import pandas as pd
    >>> import numpy as np
    >>> import arctern
    >>> import matplotlib.pyplot as plt
    >>> # read from test_data.csv
    >>> # Download link: https://raw.githubusercontent.com/arctern-io/arctern-resources/benchmarks/benchmarks/dataset/layer_rendering_test_data/test_data.csv
    >>> df = pd.read_csv("/path/to/test_data.csv", dtype={'longitude':np.float64, 'latitude':np.float64, 'color_weights':np.float64, 'size_weights':np.float64, 'region_boundaries':np.object})
    >>> points = arctern.GeoSeries.point(df['longitude'], df['latitude'])
    >>>
    >>> # plot heatmap
    >>> fig, ax = plt.subplots(figsize=(10, 6), dpi=200)
    >>> arctern.plot.heatmap(ax, points, df['color_weights'], bounding_box=[-74.01424568752932, 40.72759334104623, -73.96056823889673, 40.76721122683304], coordinate_system='EPSG:4326')
    >>> plt.show()
    """
    from matplotlib import pyplot as plt
    import contextily as cx
    bbox = _transform_bbox(bounding_box, coordinate_system, 'epsg:3857')
    w, h = _get_recom_size(bbox[2] - bbox[0], bbox[3] - bbox[1])
    if map_zoom_level is None:
        map_zoom_level = _calc_zoom(bounding_box, coordinate_system)
    vega = vega_heatmap(w,
                        h,
                        bounding_box=bounding_box,
                        map_zoom_level=map_zoom_level,
                        aggregation_type=aggregation_type,
                        coordinate_system=coordinate_system)
    hexstr = arctern.heat_map_layer(vega, points, weights)
    f = io.BytesIO(base64.b64decode(hexstr))

    img = plt.imread(f)
    ax.set(xlim=(bbox[0], bbox[2]), ylim=(bbox[1], bbox[3]))
    cx.add_basemap(ax, **extra_contextily_params)
    ax.imshow(img,
              alpha=img[:, :, 3],
              extent=(bbox[0], bbox[2], bbox[1], bbox[3]))
    ax.axis('off')
Ejemplo n.º 9
0
def db_query():
    """
    /db/query handler
    """
    log.INSTANCE.info('POST /db/query: {}'.format(request.json))

    if not utils.check_json(request.json, 'id') \
            or not utils.check_json(request.json, 'query') \
            or not utils.check_json(request.json['query'], 'type') \
            or not utils.check_json(request.json['query'], 'sql'):
        return jsonify(status='error', code=-1, message='query format error')

    query_sql = request.json['query']['sql']
    query_type = request.json['query']['type']

    content = {}
    content['sql'] = query_sql
    content['err'] = False

    db_instance = db.CENTER.get(str(request.json['id']), None)
    if db_instance is None:
        return jsonify(status="error",
                       code=-1,
                       message='there is no database whose id equal to ' +
                       str(request.json['id']))

    if query_type == 'sql':
        res = db_instance.run_for_json(query_sql)
        data = []
        for row in res:
            obj = json.loads(row)
            data.append(obj)
        content['result'] = data
    else:
        if not utils.check_json(request.json['query'], 'params'):
            return jsonify(status='error',
                           code=-1,
                           message='query format error')
        query_params = request.json['query']['params']

        res = db_instance.run(query_sql)

        if query_type == 'point':
            vega = vega_pointmap(int(query_params['width']),
                                 int(query_params['height']),
                                 query_params['point']['bounding_box'],
                                 int(query_params['point']['point_size']),
                                 query_params['point']['point_color'],
                                 float(query_params['point']['opacity']),
                                 query_params['point']['coordinate_system'])
            data = pointmap(vega, res)
            content['result'] = data
        elif query_type == 'heat':
            vega = vega_heatmap(int(query_params['width']),
                                int(query_params['height']),
                                query_params['heat']['bounding_box'],
                                float(query_params['heat']['map_zoom_level']),
                                query_params['heat']['coordinate_system'],
                                query_params['heat']['aggregation_type'])
            data = heatmap(vega, res)
            content['result'] = data
        elif query_type == 'choropleth':
            vega = vega_choroplethmap(
                int(query_params['width']), int(query_params['height']),
                query_params['choropleth']['bounding_box'],
                query_params['choropleth']['color_gradient'],
                query_params['choropleth']['color_bound'],
                float(query_params['choropleth']['opacity']),
                query_params['choropleth']['coordinate_system'],
                query_params['choropleth']['aggregation_type'])
            data = choroplethmap(vega, res)
            content['result'] = data
        elif query_type == 'weighted':
            vega = vega_weighted_pointmap(
                int(query_params['width']), int(query_params['height']),
                query_params['weighted']['bounding_box'],
                query_params['weighted']['color_gradient'],
                query_params['weighted']['color_bound'],
                query_params['weighted']['size_bound'],
                float(query_params['weighted']['opacity']),
                query_params['weighted']['coordinate_system'])
            data = weighted_pointmap(vega, res)
            content['result'] = data
        elif query_type == 'icon':
            vega = vega_icon(int(query_params['width']),
                             int(query_params['height']),
                             query_params['icon']['bounding_box'],
                             query_params['icon']['icon_path'],
                             query_params['icon']['coordinate_system'])
            data = icon_viz(vega, res)
            content['result'] = data
        else:
            return jsonify(status="error",
                           code=-1,
                           message='{} not support'.format(query_type))

    return jsonify(status="success", code=200, data=content)
Ejemplo n.º 10
0
    bounding_box=[pos1[0], pos1[1], pos2[0], pos2[1]],
    color_gradient=["#115f9a", "#d0f400"],
    color_bound=[1, 50],
    size_bound=[3, 15],
    opacity=1.0,
    coordinate_system="EPSG:4326")
png = weighted_point_map_layer(vega,
                               ST_Point(pickup_df.pickup_longitude,
                                        pickup_df.pickup_latitude),
                               color_weights=df.head(limit_num).fare_amount,
                               size_weights=df.head(limit_num).total_amount)
save_png(png, "/tmp/arctern_weighted_pointmap_pandas.png")

vega = vega_heatmap(1024,
                    384,
                    bounding_box=[pos1[0], pos1[1], pos2[0], pos2[1]],
                    map_zoom_level=13.0,
                    coordinate_system="EPSG:4326")
png = heat_map_layer(
    vega, ST_Point(pickup_df.pickup_longitude, pickup_df.pickup_latitude),
    df.head(limit_num).fare_amount)
save_png(png, "/tmp/arctern_heatmap_pandas.png")

vega = vega_choroplethmap(1024,
                          384,
                          bounding_box=[pos1[0], pos1[1], pos2[0], pos2[1]],
                          color_gradient=["#115f9a", "#d0f400"],
                          color_bound=[2.5, 5],
                          opacity=1.0,
                          coordinate_system="EPSG:4326")
png = choropleth_map_layer(vega,
Ejemplo n.º 11
0
def heatmap(ax,
            points,
            weights,
            bounding_box,
            map_zoom_level=None,
            coordinate_system='EPSG:3857',
            aggregation_type='max',
            **extra_contextily_params):
    """
    Plots a heat map in matplotlib.

    Parameters
    ----------
    ax : matplotlib.axes.Axes
        Axes where geometries will be plotted.
    points : GeoSeries
        Sequence of points.
    weights : Series
        Weights of point intensity.
    bounding_box : list
        Bounding box of the map. For example, [west, south, east, north].
    map_zoom_level : [type], optional
        Zoom level of the map by default 'auto'.
    coordinate_system : str, optional
        The Coordinate Reference System (CRS) set to all geometries, by default 'EPSG:3857'.
        Only supports SRID as a WKT representation of CRS by now.
    aggregation_type : str, optional
        Aggregation type, by default 'max'.
    **extra_contextily_params: dict
        Extra parameters passed to `contextily.add_basemap. <https://contextily.readthedocs.io/en/latest/reference.html>`_

    Examples
    -------
    >>> import pandas as pd
    >>> import numpy as np
    >>> import arctern
    >>> import matplotlib.pyplot as plt
    >>> # read from test_data.csv
    >>> # Download link: https://raw.githubusercontent.com/arctern-io/arctern-resources/benchmarks/benchmarks/dataset/layer_rendering_test_data/test_data.csv
    >>> df = pd.read_csv("/path/to/test_data.csv", dtype={'longitude':np.float64, 'latitude':np.float64, 'color_weights':np.float64, 'size_weights':np.float64, 'region_boundaries':np.object})
    >>> points = arctern.GeoSeries.point(df['longitude'], df['latitude'])
    >>>
    >>> # plot heatmap
    >>> fig, ax = plt.subplots(figsize=(10, 6), dpi=200)
    >>> arctern.plot.heatmap(ax, points, df['color_weights'], bounding_box=[-74.01424568752932, 40.72759334104623, -73.96056823889673, 40.76721122683304], coordinate_system='EPSG:4326')
    >>> plt.show()
    """
    from matplotlib import pyplot as plt
    import contextily as cx
    bbox = _transform_bbox(bounding_box, coordinate_system, 'epsg:3857')
    w, h = _get_recom_size(bbox[2] - bbox[0], bbox[3] - bbox[1])
    if map_zoom_level is None:
        map_zoom_level = _calc_zoom(bounding_box, coordinate_system)
    vega = vega_heatmap(w,
                        h,
                        bounding_box=bounding_box,
                        map_zoom_level=map_zoom_level,
                        aggregation_type=aggregation_type,
                        coordinate_system=coordinate_system)
    hexstr = arctern.heat_map_layer(vega, points, weights)
    f = io.BytesIO(base64.b64decode(hexstr))

    img = plt.imread(f)
    ax.set(xlim=(bbox[0], bbox[2]), ylim=(bbox[1], bbox[3]))
    cx.add_basemap(ax, **extra_contextily_params)
    ax.imshow(img,
              alpha=img[:, :, 3],
              extent=(bbox[0], bbox[2], bbox[1], bbox[3]))
    ax.axis('off')
Ejemplo n.º 12
0
def db_query():
    """
    /db/query handler
    """
    if not utils.check_json(request.json, 'id') \
            or not utils.check_json(request.json, 'query') \
            or not utils.check_json(request.json['query'], 'type') \
            or not utils.check_json(request.json['query'], 'sql'):
        return jsonify(status='error', code=-1, message='query format error')

    query_sql = request.json['query']['sql']
    query_type = request.json['query']['type']

    content = {}
    content['sql'] = query_sql
    content['err'] = False

    if query_type == 'sql':
        res = spark.Spark.run_for_json(query_sql)
        data = []
        for row in res:
            obj = json.loads(row)
            data.append(obj)
        content['result'] = data
    else:
        if not utils.check_json(request.json['query'], 'params'):
            return jsonify(status='error',
                           code=-1,
                           message='query format error')
        query_params = request.json['query']['params']

        res = spark.Spark.run(query_sql)

        if query_type == 'point':
            vega = vega_pointmap(int(query_params['width']),
                                 int(query_params['height']),
                                 query_params['point']['bounding_box'],
                                 int(query_params['point']['stroke_width']),
                                 query_params['point']['stroke'],
                                 float(query_params['point']['opacity']),
                                 query_params['point']['coordinate'])
            data = pointmap(res, vega)
            content['result'] = data
        elif query_type == 'heat':
            vega = vega_heatmap(int(query_params['width']),
                                int(query_params['height']),
                                float(query_params['heat']['map_scale']),
                                query_params['heat']['bounding_box'],
                                query_params['heat']['coordinate'])
            data = heatmap(res, vega)
            content['result'] = data
        elif query_type == 'choropleth':
            vega = vega_choroplethmap(
                int(query_params['width']), int(query_params['height']),
                query_params['choropleth']['bounding_box'],
                query_params['choropleth']['color_style'],
                query_params['choropleth']['rule'],
                float(query_params['choropleth']['opacity']),
                query_params['choropleth']['coordinate'])
            data = choroplethmap(res, vega)
            content['result'] = data
        else:
            return jsonify(status="error",
                           code=-1,
                           message='{} not support'.format(query_type))
    return jsonify(status="success", code=200, data=content)
Ejemplo n.º 13
0
def run_test_heat_map(spark):
    df = spark.read.format("csv").option("header", True).option("delimiter", ",").schema(
        "VendorID string, tpep_pickup_datetime timestamp, tpep_dropoff_datetime timestamp, passenger_count long, "
        "trip_distance double, pickup_longitude double, pickup_latitude double, dropoff_longitude double, "
        "dropoff_latitude double, fare_amount double, tip_amount double, total_amount double, buildingid_pickup long, "
        "buildingid_dropoff long, buildingtext_pickup string, buildingtext_dropoff string").load(
        file_path).cache()
    df.createOrReplaceTempView("nyc_taxi")

    register_funcs(spark)
    res = spark.sql(
        "select ST_Point(pickup_longitude, pickup_latitude) as point, passenger_count as w from nyc_taxi where ST_Within(ST_Point(pickup_longitude, pickup_latitude),  'POLYGON ((-73.998427 40.730309, -73.954348 40.730309, -73.954348 40.780816 ,-73.998427 40.780816, -73.998427 40.730309))')")

    # 1 size:1024*896, map_scale: 10.0
    vega_1 = vega_heatmap(1024, 896, 10.0, [-73.998427, 40.730309, -73.954348, 40.780816], 'EPSG:4326')
    baseline1 = heatmap(res, vega_1)
    heat_map1_1 = heatmap(res, vega_1)
    heat_map1_2 = heatmap(res, vega_1)

    baseline_png1 = png_path + "heat_map_nyc_1.png"
    save_png(baseline1, baseline_png1)
    save_png(heat_map1_1, png_path + "test_heat_map_nyc_1-1.png")
    save_png(heat_map1_2, png_path + "test_heat_map_nyc_1-2.png")

    # 2 map_scale: 0.0
    vega_2 = vega_heatmap(1024, 896, 0.0, [-73.998427, 40.730309, -73.954348, 40.780816], 'EPSG:4326')
    baseline2 = heatmap(res, vega_2)
    heat_map2_1 = heatmap(res, vega_2)
    heat_map2_2 = heatmap(res, vega_2)

    baseline_png2 = png_path + "heat_map_nyc_2.png"
    save_png(baseline2, baseline_png2)
    save_png(heat_map2_1, png_path + "test_heat_map_nyc_2-1.png")
    save_png(heat_map2_2, png_path + "test_heat_map_nyc_2-2.png")

    # 3 map_scale: 12.0
    vega_3 = vega_heatmap(1024, 896, 12.0, [-73.998427, 40.730309, -73.954348, 40.780816], 'EPSG:4326')
    baseline3 = heatmap(res, vega_3)
    heat_map3_1 = heatmap(res, vega_3)
    heat_map3_2 = heatmap(res, vega_3)

    baseline_png3 = png_path + "heat_map_nyc_3.png"
    save_png(baseline3, baseline_png3)
    save_png(heat_map3_1, png_path + "test_heat_map_nyc_3-1.png")
    save_png(heat_map3_2, png_path + "test_heat_map_nyc_3-2.png")

    # 4 map_scale: 5.5
    vega_4 = vega_heatmap(1024, 896, 5.5, [-73.998427, 40.730309, -73.954348, 40.780816], 'EPSG:4326')
    baseline4 = heatmap(res, vega_4)
    heat_map4_1 = heatmap(res, vega_4)
    heat_map4_2 = heatmap(res, vega_4)

    baseline_png4 = png_path + "heat_map_nyc_4.png"
    save_png(baseline4, baseline_png4)
    save_png(heat_map4_1, png_path + "test_heat_map_nyc_4-1.png")
    save_png(heat_map4_2, png_path + "test_heat_map_nyc_4-2.png")

    # 5 size:200*200
    vega_5 = vega_heatmap(200, 200, 10.0, [-73.998427, 40.730309, -73.954348, 40.780816], 'EPSG:4326')
    baseline5 = heatmap(res, vega_5)
    heat_map5_1 = heatmap(res, vega_5)
    heat_map5_2 = heatmap(res, vega_5)

    baseline_png5 = png_path + "heat_map_nyc_5.png"
    save_png(baseline5, baseline_png5)
    save_png(heat_map5_1, png_path + "test_heat_map_nyc_5-1.png")
    save_png(heat_map5_2, png_path + "test_heat_map_nyc_5-2.png")

    spark.catalog.dropGlobalTempView("nyc_taxi")

    assert run_diff_png(baseline_png1, png_path + "test_heat_map_nyc_1-1.png", 0.1)
    assert run_diff_png(baseline_png1, png_path + "test_heat_map_nyc_1-2.png", 0.1)
    assert run_diff_png(baseline_png2, png_path + "test_heat_map_nyc_2-1.png", 0.1)
    assert run_diff_png(baseline_png2, png_path + "test_heat_map_nyc_2-2.png", 0.1)
    assert run_diff_png(baseline_png3, png_path + "test_heat_map_nyc_3-1.png", 0.15)
    assert run_diff_png(baseline_png3, png_path + "test_heat_map_nyc_3-2.png", 0.15)
    assert run_diff_png(baseline_png4, png_path + "test_heat_map_nyc_4-1.png", 0.1)
    assert run_diff_png(baseline_png4, png_path + "test_heat_map_nyc_4-2.png", 0.1)
    assert run_diff_png(baseline_png5, png_path + "test_heat_map_nyc_5-1.png", 0.2)
    assert run_diff_png(baseline_png5, png_path + "test_heat_map_nyc_5-2.png", 0.2)