Skip to content

Commit

Permalink
add plotter
Browse files Browse the repository at this point in the history
  • Loading branch information
jpacilo committed Jul 25, 2023
1 parent 6982ef4 commit af2e548
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
Binary file added sds4gdsp/__pycache__/plotter.cpython-38.pyc
Binary file not shown.
Binary file modified sds4gdsp/__pycache__/processor.cpython-38.pyc
Binary file not shown.
37 changes: 37 additions & 0 deletions sds4gdsp/plotter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import shapely
import geopandas as gpd
import matplotlib.pyplot as plt
from PIL import Image

def get_route_fig(r):
fig, ax = plt.subplots(1, 1)
gpd.GeoSeries(r).plot(ax=ax, linewidth=5, zorder=1)
orig = shapely.geometry.Point([r.xy[0][0], r.xy[1][0]])
dest = shapely.geometry.Point([r.xy[0][-1], r.xy[1][-1]])
gpd.GeoSeries(orig).plot(ax=ax, color="red", markersize=250, zorder=2, alpha=0.8)
gpd.GeoSeries(dest).plot(ax=ax, color="green", markersize=250, zorder=2, alpha=0.8)
plt.axis("off")
ax.ticklabel_format(useOffset=False)
return fig

def load_images(dirpath, extension=".jpg"):
imgs = []
for f in sorted(os.listdir(dirpath)):
if f.endswith(extension):
img_path = os.path.join(dirpath, f)
imgs.append(Image.open(img_path))
return imgs

def plot_images(imgs, nrows=5, ncols=6, figsize=(10, 10)):
num_figs = nrows * ncols
num_imgs = len(imgs)
num_figs = min(num_figs, num_imgs)
fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=figsize)
for i, ax in enumerate(axes.flat):
if i < num_imgs:
ax.imshow(imgs[i])
ax.axis("off")
plt.tight_layout()
plt.show()
return fig
9 changes: 7 additions & 2 deletions sds4gdsp/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def get_coords_from_graph(G: Graph, nodes: List[int]):
coords.append((G.nodes[node]["x"], G.nodes[node]["y"]))
return coords

def convert_cel_to_point(cel_id: str, ref: pd.DataFrame):
"""Convert cellsite to shapely point."""
coord = ref.loc[ref.uid==cel_id].coords.item()
point = loads(coord)
return point

def dedupe_points(points: List[Point], distance_threshold: int):
"""Naive way to dedupe a points dataset given a distance threshold in meters."""
pointpairs_df = pd.DataFrame(list(combinations(points, 2)), columns=["p1", "p2"])
Expand Down Expand Up @@ -50,8 +56,7 @@ def apply_softmax(arr: np.ndarray) -> np.ndarray:

def convert_distances_to_probas(distances) -> np.ndarray:
reversed_distances = distances ** -1
# probas = np.exp(-a*scaled_distances)
probas = apply_softmax(distances)
probas = apply_softmax(reversed_distances)
return probas

def scale_feature(feature, scaler) -> np.ndarray:
Expand Down

0 comments on commit af2e548

Please sign in to comment.