changed name of functions for observatory
This commit is contained in:
parent
eecbe39547
commit
bc67ae8f69
@ -1,6 +1,6 @@
|
|||||||
-- Moran's I (global)
|
-- Moran's I (global)
|
||||||
CREATE OR REPLACE FUNCTION
|
CREATE OR REPLACE FUNCTION
|
||||||
cdb_moran (
|
CDB_AreasOfInterest_Global (
|
||||||
subquery TEXT,
|
subquery TEXT,
|
||||||
attr_name TEXT,
|
attr_name TEXT,
|
||||||
permutations INT DEFAULT 99,
|
permutations INT DEFAULT 99,
|
||||||
@ -17,7 +17,7 @@ $$ LANGUAGE plpythonu;
|
|||||||
|
|
||||||
-- Moran's I Local
|
-- Moran's I Local
|
||||||
CREATE OR REPLACE FUNCTION
|
CREATE OR REPLACE FUNCTION
|
||||||
cdb_moran_local (
|
CDB_AreasOfInterest_Local(
|
||||||
subquery TEXT,
|
subquery TEXT,
|
||||||
attr TEXT,
|
attr TEXT,
|
||||||
permutations INT DEFAULT 99,
|
permutations INT DEFAULT 99,
|
||||||
@ -34,7 +34,7 @@ $$ LANGUAGE plpythonu;
|
|||||||
|
|
||||||
-- Moran's I Rate (global)
|
-- Moran's I Rate (global)
|
||||||
CREATE OR REPLACE FUNCTION
|
CREATE OR REPLACE FUNCTION
|
||||||
cdb_moran_rate (
|
CDB_AreasOfInterest_Global_Rate(
|
||||||
subquery TEXT,
|
subquery TEXT,
|
||||||
numerator TEXT,
|
numerator TEXT,
|
||||||
denominator TEXT,
|
denominator TEXT,
|
||||||
@ -53,7 +53,7 @@ $$ LANGUAGE plpythonu;
|
|||||||
|
|
||||||
-- Moran's I Local Rate
|
-- Moran's I Local Rate
|
||||||
CREATE OR REPLACE FUNCTION
|
CREATE OR REPLACE FUNCTION
|
||||||
cdb_moran_local_rate(
|
CDB_AreasOfInterest_Local_Rate(
|
||||||
subquery TEXT,
|
subquery TEXT,
|
||||||
numerator TEXT,
|
numerator TEXT,
|
||||||
denominator TEXT,
|
denominator TEXT,
|
||||||
|
@ -110,7 +110,7 @@ INSERT INTO ppoints2 VALUES
|
|||||||
(24,'0101000020E61000009C5F91C5095C17C0C78784B15A4F4540'::geometry,'24','07',0.3, 1.0),
|
(24,'0101000020E61000009C5F91C5095C17C0C78784B15A4F4540'::geometry,'24','07',0.3, 1.0),
|
||||||
(29,'0101000020E6100000C34D4A5B48E712C092E680892C684240'::geometry,'29','01',0.3, 1.0),
|
(29,'0101000020E6100000C34D4A5B48E712C092E680892C684240'::geometry,'29','01',0.3, 1.0),
|
||||||
(52,'0101000020E6100000406A545EB29A07C04E5F0BDA39A54140'::geometry,'52','19',0.0, 1.01)
|
(52,'0101000020E6100000406A545EB29A07C04E5F0BDA39A54140'::geometry,'52','19',0.0, 1.01)
|
||||||
-- Moral functions perform some nondeterministic computations
|
-- Areas of Interest functions perform some nondeterministic computations
|
||||||
-- (to estimate the significance); we will set the seeds for the RNGs
|
-- (to estimate the significance); we will set the seeds for the RNGs
|
||||||
-- that affect those results to have repeateble results
|
-- that affect those results to have repeateble results
|
||||||
SELECT cdb_crankshaft._cdb_random_seeds(1234);
|
SELECT cdb_crankshaft._cdb_random_seeds(1234);
|
||||||
@ -121,15 +121,15 @@ SELECT cdb_crankshaft._cdb_random_seeds(1234);
|
|||||||
|
|
||||||
SELECT ppoints.code, m.quads
|
SELECT ppoints.code, m.quads
|
||||||
FROM ppoints
|
FROM ppoints
|
||||||
JOIN cdb_crankshaft.cdb_moran_local('SELECT * FROM ppoints', 'value') m
|
JOIN cdb_crankshaft.CDB_AreasOfInterest_Local('SELECT * FROM ppoints', 'value') m
|
||||||
ON ppoints.cartodb_id = m.ids
|
ON ppoints.cartodb_id = m.ids
|
||||||
ORDER BY ppoints.code;
|
ORDER BY ppoints.code;
|
||||||
NOTICE: ** Constructing query
|
NOTICE: ** Constructing query
|
||||||
CONTEXT: PL/Python function "cdb_moran_local"
|
CONTEXT: PL/Python function "cdb_areasofinterest_local"
|
||||||
NOTICE: ** Query returned with 52 rows
|
NOTICE: ** Query returned with 52 rows
|
||||||
CONTEXT: PL/Python function "cdb_moran_local"
|
CONTEXT: PL/Python function "cdb_areasofinterest_local"
|
||||||
NOTICE: ** Finished calculations
|
NOTICE: ** Finished calculations
|
||||||
CONTEXT: PL/Python function "cdb_moran_local"
|
CONTEXT: PL/Python function "cdb_areasofinterest_local"
|
||||||
code | quads
|
code | quads
|
||||||
------+-------
|
------+-------
|
||||||
01 | HH
|
01 | HH
|
||||||
@ -194,15 +194,15 @@ SELECT cdb_crankshaft._cdb_random_seeds(1234);
|
|||||||
|
|
||||||
SELECT ppoints2.code, m.quads
|
SELECT ppoints2.code, m.quads
|
||||||
FROM ppoints2
|
FROM ppoints2
|
||||||
JOIN cdb_crankshaft.cdb_moran_local_rate('SELECT * FROM ppoints2', 'numerator', 'denominator') m
|
JOIN cdb_crankshaft.CDB_AreasOfInterest_Local_Rate('SELECT * FROM ppoints2', 'numerator', 'denominator') m
|
||||||
ON ppoints2.cartodb_id = m.ids
|
ON ppoints2.cartodb_id = m.ids
|
||||||
ORDER BY ppoints2.code;
|
ORDER BY ppoints2.code;
|
||||||
NOTICE: ** Constructing query
|
NOTICE: ** Constructing query
|
||||||
CONTEXT: PL/Python function "cdb_moran_local_rate"
|
CONTEXT: PL/Python function "cdb_areasofinterest_local_rate"
|
||||||
NOTICE: ** Query returned with 51 rows
|
NOTICE: ** Query returned with 51 rows
|
||||||
CONTEXT: PL/Python function "cdb_moran_local_rate"
|
CONTEXT: PL/Python function "cdb_areasofinterest_local_rate"
|
||||||
NOTICE: ** Finished calculations
|
NOTICE: ** Finished calculations
|
||||||
CONTEXT: PL/Python function "cdb_moran_local_rate"
|
CONTEXT: PL/Python function "cdb_areasofinterest_local_rate"
|
||||||
code | quads
|
code | quads
|
||||||
------+-------
|
------+-------
|
||||||
01 | LL
|
01 | LL
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
\i test/fixtures/ppoints.sql
|
\i test/fixtures/ppoints.sql
|
||||||
\i test/fixtures/ppoints2.sql
|
\i test/fixtures/ppoints2.sql
|
||||||
|
|
||||||
-- Moral functions perform some nondeterministic computations
|
-- Areas of Interest functions perform some nondeterministic computations
|
||||||
-- (to estimate the significance); we will set the seeds for the RNGs
|
-- (to estimate the significance); we will set the seeds for the RNGs
|
||||||
-- that affect those results to have repeateble results
|
-- that affect those results to have repeateble results
|
||||||
SELECT cdb_crankshaft._cdb_random_seeds(1234);
|
SELECT cdb_crankshaft._cdb_random_seeds(1234);
|
||||||
|
|
||||||
SELECT ppoints.code, m.quads
|
SELECT ppoints.code, m.quads
|
||||||
FROM ppoints
|
FROM ppoints
|
||||||
JOIN cdb_crankshaft.cdb_moran_local('SELECT * FROM ppoints', 'value') m
|
JOIN cdb_crankshaft.CDB_AreasOfInterest_Local('SELECT * FROM ppoints', 'value') m
|
||||||
ON ppoints.cartodb_id = m.ids
|
ON ppoints.cartodb_id = m.ids
|
||||||
ORDER BY ppoints.code;
|
ORDER BY ppoints.code;
|
||||||
|
|
||||||
@ -16,6 +16,6 @@ SELECT cdb_crankshaft._cdb_random_seeds(1234);
|
|||||||
|
|
||||||
SELECT ppoints2.code, m.quads
|
SELECT ppoints2.code, m.quads
|
||||||
FROM ppoints2
|
FROM ppoints2
|
||||||
JOIN cdb_crankshaft.cdb_moran_local_rate('SELECT * FROM ppoints2', 'numerator', 'denominator') m
|
JOIN cdb_crankshaft.CDB_AreasOfInterest_Local_Rate('SELECT * FROM ppoints2', 'numerator', 'denominator') m
|
||||||
ON ppoints2.cartodb_id = m.ids
|
ON ppoints2.cartodb_id = m.ids
|
||||||
ORDER BY ppoints2.code;
|
ORDER BY ppoints2.code;
|
||||||
|
@ -9,7 +9,7 @@ SET search_path TO public,cartodb,cdb_crankshaft;
|
|||||||
-- Exercise public functions
|
-- Exercise public functions
|
||||||
SELECT ppoints.code, m.quads
|
SELECT ppoints.code, m.quads
|
||||||
FROM ppoints
|
FROM ppoints
|
||||||
JOIN cdb_moran_local('ppoints', 'value') m
|
JOIN CDB_AreasOfInterest_Local('ppoints', 'value') m
|
||||||
ON ppoints.cartodb_id = m.ids
|
ON ppoints.cartodb_id = m.ids
|
||||||
ORDER BY ppoints.code;
|
ORDER BY ppoints.code;
|
||||||
SELECT round(cdb_overlap_sum(
|
SELECT round(cdb_overlap_sum(
|
||||||
|
@ -14,6 +14,7 @@ import plpy
|
|||||||
def moran(subquery, attr_name, permutations, geom_col, id_col, w_type, num_ngbrs):
|
def moran(subquery, attr_name, permutations, geom_col, id_col, w_type, num_ngbrs):
|
||||||
"""
|
"""
|
||||||
Moran's I (global)
|
Moran's I (global)
|
||||||
|
Implementation building neighors with a PostGIS database and Moran's I core clusters with PySAL.
|
||||||
Andy Eschbacher
|
Andy Eschbacher
|
||||||
"""
|
"""
|
||||||
qvals = {"id_col": id_col,
|
qvals = {"id_col": id_col,
|
||||||
@ -172,8 +173,6 @@ def moran_local_rate(subquery, numerator, denominator, permutations, geom_col, i
|
|||||||
plpy.notice('** Exiting function')
|
plpy.notice('** Exiting function')
|
||||||
return zip([None], [None], [None], [None], [None])
|
return zip([None], [None], [None], [None], [None])
|
||||||
|
|
||||||
plpy.notice('r.nrows() = %d' % r.nrows())
|
|
||||||
|
|
||||||
## collect attributes
|
## collect attributes
|
||||||
numer = get_attributes(r, 1)
|
numer = get_attributes(r, 1)
|
||||||
denom = get_attributes(r, 2)
|
denom = get_attributes(r, 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user