oceanmodeling / StormEvents

Python interfaces for observational data surrounding named storm events, born from @jreniel's ADCIRCpy

Home Page:https://stormevents.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Are there built-in methods for writing geometry files?

SorooshMani-NOAA opened this issue · comments

For example when one fetches data for isotachs or windswath, is there an easy way to write it to disk as Shapefile? Of course one can always use Geopandas or Fiona or OGR to do it, but it would be nice if part of that functionality could be added into this package.

Maybe add Geopandas is too much since it has a lot of dependencies when you install it in the environment, but Fiona is already installed for your current dependencies and a method could be added to write out the fetched Shapely objects in case it doesn't already exist.

that's a good idea, but the default environment doesn't currently have fiona or geopandas.

However, we could maybe add an optional dependency for fiona / geopandas, such as importing locally within the writing function and raising an error like "fiona must be installed in order to write to a spatial file" if the user calls the writing function without having it installed.

I think xarray does something very similar if you try to read a NetCDF file and don't have netcdf4 installed

For some reason I thought fiona was installed on my env when installing StormEvents. But Now that I checked again it's not there. Sorry, my mistake!

But having an optional dependency is a good idea for this.

https://github.com/pydata/xarray/blob/d3b6aa6d8b997df115a53c001d00222a0f92f63a/xarray/backends/plugins.py
^ here is the way that xarray does it for engines

import xarray

xarray.open_dataset("/home/zrb/Data/COASTAL_Act/runs/run_20211027_florence_besttrack_250msubset_quadrature/perturbations.nc")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/zrb/environments/test/lib/python3.10/site-packages/xarray/backends/api.py", line 479, in open_dataset
    engine = plugins.guess_engine(filename_or_obj)
  File "/home/zrb/environments/test/lib/python3.10/site-packages/xarray/backends/plugins.py", line 155, in guess_engine
    raise ValueError(error_msg)
ValueError: found the following matches with the input file in xarray's IO backends: ['netcdf4', 'h5netcdf']. But their dependencies may not be installed, see:
http://xarray.pydata.org/en/stable/user-guide/io.html 
http://xarray.pydata.org/en/stable/getting-started-guide/installing.html