Skip to content

Commit

Permalink
clean cache
Browse files Browse the repository at this point in the history
  • Loading branch information
tillwenke committed Jan 12, 2025
1 parent 4a7d1c0 commit 36b894a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions heatchmap/gpmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import requests
import zipfile
import io
import shutil

import geopandas as gpd
import numpy as np
Expand All @@ -31,7 +32,9 @@ class GPMap(MapBasedModel):
def __init__(self, region="world", resolution=10, version="prod", visual:bool=False):
self.visual = visual

os.makedirs(f"{HERE}/cache/hitchmap", exist_ok=True)
self.cache_dir = f"{HERE}/cache"

os.makedirs(f"{self.cache_dir}/hitchmap", exist_ok=True)
self.points_path = f"{HERE}/cache/hitchmap/dump.sqlite"
hitchmap_url = 'https://hitchmap.com/dump.sqlite'
response = requests.get(hitchmap_url)
Expand Down Expand Up @@ -76,10 +79,10 @@ def __init__(self, region="world", resolution=10, version="prod", visual:bool=Fa
self.recalc_radius = 800000 # TODO: determine from model largest influence radius


self.shapely_countries = f"{HERE}/cache/countries/ne_110m_admin_0_countries.shp"
self.shapely_countries = f"{self.cache_dir}/countries/ne_110m_admin_0_countries.shp"

if not os.path.exists(self.shapely_countries):
output_dir = f"{HERE}/cache/countries"
output_dir = f"{self.cache_dir}/countries"
os.makedirs(output_dir, exist_ok=True)

# URL for the 110m countries shapefile from Natural Earth
Expand Down Expand Up @@ -302,7 +305,10 @@ def get_landmass_raster(self):
os.remove(self.landmass_path)

def upload(self):
"""Uploads the recalculated map to the Hugging Face model hub."""
"""Uploads the recalculated map to the Hugging Face model hub.
Clean cached files.
"""
print(self.raw_raster.shape)
d = {"numpy": self.raw_raster}
ds = Dataset.from_dict(d)
Expand All @@ -311,4 +317,6 @@ def upload(self):
print(ds["numpy"].shape)
ds.info.version = str(self.today)
ds.push_to_hub("tillwenke/heatchmap-map")
print("Uploaded new map to Hugging Face dataset hub.")
print("Uploaded new map to Hugging Face dataset hub.")

shutil.rmtree(self.cache_dir)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import setuptools

VERSION = "0.1.18"
VERSION = "0.1.19"

NAME = "heatchmap"

Expand Down

0 comments on commit 36b894a

Please sign in to comment.