schism-dev / pyschism

Python interface for handling the SCHISM model.
https://schism-dev.github.io/schism/master/getting-started/pre-processing-with-pyschism/overview.html
Apache License 2.0
25 stars 21 forks source link

PySCHISM: TypeError in fgrid.py: 'sjoin() got an unexpected keyword argument 'op'' #130

Closed mansurjisan closed 3 months ago

mansurjisan commented 3 months ago

PySCHISM: TypeError in fgrid.py: 'sjoin() got an unexpected keyword argument 'op''

I encountered a TypeError in fgrid.py when trying to use the modify_by_region method in PySCHISM. The error message indicates that sjoin() got an unexpected keyword argument 'op'. This issue seems to be caused by a change in the geopandas API, where the op parameter has been replaced by predicate.

Steps to Reproduce

  1. Run the following code:
from pyschism.mesh.hgrid import Hgrid
from pyschism.mesh.fgrid import DragCoefficient

if __name__ == '__main__':

    hgrid=Hgrid.open('hgrid.gr3', crs='epsg:4326')

    depth1=-1.0
    depth2=-3.0
    bfric_river=0.0025
    bfric_land=0.025

    fgrid=DragCoefficient.linear_with_depth(hgrid, depth1, depth2, bfric_river, bfric_land)

    regions=['region1.reg', 'region2.reg']
    values=[0.001, 0.0]
    flags=[1, 0] 

    for reg, value, flag in zip(regions, values, flags):
        fgrid.modify_by_region(hgrid, f'./{reg}', value, depth1, flag)

    fgrid.write('drag.gr3', overwrite=True)
  1. The error occurs on this line in fgrid.py:
gdf_in = gpd.sjoin(gdf2, gdf1, op="within")

Proposed Fix

The issue can be fixed by replacing op with predicate:

gdf_in = gpd.sjoin(gdf2, gdf1, predicate="within")

Additional Information

PySCHISM version: 0.1.15 Geopandas version: 1.0.1 Python version: 3.9.19

SorooshMani-NOAA commented 3 months ago

@mansurjisan can you test the update in PR and see if it resolves the issues. Unfortunately pyschism doesn't yet have any automated tests, so we need manual testing to confirm it works. See #131