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

Generalize to output CFE inputs for any portion of VPU #45

Open
jameshalgren opened this issue Apr 27, 2023 · 0 comments
Open

Generalize to output CFE inputs for any portion of VPU #45

jameshalgren opened this issue Apr 27, 2023 · 0 comments

Comments

@jameshalgren
Copy link
Contributor

If an empty "upstream" input is passed to the function, could we make it return the CFE input files for the whole geopackage?

parser.add_argument("upstream", type=str, help="id to subset upstream from")

This would allow us to combine (and perhaps reference) the functionality of the script living here (and copied below for reference.)

See also: https://github.com/NOAA-OWP/ngen/pull/459/files#r1179488490

import geopandas as gpd
import pandas as pd
import json
import argparse
from shapely.geometry import Point

def main():
    #setup the argument parser
    parser = argparse.ArgumentParser()
    parser.add_argument("-i", dest="infile", type=str, required=True, help="A gpkg file containing divides and nexus layers")
    parser.add_argument("-C", dest="catchments_prime", type=str, required=True, help="Hydrofabric catchments destination")
    parser.add_argument("-N", dest="nexuses_prime", type=str, required=True, help="Hydrofabric nexus desination")
    args = parser.parse_args()

    infile = args.infile
    catchments_prime = args.catchments_prime
    nexuses_prime = args.nexuses_prime

    print("Reading catchment data...")
    df_cat = gpd.read_file(str(infile), layer="divides")

    print("Reading nexus data...")
    df_nex = gpd.read_file(str(infile), layer="nexus")

    df_cat.set_index('id', inplace=True)
    df_nex.set_index('id', inplace=True)

    print("Reprojecting catchments...")
    df_cat = df_cat.to_crs(epsg=4326)

    print("Reprojecting nexuses...")
    df_nex = df_nex.to_crs(epsg=4326)


    print("Writing catchment data...")
    df_cat.to_file(catchments_prime, driver='GeoJSON')
    print("Writing nexus data...")
    df_nex.to_file(nexuses_prime, driver='GeoJSON')
    print("Complete!")

if __name__ == "__main__":
    main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant