Skip to content

Conversation

jlarsen-usgs
Copy link
Contributor

@jlarsen-usgs jlarsen-usgs commented Aug 7, 2025

The purpose of this PR is to begin overhauling the shapefile exporting support in FloPy. This PR adds geopandas GeoDataFrame constructors to data, package, model, and some output objects.

  • Support for MFList, MFTransientList, and pandas equivalent data classes
  • Support for MFArray, MFTransientArray
  • MF2005 and USG support
  • LayerFile support for exporting model outputs
  • CellBudgetFile support for exporting model outputs
  • horizontal flow barrier linestring support

Todo:

  • PRT/Modpath locations and pathlines?
  • MVR geospatial representation (vectors?)
  • Head contours to geospatial
  • Documentation and examples
  • Begin deprecation of existing shapefile export methods
  • Unit tests

Functionally the geopandas supports works as follows:

sim = flopy.mf6.MFSimulation.load(sim_ws="my_sim_folder")
gwf = sim.get_model()

# model data to geopandas dataframe
mgdf = gwf.to_geo_dataframe(kper=0)

# package to geopandas dataframe
disgdf = gwf.dis.to_geo_dataframe()
welgdf = gwf.wel.to_geo_dataframe(kper=0, sparse=True)

# data object to geodataframe
gdf = gwf.dis.top.to_geo_dataframe()
gdf = gwf.dis.botm.to_geo_dataframe(gdf=gdf) # tack on additional data to existing gdf

# hfb linestring geodataframe
hfbgdf = gwf.hfb.to_geo_dataframe()

# user can then export any of these using `.to_file()` to their favorite geospatial format

Input is requested on the to_geo_dataframe() method name. I keep going back and forth between that and to_geodataframe(). Any preferences or other suggestions on naming convention?

Other considerations and support suggestions are welcome

Copy link

codecov bot commented Aug 7, 2025

Codecov Report

❌ Patch coverage is 20.88975% with 409 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.8%. Comparing base (556c088) to head (862ec36).
⚠️ Report is 33 commits behind head on develop.

Files with missing lines Patch % Lines
flopy/mf6/data/mfdataarray.py 3.5% 55 Missing ⚠️
flopy/mf6/data/mfdatalist.py 3.8% 50 Missing ⚠️
flopy/mf6/data/mfdataplist.py 5.8% 48 Missing ⚠️
flopy/utils/util_array.py 8.5% 43 Missing ⚠️
flopy/plot/plotutil.py 2.5% 38 Missing ⚠️
flopy/mf6/mfpackage.py 6.4% 29 Missing ⚠️
flopy/utils/binaryfile/__init__.py 3.8% 25 Missing ⚠️
flopy/utils/util_list.py 4.0% 24 Missing ⚠️
flopy/modflow/mfsfr2.py 5.2% 18 Missing ⚠️
flopy/pakbase.py 5.2% 18 Missing ⚠️
... and 6 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2573      +/-   ##
===========================================
+ Coverage     55.5%    71.8%   +16.2%     
===========================================
  Files          644      643       -1     
  Lines       124135   122986    -1149     
===========================================
+ Hits         68947    88341   +19394     
+ Misses       55188    34645   -20543     
Files with missing lines Coverage Δ
flopy/mf6/data/mfdatautil.py 58.5% <100.0%> (-19.4%) ⬇️
flopy/utils/particletrackfile.py 95.6% <94.8%> (-0.4%) ⬇️
flopy/utils/modpathfile.py 85.4% <78.5%> (-3.1%) ⬇️
flopy/mbase.py 69.0% <8.3%> (-3.7%) ⬇️
flopy/mf6/mfmodel.py 56.3% <8.3%> (-24.6%) ⬇️
flopy/modflow/mfhfb.py 84.2% <29.4%> (-0.3%) ⬇️
flopy/modflow/mfsfr2.py 85.6% <5.2%> (-1.8%) ⬇️
flopy/pakbase.py 78.9% <5.2%> (-5.6%) ⬇️
flopy/utils/datafile.py 70.2% <18.1%> (-4.1%) ⬇️
flopy/utils/util_list.py 70.5% <4.0%> (-5.1%) ⬇️
... and 7 more

... and 368 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@christianlangevin
Copy link

FWIW, I like to_geodataframe()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants