Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement pipeline operation utilities #226

Open
r-leyshon opened this issue Jan 8, 2024 · 0 comments
Open

implement pipeline operation utilities #226

r-leyshon opened this issue Jan 8, 2024 · 0 comments

Comments

@r-leyshon
Copy link
Contributor

def prepare_aoi_folders(aoi_nm:str=uc_config["aoi_nm"]) -> None:
    """Prepare the case study folder for the given area of interest."""
    aoi_dir = os.path.join("outputs/e2e/", aoi_nm)
    dirs = [
        aoi_dir,
        os.path.join(aoi_dir, "analyse_network"),
        os.path.join(aoi_dir, "gtfs"),
        os.path.join(aoi_dir, "metrics"),
        os.path.join(aoi_dir, "population"),
        os.path.join(aoi_dir, "urban_centre"),
    ]
    for d in dirs:
        try:
            os.mkdir(here(d))
        except FileExistsError:
            pass

# %%
def prep_new_toml(toml_template:Union[pathlib.Path, str], new_aoi_nm:str) -> None:
    with open(toml_template, "r") as f:
        lines = f.read()
        f.close()
    # get the aoi_nm from the filenm
    aoi = os.path.basename(toml_template)
    aoi = aoi.replace("e2e_", "").split(".")[0].strip()
    old_aoi_pat = re.compile(aoi)
    n_hits = len(list(old_aoi_pat.finditer(lines, re.IGNORECASE)))
    new_lines = lines
    new_lines = re.sub(old_aoi_pat, new_aoi_nm, new_lines, count=n_hits)
    parent_dir = os.path.dirname(toml_template)
    out_pth = here(os.path.join(parent_dir, f"e2e_{new_aoi_nm}.toml"))
    with open(out_pth, "w") as f:
        f.write(new_lines)
        f.close()


@r-leyshon r-leyshon added this to the sprint 7 end milestone Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant