Writing Spatial Weights Matrix Error

90 views
Skip to first unread message

Kellen Byrnes

unread,
Jan 9, 2021, 3:45:18 AM1/9/21
to Openspace List

Hello, I get the following error when I write my Contiguity Spatial Weights matrices to my local machine:

TypeError: Expected a pysal weights object, got: <class 'pysal.lib.weights.contiguity.Queen'>

It seems like my object is being rejected even though it is a spatial weights object?

Here is a reproducible code example courtesy of this tutorial here: https://darribas.org/gds_course/content/bE/lab_E.html#reading-and-writing-spatial-weights-in-pysal

---------------------------------------------------------------------------------------------------------------------------------------------

import seaborn as sns
import pandas as pd
from pysal.lib import weights
from libpysal.io import open as psopen
import geopandas as gpd
import numpy as np
import matplotlib.pyplot as plt

# Read the file in
db = gpd.read_file("https://darribas.org/gds_course/content/data/liv_lsoas.gpkg")
# Index table on the LSOA ID
db = db.set_index("LSOA11CD", drop=False)

w_queen = weights.Queen.from_dataframe(db, idVariable="LSOA11CD")

# Open file to write into
fo = psopen('C:/Users/Owner/Documents/GeoComputation/imd_queen.gal', 'w')
# Write the matrix into the file
fo.write(w_queen)
# Close the file
fo.close()



Daniel Arribas Bel

unread,
Jan 10, 2021, 7:51:53 AM1/10/21
to Openspace List
Hello Kellen,

Thanks for the interest in the course. What version of PySAL/geopandas are you using? I just tried with the `gds_env:5.0` (pysal 2.3.0 and geopandas 0.8.1) and the matrix is written to the `.gal` fine, no warnings or errors. My hunch is that it probably relates to an older version of pysal? If you can follow up with the versions you're using, we should be able to get to the bottom of this :-)

]d[

--
You received this message because you are subscribed to the Google Groups "Openspace List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openspace-lis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openspace-list/1e31d30c-2f5e-4eb0-b060-bc79e11bf133n%40googlegroups.com.


--
================================
Daniel Arribas-Bel, PhD.Senior Lecturer in Geographic Data Science
Department of Geography and Planning
University of Liverpool (UK)
================================

Kellen Byrnes

unread,
Jan 10, 2021, 7:57:16 AM1/10/21
to Openspace List
Dear Daniel,  The course is amazing--thank you!

I'm using pysal 2.1.0 and geopandas 0.0.1 installed via conda-forge.

Mil Gracias,

Kellen

Daniel Arribas Bel

unread,
Jan 10, 2021, 8:01:06 AM1/10/21
to Openspace List
I suspect updating both would help. The geopandas version you're using is fairly outdated and a lot has changed in between. I think 2.1 for pysal would be OK but again I'd recommend, if possible, to run on 2.3. Very glad to hear the course seems useful :-)

]d[

Reply all
Reply to author
Forward
0 new messages