Skip to content

For indicator users

Saif Shabou edited this page Dec 6, 2023 · 7 revisions

Setup

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 - 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
import os
os.chdir('..')

You should print the path with .\\cities-cif at the end to be sure that you are in the right directory

os.getcwd()

Get data layers

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
Clone this wiki locally