ArcticSnow / TopoPyScale

TopoPyScale: a Python library to perform simplistic climate downscaling at the hillslope scale
https://topopyscale.readthedocs.io
MIT License
39 stars 9 forks source link

AttributeError: 'Series' object has no attribute 'lat' #96

Closed NILICK closed 8 months ago

NILICK commented 10 months ago

It seems that there is a mistake in lines (141-142) of topo_scale.py file:

    ind_lat = np.abs(ds_.latitude - row.lat).argmin()
    ind_lon = np.abs(ds_.longitude - row.lon).argmin()

With the current code, I got the below error:

Traceback (most recent call last):
  File ".../lib/python3.9/site-packages/IPython/core/magics/execution.py", line 1317, in time
    out = eval(code, glob, local_ns)
  File "<timed eval>", line 3, in <module>
  File .../topopyscale/lib/python3.9/site-packages/TopoPyScale/topoclass.py", line 496, in downscale_climate
    ta.downscale_climate(self.config.project.directory,
  File ".../topopyscale/lib/python3.9/site-packages/TopoPyScale/topo_scale.py", line 209, in downscale_climate
    multithread_pooling(_subset_climate_dataset, fun_param, n_threads=n_core)
  File ".../topopyscale/lib/python3.9/site-packages/TopoPyScale/topo_scale.py", line 89, in multithread_pooling
    tpool.starmap(fun, fun_param)
  File ".../topopyscale/lib/python3.9/multiprocessing/pool.py", line 372, in starmap
    return self._map_async(func, iterable, starmapstar, chunksize).get()
  File ".../topopyscale/lib/python3.9/multiprocessing/pool.py", line 771, in get
    raise self._value
  File ".../topopyscale/lib/python3.9/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File ".../topopyscale/lib/python3.9/multiprocessing/pool.py", line 51, in starmapstar
    return list(itertools.starmap(args[0], args[1]))
  File ".../topopyscale/lib/python3.9/site-packages/TopoPyScale/topo_scale.py", line 177, in _subset_climate_dataset
    ind_lat = np.abs(ds_.latitude - row.lat).argmin()
  File ".../topopyscale/lib/python3.9/site-packages/pandas/core/generic.py", line 5989, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'lat'

But when I changed lines (141-142) of topo_scale.py file to:

    ind_lat = np.abs(ds_.latitude - row.latitude).argmin()
    ind_lon = np.abs(ds_.longitude - row.longitude).argmin()

then It runs without error. Do these lines need to improve as above?

ArcticSnow commented 10 months ago

hello @NILICK , I am surprised by the bug you encountered as this has ran smoothly until now in this configuration.

row iterates over the rows of df_centroids which is defined here: https://github.com/ArcticSnow/TopoPyScale/blob/4d1d3b772850ea8af86ed80c138f16d479200b58/TopoPyScale/topoclass.py#L358

Did you modify the name of the columns of df_centroids somewhere in your code?

NILICK commented 10 months ago

Hello @ArcticSnow, I did not any changes in the main codes of the TopoPyScale folder. I installed again TopoPyScale in the new env of the mamba and I got the above error again.

ArcticSnow commented 10 months ago

What is mp.toposub.df_centroids.columns showing in your project?

Somehow, the columns, lat, lon got changed to latitude, longitude. Can you identify where it may occur, either in TPS code, or some other processing done?

df_centroids is created by the function extract_topo_param()

NILICK commented 10 months ago

The result of mp.toposub.df_centroids.columns is:

Index(['x', 'y', 'elevation', 'slope', 'aspect_cos', 'aspect_sin', 'svf',
       'spatial_ref', 'aspect', 'point_id', 'longitude', 'latitude',
       'hori_azi_-175.0', 'hori_azi_-165.0', 'hori_azi_-155.0',
       'hori_azi_-145.0', 'hori_azi_-135.0', 'hori_azi_-125.0',
       'hori_azi_-115.0', 'hori_azi_-105.0', 'hori_azi_-95.0',
       'hori_azi_-85.0', 'hori_azi_-75.0', 'hori_azi_-65.0', 'hori_azi_-55.0',
       'hori_azi_-45.0', 'hori_azi_-35.0', 'hori_azi_-25.0', 'hori_azi_-15.0',
       'hori_azi_-5.0', 'hori_azi_5.0', 'hori_azi_15.0', 'hori_azi_25.0',
       'hori_azi_35.0', 'hori_azi_45.0', 'hori_azi_55.0', 'hori_azi_65.0',
       'hori_azi_75.0', 'hori_azi_85.0', 'hori_azi_95.0', 'hori_azi_105.0',
       'hori_azi_115.0', 'hori_azi_125.0', 'hori_azi_135.0', 'hori_azi_145.0',
       'hori_azi_155.0', 'hori_azi_165.0', 'hori_azi_175.0'],
      dtype='object')