Skip to content

Commit

Permalink
Add initialization script, golden dataset mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
bfhealy committed Jan 26, 2024
1 parent 9ca95a4 commit e8c1bc9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license = "MIT"
packages = [
{include = "scope"},
]
include = ["config.defaults.yaml"]
include = ["config.defaults.yaml", "tools/golden_dataset_mapper.json"]

[tool.poetry.dependencies]
python = "^3.9, <3.12"
Expand Down Expand Up @@ -56,6 +56,7 @@ tables = ">=3.7,<3.9.2"
pre-commit = ">=3.5.0"

[tool.poetry.scripts]
scope-initialize = "scope.scope_class:Scope.initialize"
scope-develop = "scope._instantiate:develop"
scope-lint = "scope.scope_class:Scope.lint"
scope-doc = "scope._instantiate:doc"
Expand Down
36 changes: 36 additions & 0 deletions scope/scope_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import json
import shutil
import argparse
import site


@contextmanager
Expand Down Expand Up @@ -563,6 +564,41 @@ def fetch_datasets(gcs_path: str = "gs://ztf-scope/datasets"):
if p.returncode != 0:
raise RuntimeError("Failed to fetch SCoPe datasets")

@staticmethod
def initialize():
main_dir = "scope-ml"
scope_dirs = ["tools"]
os.makedirs(main_dir, exist_ok=True)
for directory in scope_dirs:
os.makedirs(f"{main_dir}/{directory}", exist_ok=True)

site_packages_path = site.getsitepackages()[0]
default_config_name = "config.defaults.yaml"
copied_config_name = "config.yaml"
tools_dir = "tools"
mappers = ["golden_dataset_mapper.json"]

# Copy config defaults to new directory strucutre if needed
if not os.path.exists(f"{main_dir}/{copied_config_name}"):
shutil.copy(
f"{site_packages_path}/{default_config_name}",
f"{main_dir}/{copied_config_name}",
)
print(
f"Created new '{copied_config_name}' config file. Please customize/add tokens there before running scope."
)
else:
print(f"{copied_config_name} already exists in the '{main_dir}' directory.")

for mapper in mappers:
print(f"Copying dataset mapper '{mapper}'")
shutil.copy(
f"{site_packages_path}/{tools_dir}/{mapper}",
{main_dir} / {tools_dir} / {mapper},
)

print(f"scope-ml initialized. Run scripts from '{main_dir}' directory.")

def parse_run_train(self):
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down

0 comments on commit e8c1bc9

Please sign in to comment.