kvos / CoastSat

Global shoreline mapping tool from satellite imagery
http://coastsat.wrl.unsw.edu.au/
GNU General Public License v3.0
667 stars 245 forks source link

deprecated 'in_place' argument #397

Closed lexterspiritus97 closed 1 year ago

lexterspiritus97 commented 1 year ago

Hi Kilian @kvos When I try to run the example of Narra, in jupyter notebook, in the cells related to: SDS_preprocess.save_jpg(metadata, settings) and %matplotlib qt output = SDS_shoreline.extract_shorelines(metadata, settings) I got for both, the same TypeError:

Mapping shorelines: L8: 11%

TypeError Traceback (most recent call last) Cell In[10], line 2 1 get_ipython().run_line_magic('matplotlib', 'qt') ----> 2 output = SDS_shoreline.extract_shorelines(metadata, settings)

File D:\SoftwarePython_CoastSat_V3\CoastSat-master\coastsat\SDS_shoreline.py:150, in extract_shorelines(metadata, settings) 148 fn = SDS_tools.get_filenames(filenames[i],filepath, satname) 149 # preprocess image (cloud mask + pansharpening/downsampling) --> 150 im_ms, georef, cloud_mask, im_extra, im_QA, im_nodata = SDS_preprocess.preprocess_single(fn, satname, 151 settings['cloud_mask_issue'], 152 settings['pan_off'], 153 collection) 154 # get image spatial reference system (epsg code) from metadata dict 155 image_epsg = metadata[satname]['epsg'][i]

File D:\SoftwarePython_CoastSat_V3\CoastSat-master\coastsat\SDS_preprocess.py:148, in preprocess_single(fn, satname, cloud_mask_issue, pan_off, collection) 146 bands = [data.GetRasterBand(k + 1).ReadAsArray() for k in range(data.RasterCount)] 147 im_QA = bands[0] --> 148 cloud_mask = create_cloud_mask(im_QA, satname, cloud_mask_issue, collection) 149 # check if -inf or nan values on any band and eventually add those pixels to cloud mask 150 im_nodata = np.zeros(cloud_mask.shape).astype(bool)

File D:\SoftwarePython_CoastSat_V3\CoastSat-master\coastsat\SDS_preprocess.py:331, in create_cloud_mask(im_QA, satname, cloud_mask_issue, collection) 328 # remove cloud pixels that form very thin features. These are beach or swash pixels that are 329 # erroneously identified as clouds by the CFMASK algorithm applied to the images by the USGS. 330 if sum(sum(cloud_mask)) > 0 and sum(sum(~cloud_mask)) > 0: --> 331 morphology.remove_small_objects(cloud_mask, min_size=40, connectivity=1, in_place=True) 333 if cloud_mask_issue: 334 elem = morphology.square(6) # use a square of width 6 pixels

TypeError: remove_small_objects() got an unexpected keyword argument 'in_place'

I feel it is related to the Sorry to disturb you with such a basic issue. But I can't solve it. Do I have to change the min_size, connectivity, or in_place parameters? Help me please. Thanks a lot in advance, Lester from Chile

kvos commented 1 year ago

it's the inplace parameter, I will fix it later and update the code. Basically, you just need to remove inplace as it's deprecated and write at line 331: cloud_mask = morphology.remove_small_objects(cloud_mask, min_size=40, connectivity=1)

lexterspiritus97 commented 1 year ago

Thanks, Kilian for your soon reply. I solved it with your recommendation, great!!!! But it advanced until a new error raised. Related with the SDS_tools.py toolbox when trying to export the save the mapped shorelines in GEOJSON format, also with the tool generic.py located inside the coastsat environment:

AttributeError Traceback (most recent call last) Cell In[9], line 3 1 from pyproj import CRS 2 geomtype = 'points' # choose 'points' or 'lines' for the layer geometry ----> 3 gdf = SDS_tools.output_to_gdf(output, geomtype) 4 if gdf is None: 5 raise Exception("output does not contain any mapped shorelines")

File D:\SoftwarePython_CoastSat_V3\CoastSat-master\coastsat\SDS_tools.py:708, in output_to_gdf(output, geomtype) 706 gdf_all = gdf 707 else: --> 708 gdf_all = gdf_all.append(gdf) 709 counter = counter + 1 711 return gdf_all

File ~\anaconda3\envs\coastsat\lib\site-packages\pandas\core\generic.py:5989, in NDFrame.getattr(self, name) 5982 if ( 5983 name not in self._internal_names_set 5984 and name not in self._metadata 5985 and name not in self._accessors 5986 and self._info_axis._can_hold_identifiers_and_holds_name(name) 5987 ): 5988 return self[name] -> 5989 return object.getattribute(self, name)

AttributeError: 'GeoDataFrame' object has no attribute 'append'

I'm not a specialist in Python, so I can't understand exactly what it means. More or less I feel that it fails when appending the GeoDataFrame object. But how can it be fixed? Could you help me please? Thanks a lot in advance, Lexter.

kvos commented 1 year ago

Hi lexter, not sure how this one can be fixed, unless .append is also deprecated for geodataframes, can you check that online? If you want to continue with the analysis you can as that cell is just to create a geospatial layer but it's not used in the next steps.

lexterspiritus97 commented 1 year ago

Thank you Kilian. I'll continue with the analysis and also I'll look for the relation between geodataframes and the append function. I'll let you know what I find. Have I nice weekend!!

kvos commented 1 year ago

this has been fixed by @jimpaulobautista ! #400