-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add huggingface-based data storage (#43)
* Add huggingface-based data storage Fixes #42 * Update deps and add GH upload action to test * Format * Adjust download script * Add logging * Fix download script * Add auto-calibrate
- Loading branch information
1 parent
89b035d
commit a9437a9
Showing
10 changed files
with
96 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
FROM python:latest | ||
COPY . . | ||
RUN make install | ||
RUN make data | ||
RUN make upload |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,8 @@ | ||
from policyengine_uk_data.utils.github import upload | ||
from pathlib import Path | ||
from tqdm import tqdm | ||
from policyengine_uk_data.datasets import EnhancedFRS_2022_23, FRS_2022_23 | ||
|
||
FOLDER = Path(__file__).parent | ||
datasets = [EnhancedFRS_2022_23, FRS_2022_23] | ||
|
||
FILES = [ | ||
"frs_2022_23.h5", | ||
"enhanced_frs_2022_23.h5", | ||
"extended_frs_2022_23.h5", | ||
"reweighted_frs_2022_23.h5", | ||
] | ||
|
||
for file in tqdm(FILES): | ||
upload( | ||
"PolicyEngine", | ||
"ukda", | ||
"release", | ||
file, | ||
FOLDER / file, | ||
) | ||
for dataset in datasets: | ||
ds = dataset() | ||
print(f"Uploading {ds.name} with url {ds.url}") | ||
ds.upload() |
34 changes: 34 additions & 0 deletions
34
policyengine_uk_data/storage/upload_private_prerequisites.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from policyengine_uk_data.utils.huggingface import upload | ||
from pathlib import Path | ||
import zipfile | ||
|
||
|
||
def zip_folder(folder): | ||
folder = Path(folder) | ||
with zipfile.ZipFile(folder.with_suffix(".zip"), "w") as zip_ref: | ||
for file in folder.glob("*"): | ||
zip_ref.write(file, file.name) | ||
|
||
|
||
FOLDER = Path(__file__).parent | ||
|
||
FILES = [ | ||
"frs_2022_23.zip", | ||
"lcfs_2021_22.zip", | ||
"was_2006_20.zip", | ||
"etb_1977_21.zip", | ||
"spi_2020_21.zip", | ||
] | ||
|
||
FILES = [Path(FOLDER / file) for file in FILES] | ||
|
||
for file in FILES: | ||
if not file.exists(): | ||
zip_folder(FOLDER / file.name[:-4]) | ||
if not file.exists(): | ||
raise FileNotFoundError(f"File {file} not found") | ||
upload( | ||
repo="policyengine/policyengine-uk-data", | ||
repo_file_path=file.name, | ||
local_file_path=file, | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from huggingface_hub import hf_hub_download, login, HfApi | ||
import os | ||
import pkg_resources | ||
|
||
|
||
def download( | ||
repo: str, repo_filename: str, local_folder: str, version: str = None | ||
): | ||
token = os.environ.get( | ||
"HUGGING_FACE_TOKEN", | ||
) | ||
login(token=token) | ||
|
||
hf_hub_download( | ||
repo_id=repo, | ||
repo_type="model", | ||
filename=repo_filename, | ||
local_dir=local_folder, | ||
revision=version, | ||
) | ||
|
||
|
||
def upload(local_file_path: str, repo: str, repo_file_path: str): | ||
token = os.environ.get( | ||
"HUGGING_FACE_TOKEN", | ||
) | ||
login(token=token) | ||
api = HfApi() | ||
api.upload_file( | ||
path_or_fileobj=local_file_path, | ||
path_in_repo=repo_file_path, | ||
repo_id=repo, | ||
repo_type="model", | ||
) |
This file contains 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