Run main function of plotting script. Parses json-file with plot setups and runs the plotting for each plot setup.
(plotdefs, outdir, plots=[])
| 311 | |
| 312 | |
| 313 | def main(plotdefs, outdir, plots=[]): |
| 314 | """Run main function of plotting script. |
| 315 | |
| 316 | Parses json-file with plot setups and runs the plotting |
| 317 | for each plot setup. |
| 318 | """ |
| 319 | try: |
| 320 | # Check 'proj' command, show version |
| 321 | proc = run_proj_cmd(text=True) |
| 322 | print(proc.stderr.splitlines()[0]) |
| 323 | except (FileNotFoundError, OSError) as e: |
| 324 | sys.stderr.write( |
| 325 | "'proj' binary not found, set the PROJ_EXE environment variable " |
| 326 | "to point to your local 'proj' binary\n{}\n".format(e) |
| 327 | ) |
| 328 | return 1 |
| 329 | |
| 330 | outdir = Path(outdir) |
| 331 | if not outdir.exists(): |
| 332 | outdir.mkdir(parents=True) |
| 333 | if not outdir.is_dir(): |
| 334 | raise OSError("outdir is not a directory") |
| 335 | |
| 336 | plotdefs = json.loads(Path(plotdefs).read_text()) |
| 337 | |
| 338 | data = { |
| 339 | ("line", "low"): geojson2geom_array(LINE_LOW), |
| 340 | ("line", "med"): geojson2geom_array(LINE_MED), |
| 341 | ("poly", "low"): geojson2geom_array(POLY_LOW), |
| 342 | ("poly", "med"): geojson2geom_array(POLY_MED), |
| 343 | } |
| 344 | |
| 345 | for i, plotdef in enumerate(plotdefs): |
| 346 | if plots != [] and plotdef["name"] not in plots: |
| 347 | continue |
| 348 | |
| 349 | print("{}: {!r} {}".format(i, plotdef["filename"], plotdef["projstring"])) |
| 350 | if "skip" in plotdef.keys(): |
| 351 | print("skipping") |
| 352 | continue |
| 353 | |
| 354 | plotproj(plotdef, data[(plotdef["type"], plotdef["res"])], outdir) |
| 355 | |
| 356 | |
| 357 | if __name__ == "__main__": |
no test coverage detected