Skip to content

Commit

Permalink
handled condition if output directory doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
swaradgat19 committed Aug 16, 2023
1 parent ee116d0 commit e606e5e
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions wsinfer/write_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ def parallelize_geojson(csvs: list, results_dir: Path, num_workers: int) -> None

if not results_dir.exists():
raise FileExistsError(f"results_dir does not exist: {results_dir}")
if output.exists():
geojsons = list((results_dir / "model-outputs-geojson").glob("*.json"))

# Makes a list of filenames for both geojsons and csvs
geojson_filenames = [filename.name.split(".")[0] for filename in geojsons]
csv_filenames = [filename.name.split(".")[0] for filename in csvs]

# Makes a list of new csvs that need to be converted to geojson
csvs_new = [filename for filename in csv_filenames if filename not in geojson_filenames]
csvs_final = [path for path in csvs if path.name.split(".")[0] in csvs_new]
if (
not (results_dir / "model-outputs-csv").exists()
and (results_dir / "patches").exists()
Expand All @@ -105,8 +95,23 @@ def parallelize_geojson(csvs: list, results_dir: Path, num_workers: int) -> None
" not. Please provide the path to the directory that contains"
" model-outputs, masks, and patches."
)
if output.exists():
geojsons = list((results_dir / "model-outputs-geojson").glob("*.json"))

# Makes a list of filenames for both geojsons and csvs
geojson_filenames = [filename.name.split(".")[0] for filename in geojsons]
csv_filenames = [filename.name.split(".")[0] for filename in csvs]

# Makes a list of new csvs that need to be converted to geojson
csvs_new = [filename for filename in csv_filenames if filename not in geojson_filenames]
csvs_final = [path for path in csvs if path.name.split(".")[0] in csvs_new]

output.mkdir(parents=True, exist_ok=True)
# if len(csvs_final) == 0:
# raise FileExistsError("All outputs have been converted to geojson")
else:
# If output directory doesn't exist, make one and set csvs_final to csvs
output.mkdir(parents=True, exist_ok=True)
csvs_final = csvs

func = partial(make_geojson, results_dir)
process_map(func, csvs_final, max_workers=num_workers)

0 comments on commit e606e5e

Please sign in to comment.