modflowpy / flopy

A Python package to create, run, and post-process MODFLOW-based models.
https://flopy.readthedocs.io
Other
517 stars 313 forks source link

Error when exporting model to NetCDF #103

Closed jbellino-usgs closed 8 years ago

jbellino-usgs commented 8 years ago

I'm getting an error that stems from Pyproj when trying to export anything (model, package, array) to NetCDF (and does not occur when exporting to shapefile).

ml = flopy.modflow.Modflow.load(os.path.join(modelpath, 'fas.nam'), check=False)
ml.export(os.path.join(outputpath, 'model.nc'))

Traceback (most recent call last):
  File "E:\modflow\FAS.2010_ss\python\ProcessFASModelExportInputData.py", line 19, in <module>
    fnc = ml.export(os.path.join(outputpath, 'model.nc'))
  File "E:\modflow\local_repo\flopy\flopy\mbase.py", line 167, in export
    return utils.model_helper(f, self, **kwargs)
  File "E:\modflow\local_repo\flopy\flopy\export\utils.py", line 260, in model_helper
    f = NetCdf(f, ml, **kwargs)
  File "E:\modflow\local_repo\flopy\flopy\export\netcdf.py", line 160, in __init__
    self.initialize_file(time_values=time_values)
  File "E:\modflow\local_repo\flopy\flopy\export\netcdf.py", line 440, in initialize_file
    self.initialize_geometry()
  File "E:\modflow\local_repo\flopy\flopy\export\netcdf.py", line 402, in initialize_geometry
    nc_crs = Proj(init=self.nc_epsg_str)
  File "C:\Anaconda\lib\site-packages\pyproj\__init__.py", line 348, in __new__
    return _proj.Proj.__new__(self, projstring)
  File "_proj.pyx", line 84, in _proj.Proj.__cinit__ (_proj.c:1190)
RuntimeError: Invalid argument

When loading the model, a printout of projstring feeding into line 348 of pyproj\__init__ shows an initialization value of "+units=m +init=epsg:4326" and then the proj4 string defined in the DIS package: "+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-84 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" (note: the units are changed from "ft" to "m", though the correct units are listed in the .nam file). Once the export function is called we get the same proj4 string as above and then a second call comes through with a value of "+units=m +init=epsg:4326" (with a trailing whitespace). Removal of the whitespace does not fix the error.

jtwhite79 commented 8 years ago

I've seen this before on windows and I think its a problem with the anaconda install of pyproj. I had to install pyproj from the ioos channel: [https://github.com/jswhit/pyproj/issues/17]

jbellino-usgs commented 8 years ago

Thanks for the tip. After installing pyproj from the ioos (conda install -c https://conda.anaconda.org/ioos pyproj), the NetCDF export function works.