pysal / libpysal

Core components of Python Spatial Analysis Library
http://pysal.org/libpysal
Other
258 stars 78 forks source link

AttributeError: 'Queen' object has no attribute 'silent_island_warning' #204

Closed TransUMD closed 4 years ago

TransUMD commented 4 years ago

Hello,

I was using libpysal to conduct esda. I was doing the spatial weights using continuity weights but it pops up the following errors:


AttributeError Traceback (most recent call last)

in 13 break 14 c_type = crime_type[i*2+j] ---> 15 li_bg = esda.moran.Moran_Local(blgp_crime[c_type], qW_blgp) 16 mi_bg = esda.moran.Moran(blgp_crime[c_type], qW_blgp) 17 sig = 1 * (li_bg.p_sim < 0.05) E:\Anaconda\envs\incenTrip\lib\site-packages\pysal\explore\esda\moran.py in __init__(self, y, w, transformation, permutations, geoda_quads) 870 np.seterr(**orig_settings) 871 self.z = z --> 872 w.transform = transformation 873 self.w = w 874 self.permutations = permutations E:\Anaconda\envs\incenTrip\lib\site-packages\libpysal\weights\weights.py in set_transform(self, value) 943 row_sum = sum(wijs) * 1.0 944 if row_sum == 0.0: --> 945 if not self.silent_island_warning: 946 print(('WARNING: ', i, ' is an island (no neighbors)')) 947 weights[i] = [wij / row_sum for wij in wijs] AttributeError: 'Queen' object has no attribute 'silent_island_warning' I check the raw code and can't find things about silent_island_warning. Thank you. Best,
sjsrey commented 4 years ago

Could you include your example code and data so we can debug?

TransUMD commented 4 years ago

SampleCode&Data.zip

TransUMD commented 4 years ago

Hello,

I attached the sample code and data. It is basically a hexagon-based shapefile with the value attached in each hexagon, and I am trying to apply queen weight but it reported the silent_island_warning message.

The kernel weights works.

jakeandersonbell commented 4 years ago

Hi, I have also been experiencing this error.

I think the issue lies within weights.py of libpysal. At line 941-946, where the script checks for items that have no neighbours, it checks the bool of the attribute 'silent_island_warning'. This attribute is not mentioned anywhere else in the file, pehaps the devs were planning on implementing it at some point.

There is an existing, presumably more general, 'silence_warnings' bool setting. When I substituted in 'silence_warnings' for 'silent_island_warning' on line 945 of weights.py I acheived the desired result of the module warning me when I have islands.

jGaboardi commented 4 years ago

This should be resolved via #206

TransUMD commented 4 years ago

This should be resolved via #206

Thanks. I merged the latest code and it ran through now.

Thanks for the development team for the prompt reply.

TransUMD commented 4 years ago

Dear developers,

Following up with this question. I was able solve the problem as mentioned above.

But when I applied esda.moran.Moran_Local to shapefile I provide above, it reported lots of silent island (no neighbors). However, the shapefile is a fully connected hexagon, as shown below.

image

I was not sure why this happened.

Thank you.

Best,

sjsrey commented 4 years ago

can you include the files so that we can check into this?

Sergio (Serge) Rey Founding Director, Center for Geospatial Sciences Professor, School of Public Policy University of California, Riverside sergio.rey@ucr.edu

On Tue, Dec 3, 2019 at 10:39 AM M.Yang notifications@github.com wrote:

Dear developers,

Following up with this question. I was able solve the problem as mentioned above.

But when I applied esda.moran.Moran_Local to shapefile I provide above, it reported lots of silent island (no neighbors). However, the shapefile is a fully connected hexagon, as shown below.

[image: image] https://user-images.githubusercontent.com/29628412/70079190-3b464d80-15d2-11ea-8af6-edd1a7c4843e.png

I was not sure why this happened.

Thank you.

Best,

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pysal/libpysal/issues/204?email_source=notifications&email_token=AAA42GQNZIVB52EGL4GIJNDQW2RUXA5CNFSM4JH7OF22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEF2MGCI#issuecomment-561300233, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA42GS4KT57R6BICF3ZLDTQW2RUXANCNFSM4JH7OF2Q .

TransUMD commented 4 years ago

SampleCode.Data.zip

Data and sample code attached.

Thank you.

sjsrey commented 4 years ago

The hexagon lattice may look as if there are no islands (and should form a single connected component), but this is not the case.

For details, see this gist.

TL;DR: You can get a w with a single component using:

w = libpysal.weights.fuzzy_contiguity(blgp)
TransUMD commented 4 years ago

The hexagon lattice may look as if there are no islands (and should form a single connected component), but this is not the case.

For details, see this gist.

TL;DR: You can get a w with a single component using:

w = libpysal.weights.fuzzy_contiguity(blgp)

Thank you very much for the help!

LuYan5203 commented 8 months ago

Hello, I used this a few months ago, but now it always has errors, TypeError: float() argument must be a string or a number, not 'Point', how can I do to solve this problem?

sjsrey commented 8 months ago

Can you share a mre so that we can try to help you more effectively?