danioxoli / HotSpotAnalysis_Plugin

A QGIS plugin for hotspot analysis
GNU General Public License v3.0
55 stars 12 forks source link

"Unsupported Operand Type(s) Error" for New Data #50

Closed NateTillern closed 3 years ago

NateTillern commented 4 years ago

I installed this plugin and used it successfully towards the beginning of this year on German NUTS3 level data. After some installation issues, which you helped me with (thank you!), the plugin worked perfectly for the German data I had. I recently received additional data for the NUTS3 level in Italy and Switzerland. I have added two shape files to my project with the functioning German project which have the new data joined with Italian and Swiss NUTS3 files. As far as I can tell, everything I've done to set them up is identical to the German data. However, when I run the hotspot analysis, for Moran (Getis looks slightly different), I receive the same error for both countries (the plugin still works for my German data). The error looks as follows for both countries:


2020-06-01T12:40:15 WARNING Traceback (most recent call last): File "C:/Users/Tillern/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\HotspotAnalysis\hotspot_analysis.py", line 629, in run statistics = Moran_Local(y, w, transformation=type_w, permutations=permutationsValue) File "C:\Users\clark\AppData\Roaming\Python\Python37\site-packages\pysal\esda\moran.py", line 820, in init z = y - y.mean() File "D:\Program Files\apps\Python37\lib\site-packages\numpy\core_methods.py", line 151, in _mean ret = umr_sum(arr, axis, dtype, out, keepdims) TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'


My data for both Switzerland and Italy exists for every NUTS3 region and always takes a value between 0 and 1 (inclusive). I can make heatmaps so I know Qgis has read in the variables as real numbers.

The traceback looks slightly different when I try the Getis analysis (although the Moran's is what I am interested in):


2020-06-01T13:00:43 WARNING Traceback (most recent call last): File "C:/Users/clark/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\HotspotAnalysis\hotspot_analysis.py", line 627, in run statistics = G_Local(y, w, star=True, transform=type_w, permutations=permutationsValue) File "C:\Users\clark\AppData\Roaming\Python\Python37\site-packages\pysal\esda\getisord.py", line 352, in init self.calc() File "C:\Users\clark\AppData\Roaming\Python\Python37\site-packages\pysal\esda\getisord.py", line 403, in calc y2 = y y TypeError: unsupported operand type(s) for : 'NoneType' and 'NoneType'


I have uninstalled and reinstalled the plugin as well as Pysal with no change.

I have tried reading up on what can cause this python error, however, the cases in which it occurs is quite varied and I can't identify what could be causing it in my case. Any help would be greatly appreciated!

Please let me know what additional information I can provide to help with diagnosing the issue, I am continuing to look into this on my end as well.

danioxoli commented 4 years ago

From my experience, the error is due to bad formatting of the shapefile attribute field that is used for the computation. This should be a numeric field (int or float) with no missing or NULL values.

Please, check that both the conditions are fulfilled and let me know!

Best, Daniele