From 0b4fe07be4a259fa24a23be6f12816f8d10a51b5 Mon Sep 17 00:00:00 2001 From: Austin Raney Date: Mon, 25 Mar 2024 12:30:14 -0400 Subject: [PATCH] example: writing configs to tar.gz file --- .../examples/write_to_tar_gz/main.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 python/ngen_config_gen/examples/write_to_tar_gz/main.py diff --git a/python/ngen_config_gen/examples/write_to_tar_gz/main.py b/python/ngen_config_gen/examples/write_to_tar_gz/main.py new file mode 100644 index 00000000..d93c19c5 --- /dev/null +++ b/python/ngen_config_gen/examples/write_to_tar_gz/main.py @@ -0,0 +1,28 @@ +import geopandas as gpd +import pandas as pd + +from ngen.config_gen.file_writer import TarFileWriter, Compression +from ngen.config_gen.hook_providers import DefaultHookProvider +from ngen.config_gen.generate import generate_configs + +from ngen.config_gen.models.cfe import Cfe +from ngen.config_gen.models.pet import Pet + +if __name__ == "__main__": + # or pass local file paths instead + hf_file = "https://lynker-spatial.s3.amazonaws.com/v20.1/gpkg/nextgen_09.gpkg" + hf_lnk_file = "https://lynker-spatial.s3.amazonaws.com/v20.1/model_attributes/nextgen_09.parquet" + + hf: gpd.GeoDataFrame = gpd.read_file(hf_file, layer="divides") + hf_lnk_data: pd.DataFrame = pd.read_parquet(hf_lnk_file) + + hook_provider = DefaultHookProvider(hf=hf, hf_lnk_data=hf_lnk_data) + # files will be written to `init_configs.tar.gz` + tar_file_writer = TarFileWriter("init_configs.tar.gz", compression=Compression.GZIP) + + with tar_file_writer as file_writer: + generate_configs( + hook_providers=hook_provider, + hook_objects=[Cfe, Pet], + file_writer=file_writer, + )