Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
positions_df_byhex = df_subset.groupby("hex_id", as_index=False).agg({ | |
"longitude": "mean", | |
"latitude": "mean", | |
"vector_component_x": "mean", | |
"vector_component_y": "mean", | |
"bearing": "count", # "mean" would be wrong here; we need circmean | |
"speed_kmh": "mean" | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arrow_tip_x = size_of_arrow_x * math.cos(bearing_rad) + center_lat | |
arrow_tip_y = size_of_arrow_y * math.sin(bearing_rad) + center_long | |
arrow_back_left_x = size_of_arrow_x * math.cos(bearing_rad + 2*math.pi * 135.0 / 360.0 ) + center_lat | |
arrow_back_left_y = size_of_arrow_y * math.sin(bearing_rad + 2*math.pi * 135.0 / 360.0 ) + center_long | |
arrow_back_x = size_of_arrow_x * 0.2 * math.cos(bearing_rad + 2*math.pi * 180.0 / 360.0 ) + center_lat | |
arrow_back_y = size_of_arrow_y * 0.2 * math.sin(bearing_rad + 2*math.pi * 180.0 / 360.0 ) + center_long | |
arrow_back_right_x = size_of_arrow_x * math.cos(bearing_rad + 2*math.pi * 225.0 / 360.0 ) + center_lat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import scipy.stats | |
# compass bearings in degrees: | |
data = [2, 356] | |
# average bearing: | |
print(np.mean(data)) # == 179.0, aka "wrong" | |
print(scipy.stats.circmean(data, high=360, low=0)) # == 359.0, aka "correct" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!conda install -y folium geojson | |
import folium | |
from geojson import Feature, Point, FeatureCollection | |
import json | |
def hexagons_dataframe_to_geojson(df_hex, file_output = None, column_name = "value"): | |
""" | |
Produce the GeoJSON for a dataframe, constructing the geometry from the "hex_id" column | |
and with a property matching the one in column_name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dataset2001byhexid = dataset2001.groupby("hex_id", as_index=False).agg({"pop_2001": "sum"}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!conda install -y h3-py | |
import h3 | |
hex_ids = dataset2001.apply(lambda row: h3.geo_to_h3(row.lat, row.long, resolution), axis = 1) | |
dataset2001 = dataset2001.assign(hex_id=hex_ids.values) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sagemaker.pipeline import PipelineModel | |
from sagemaker.model import Model | |
from sagemaker.transformer import Transformer | |
import sagemaker | |
# The location of the input dataset, WITHOUT the column to predict (and WITHOUT headers) | |
batch_input = 's3://YOURBUCKET/YOURFOLDER/predictmeplease.csv' | |
# The location to store the results of the batch transform job (will be stored under this folder, with a single value per line) |