SpatioTemporal / STAREPandas

STAREpandas adds SpatioTemporal Adaptive Resolution Encoding (STARE) support to pandas DataFrames. https://starepandas.readthedocs.io/en/latest/
MIT License
4 stars 1 forks source link

geopandas throws an error #163

Open mbauer288 opened 6 months ago

mbauer288 commented 6 months ago

This worked when I made the Snow animations back in January... Any idea why this error cropped up?

Name Version Build Channel

cartopy 0.22.0 py311h6e08293_1 conda-forge
geopandas 0.14.3 pyhd8ed1ab_0 conda-forge
geopandas-base 0.14.3 pyha770c72_0 conda-forge matplotlib 3.8.3 py311ha1ab1f8_0 conda-forge matplotlib-base 3.8.3 py311hb58f1d1_0 conda-forge pandas 2.2.1 py311hfbe21a1_0 conda-forge pystare 0.8.13 pypi_0 pypi shapely 2.0.3 py311h0815064_0 conda-forge starepandas 0.6.6+60.g1d9b635 pypi_0 pypi

top_sdf.info()
  <class 'geopandas.geodataframe.GeoDataFrame'>                                                                                                                                                   
  RangeIndex: 1 entries, 0 to 0                                                                                                                                                                   
  Data columns (total 5 columns):                                                                                                                                                                 
   #   Column     Non-Null Count  Dtype                                                                                                                                                           
  ---  ------     --------------  -----                                                                                                                                                           
   0   label      1 non-null      int64                                                                                                                                                           
   1   tidx       1 non-null      int64                                                                                                                                                           
   2   timestamp  1 non-null      datetime64[ns]                                                                                                                                                  
   3   sids       1 non-null      object                                                                                                                                                          
   4   trixels    1 non-null      geometry                                                                                                                                                        
  dtypes: datetime64[ns](1), geometry(1), int64(2), object(1)                                                                                                                                     
  memory usage: 172.0+ bytes  
top_sdf.plot(ax=geo_axes, trixels=True, boundary=True, figsize=plot_size, aspect=None, zorder=ar_trix.zorder + 1, ...                                                                           

  File "/Users/mbauer/miniconda3/envs/stare/lib/python3.11/site-packages/geopandas/plotting.py", line 979, in __call__                                                                          
    return plot_dataframe(data, *args, **kwargs)                                                                                                                                                
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                
  File "/Users/mbauer/miniconda3/envs/stare/lib/python3.11/site-packages/geopandas/plotting.py", line 717, in plot_dataframe                                                                    
    df.geometry,                                                                                                                                                                                
    ^^^^^^^^^^^                                                                                                                                                                                 
  File "/Users/mbauer/miniconda3/envs/stare/lib/python3.11/site-packages/pandas/core/generic.py", line 6296, in __getattr__                                                                     
    return object.__getattribute__(self, name)                                                                                                                                                  
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                  
  File "/Users/mbauer/miniconda3/envs/stare/lib/python3.11/site-packages/geopandas/geodataframe.py", line 236, in _get_geometry                                                                 
    raise AttributeError(msg)  

AttributeError: You are calling a geospatial method on the GeoDataFrame, but the active geometry column to use has not been set.                                                                
There are columns with geometry data type (['trixels']), and you can either set one as the active geometry with df.set_geometry("name") or access the column as a GeoSeries (df["name"]) and call the method directly on it.  

If I add top_sdf.set_geometry("trixels", inplace=True) I get different errors.

 File "/Users/mbauer/miniconda3/envs/stare/lib/python3.11/site-packages/geopandas/plotting.py", line 979, in __call__
    return plot_dataframe(data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mbauer/miniconda3/envs/stare/lib/python3.11/site-packages/geopandas/plotting.py", line 716, in plot_dataframe
    return plot_series(
           ^^^^^^^^^^^^
  File "/Users/mbauer/miniconda3/envs/stare/lib/python3.11/site-packages/geopandas/plotting.py", line 470, in plot_series
    _plot_polygon_collection(
  File "/Users/mbauer/miniconda3/envs/stare/lib/python3.11/site-packages/geopandas/plotting.py", line 184, in _plot_polygon_collection
    collection = PatchCollection([_PolygonPatch(poly) for poly in geoms], **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mbauer/miniconda3/envs/stare/lib/python3.11/site-packages/matplotlib/collections.py", line 1899, in __init__
    super().__init__(**kwargs)
  File "/Users/mbauer/miniconda3/envs/stare/lib/python3.11/site-packages/matplotlib/collections.py", line 203, in __init__
    self._internal_update(kwargs)
  File "/Users/mbauer/miniconda3/envs/stare/lib/python3.11/site-packages/matplotlib/artist.py", line 1219, in _internal_update
    return self._update_props(
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/mbauer/miniconda3/envs/stare/lib/python3.11/site-packages/matplotlib/artist.py", line 1193, in _update_props
    raise AttributeError(
AttributeError: PatchCollection.set() got an unexpected keyword argument 'trixels'
NiklasPhabian commented 6 months ago

hmm. Not clear to me what is going on just yet. Could you tell me what the outputs of the following are:

top_df.has_trixels()
top_df._trixel_column_name
top_df._geometry_column_name

Can you plot the outputs from the examples; i.e. do:

world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
world.sort_values(by='name', inplace=True)
africa = world[world.continent=='Africa']

stare = starepandas.sids_from_gdf(africa, level=5, force_ccw=True)
africa = starepandas.STAREDataFrame(africa, sids=stare)
trixels = africa.make_trixels()
africa.set_trixels(trixels, inplace=True)
africa.plot(trixels=True, boundary=True)
NiklasPhabian commented 6 months ago

Ohhh. I see it now. top_df is a GeoDataFrame, not a STAREDataFrame. You can either cast it to a STAREDataFrame by doing

starepandas.STAREDataFrame(top_df)

Or, the following: the plot method of STAREDataFrames and GeoDataFrames are slightly different. The GeoDataFrame plot function does not understand the kwarg trixels or boundary. So you could do:

top_df.set_geometry('trixels').boundary.plot()
mbauer288 commented 6 months ago

The starepandas.STAREDataFrame(top_df) worked. Thanks. I wonder why/how that worked before?