From 7ecef3b3bb08da6e4c6b27c5705b4a980e1c5dbb Mon Sep 17 00:00:00 2001 From: weiqi-tori Date: Fri, 26 Jul 2024 16:56:58 +0800 Subject: [PATCH 1/5] update setup --- city_metrix/layers/smart_surface_lulc.py | 3 ++- city_metrix/models/__init__.py | 0 .../models/building_classifier/__init__.py | 0 setup.py | 16 ++++++++++++++-- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 city_metrix/models/__init__.py create mode 100644 city_metrix/models/building_classifier/__init__.py diff --git a/city_metrix/layers/smart_surface_lulc.py b/city_metrix/layers/smart_surface_lulc.py index 171bca5..d58f468 100644 --- a/city_metrix/layers/smart_surface_lulc.py +++ b/city_metrix/layers/smart_surface_lulc.py @@ -7,6 +7,7 @@ import psutil from exactextract import exact_extract import pickle +import importlib.resources as pkg_resources import warnings warnings.filterwarnings('ignore',category=UserWarning) @@ -24,7 +25,7 @@ def get_data(self, bbox): crs = get_utm_zone_epsg(bbox) # load building roof slope classifier - with open('city_metrix/models/building_classifier/building_classifier.pkl', 'rb') as f: + with pkg_resources.files('city_metrix.models.building_classifier').joinpath('building_classifier.pkl').open('rb') as f: clf = pickle.load(f) # ESA world cover diff --git a/city_metrix/models/__init__.py b/city_metrix/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/city_metrix/models/building_classifier/__init__.py b/city_metrix/models/building_classifier/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py index c2d24d8..c6d4190 100644 --- a/setup.py +++ b/setup.py @@ -2,9 +2,16 @@ setup( name="city_metrix", - version="0.1.0", + version="0.1.1", description="Module to calculate various metrics on cities.", - packages=["city_metrix", "city_metrix.layers", "city_metrix.metrics"], + packages=["city_metrix", "city_metrix.layers", "city_metrix.metrics", "city_metrix.models", "city_metrix.models.building_classifier"], + include_package_data=True, + package_data={ + 'city_metrix.models.building_classifier': [ + 'building_classifier.pkl', + 'V2-building-class-data.geojson', + ], + }, author="Justin Terry", license="MIT", install_requires=[ @@ -21,5 +28,10 @@ "osmnx", "geopandas", "s3fs", + "dask==2023.11.0", + "boto3", + "exactextract", + "overturemaps", + "scikit-learn==1.5.0", ], ) From f853bd262c450b315626db649af33a303c5587fa Mon Sep 17 00:00:00 2001 From: weiqi-tori Date: Tue, 30 Jul 2024 14:37:29 +0800 Subject: [PATCH 2/5] remove unused packages --- environment.yml | 1 - setup.py | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/environment.yml b/environment.yml index 18f95f4..a18ec25 100644 --- a/environment.yml +++ b/environment.yml @@ -23,6 +23,5 @@ dependencies: - boto3=1.34.124 - scikit-learn=1.5.0 - pip: - - cartoframes==1.2.5 - git+https://github.com/isciences/exactextract - overturemaps==0.6.0 diff --git a/setup.py b/setup.py index c6d4190..49aed19 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,6 @@ package_data={ 'city_metrix.models.building_classifier': [ 'building_classifier.pkl', - 'V2-building-class-data.geojson', ], }, author="Justin Terry", @@ -17,7 +16,6 @@ install_requires=[ "earthengine-api", "geocube", - "odc-stac", "geemap", "pystac-client", "xarray-spatial", @@ -28,7 +26,7 @@ "osmnx", "geopandas", "s3fs", - "dask==2023.11.0", + "dask", "boto3", "exactextract", "overturemaps", From bf55d05e188a760bb4d85dc825a7e43a9c95d31a Mon Sep 17 00:00:00 2001 From: weiqi-tori Date: Tue, 30 Jul 2024 14:47:42 +0800 Subject: [PATCH 3/5] add odc-stac back --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 49aed19..b16a506 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,7 @@ install_requires=[ "earthengine-api", "geocube", + "odc-stac", "geemap", "pystac-client", "xarray-spatial", @@ -26,7 +27,7 @@ "osmnx", "geopandas", "s3fs", - "dask", + "dask>=2023.11.0", "boto3", "exactextract", "overturemaps", From 14d51ade2ad7d848bbb79ac741911ea286200120 Mon Sep 17 00:00:00 2001 From: weiqi-tori Date: Tue, 30 Jul 2024 16:06:34 +0800 Subject: [PATCH 4/5] update setup --- setup.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index b16a506..cc94eb4 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,10 @@ -from setuptools import setup +from setuptools import setup, find_packages setup( name="city_metrix", version="0.1.1", description="Module to calculate various metrics on cities.", - packages=["city_metrix", "city_metrix.layers", "city_metrix.metrics", "city_metrix.models", "city_metrix.models.building_classifier"], + packages=find_packages(), include_package_data=True, package_data={ 'city_metrix.models.building_classifier': [ @@ -22,7 +22,6 @@ "xarray-spatial", "xee", "rioxarray", - "cartoframes", "utm", "osmnx", "geopandas", @@ -31,6 +30,6 @@ "boto3", "exactextract", "overturemaps", - "scikit-learn==1.5.0", + "scikit-learn>=1.5.0", ], ) From 77037d6138c7630172977aaec7865ca26017077c Mon Sep 17 00:00:00 2001 From: weiqi-tori Date: Tue, 30 Jul 2024 19:50:51 +0800 Subject: [PATCH 5/5] update developer.md --- docs/developer.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/developer.md b/docs/developer.md index e273e9f..c6b1855 100644 --- a/docs/developer.md +++ b/docs/developer.md @@ -11,7 +11,7 @@ The `city_metrix` library allows users of geospatial data to collect and apply z It provides two main functionalities: 1. Extracting geospatial `layers` based on specific areas of interests (defined as geodataframe)' These data layers are collected from any cloud source (Google Earth Engine, AWS S3 public buckets, Public APIs). Two formats of data layers are handled in `city_metrix`: Rasters and vectors. - Rasters data are collected and transformed into _arrays_ using `xarray` (GEE images collections are converted also into `arrays` using `xee`). - - Vectors adata are stored as `GeoDataFrame`. + - Vectors data are stored as `GeoDataFrame`. 2. Measuring `indicators` using the extracted `layers` by implementing zonal statistics operations The main package source code is located in the `city_metrix` directory. @@ -81,9 +81,11 @@ Hopefully we already have the layers you need in `city_metrix/layers/` and you c 5. Add a test to [tests/layers.py](../tests/layers.py) to ensure the new layer is working as expected. -6. Add a section to the get layers.ipynb notebook to demonstrate how to use the new layer. +6. Add new dependencies to [setup.py](../setup.py) and [environment.yml](../environment.yml). -7. Create a PR to merge the new layer into the main branch with these in the PR description: +7. Add a section to the get layers.ipynb notebook to demonstrate how to use the new layer. + +8. Create a PR to merge the new layer into the main branch with these in the PR description: - Link to Jira ticket (if any) - A brief description of the new layer - A link to the Airtable record for the new layer @@ -101,6 +103,16 @@ Once you have all the data layers you need as inputs, here is the process to cre Define a function for new indicator with the input of the calculation zones as a `GeoDataFrame` and output of the calculated indicators as a `GeoSeries`. +3. Add a test to [tests/metrics.py](../tests/metrics.py) to ensure the new indicator is working as expected. + +4. Add new dependencies to [setup.py](../setup.py) and [environment.yml](../environment.yml). + +5. Create a PR to merge the new indicator into the main branch with these in the PR description: + - Link to Jira ticket (if any) + - A brief description of the new indicator + - A link to the Airtable record for the new indicator + - Explain how to test the new indicator + ## Adding Cities You can always have users just provide their own boudary files, but if you are working on a project where you want to provide access to a common set of city boundaries, the best option is to add them to the API