diff --git a/docs/_modules/tobler/area_weighted/area_weighted.html b/docs/_modules/tobler/area_weighted/area_weighted.html index 8d1e7db..8deb570 100644 --- a/docs/_modules/tobler/area_weighted/area_weighted.html +++ b/docs/_modules/tobler/area_weighted/area_weighted.html @@ -121,6 +121,7 @@

Source code for tobler.area_weighted.area_weighted

from .vectorized_raster_interpolation import fast_append_profile_in_gdf import warnings from scipy.sparse import dok_matrix, diags +import pandas as pd from tobler.util.util import _check_crs, _nan_check, _check_presence_of_crs @@ -292,8 +293,8 @@

Source code for tobler.area_weighted.area_weighted

def area_interpolate_binning( source_df, target_df, - extensive_variables=[], - intensive_variables=[], + extensive_variables=None, + intensive_variables=None, table=None, allocate_total=True, ): @@ -317,9 +318,9 @@

Source code for tobler.area_weighted.area_weighted

Returns ------- - estimates : tuple (2) - (extensive variable array, intensive variables array) - Each is of shape n,v where n is number of target units and v is the number of variables for each variable type. + estimates : geopandas.GeoDataFrame + new geodaraframe with interpolated variables as columns and target_df geometry + as output geometry Notes ----- @@ -368,6 +369,7 @@

Source code for tobler.area_weighted.area_weighted

den = diags([den], [0]) weights = den.dot(table) # row standardize table + dfs = [] extensive = [] if extensive_variables: for variable in extensive_variables: @@ -377,6 +379,8 @@

Source code for tobler.area_weighted.area_weighted

extensive.append(estimates.tolist()[0]) extensive = np.asarray(extensive) + extensive = np.array(extensive) + extensive = pd.DataFrame(extensive.T, columns=extensive_variables) area = np.asarray(table.sum(axis=0)) den = 1.0 / (area + (area == 0)) @@ -396,14 +400,24 @@

Source code for tobler.area_weighted.area_weighted

intensive.append(estimates.tolist()[0]) intensive = np.asarray(intensive) - return (extensive.T, intensive.T) + intensive = pd.DataFrame(intensive.T, columns=intensive_variables) + + if extensive_variables: + dfs.append(extensive) + if intensive_variables: + dfs.append(intensive) + + df = pd.concat(dfs, axis=0) + df["geometry"] = target_df["geometry"] + df = gpd.GeoDataFrame(df) + return df
[docs]def area_interpolate( source_df, target_df, - extensive_variables=[], - intensive_variables=[], + extensive_variables=None, + intensive_variables=None, tables=None, allocate_total=True, ): @@ -432,8 +446,9 @@

Source code for tobler.area_weighted.area_weighted

Returns ------- - estimates : tuple (2) - (extensive variable array, intensive variables array) + estimates : geopandas.GeoDataFrame + new geodaraframe with interpolated variables as columns and target_df geometry + as output geometry Notes ----- @@ -482,6 +497,7 @@

Source code for tobler.area_weighted.area_weighted

den = den + (den == 0) weights = np.dot(np.diag(1 / den), SU) + dfs = [] extensive = [] if extensive_variables: for variable in extensive_variables: @@ -491,6 +507,7 @@

Source code for tobler.area_weighted.area_weighted

estimates = estimates.sum(axis=0) extensive.append(estimates) extensive = np.array(extensive) + extensive = pd.DataFrame(extensive.T, columns=extensive_variables) ST = np.dot(SU, UT) area = ST.sum(axis=0) @@ -504,8 +521,17 @@

Source code for tobler.area_weighted.area_weighted

