changed name of functions for observatory

This commit is contained in:
Andy Eschbacher 2016-03-29 12:18:52 -07:00
parent eecbe39547
commit bc67ae8f69
5 changed files with 20 additions and 21 deletions

View File

@ -1,6 +1,6 @@
-- Moran's I (global)
CREATE OR REPLACE FUNCTION
cdb_moran (
CDB_AreasOfInterest_Global (
subquery TEXT,
attr_name TEXT,
permutations INT DEFAULT 99,
@ -17,7 +17,7 @@ $$ LANGUAGE plpythonu;
-- Moran's I Local
CREATE OR REPLACE FUNCTION
cdb_moran_local (
CDB_AreasOfInterest_Local(
subquery TEXT,
attr TEXT,
permutations INT DEFAULT 99,
@ -34,7 +34,7 @@ $$ LANGUAGE plpythonu;
-- Moran's I Rate (global)
CREATE OR REPLACE FUNCTION
cdb_moran_rate (
CDB_AreasOfInterest_Global_Rate(
subquery TEXT,
numerator TEXT,
denominator TEXT,
@ -53,7 +53,7 @@ $$ LANGUAGE plpythonu;
-- Moran's I Local Rate
CREATE OR REPLACE FUNCTION
cdb_moran_local_rate(
CDB_AreasOfInterest_Local_Rate(
subquery TEXT,
numerator TEXT,
denominator TEXT,
@ -86,4 +86,4 @@ $$ LANGUAGE plpythonu;
-- from crankshaft.clustering import moran_local_bv
-- # TODO: use named parameters or a dictionary
-- return moran_local_bv(t, attr1, attr2, permutations, geom_col, id_col, w_type, num_ngbrs)
-- $$ LANGUAGE plpythonu;
-- $$ LANGUAGE plpythonu;

View File

@ -110,7 +110,7 @@ INSERT INTO ppoints2 VALUES
(24,'0101000020E61000009C5F91C5095C17C0C78784B15A4F4540'::geometry,'24','07',0.3, 1.0),
(29,'0101000020E6100000C34D4A5B48E712C092E680892C684240'::geometry,'29','01',0.3, 1.0),
(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
-- that affect those results to have repeateble results
SELECT cdb_crankshaft._cdb_random_seeds(1234);
@ -121,15 +121,15 @@ SELECT cdb_crankshaft._cdb_random_seeds(1234);
SELECT ppoints.code, m.quads
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
ORDER BY ppoints.code;
NOTICE: ** Constructing query
CONTEXT: PL/Python function "cdb_moran_local"
CONTEXT: PL/Python function "cdb_areasofinterest_local"
NOTICE: ** Query returned with 52 rows
CONTEXT: PL/Python function "cdb_moran_local"
CONTEXT: PL/Python function "cdb_areasofinterest_local"
NOTICE: ** Finished calculations
CONTEXT: PL/Python function "cdb_moran_local"
CONTEXT: PL/Python function "cdb_areasofinterest_local"
code | quads
------+-------
01 | HH
@ -194,15 +194,15 @@ SELECT cdb_crankshaft._cdb_random_seeds(1234);
SELECT ppoints2.code, m.quads
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
ORDER BY ppoints2.code;
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
CONTEXT: PL/Python function "cdb_moran_local_rate"
CONTEXT: PL/Python function "cdb_areasofinterest_local_rate"
NOTICE: ** Finished calculations
CONTEXT: PL/Python function "cdb_moran_local_rate"
CONTEXT: PL/Python function "cdb_areasofinterest_local_rate"
code | quads
------+-------
01 | LL

View File

@ -1,14 +1,14 @@
\i test/fixtures/ppoints.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
-- that affect those results to have repeateble results
SELECT cdb_crankshaft._cdb_random_seeds(1234);
SELECT ppoints.code, m.quads
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
ORDER BY ppoints.code;
@ -16,6 +16,6 @@ SELECT cdb_crankshaft._cdb_random_seeds(1234);
SELECT ppoints2.code, m.quads
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
ORDER BY ppoints2.code;

View File

@ -9,7 +9,7 @@ SET search_path TO public,cartodb,cdb_crankshaft;
-- Exercise public functions
SELECT ppoints.code, m.quads
FROM ppoints
JOIN cdb_moran_local('ppoints', 'value') m
JOIN CDB_AreasOfInterest_Local('ppoints', 'value') m
ON ppoints.cartodb_id = m.ids
ORDER BY ppoints.code;
SELECT round(cdb_overlap_sum(

View File

@ -14,6 +14,7 @@ import plpy
def moran(subquery, attr_name, permutations, geom_col, id_col, w_type, num_ngbrs):
"""
Moran's I (global)
Implementation building neighors with a PostGIS database and Moran's I core clusters with PySAL.
Andy Eschbacher
"""
qvals = {"id_col": id_col,
@ -172,8 +173,6 @@ def moran_local_rate(subquery, numerator, denominator, permutations, geom_col, i
plpy.notice('** Exiting function')
return zip([None], [None], [None], [None], [None])
plpy.notice('r.nrows() = %d' % r.nrows())
## collect attributes
numer = get_attributes(r, 1)
denom = get_attributes(r, 2)
@ -389,4 +388,4 @@ def quad_position(quads):
lisa_sig = np.array([map_quads(q) for q in quads])
return lisa_sig
return lisa_sig