<jupyter_start><jupyter_text>Generate urban morphological indices automatically with *Morphoindex_generator*This section showcases some very easy-to-use methods to generate morphological indices automatically from the built environment Shapefiles with our `morphoindex_generator`. First, as an example, let us have a look at the original grids Shapefile in Singapore.<jupyter_code>import geopandas as gpd
grid_path = './data/Singapore/grids/grids.shp'
grids = gpd.read_file(grid_path)
grids<jupyter_output><empty_output><jupyter_text>Traditional morphological indicesThe grid Shapefile for now seems to only contains the information of grid IDs and geometries. No worries! In the next step, we would show a very simple approach to generate the most popular traditioanl urban morphological indices with our `morphoindex_generator`.<jupyter_code>from morphoindex_generator import get_MorphoIndex
# Specify the filepaths of the Shapefiles.

road_path = './data/Singapore/osm_data.shp/gis_osm_roads_free_1.shp'
building_path = './data/Singapore/osm_data.shp/gis_osm_buildings_a_free_1.shp'
landuse_path = './data/Singapore/osm_data.shp/gis_osm_landuse_a_free_1.shp'

# If you want to save the results as a new file, you should specifiy the save_path, or the default would be saving inplace

save_path =  './data/Singapore/grids/grids_morpho.shp'

# Get the morphological indices with just a single line of code.

grids = get_MorphoIndex(grid_path, road_path, building_path, landuse_path, save_path, 
                       get_intersection=False,  # whether to calculate intersection density
                       drop_nonbuilt=True  # whether to drop grids without buildings and roads.
                      )
grids<jupyter_output><empty_output><jupyter_text>Now you get the morphological indices calculated for each grid. All you need to do are to provide the filepaths of your road, building and land use Shapefiles, and then wait for the outcome with patience. The indices include:* RD -> Road density* Bud -> Building density* ABFA -> Average building footprint area* BlD -> Block density* ABA -> Average building area* LUM -> Land use mixture* ID -> Intersection densityYou can also get another index ID (Intersection density) if you set the parameter `get_intersection` to `True`. It should be noted that the calculation is based on `OSMnx`. It would cost a few time to do so.  Categorical probabilitiesBesides traditional morphological indices, `morphoindex generator` also provides east-to-use method to get road network categorical probabilities.<jupyter_code>from morphoindex_generator import prob_calculator
# # Specify the filepaths.
model_path = './model/ResNet34-4class6/ResNet34-4class6.h5'  # filepath of your model
grid_path = './data/Singapore/grids/grids.shp'
image_path = './data/Singapore/images/'   # filepath of your CRHD images
save_path = './data/Singapore/grids/grids_probs.shp'

pc = prob_calculator(channeles=3)  # Define a prob_calculator that deal with images of three channeles
pc.load_model(model_path)  # Load the road network classification model
grids = pc.getProb(grid_path, image_path, save_path)
grids.head(10)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06832493702770781, 'fraction_numerical': 0.004722921914357683, 'mean_word_length': 4.994339622641509, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '225559', 'license': 'MIT', 'n_tokens_mistral': 956, 'n_tokens_neox': 912, 'n_words': 328, 'path': 'tutorials/mophoindex_generator_tutorial.ipynb', 'repo_name': 'ualsg/Road-Network-Classification', 'size': '3176'}