Skip to content

Fixed 4 Errors in TCSI_Demo.ipynb #39

Description

@BonnieRuefenacht

While using/modifying the TCSI_Demo.ipynb, I encountered four errors.

  1. I changed
    !pip install py3dep ==0.17.1
    to
    !pip install py3dep

  2. This code here:

    rds.data['speed'].where(rds.data['maxspeed'].isna(),rds.data['maxspeed'].str.slice(0,2).astype(float))

    does not do anything because it's not being saved to a variable. The output is only in memory. When I changed this to save to a variable, it threw an error because the maxspeed field had a value of "default". I did the following code:

    roads_vec = features.features_from_polygon(bounding_box_4326,osm_rds)
    roads_vec = roads_vec.to_crs(study_area_crs).reset_index()
    roads_vec = dgpd.from_geopandas(roads_vec,chunksize=_TARGET_CHUNK_SIZE)
    
    # assigns the speeds in miles per hour to the "speed" attribute
    roads_vec = roads_vec.assign(maxspeed=roads_vec['maxspeed'].where(roads_vec['maxspeed'] != 'default', np.nan))
    roads_vec['speed'] = roads_vec['highway'].map(h_speed, meta = pandas.Series(dtype = 'float32'))
    roads_vec['speed'] = roads_vec['speed'].where(roads_vec['maxspeed'].isna(),roads_vec['maxspeed'].str.slice(0,2))
    roads_vec['speed'] = roads_vec['speed'].astype(float)
  3. This has been deprecated:
    import osmnx as ox
    use
    from osmnx import features

    I changed the code from this:

    out_gdf=ox.geometries_from_polygon(sgeo,osm_dic)
    if(not out_crs is None):
        out_gdf=out_gdf.to_crs(out_crs)
    return out_gdf

    to this:

    out_gdf=features.features_from_polygon(sgeo,osm_dic)
    if(not out_crs is None):
        out_gdf=out_gdf.to_crs(out_crs)
    
    return out_gdf
  4. This code:

    rd_dist=distance.cda_cost_distance(c_rs,(rds_rs>0).astype(int),elv)

    has problems because (rds_rs>0) returns a raster with infinite values.
    I did this:

    rds.data['gt0'] = rds.data['conv'].where(rds.data['conv'] == 0, 1)
    rds.data['gt0'] = rds.data['gt0'].astype(int)
    rds_rs_gt0 = (rds.to_raster(elv,'gt0').set_null_value(0)).eval() #source surface with all non-road cells (value of zero) set to null
    rd_dist=distance.cda_cost_distance(c_rs,rds_rs_gt0,elv)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions