From bc67ae8f69e710e0eddaf6f63a5304b68131558e Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Tue, 29 Mar 2016 12:18:52 -0700 Subject: [PATCH] changed name of functions for observatory --- src/pg/sql/10_moran.sql | 10 +++++----- src/pg/test/expected/02_moran_test.out | 18 +++++++++--------- src/pg/test/sql/02_moran_test.sql | 6 +++--- src/pg/test/sql/90_permissions.sql | 2 +- .../crankshaft/crankshaft/clustering/moran.py | 5 ++--- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/pg/sql/10_moran.sql b/src/pg/sql/10_moran.sql index dba7069..3089fc6 100644 --- a/src/pg/sql/10_moran.sql +++ b/src/pg/sql/10_moran.sql @@ -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; \ No newline at end of file +-- $$ LANGUAGE plpythonu; diff --git a/src/pg/test/expected/02_moran_test.out b/src/pg/test/expected/02_moran_test.out index 92cb218..20b92cd 100644 --- a/src/pg/test/expected/02_moran_test.out +++ b/src/pg/test/expected/02_moran_test.out @@ -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 diff --git a/src/pg/test/sql/02_moran_test.sql b/src/pg/test/sql/02_moran_test.sql index a0bc401..de9c6cf 100644 --- a/src/pg/test/sql/02_moran_test.sql +++ b/src/pg/test/sql/02_moran_test.sql @@ -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; diff --git a/src/pg/test/sql/90_permissions.sql b/src/pg/test/sql/90_permissions.sql index 2e7a89c..187f795 100644 --- a/src/pg/test/sql/90_permissions.sql +++ b/src/pg/test/sql/90_permissions.sql @@ -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( diff --git a/src/py/crankshaft/crankshaft/clustering/moran.py b/src/py/crankshaft/crankshaft/clustering/moran.py index 2d65db5..728e72f 100644 --- a/src/py/crankshaft/crankshaft/clustering/moran.py +++ b/src/py/crankshaft/crankshaft/clustering/moran.py @@ -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 \ No newline at end of file + return lisa_sig