kleok / FLOODPY

Flood Python Toolbox
https://floodpy.readthedocs.io/en/latest/
Other
164 stars 28 forks source link

'NoneType' object is not subscriptable' when running Run_preprocessing_S1_data #47

Closed JPPereira93 closed 1 year ago

JPPereira93 commented 1 year ago

Hello! I download the recent version of the repo and I started doing a new project to test a flood event that occured in Portugal.

However, when running the Run_preprocessing_S1_data it gives me a "NoneType" error as following:


TypeError Traceback (most recent call last) Input In [13], in <cell line: 1>() ----> 1 app.run_preprocessing_S1_data('Preprocessing_S1_data')

File ~/FLOODPY/floodpy/FLOODPYapp.py:317, in FloodwaterEstimation.run_preprocessing_S1_data(self, step_name) 315 def run_preprocessing_S1_data(self, step_name): --> 317 Get_images_for_baseline_stack(projectfolder = self.projectfolder, 318 S1_dir = self.S1_dir, 319 Precipitation_data = self.precipitation_df, 320 flood_datetime = self.flood_datetime, 321 days_back = self.days_back, 322 rain_thres=self.rain_thres) 324 Run_Preprocessing(projectfolder = self.projectfolder, 325 gpt_exe = self.gptcommand, 326 graph_dir = self.graph_dir, 327 S1_dir = self.S1_dir, 328 geojson_S1 = self.geojson_S1, 329 Preprocessing_dir = self.Preprocessing_dir) 331 return 0

File ~/FLOODPY/floodpy/Preprocessing_S1_data/Classify_S1_images.py:22, in Get_images_for_baseline_stack(projectfolder, S1_dir, Precipitation_data, flood_datetime, days_back, rain_thres) 10 def Get_images_for_baseline_stack(projectfolder, 11 S1_dir, 12 Precipitation_data, 13 flood_datetime, 14 days_back=5, 15 rain_thres=20): 16 ''' 17 Creates a pandas DataFrame of Sentinel-1 acquisitions. Creates a column with 18 boolean values with name 'baseline'. If True the particular acquisition 19 can be used for calculation of baseline stack 20 21 ''' ---> 22 Precipitation_data.index = Precipitation_data['Datetime'] 23 Precipitation_data.drop(columns = ['Datetime'], inplace=True) 25 # calculate cumulative rain over the past days (given) for each date

TypeError: 'NoneType' object is not subscriptable

image: image

previous step:

image

digasico commented 1 year ago

The problem is that if you run app.run_download_Precipitation_data('Download_Precipitation_data') more than once, for the same period of time, the Get_ERA5_data function will return None , because the data already exists. While the bug is not patched delete the folder containing the precipitation data before reruning app.run_download_Precipitation_data('Download_Precipitation_data') will hotfix it. One option to remove the data is to do rm -r <<< echo {app.ERA5_dir}/*

JPPereira93 commented 1 year ago

thank you @digasico ! it is working

kleok commented 1 year ago

Hello @JPPereira93, I updated the download function of meteo data to tackle this issue. Thanks for your suggestion @digasico Kind regards