Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
db = pysal.open(pysal.examples.get_path('columbus.dbf'),'r')
y = np.array(db.by_col("HOVAL"))
y = np.reshape(y, (49,1))
self.y = np.round(y).astype(int)
X = []
X.append(db.by_col("INC"))
X.append(db.by_col("CRIME"))
self.X = np.array(X).T
model.schwarz = DIAG.schwarz(reg=model)
return model
def _test():
import doctest
start_suppress = np.get_printoptions()['suppress']
np.set_printoptions(suppress=True)
doctest.testmod()
np.set_printoptions(suppress=start_suppress)
if __name__ == "__main__":
_test()
import numpy as np
import pysal as ps
db = ps.open(ps.examples.get_path("baltim.dbf"), 'r')
ds_name = "baltim.dbf"
y_name = "PRICE"
y = np.array(db.by_col(y_name)).T
y.shape = (len(y), 1)
x_names = ["NROOM", "NBATH", "PATIO", "FIREPL",
"AC", "GAR", "AGE", "LOTSZ", "SQFT"]
x = np.array([db.by_col(var) for var in x_names]).T
ww = ps.open(ps.examples.get_path("baltim_q.gal"))
w = ww.read()
ww.close()
w_name = "baltim_q.gal"
w.transform = 'r'
regimes = db.by_col("CITCOU")
mllag = ML_Lag_Regimes(y, x, regimes, w=w, method='full', name_y=y_name, name_x=x_names,
name_w=w_name, name_ds=ds_name, regime_lag_sep=True, constant_regi='many',
return model
def _test():
import doctest
start_suppress = np.get_printoptions()['suppress']
np.set_printoptions(suppress=True)
doctest.testmod()
np.set_printoptions(suppress=start_suppress)
if __name__ == '__main__':
_test()
import pysal
import numpy as np
dbf = pysal.open(pysal.examples.get_path('columbus.dbf'), 'r')
y = np.array([dbf.by_col('CRIME')]).T
names_to_extract = ['INC']
x = np.array([dbf.by_col(name) for name in names_to_extract]).T
yd_var = ['HOVAL']
yend = np.array([dbf.by_col(name) for name in yd_var]).T
q_var = ['DISCBD']
q = np.array([dbf.by_col(name) for name in q_var]).T
regimes = regimes = dbf.by_col('NSA')
w = pysal.open(pysal.examples.get_path("columbus.gal"), 'r').read()
w.transform = 'r'
model = GM_Error_Regimes(y, x, regimes=regimes, w=w, name_y='crime', name_x=[
'income'], name_regimes='nsa', name_ds='columbus', regime_err_sep=True)
print model.summary
return vm
def _test():
import doctest
start_suppress = np.get_printoptions()['suppress']
np.set_printoptions(suppress=True)
doctest.testmod()
np.set_printoptions(suppress=start_suppress)
if __name__ == '__main__':
_test()
import numpy as np
import pysal
from sur_utils import sur_dictxy,sur_dictZ
db = pysal.open(pysal.examples.get_path('NAT.dbf'), 'r')
y_var = ['HR80','HR90']
x_var = [['PS80','UE80'],['PS90','UE90']]
w = pysal.queen_from_shapefile(pysal.examples.get_path("NAT.shp"))
w.transform='r'
bigy0,bigX0,bigyvars0,bigXvars0 = sur_dictxy(db,y_var,x_var)
reg0 = SURerrorML(bigy0,bigX0,w,name_bigy=bigyvars0,name_bigX=bigXvars0,\
name_w="natqueen",name_ds="natregimes",vm=False,nonspat_diag=True,spat_diag=True)
#print reg0.summary
# each polygon chain is converted to a series of connected edges
import pysal as ps
import numpy as np
import os
shpf = ps.open(ps.examples.get_path("geodanet/streets.shp"))
shps = []
for shp in shpf:
shps.append(shp)
shpf.close()
edge2id = {}
id2edge = {}
id2coord = {}
coord2id = {}
n_edges = n_nodes = 0
for i,shp in enumerate(shps):
print i, len(shp.vertices)
print shp.vertices
for j in range(1, len(shp.vertices)):
o = shp.vertices[j-1]
common = set(poly0.vertices).intersection(set(poly1.vertices))
if len(common) > 1 and self.joinType == ROOK:
#double check rook
if get_shared_segments(poly0, poly1, True):
return ROOK
return False
elif len(common) > 0:
return QUEEN
else:
return False
if __name__ == '__main__':
import pysal
import time
t0 = time.time()
shp = pysal.open(pysal.examples.get_path('10740.shp'), 'r')
w = ContiguityWeights_rtree(shp, QUEEN)
t1 = time.time()
print "Completed in: ", t1 - t0, "seconds using rtree"
# field specs
for name, (typ, size, deci) in itertools.izip(self.header, self.field_spec):
typ = typ.encode()
name = name.ljust(11, '\x00')
name = name.encode()
fld = struct.pack('<11sc4xBB14x', name, typ, size, deci)
self.f.write(fld)
# terminator
term = '\r'.encode()
self.f.write(term)
if self.f.tell() != POS and not self.FIRST_WRITE:
self.f.seek(POS)
if __name__ == '__main__':
import pysal
file_name = pysal.examples.get_path("10740.dbf")
f = pysal.open(file_name, 'r')
newDB = pysal.open('copy.dbf', 'w')
newDB.header = f.header
newDB.field_spec = f.field_spec
print f.header
for row in f:
print row
newDB.write(row)
newDB.close()
copy = pysal.open('copy.dbf', 'r')
f.seek(0)
print "HEADER: ", copy.header == f.header
print "SPEC: ", copy.field_spec == f.field_spec
print "DATA: ", list(copy) == list(f)
markerobj.get_transform())
scales = np.array([2, 2])
fig = plt.figure()
ax = fig.add_subplot(111)
pc = PathCollection((path,), scales, offsets=xy, \
facecolors='r', transOffset=mpl.transforms.IdentityTransform())
#pc.set_transform(mpl.transforms.IdentityTransform())
#_ = _add_axes2col(pc, [0, 0, 5, 5])
ax.add_collection(pc)
fig.add_axes(ax)
#ax = setup_ax([pc], ax)
plt.show()
'''
shp_link = ps.examples.get_path('columbus.shp')
values = np.array(ps.open(ps.examples.get_path('columbus.dbf')).by_col('HOVAL'))
w = ps.queen_from_shapefile(shp_link)
lisa = ps.Moran_Local(values, w, permutations=999)
_ = plot_lisa_cluster(shp_link, lisa)
#_ = plot_choropleth(shp_link, values, 'fisher_jenks')
edgeCache[j] = jEdges
# for edge in edgeCache[j]:
if iEdgeSet.intersection(edgeCache[j].keys()):
w[polyId].add(j)
if j not in w:
w[j] = set()
w[j].add(polyId)
# break
else:
raise Exception("Unsupported weight type.")
self.w = w
if __name__ == "__main__":
import time
fname = pysal.examples.get_path('NAT.shp')
print('QUEEN binning')
t0 = time.time()
qb = ContiguityWeights_binning(pysal.open(fname), QUEEN)
t1 = time.time()
print("using " + str(fname))
print("time elapsed for queen... using bins: " + str(t1 - t0))
t0 = time.time()
rb = ContiguityWeights_binning(pysal.open(fname), ROOK)
t1 = time.time()
print('Rook binning')
print("using " + str(fname))
print("time elapsed for rook... using bins: " + str(t1 - t0))
from pysal.weights._contW_rtree import ContiguityWeights_rtree
for name in dir(self._called):
try:
exec('self.{n} = self._called.{n}'.format(n=name))
except:
print("Assigning {a} from {s} to {d} failed!".format(a=name,
s=self._called,
d=self))
#need to still pass names down from formula into relevant pysal arguments
if __name__ == '__main__':
import pysal as ps
dbf = ps.open(ps.examples.get_path('columbus.dbf'))
y, X = dbf.by_col_array(['HOVAL']), dbf.by_col_array(['INC', 'CRIME'])
Wcol = ps.open(ps.examples.get_path('columbus.gal')).read()
mod1 = sr.OLS(y,X)
hmod1 = Model(y,X)
mod2 = sr.OLS(y,X,Wcol)
hmod2 = Model(y,X,Wcol)
mod3 = sr.ML_Lag(y,X,Wcol)
hmod3 = Model(y,X,Wcol, mtype='ML_Lag')
mod4 = sr.ML_Error(y,X,Wcol)
hmod4 = Model(y,X,Wcol,mtype='ML_Error')