-
Notifications
You must be signed in to change notification settings - Fork 1
For indicator users
1 - Clone the github repos in a local directory
- create a local directory where you want to download the package
- use git command and cd in this new directory
- clone the github repos
git clone https://github.com/wri/cities-cif.git
2 - set environment variables
3 - Create your notebook inside the package
- open jupyter notebook
- navigate in directory to
./cities-cif/notebooks/
- create a new notebook in the 'notebooks' folder
- update the working directory to
/cities-cif
using the following commands
import os
os.chdir('..')
To verify that you are in the right directory, print working directory using the following command. The directory should end with: .\\cities-cif
os.getcwd()
The package allows you to extract different data layers based on any input geopandas dataframe. You can find in this notebook, different examples of loading data layers using the city_metricx library: https://github.com/wri/cities-cif/blob/feature/tutorial_notebook_layers/notebooks/get_layers.ipynb
- First, load the layers of interest from
city_metrix.layers
. In the following example, we will load the "tropical Tree Cover" layer
from city_metrix.layers import TreeCover
- Load the geometry of interest as a geopandas data frame.
import geopandas as gpd
# load boundary
boundary_path = 'https://cities-indicators.s3.eu-west-3.amazonaws.com/data/boundaries/boundary-BRA-Salvador-ADM4union.geojson'
city_gdf = gpd.read_file(boundary_path, driver='GeoJSON')
- Get the layers by calling the respective class and specifying the geopandasdatafame we want to use to extract the bounding box, using the
get_data
function. You can find the list of layers classes in this section
# Extract Tree cover layer based on the bounding box of `city_gdf`
city_TreeCover = TreeCover().get_data(city_gdf.total_bounds)
city_TreeCover
The output, is a raster layer stored as xarray, that you can use for further analysis.
Some layers provides parameters that you can specify during the extraction. FOr the TreeCover layer, you can specify a threshold of percent of tree cover during the extraction using min_tree_cover
parameter
# tropical tree cover by specifying minimum tree cover param
city_TreeCover_50= TreeCover(min_tree_cover = 50).get_data(city_gdf.total_bounds)
city_TreeCover_50
City_metrix allows you to use our implemented indicators methods to calculate indicators for any geography. You just need to call the indicator function and specify your geodataframe as parameter. It will return the indicator value. You can add the indicator as a new field in your dataframe by specifying its name as showed in the example below :
city_gdf["idnicator_name"] = mean_tree_cover(city_gdf)
city_gdf
If your geodataframe contains multiple geographies, for example different districts within one city, then the indicator function will calculate automatically indicator's values for every polygon and return the corresponding metrics in the same field
If you want to calculate an indicator over multiple geographies, it is better to loop over the different geographies to treat them separately and avoid having an error due to the geometry size. You find in this notebook example of calculating indicator over multiple cities: https://github.com/wri/cities-cif/blob/feature/tutorial_notebook_layers/notebooks/compute_indicators.ipynb