carpentries-incubator / geospatial-python

Introduction to Geospatial Raster and Vector Data with Python
https://carpentries-incubator.github.io/geospatial-python/
Other
159 stars 57 forks source link

Episode 7 - code fixes needed in solution to Challenge #18

Closed bmcandr closed 4 years ago

bmcandr commented 4 years ago

In the solutions to the Challenge at the end of Episode 7 there are two code snippets that need to be fixed:

  1. The following snippet should be updated from:

    plt.figure()
    canopy_SJER.plot(robust=True, cmap="viridis")
    plt.title("Canopy Height Model for San Joaquin Experimental Range, Z Units: Meters")
    plt.savefig("fig/03-SJER-CHM-map-05.png")
    canopy_SJER.rio.to_raster("./data/outputs/CHM_SJER.tif")

    To create the fig directory before saving to it and use os.path.join to build the save path in an OS agnostic way:

    plt.figure()
    canopy_SJER.plot(robust=True, cmap="viridis")
    plt.title("Canopy Height Model for San Joaquin Experimental Range, Z Units: Meters")
    os.makedirs("fig", exist_ok=True)
    plt.savefig(os.path.join("fig", "03-SJER-CHM-map-05.png"))
    canopy_SJER.rio.to_raster("./data/outputs/CHM_SJER.tif")
  2. The final code snippet throws a TypeError: 'Figure' object is not iterable error and also contains a misnamed variable. This code snippet:

    fig, ax = plt.figure(figsize=(9,6))
    canopy_height_HARV_xarr.plot.hist(ax = ax, bins=50, color = "green").
    plt.figure(figsize=(9,6))
    canopy_SJER.plot.hist(ax = ax, bins=50, color = "brown")

    ...should be updated to change the call to plt.figure(figsize=(9,6)) to plt.subplots(figsize=(9,6), correct the variable name on the second line from canopy_height_HARV_xarr to canopy_HARV, and remove the extraneous call to plt.figure(figsize=(9,6)):

    fig, ax = plt.subplots(figsize=(9,6))
    canopy_HARV.plot.hist(ax = ax, bins=50, color = "green")
    canopy_SJER.plot.hist(ax = ax, bins=50, color = "brown")
rbavery commented 4 years ago

closed by https://github.com/carpentries-incubator/geospatial-python/commit/a76b445fbd0f7ff808c7b2559cb6dfff8e3bf938