est = (vals * weights).sum(axis=0) intensive.append(est) intensive = np.array(intensive) + intensive = pd.DataFrame(intensive.T, columns=intensive_variables) + + if extensive_variables: + dfs.append(extensive) + if intensive_variables: + dfs.append(intensive) - return (extensive.T, intensive.T)
+ df = pd.concat(dfs, axis=0) + df["geometry"] = target_df["geometry"] + df = gpd.GeoDataFrame(df) + return df
[docs]def area_tables_raster( diff --git a/docs/_modules/tobler/dasymetric/masked_area_interpolate.html b/docs/_modules/tobler/dasymetric/masked_area_interpolate.html index 6b8fc8e..c03cf27 100644 --- a/docs/_modules/tobler/dasymetric/masked_area_interpolate.html +++ b/docs/_modules/tobler/dasymetric/masked_area_interpolate.html @@ -119,7 +119,7 @@

Source code for tobler.dasymetric.masked_area_interpolate

[docs]def masked_area_interpolate( source_df, target_df, - raster_path="nlcd_2011", + raster="nlcd_2011", codes=None, force_crs_match=True, extensive_variables=None, @@ -135,7 +135,7 @@

Source code for tobler.dasymetric.masked_area_interpolate

source data to be converted to another geometric representation. target_df : geopandas.GeoDataFrame target geometries that will form the new representation of the input data - raster_path : str + raster : str path to raster file that contains ancillary data. alternatively a user can pass `ncld_2001` or `nlcd_2011` to use built-in data from the National Land Cover Database @@ -161,17 +161,19 @@

Source code for tobler.dasymetric.masked_area_interpolate

variables as the columns """ + if not codes: + codes = [21, 22, 23, 24] + if not raster: + raster = 'nlcd_2011' if not tables: tables = area_tables_raster( source_df, target_df.copy(), - raster_path=raster_path, + raster_path=raster, codes=codes, force_crs_match=force_crs_match, ) - if not codes: - codes = [21, 22, 23, 24] # In area_interpolate, the resulting variable has same length as target_df interpolation = _slow_area_interpolate( diff --git a/docs/_modules/tobler/dasymetric/models.html b/docs/_modules/tobler/dasymetric/models.html index 1364946..6a45762 100644 --- a/docs/_modules/tobler/dasymetric/models.html +++ b/docs/_modules/tobler/dasymetric/models.html @@ -111,18 +111,23 @@

Source code for tobler.dasymetric.models

-from ..area_weighted.vectorized_raster_interpolation import (
+"""Model-based methods for areal interpolation."""
+
+import numpy as np
+import statsmodels.formula.api as smf
+from statsmodels.genmod.families import Gaussian, NegativeBinomial, Poisson
+
+from ..area_weighted.vectorized_raster_interpolation import (
+    _check_presence_of_crs,
     calculate_interpolated_population_from_correspondence_table,
-    return_weights_from_regression,
     create_non_zero_population_by_pixels_locations,
-    _check_presence_of_crs,
+    fast_append_profile_in_gdf,
+    return_weights_from_regression,
 )
-from ..data import fetch_quilt_path
-import rasterio
-import warnings
+from tobler.util import project_gdf
 
 
-
[docs]def linear_model( +
[docs]def glm_pixel_adjusted( source_df=None, target_df=None, raster="nlcd_2011", @@ -131,8 +136,13 @@

Source code for tobler.dasymetric.models

     formula=None,
     likelihood="poisson",
     force_crs_match=True,
+    **kwargs,
 ):
-    """Interpolate data between two polygonal datasets using an auxiliary raster to as inut to a linear regression model.
+    """Estimate interpolated values using raster data as input to a generalized linear model, then apply an adjustmnent factor based on pixel values.
+
+    Unlike the regular `glm` function, this version applies an experimental pixel-level adjustment
+    subsequent to fitting the model. This has the benefit of making sure local control totals are
+    respected, but can also induce unknown error. Use with caution.
 
     Parameters
     ----------
@@ -145,8 +155,8 @@ 

Source code for tobler.dasymetric.models

         i.e. a coefficients refer to the relationship between pixel counts and population counts.
         Defaults to 2011 NLCD
     raster_codes : list, required (default =[21, 22, 23, 24])
-        list of inteegers that represent different types of raster cells. Defaults to [21, 22, 23, 24] which
-        are considered developed land types in the NLCD
+        list of integers that represent different types of raster cells.
+        Defaults to [21, 22, 23, 24] whichare considered developed land types in the NLCD
     variable : str, required
         name of the variable (column) to be modeled from the `source_df`
     formula : str, optional
@@ -156,35 +166,124 @@ 

Source code for tobler.dasymetric.models

 
     Returns
     --------
-    interpolated: geopandas.GeoDataFrame
-        a new geopandas dataframe with boundaries from `target_df` and modeled attribute data from the `source_df`
+    interpolated : geopandas.GeoDataFrame
+        a new geopandas dataframe with boundaries from `target_df` and modeled attribute data
+        from the `source_df`
 
     """
     if not raster_codes:
         raster_codes = [21, 22, 23, 24]
 
-        # build weights from raster and vector data
-        weights = return_weights_from_regression(
-            geodataframe=source_df,
-            raster_path=raster,
-            pop_string=variable,
-            formula_string=formula,
-            codes=raster_codes,
-            force_crs_match=force_crs_match,
-            likelihood=likelihood,
-        )
+    # build weights from raster and vector data
+    weights = return_weights_from_regression(
+        geodataframe=source_df,
+        raster_path=raster,
+        pop_string=variable,
+        formula_string=formula,
+        codes=raster_codes,
+        force_crs_match=force_crs_match,
+        likelihood=likelihood,
+        na_value=255,
+        ReLU=False,
+    )
 
-        # match vector population to pixel counts
-        correspondence_table = create_non_zero_population_by_pixels_locations(
-            geodataframe=source_df, raster=raster, pop_string=variable, weights=weights
-        )
+    # match vector population to pixel counts
+    correspondence_table = create_non_zero_population_by_pixels_locations(
+        geodataframe=source_df, raster=raster, pop_string=variable, weights=weights
+    )
 
-        # estimate the model
-        interpolated = calculate_interpolated_population_from_correspondence_table(
-            target_df, raster, correspondence_table
-        )
+    # estimate the model
+    interpolated = calculate_interpolated_population_from_correspondence_table(
+        target_df, raster, correspondence_table, variable_name=variable
+    )
 
     return interpolated
+ + +
[docs]def glm( + source_df=None, + target_df=None, + raster="nlcd_2011", + raster_codes=None, + variable=None, + formula=None, + likelihood="poisson", + force_crs_match=True, + return_model=False, +): + """Estimate interpolated values using raster data as input to a generalized linear model. + + Parameters + ---------- + source_df : geopandas.GeoDataFrame, required + geodataframe containing source original data to be represented by another geometry + target_df : geopandas.GeoDataFrame, required + geodataframe containing target boundaries that will be used to represent the source data + raster : str, required (default="nlcd_2011") + path to raster file that will be used to input data to the regression model. + i.e. a coefficients refer to the relationship between pixel counts and population counts. + Defaults to 2011 NLCD + raster_codes : list, required (default =[21, 22, 23, 24, 41, 42, 52]) + list of integers that represent different types of raster cells. If no formula is given, + the model will be fit from a linear combination of the logged count of each cell type + listed here. Defaults to [21, 22, 23, 24, 41, 42, 52] which + are informative land type cells from the NLCD + variable : str, required + name of the variable (column) to be modeled from the `source_df` + formula : str, optional + patsy-style model formula that specifies the model. Raster codes should be prefixed with + "Type_", e.g. `"n_total_pop ~ -1 + np.log1p(Type_21) + np.log1p(Type_22)` + likelihood : str, {'poisson', 'gaussian', 'neg_binomial'} (default = "poisson") + the likelihood function used in the model + force_crs_match : bool + whether to coerce geodataframe and raster to the same CRS + return model : bool + whether to return the fitted model in addition to the interpolated geodataframe. + If true, this will return (geodataframe, model) + + Returns + -------- + interpolated : geopandas.GeoDataFrame + a new geopandas dataframe with boundaries from `target_df` and modeled attribute + data from the `source_df`. If `return_model` is true, the function will also return + the fitted regression model for further diagnostics + + + """ + _check_presence_of_crs(source_df) + liks = {"poisson": Poisson, "gaussian": Gaussian, "neg_binomial": NegativeBinomial} + + if likelihood not in liks.keys(): + raise ValueError(f"likelihood must one of {liks.keys()}") + + if not raster_codes: + raster_codes = [21, 22, 23, 24, 41, 42, 52] + raster_codes = ["Type_" + str(i) for i in raster_codes] + + if not formula: + formula = ( + variable + + "~ -1 +" + + "+".join(["np.log1p(" + code + ")" for code in raster_codes]) + ) + source_df["area"] = project_gdf(source_df.copy()).area + + profiled_df = fast_append_profile_in_gdf( + source_df[["geometry", variable, "area"]], raster, force_crs_match + ) + + results = smf.glm(formula, data=profiled_df, family=liks[likelihood]()).fit() + + out = target_df.copy()[["geometry"]] + temp = fast_append_profile_in_gdf(out[["geometry"]], raster, force_crs_match) + temp["area"] = project_gdf(out.copy()).area + + out[variable] = results.predict(temp.drop(columns=["geometry"]).fillna(0)) + + if return_model: + return out, results + + return out
diff --git a/docs/_modules/tobler/data.html b/docs/_modules/tobler/data.html index 06b64a4..f544dc4 100644 --- a/docs/_modules/tobler/data.html +++ b/docs/_modules/tobler/data.html @@ -112,6 +112,8 @@

Source code for tobler.data

 from urllib.parse import unquote, urlparse
+from warnings import warn
+from requests.exceptions import Timeout
 
 import quilt3
 
@@ -153,12 +155,12 @@ 

Source code for tobler.data

 
             full_path = unquote(nlcd[path + ".tif"].get())
             full_path = urlparse(full_path).path
+
         except ImportError:
-            raise IOError(
+            warn(
                 "Unable to locate local raster data. If you would like to use "
                 "raster data from the National Land Cover Database, you can "
-                "store it locally using the `data.store_rasters()` function"
-            )
+                "store it locally using the `data.store_rasters()` function")
 
     else:
         return path
diff --git a/docs/_sources/api.rst.txt b/docs/_sources/api.rst.txt
index 93cc826..cdf78d6 100644
--- a/docs/_sources/api.rst.txt
+++ b/docs/_sources/api.rst.txt
@@ -34,7 +34,8 @@ variables being assigned to the target
 .. autosummary::
    :toctree: generated/
 
-   linear_model
+   glm
+   glm_pixel_adjusted
    masked_area_interpolate
    
 
diff --git a/docs/_sources/generated/tobler.dasymetric.glm.rst.txt b/docs/_sources/generated/tobler.dasymetric.glm.rst.txt
new file mode 100644
index 0000000..fac89c4
--- /dev/null
+++ b/docs/_sources/generated/tobler.dasymetric.glm.rst.txt
@@ -0,0 +1,6 @@
+tobler.dasymetric.glm
+=====================
+
+.. currentmodule:: tobler.dasymetric
+
+.. autofunction:: glm
\ No newline at end of file
diff --git a/docs/_sources/generated/tobler.dasymetric.glm_pixel_adjusted.rst.txt b/docs/_sources/generated/tobler.dasymetric.glm_pixel_adjusted.rst.txt
new file mode 100644
index 0000000..f8f2fb4
--- /dev/null
+++ b/docs/_sources/generated/tobler.dasymetric.glm_pixel_adjusted.rst.txt
@@ -0,0 +1,6 @@
+tobler.dasymetric.glm\_pixel\_adjusted
+======================================
+
+.. currentmodule:: tobler.dasymetric
+
+.. autofunction:: glm_pixel_adjusted
\ No newline at end of file
diff --git a/docs/_sources/generated/tobler.dasymetric.linear_model.rst.txt b/docs/_sources/generated/tobler.dasymetric.linear_model.rst.txt
deleted file mode 100644
index 6e42281..0000000
--- a/docs/_sources/generated/tobler.dasymetric.linear_model.rst.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-tobler.dasymetric.linear\_model
-===============================
-
-.. currentmodule:: tobler.dasymetric
-
-.. autofunction:: linear_model
\ No newline at end of file
diff --git a/docs/api.html b/docs/api.html
index da4d265..c9ea0d9 100644
--- a/docs/api.html
+++ b/docs/api.html
@@ -157,10 +157,13 @@ 

Dasymetric -

linear_model([source_df, target_df, raster, …])

-

Interpolate data between two polygonal datasets using an auxiliary raster to as inut to a linear regression model.

+

glm([source_df, target_df, raster, …])

+

Estimate interpolated values using raster data as input to a generalized linear model.

-

masked_area_interpolate(source_df, target_df)

+

glm_pixel_adjusted([source_df, target_df, …])

+

Estimate interpolated values using raster data as input to a generalized linear model, then apply an adjustmnent factor based on pixel values.

+ +

masked_area_interpolate(source_df, target_df)

Interpolate data between two polygonal datasets using an auxiliary raster to mask out uninhabited land.

diff --git a/docs/generated/tobler.area_weighted.area_interpolate.html b/docs/generated/tobler.area_weighted.area_interpolate.html index 6d3e85a..bed33cd 100644 --- a/docs/generated/tobler.area_weighted.area_interpolate.html +++ b/docs/generated/tobler.area_weighted.area_interpolate.html @@ -119,18 +119,18 @@

tobler.area_weighted.area_interpolate

-tobler.area_weighted.area_interpolate(source_df, target_df, extensive_variables=[], intensive_variables=[], table=None, allocate_total=True)[source]
+tobler.area_weighted.area_interpolate(source_df, target_df, extensive_variables=None, intensive_variables=None, table=None, allocate_total=True)[source]

Area interpolation for extensive and intensive variables.

Parameters
-
source_dfgeopandas.GeoDataFrame
-
target_dfgeopandas.GeoDataFrame
+
source_dfgeopandas.GeoDataFrame
+
target_dfgeopandas.GeoDataFrame
extensive_variableslist

columns in dataframes for extensive variables

intensive_variableslist

columns in dataframes for intensive variables

-
tablescipy.sparse.dok_matrix
+
tablescipy.sparse.dok_matrix
allocate_totalbool

True if total value of source area should be allocated. False if denominator is area of i. Note that the two cases would be identical when the area of the source polygon is @@ -140,8 +140,8 @@

tobler.area_weighted.area_interpolateReturns
-
estimatestuple (2)

(extensive variable array, intensive variables array) -Each is of shape n,v where n is number of target units and v is the number of variables for each variable type.

+
estimatesgeopandas.GeoDataFrame

new geodaraframe with interpolated variables as columns and target_df geometry +as output geometry

diff --git a/docs/generated/tobler.area_weighted.area_tables.html b/docs/generated/tobler.area_weighted.area_tables.html index 4aa4510..2df8643 100644 --- a/docs/generated/tobler.area_weighted.area_tables.html +++ b/docs/generated/tobler.area_weighted.area_tables.html @@ -124,8 +124,8 @@

tobler.area_weighted.area_tables
Parameters
-
source_dfgeopandas.GeoDataFrame
-
target_dfgeopandas.GeoDataFrame
+
source_dfgeopandas.GeoDataFrame
+
target_dfgeopandas.GeoDataFrame
Returns
diff --git a/docs/generated/tobler.area_weighted.area_tables_binning.html b/docs/generated/tobler.area_weighted.area_tables_binning.html index 70e8f6b..59aced5 100644 --- a/docs/generated/tobler.area_weighted.area_tables_binning.html +++ b/docs/generated/tobler.area_weighted.area_tables_binning.html @@ -124,7 +124,7 @@

tobler.area_weighted.area_tables_binning
Parameters
-
source_dfgeopandas.GeoDataFrame

GeoDataFrame containing input data and polygons

+
source_dfgeopandas.GeoDataFrame

GeoDataFrame containing input data and polygons

target_dfgeopandas.GeoDataFramee

GeoDataFrame defining the output geometries

@@ -132,7 +132,7 @@

tobler.area_weighted.area_tables_binningReturns
-
tablesscipy.sparse.dok_matrix
+
tablesscipy.sparse.dok_matrix

diff --git a/docs/generated/tobler.area_weighted.area_tables_raster.html b/docs/generated/tobler.area_weighted.area_tables_raster.html index 8af0278..60e2fd2 100644 --- a/docs/generated/tobler.area_weighted.area_tables_raster.html +++ b/docs/generated/tobler.area_weighted.area_tables_raster.html @@ -15,7 +15,7 @@ - + @@ -124,9 +124,9 @@

tobler.area_weighted.area_tables_raster
Parameters
-
source_dfgeopandas.GeoDataFrame

geeodataframe with geometry column of polygon type

+
source_dfgeopandas.GeoDataFrame

geeodataframe with geometry column of polygon type

-
target_dfgeopandas.GeoDataFrame

geodataframe with geometry column of polygon type

+
target_dfgeopandas.GeoDataFrame

geodataframe with geometry column of polygon type

raster_pathstr

the path to the associated raster image.

diff --git a/docs/generated/tobler.dasymetric.glm.html b/docs/generated/tobler.dasymetric.glm.html new file mode 100644 index 0000000..4119eb4 --- /dev/null +++ b/docs/generated/tobler.dasymetric.glm.html @@ -0,0 +1,192 @@ + + + + + + tobler.dasymetric.glm — tobler v0.1.0 Manual + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+

tobler.dasymetric.glm

+
+
+tobler.dasymetric.glm(source_df=None, target_df=None, raster='nlcd_2011', raster_codes=None, variable=None, formula=None, likelihood='poisson', force_crs_match=True, return_model=False)[source]
+

Estimate interpolated values using raster data as input to a generalized linear model.

+
+
Parameters
+
+
source_dfgeopandas.GeoDataFrame, required

geodataframe containing source original data to be represented by another geometry

+
+
target_dfgeopandas.GeoDataFrame, required

geodataframe containing target boundaries that will be used to represent the source data

+
+
rasterstr, required (default=”nlcd_2011”)

path to raster file that will be used to input data to the regression model. +i.e. a coefficients refer to the relationship between pixel counts and population counts. +Defaults to 2011 NLCD

+
+
raster_codeslist, required (default =[21, 22, 23, 24, 41, 42, 52])

list of integers that represent different types of raster cells. If no formula is given, +the model will be fit from a linear combination of the logged count of each cell type +listed here. Defaults to [21, 22, 23, 24, 41, 42, 52] which +are informative land type cells from the NLCD

+
+
variablestr, required

name of the variable (column) to be modeled from the source_df

+
+
formulastr, optional

patsy-style model formula that specifies the model. Raster codes should be prefixed with +“Type_”, e.g. “n_total_pop ~ -1 + np.log1p(Type_21) + np.log1p(Type_22)

+
+
likelihoodstr, {‘poisson’, ‘gaussian’, ‘neg_binomial’} (default = “poisson”)

the likelihood function used in the model

+
+
force_crs_matchbool

whether to coerce geodataframe and raster to the same CRS

+
+
return modelbool

whether to return the fitted model in addition to the interpolated geodataframe. +If true, this will return (geodataframe, model)

+
+
+
+
Returns
+
+
interpolatedgeopandas.GeoDataFrame

a new geopandas dataframe with boundaries from target_df and modeled attribute +data from the source_df. If return_model is true, the function will also return +the fitted regression model for further diagnostics

+
+
+
+
+
+ +
+ + +
+ +
+
+
+
+

+ Back to top + +
+ +

+ +

+

+ © Copyright 2018, pysal developers.
+ Created using Sphinx 2.2.2.
+

+
+
+ + \ No newline at end of file diff --git a/docs/generated/tobler.dasymetric.linear_model.html b/docs/generated/tobler.dasymetric.glm_pixel_adjusted.html similarity index 76% rename from docs/generated/tobler.dasymetric.linear_model.html rename to docs/generated/tobler.dasymetric.glm_pixel_adjusted.html index 430434e..36dc514 100644 --- a/docs/generated/tobler.dasymetric.linear_model.html +++ b/docs/generated/tobler.dasymetric.glm_pixel_adjusted.html @@ -3,7 +3,7 @@ - tobler.dasymetric.linear_model — tobler v0.1.0 Manual + tobler.dasymetric.glm_pixel_adjusted — tobler v0.1.0 Manual @@ -16,7 +16,7 @@ - + @@ -85,7 +85,7 @@ @@ -115,25 +115,28 @@
-
-

tobler.dasymetric.linear_model

+
+

tobler.dasymetric.glm_pixel_adjusted

-
-tobler.dasymetric.linear_model(source_df=None, target_df=None, raster='nlcd_2011', raster_codes=None, variable=None, formula=None, likelihood='poisson', force_crs_match=True)[source]
-

Interpolate data between two polygonal datasets using an auxiliary raster to as inut to a linear regression model.

+
+tobler.dasymetric.glm_pixel_adjusted(source_df=None, target_df=None, raster='nlcd_2011', raster_codes=None, variable=None, formula=None, likelihood='poisson', force_crs_match=True, **kwargs)[source]
+

Estimate interpolated values using raster data as input to a generalized linear model, then apply an adjustmnent factor based on pixel values.

+

Unlike the regular glm function, this version applies an experimental pixel-level adjustment +subsequent to fitting the model. This has the benefit of making sure local control totals are +respected, but can also induce unknown error. Use with caution.

Parameters
-
source_dfgeopandas.GeoDataFrame, required

geodataframe containing source original data to be represented by another geometry

+
source_dfgeopandas.GeoDataFrame, required

geodataframe containing source original data to be represented by another geometry

-
target_dfgeopandas.GeoDataFrame, required

geodataframe containing target boundaries that will be used to represent the source data

+
target_dfgeopandas.GeoDataFrame, required

geodataframe containing target boundaries that will be used to represent the source data

rasterstr, required (default=”nlcd_2011”)

path to raster file that will be used to input data to the regression model. i.e. a coefficients refer to the relationship between pixel counts and population counts. Defaults to 2011 NLCD

-
raster_codeslist, required (default =[21, 22, 23, 24])

list of inteegers that represent different types of raster cells. Defaults to [21, 22, 23, 24] which -are considered developed land types in the NLCD

+
raster_codeslist, required (default =[21, 22, 23, 24])

list of integers that represent different types of raster cells. +Defaults to [21, 22, 23, 24] whichare considered developed land types in the NLCD

variablestr, required

name of the variable (column) to be modeled from the source_df

@@ -144,8 +147,9 @@

tobler.dasymetric.linear_modelReturns -
-
interpolated: geopandas.GeoDataFrame

a new geopandas dataframe with boundaries from target_df and modeled attribute data from the source_df

+
+
interpolatedgeopandas.GeoDataFrame

a new geopandas dataframe with boundaries from target_df and modeled attribute data +from the source_df

@@ -167,7 +171,7 @@

tobler.dasymetric.linear_model - Source

diff --git a/docs/generated/tobler.dasymetric.masked_area_interpolate.html b/docs/generated/tobler.dasymetric.masked_area_interpolate.html index da2fcb2..d6b2df2 100644 --- a/docs/generated/tobler.dasymetric.masked_area_interpolate.html +++ b/docs/generated/tobler.dasymetric.masked_area_interpolate.html @@ -16,7 +16,7 @@ - + @@ -119,16 +119,16 @@

tobler.dasymetric.masked_area_interpolate

-tobler.dasymetric.masked_area_interpolate(source_df, target_df, raster_path='nlcd_2011', codes=None, force_crs_match=True, extensive_variables=None, intensive_variables=None, allocate_total=True, tables=None)[source]
+tobler.dasymetric.masked_area_interpolate(source_df, target_df, raster='nlcd_2011', codes=None, force_crs_match=True, extensive_variables=None, intensive_variables=None, allocate_total=True, tables=None)[source]

Interpolate data between two polygonal datasets using an auxiliary raster to mask out uninhabited land.

Parameters
-
source_dfgeopandas.GeoDataFrame

source data to be converted to another geometric representation.

+
source_dfgeopandas.GeoDataFrame

source data to be converted to another geometric representation.

-
target_dfgeopandas.GeoDataFrame

target geometries that will form the new representation of the input data

+
target_dfgeopandas.GeoDataFrame

target geometries that will form the new representation of the input data

-
raster_pathstr

path to raster file that contains ancillary data. +

rasterstr

path to raster file that contains ancillary data. alternatively a user can pass ncld_2001 or nlcd_2011 to use built-in data from the National Land Cover Database

@@ -150,7 +150,7 @@

tobler.dasymetric.masked_area_interpolateReturns
-
geopandas.GeoDataFrame

GeoDataFrame with geometries matching the target_df and extensive and intensive +

geopandas.GeoDataFrame

GeoDataFrame with geometries matching the target_df and extensive and intensive variables as the columns

diff --git a/docs/genindex.html b/docs/genindex.html index 739bd0f..db2d587 100644 --- a/docs/genindex.html +++ b/docs/genindex.html @@ -116,7 +116,7 @@

Index

A - | L + | G | M | S @@ -137,10 +137,14 @@

A

-

L

+

G

+
diff --git a/docs/objects.inv b/docs/objects.inv index b674a78..a14cada 100644 Binary files a/docs/objects.inv and b/docs/objects.inv differ diff --git a/docs/searchindex.js b/docs/searchindex.js index 55c5256..e6f4c18 100644 --- a/docs/searchindex.js +++ b/docs/searchindex.js @@ -1 +1 @@ -Search.setIndex({docnames:["api","generated/tobler.area_weighted.area_interpolate","generated/tobler.area_weighted.area_tables","generated/tobler.area_weighted.area_tables_binning","generated/tobler.area_weighted.area_tables_raster","generated/tobler.dasymetric.linear_model","generated/tobler.dasymetric.masked_area_interpolate","generated/tobler.data.store_rasters","index","installation","references"],envversion:{"sphinx.domains.c":1,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":1,"sphinx.domains.javascript":1,"sphinx.domains.math":2,"sphinx.domains.python":1,"sphinx.domains.rst":1,"sphinx.domains.std":1,"sphinx.ext.intersphinx":1,"sphinx.ext.viewcode":1,sphinx:56},filenames:["api.rst","generated/tobler.area_weighted.area_interpolate.rst","generated/tobler.area_weighted.area_tables.rst","generated/tobler.area_weighted.area_tables_binning.rst","generated/tobler.area_weighted.area_tables_raster.rst","generated/tobler.dasymetric.linear_model.rst","generated/tobler.dasymetric.masked_area_interpolate.rst","generated/tobler.data.store_rasters.rst","index.rst","installation.rst","references.rst"],objects:{"tobler.area_weighted":{area_interpolate:[1,0,1,""],area_tables:[2,0,1,""],area_tables_binning:[3,0,1,""],area_tables_raster:[4,0,1,""]},"tobler.dasymetric":{linear_model:[5,0,1,""],masked_area_interpolate:[6,0,1,""]},"tobler.data":{store_rasters:[7,0,1,""]}},objnames:{"0":["py","function","Python function"]},objtypes:{"0":"py:function"},terms:{"case":1,"default":[1,4,5,6],"function":[5,7],"int":6,"new":[5,6],"return":[1,2,3,4,5,6,7],"true":[1,4,5,6],CRS:[4,6],For:1,The:[1,2,4,8,9],a_i:1,accord:4,activ:9,addit:0,alloc:[1,2,3,4,6],allocate_tot:[1,6],also:9,altern:6,anaconda:9,ancillari:6,anoth:[5,6],anselin:10,approach:[0,3],area:[1,2,3,4,10],area_tables_rast:6,area_weight:6,areal:8,argument:4,arrai:[1,2,4,6],arriba:10,assign:0,associ:4,assumpt:[1,2,4],attribut:[1,5],auxiliari:[0,5,6],avail:7,base:4,being:0,bel:10,between:[0,5,6],binari:[2,4],bool:[1,4,6],both:[1,2,4],boundari:5,built:6,can:[4,6,9],cell:5,chang:9,clone:9,code:[4,6],coeffici:5,column:[1,4,5,6],command:9,complet:1,conda:9,consid:[4,5,6],consider:4,construct:[2,3,4],contain:[3,5,6],contribut:9,convert:6,coordin:[1,2,4],correspond:[2,3,4],count:5,cover:[4,6],creat:9,daniel:10,dasymetr:8,data:[3,5,6],databas:[4,6],datafram:[1,2,4,5,6],dataset:[5,6],david:10,defin:3,denomin:1,descript:4,detail:1,develop:[4,5,6,10],differ:5,directori:9,doi:10,dok_matrix:[1,3],download:9,draw:4,dynam:10,each:[1,4],econom:10,env:9,environ:9,estim:1,exhaust:1,extens:[1,6],extensive_vari:[1,6],fals:1,file:[4,5,6],folch:10,follow:[1,9],forc:6,force_crs_match:[4,5,6],fork:9,form:[2,4,6],formula:5,found:4,from:[5,6,7],gaussian:5,geeodatafram:4,gener:6,geodatafram:[1,2,3,4,5,6],geodataframe:3,geograph:8,geometr:6,geometri:[0,2,3,4,5,6],geopanda:[1,2,3,4,5,6],get:9,gov:4,guti:10,harmon:[4,7],have:[1,2,4],here:4,high:4,homag:8,html:4,http:[4,10],ident:1,imag:4,index:3,input:[3,5,6],inspir:4,inteeg:5,integ:4,intens:[1,4,6],intensive_vari:[1,6],interlant:10,interpol:[1,5,6,7,8],intersect:[1,2,4],inut:5,land:[4,5,6],landcov:4,legendari:8,let:4,librari:8,likelihood:5,lindsei:10,linear:5,list:[1,4,5,6],local:[7,9],low:4,luc:10,make:9,manual:9,map:[2,4,8],mask:6,match:6,measur:10,medium:4,metadata:4,method:9,metropolitan:10,model:5,modul:7,more:1,mrlc:4,myrna:10,name:[5,8],nation:[4,6],ncld_2001:6,nlcd:[4,5,6],nlcd_2011:[5,6],none:[1,5,6,7],note:[1,2,4],nov:10,number:1,numpi:[2,4,6],onli:[4,9],open:4,oper:9,option:[2,4,5,6],org:10,origin:5,out:6,output:3,overlap:0,packag:7,paramet:[1,2,3,4,5,6],part:6,pass:6,path:[4,5,6],patsi:5,pip:9,pixel:[5,6],pleas:9,poisson:5,polygon:[1,3,4,5,6],popul:[4,5],pull:9,pysal:9,python:9,quarterli:10,quilt:7,raf:10,raster:[4,5,6,7],raster_cod:5,raster_path:[4,6],reason:1,recommend:[4,9],refer:[1,2,4,5],registri:7,regress:5,rei:10,relationship:5,repo:9,repositori:9,repres:5,represent:6,reproject:4,request:9,requir:5,rrez:10,run:9,same:[1,2,4,6],sastr:10,save:7,scipi:[1,3],see:1,sergio:10,set:1,setup:9,shape:1,share:6,should:[1,4,6],sinc:4,site:4,sourc:[0,1,2,3,4,5,6,7,9],source_df:[1,2,3,4,5,6],space:4,spars:[1,3],spatial:[3,10],start:9,storag:7,str:[4,5,6],style:5,submit:9,sum_i:1,sum_k:1,support:9,sure:9,system:[1,2,4],tabl:[1,2,3,4,6],taken:4,target:[0,1,2,3,4,5,6],target_df:[1,2,3,4,5,6],thi:[4,6,9],tobler:9,total:[1,6],tupl:[1,2,4,6],two:[1,2,4,5,6],type:[1,4,5],uninhabit:6,union:[2,4],unit:1,url:10,use:[0,1,6,7],used:5,user:6,using:[3,4,5,6],v_i:1,v_j:1,valu:[1,4,6],variabl:[0,1,5,6],weight:1,when:1,where:1,whether:[4,6],which:[5,6],would:1,www:4,yml:9,you:9,your:9},titles:["API reference","tobler.area_weighted.area_interpolate","tobler.area_weighted.area_tables","tobler.area_weighted.area_tables_binning","tobler.area_weighted.area_tables_raster","tobler.dasymetric.linear_model","tobler.dasymetric.masked_area_interpolate","tobler.data.store_rasters","Tobler","Installation","References"],titleterms:{api:0,area:0,area_interpol:1,area_t:2,area_tables_bin:3,area_tables_rast:4,area_weight:[1,2,3,4],dasymetr:[0,5,6],data:[0,7],develop:9,instal:9,linear_model:5,masked_area_interpol:6,refer:[0,10],releas:9,store_rast:7,tobler:[1,2,3,4,5,6,7,8],version:9,weight:0}}) \ No newline at end of file +Search.setIndex({docnames:["api","generated/tobler.area_weighted.area_interpolate","generated/tobler.area_weighted.area_tables","generated/tobler.area_weighted.area_tables_binning","generated/tobler.area_weighted.area_tables_raster","generated/tobler.dasymetric.glm","generated/tobler.dasymetric.glm_pixel_adjusted","generated/tobler.dasymetric.masked_area_interpolate","generated/tobler.data.store_rasters","index","installation","references"],envversion:{"sphinx.domains.c":1,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":1,"sphinx.domains.javascript":1,"sphinx.domains.math":2,"sphinx.domains.python":1,"sphinx.domains.rst":1,"sphinx.domains.std":1,"sphinx.ext.intersphinx":1,"sphinx.ext.viewcode":1,sphinx:56},filenames:["api.rst","generated/tobler.area_weighted.area_interpolate.rst","generated/tobler.area_weighted.area_tables.rst","generated/tobler.area_weighted.area_tables_binning.rst","generated/tobler.area_weighted.area_tables_raster.rst","generated/tobler.dasymetric.glm.rst","generated/tobler.dasymetric.glm_pixel_adjusted.rst","generated/tobler.dasymetric.masked_area_interpolate.rst","generated/tobler.data.store_rasters.rst","index.rst","installation.rst","references.rst"],objects:{"tobler.area_weighted":{area_interpolate:[1,0,1,""],area_tables:[2,0,1,""],area_tables_binning:[3,0,1,""],area_tables_raster:[4,0,1,""]},"tobler.dasymetric":{glm:[5,0,1,""],glm_pixel_adjusted:[6,0,1,""],masked_area_interpolate:[7,0,1,""]},"tobler.data":{store_rasters:[8,0,1,""]}},objnames:{"0":["py","function","Python function"]},objtypes:{"0":"py:function"},terms:{"case":1,"default":[1,4,5,6,7],"function":[5,6,8],"int":7,"new":[1,5,6,7],"return":[1,2,3,4,5,6,7,8],"true":[1,4,5,6,7],CRS:[4,5,7],For:1,The:[1,2,4,9,10],Use:6,a_i:1,accord:4,activ:10,addit:[0,5],adjust:6,adjustmn:6,alloc:[1,2,3,4,7],allocate_tot:[1,7],also:[5,6,10],altern:7,anaconda:10,ancillari:7,anoth:[5,6,7],anselin:11,appli:6,approach:[0,3],area:[1,2,3,4,11],area_tables_rast:7,area_weight:7,areal:9,argument:4,arrai:[2,4,7],arriba:11,assign:0,associ:4,assumpt:[1,2,4],attribut:[1,5,6],auxiliari:[0,7],avail:8,base:[4,6],being:0,bel:11,benefit:6,between:[0,5,6,7],binari:[2,4],bool:[1,4,5,7],both:[1,2,4],boundari:[5,6],built:7,can:[4,6,7,10],caution:6,cell:[5,6],chang:10,clone:10,code:[4,5,7],coeffici:[5,6],coerc:5,column:[1,4,5,6,7],combin:5,command:10,complet:1,conda:10,consid:[4,6,7],consider:4,construct:[2,3,4],contain:[3,5,6,7],contribut:10,control:6,convert:7,coordin:[1,2,4],correspond:[2,3,4],count:[5,6],cover:[4,7],creat:10,daniel:11,dasymetr:9,data:[3,5,6,7],databas:[4,7],datafram:[1,2,4,5,6,7],dataset:7,david:11,defin:3,denomin:1,descript:4,detail:1,develop:[4,6,7,11],diagnost:5,differ:[5,6],directori:10,doi:11,dok_matrix:[1,3],download:10,draw:4,dynam:11,each:[4,5],econom:11,env:10,environ:10,error:6,estim:[1,5,6],exhaust:1,experiment:6,extens:[1,7],extensive_vari:[1,7],factor:6,fals:[1,5],file:[4,5,6,7],fit:[5,6],folch:11,follow:[1,10],forc:7,force_crs_match:[4,5,6,7],fork:10,form:[2,4,7],formula:[5,6],found:4,from:[5,6,7,8],further:5,gaussian:[5,6],geeodatafram:4,gener:[5,6,7],geodarafram:1,geodatafram:[1,2,3,4,5,6,7],geodataframe:3,geograph:9,geometr:7,geometri:[0,1,2,3,4,5,6,7],geopanda:[1,2,3,4,5,6,7],get:10,given:5,glm:6,gov:4,guti:11,harmon:[4,8],has:6,have:[1,2,4],here:[4,5],high:4,homag:9,html:4,http:[4,11],ident:1,imag:4,index:3,induc:6,inform:5,input:[3,5,6,7],inspir:4,integ:[4,5,6],intens:[1,4,7],intensive_vari:[1,7],interlant:11,interpol:[1,5,6,7,8,9],intersect:[1,2,4],kwarg:6,land:[4,5,6,7],landcov:4,legendari:9,let:4,level:6,librari:9,likelihood:[5,6],lindsei:11,linear:[5,6],list:[1,4,5,6,7],local:[6,8,10],log1p:5,log:5,low:4,luc:11,make:[6,10],manual:10,map:[2,4,9],mask:7,match:7,measur:11,medium:4,metadata:4,method:10,metropolitan:11,model:[5,6],modul:8,more:1,mrlc:4,myrna:11,n_total_pop:5,name:[5,6,9],nation:[4,7],ncld_2001:7,neg_binomi:5,nlcd:[4,5,6,7],nlcd_2011:[5,6,7],none:[1,5,6,7,8],note:[1,2,4],nov:11,numpi:[2,4,7],onli:[4,10],open:4,oper:10,option:[2,4,5,6,7],org:11,origin:[5,6],out:7,output:[1,3],overlap:0,packag:8,paramet:[1,2,3,4,5,6,7],part:7,pass:7,path:[4,5,6,7],patsi:[5,6],pip:10,pixel:[5,6,7],pleas:10,poisson:[5,6],polygon:[1,3,4,7],popul:[4,5,6],prefix:5,pull:10,pysal:10,python:10,quarterli:11,quilt:8,raf:11,raster:[4,5,6,7,8],raster_cod:[5,6],raster_path:4,reason:1,recommend:[4,10],refer:[1,2,4,5,6],registri:8,regress:[5,6],regular:6,rei:11,relationship:[5,6],repo:10,repositori:10,repres:[5,6],represent:7,reproject:4,request:10,requir:[5,6],respect:6,return_model:5,rrez:11,run:10,same:[1,2,4,5,7],sastr:11,save:8,scipi:[1,3],see:1,sergio:11,set:1,setup:10,share:7,should:[1,4,5,7],sinc:4,site:4,sourc:[0,1,2,3,4,5,6,7,8,10],source_df:[1,2,3,4,5,6,7],space:4,spars:[1,3],spatial:[3,11],specifi:5,start:10,storag:8,str:[4,5,6,7],style:[5,6],submit:10,subsequ:6,sum_i:1,sum_k:1,support:10,sure:[6,10],system:[1,2,4],tabl:[1,2,3,4,7],taken:4,target:[0,1,2,3,4,5,6,7],target_df:[1,2,3,4,5,6,7],thi:[4,5,6,7,10],tobler:10,total:[1,6,7],tupl:[2,4,7],two:[1,2,4,7],type:[4,5,6],type_21:5,type_22:5,type_:5,uninhabit:7,union:[2,4],unknown:6,unlik:6,url:11,use:[0,1,7,8],used:[5,6],user:7,using:[3,4,5,6,7],v_i:1,v_j:1,valu:[1,4,5,6,7],variabl:[0,1,5,6,7],version:6,weight:1,when:1,where:1,whether:[4,5,7],which:[5,7],whichar:6,would:1,www:4,yml:10,you:10,your:10},titles:["API reference","tobler.area_weighted.area_interpolate","tobler.area_weighted.area_tables","tobler.area_weighted.area_tables_binning","tobler.area_weighted.area_tables_raster","tobler.dasymetric.glm","tobler.dasymetric.glm_pixel_adjusted","tobler.dasymetric.masked_area_interpolate","tobler.data.store_rasters","Tobler","Installation","References"],titleterms:{api:0,area:0,area_interpol:1,area_t:2,area_tables_bin:3,area_tables_rast:4,area_weight:[1,2,3,4],dasymetr:[0,5,6,7],data:[0,8],develop:10,glm:5,glm_pixel_adjust:6,instal:10,masked_area_interpol:7,refer:[0,11],releas:10,store_rast:8,tobler:[1,2,3,4,5,6,7,8,9],version:10,weight:0}}) \ No newline at end of file diff --git a/docsrc/api.rst b/docsrc/api.rst index 93cc826..cdf78d6 100644 --- a/docsrc/api.rst +++ b/docsrc/api.rst @@ -34,7 +34,8 @@ variables being assigned to the target .. autosummary:: :toctree: generated/ - linear_model + glm + glm_pixel_adjusted masked_area_interpolate