def add_id_range_data_to_grid(iso3, tile_lookup, side_length):
    '\n    Query the Digital Elevation Model to get an estimated interdecile\n    range for each grid square.\n\n    '
    directory = os.path.join(DATA_INTERMEDIATE, iso3, 'grid')
    filename = 'grid_final.shp'
    path_output = os.path.join(directory, filename)
    if os.path.exists(path_output):
        return gpd.read_file(path_output, crs='epsg:4328')
    filename = 'grid_{}_{}_km.shp'.format(side_length, side_length)
    path = os.path.join(directory, filename)
    grid = gpd.read_file(path, crs='epsg:4328')
    output = []
    for (idx, grid_tile) in grid.iterrows():
        path_input = find_tile(grid_tile['geometry'].bounds, tile_lookup)
        stats = next(gen_zonal_stats(grid_tile['geometry'], path_input, add_stats={'interdecile_range': interdecile_range}, nodata=0))
        id_range_m = stats['interdecile_range']
        output.append({'type': 'Feature', 'geometry': grid_tile['geometry'], 'properties': {'id_range_m': id_range_m, 'area_km2': grid_tile['area_km2']}})
    output = gpd.GeoDataFrame.from_features(output, crs='epsg:4326')
    output = output.replace([np.inf, (- np.inf)], np.nan)
    output = output[output.geometry.notnull()]
    output.to_file(path_output, crs='epsg:4326')
    return output
Query the Digital Elevation Model to get an estimated interdecile
range for each grid square.
def add_id_range_data_to_grid(iso3, tile_lookup, side_length):
    '\n    Query the Digital Elevation Model to get an estimated interdecile\n    range for each grid square.\n\n    '
    directory = os.path.join(DATA_INTERMEDIATE, iso3, 'grid')
    filename = 'grid_final.shp'
    path_output = os.path.join(directory, filename)
    if os.path.exists(path_output):
        return gpd.read_file(path_output, crs='epsg:4328')
    filename = 'grid_{}_{}_km.shp'.format(side_length, side_length)
    path = os.path.join(directory, filename)
    grid = gpd.read_file(path, crs='epsg:4328')
    output = []
    for (idx, grid_tile) in grid.iterrows():
        path_input = find_tile(grid_tile['geometry'].bounds, tile_lookup)
        stats = next(gen_zonal_stats(grid_tile['geometry'], path_input, add_stats={'interdecile_range': interdecile_range}, nodata=0))
        id_range_m = stats['interdecile_range']
        output.append({'type': 'Feature', 'geometry': grid_tile['geometry'], 'properties': {'id_range_m': id_range_m, 'area_km2': grid_tile['area_km2']}})
    output = gpd.GeoDataFrame.from_features(output, crs='epsg:4326')
    output = output.replace([np.inf, (- np.inf)], np.nan)
    output = output[output.geometry.notnull()]
    output.to_file(path_output, crs='epsg:4326')
    return output