NDVI after the Las Conchas fire in New Mexico¶

This notebook will be used to further investigate NDVI rasters before and after the Las Conchas fire in New Mexico. We'll also create plot with a slider so that we can see how NDVI recovers in the years after the fire.

Step 0: Restore variables and import libraries¶

In [1]:
%store -r ndvi_da fire_bound_gdf
In [2]:
# Import libraries

import earthpy
import hvplot.pandas
import hvplot.xarray


import geopandas as gpd
import matplotlib.pyplot as plt
import pandas as pd
import panel as pn
import rioxarray as rxr
import xarray as xr

from shapely.geometry import mapping

Step 1: Assess if NDVI is different inside and outside the fire boundary¶

In [3]:
# Check CRSs, make them match if needed.

if ndvi_da.NDVI.rio.crs == fire_bound_gdf.crs:
    print('The CRSs match!')
else:
    print(ndvi_da.NDVI.rio.crs) # EPSG:4326
    print(fire_bound_gdf.crs) # EPSG:4269

# The CRSs match, so we don't need to do anything more here.
The CRSs match!

We need to clip the DataArray into two arrays, so that we can look at NDVI from inside the fire boundary, and outside.

In [4]:
# Clip data to both inside and outside the boundary

# Inner
ndvi_in = ndvi_da.rio.clip(fire_bound_gdf.geometry.apply(mapping))

# Outer
ndvi_out = ndvi_da.rio.clip(
    fire_bound_gdf.geometry.apply(mapping), invert=True
    )
In [5]:
# Quick plots
# We should see the two plots match the clipped area like puzzle pieces.

# Make plots
plot_in = ndvi_in.isel(date=0).hvplot(x='x', y='y', cmap=plt.cm.PiYG, geo=True, 
                   title='NDVI inside Fire Boundary')

plot_out = ndvi_out.isel(date=0).hvplot(x='x', y='y', cmap=plt.cm.PiYG, geo=True, 
                   title='NDVI outside Fire Boundary')

# Show plots
(plot_in + plot_out)
Out[5]:
In [6]:
# Compute mean annual NDVI

# Inside
ndvi_in_mean_df = (ndvi_in
    
    #.sel(date=ndvi_in['date'].dt.month.isin([7])) 
    # Select NDVI data in July; I've commented this out so the 
    # analysis works

    # Now group into years
    .groupby('date.year')

    # Now take the mean across all dimensions
    .mean(...)
    .to_dataframe()
    )

# Outside
ndvi_out_mean_df = (
    ndvi_out#.sel(date=ndvi_out['date'].dt.month.isin([7]))
    .groupby('date.year')
    .mean(...)
    .to_dataframe()
    )
In [7]:
# Join the inside and outside DFs

ndvi_df = (ndvi_in_mean_df[['NDVI']]
           .join(ndvi_out_mean_df[['NDVI']], 
                 lsuffix=' Inside Fire',
                 rsuffix=' Outside Fire'))
ndvi_df
Out[7]:
NDVI Inside Fire NDVI Outside Fire
year
2006 0.536539 0.470742
2007 0.575677 0.502179
2008 0.560684 0.486118
2009 0.569864 0.495966
2010 0.576190 0.491205
2011 0.426936 0.458000
2012 0.377027 0.455526
2013 0.390443 0.447340
2014 0.439131 0.479393
2015 0.472262 0.500086
2016 0.467678 0.486759
2017 0.473199 0.486518
2018 0.435072 0.445602
2019 0.484973 0.487404
2020 0.440681 0.445364
2021 0.454713 0.460829
In [8]:
# Plot annual mean NDVI inside and outside on one plot

ins_out_plot_ma_plot = ndvi_df.hvplot(
    by='column', color=['red', 'green'],
    # set inside to red, outside to blue
    title='Mean Annual NDVI inside and outside\n' \
    'Las Conchas Fire Boundary')

# Save plot
hvplot.save(ins_out_plot_ma_plot, 'Mean_NDVI_In_Out_Fire.html')

# Show the plot
ins_out_plot_ma_plot
Out[8]:

Now, we'll plot just the difference in NDVI between the two areas on an annual basis.

In [9]:
# Calculate the difference inside and outside
ndvi_df['Difference'] = ndvi_df['NDVI Outside Fire'] - ndvi_df['NDVI Inside Fire']
ndvi_df
Out[9]:
NDVI Inside Fire NDVI Outside Fire Difference
year
2006 0.536539 0.470742 -0.065797
2007 0.575677 0.502179 -0.073498
2008 0.560684 0.486118 -0.074566
2009 0.569864 0.495966 -0.073898
2010 0.576190 0.491205 -0.084985
2011 0.426936 0.458000 0.031064
2012 0.377027 0.455526 0.078499
2013 0.390443 0.447340 0.056897
2014 0.439131 0.479393 0.040262
2015 0.472262 0.500086 0.027824
2016 0.467678 0.486759 0.019082
2017 0.473199 0.486518 0.013319
2018 0.435072 0.445602 0.010529
2019 0.484973 0.487404 0.002431
2020 0.440681 0.445364 0.004683
2021 0.454713 0.460829 0.006116
In [10]:
# Plot annual mean NDVI inside and outside on one plot

difference_ma_plot = ndvi_df['Difference'].hvplot(
    title=('Difference in Mean Annual NDVI\n'
    'outside and inside Las Conchas Fire Boundary'),
    ylabel='NDVI')

# Save plot
hvplot.save(difference_ma_plot, 'NDVI_Mean_Diff_line.html')

# Show the plot
difference_ma_plot
Out[10]:

PLOT INTERPRETATION HERE

Step 2: Create a dynamic plot to see how NDVI changes each year after the fire.¶

In [11]:
# Compute annual spatial means
ndvi_mean_da = (
    ndvi_da
    .groupby('date.year')
    .mean(dim='date')
    )

ndvi_mean_da
Out[11]:
<xarray.Dataset> Size: 2MB
Dimensions:      (year: 16, y: 197, x: 137)
Coordinates:
    band         int64 8B 1
  * x            (x) float64 1kB -106.6 -106.6 -106.6 ... -106.3 -106.3 -106.3
  * y            (y) float64 2kB 36.07 36.07 36.07 36.07 ... 35.67 35.67 35.67
    spatial_ref  int64 8B 0
  * year         (year) int64 128B 2006 2007 2008 2009 ... 2018 2019 2020 2021
Data variables:
    NDVI         (year, y, x) float32 2MB 0.5589 0.5676 0.5676 ... 0.259 0.2621
xarray.Dataset
    • year: 16
    • y: 197
    • x: 137
    • band
      ()
      int64
      1
      array(1)
    • x
      (x)
      float64
      -106.6 -106.6 ... -106.3 -106.3
      array([-106.563542, -106.561458, -106.559375, -106.557292, -106.555208,
             -106.553125, -106.551042, -106.548958, -106.546875, -106.544792,
             -106.542708, -106.540625, -106.538542, -106.536458, -106.534375,
             -106.532292, -106.530208, -106.528125, -106.526042, -106.523958,
             -106.521875, -106.519792, -106.517708, -106.515625, -106.513542,
             -106.511458, -106.509375, -106.507292, -106.505208, -106.503125,
             -106.501042, -106.498958, -106.496875, -106.494792, -106.492708,
             -106.490625, -106.488542, -106.486458, -106.484375, -106.482292,
             -106.480208, -106.478125, -106.476042, -106.473958, -106.471875,
             -106.469792, -106.467708, -106.465625, -106.463542, -106.461458,
             -106.459375, -106.457292, -106.455208, -106.453125, -106.451042,
             -106.448958, -106.446875, -106.444792, -106.442708, -106.440625,
             -106.438542, -106.436458, -106.434375, -106.432292, -106.430208,
             -106.428125, -106.426042, -106.423958, -106.421875, -106.419792,
             -106.417708, -106.415625, -106.413542, -106.411458, -106.409375,
             -106.407292, -106.405208, -106.403125, -106.401042, -106.398958,
             -106.396875, -106.394792, -106.392708, -106.390625, -106.388542,
             -106.386458, -106.384375, -106.382292, -106.380208, -106.378125,
             -106.376042, -106.373958, -106.371875, -106.369792, -106.367708,
             -106.365625, -106.363542, -106.361458, -106.359375, -106.357292,
             -106.355208, -106.353125, -106.351042, -106.348958, -106.346875,
             -106.344792, -106.342708, -106.340625, -106.338542, -106.336458,
             -106.334375, -106.332292, -106.330208, -106.328125, -106.326042,
             -106.323958, -106.321875, -106.319792, -106.317708, -106.315625,
             -106.313542, -106.311458, -106.309375, -106.307292, -106.305208,
             -106.303125, -106.301042, -106.298958, -106.296875, -106.294792,
             -106.292708, -106.290625, -106.288542, -106.286458, -106.284375,
             -106.282292, -106.280208])
    • y
      (y)
      float64
      36.07 36.07 36.07 ... 35.67 35.67
      array([36.073958, 36.071875, 36.069792, 36.067708, 36.065625, 36.063542,
             36.061458, 36.059375, 36.057292, 36.055208, 36.053125, 36.051042,
             36.048958, 36.046875, 36.044792, 36.042708, 36.040625, 36.038542,
             36.036458, 36.034375, 36.032292, 36.030208, 36.028125, 36.026042,
             36.023958, 36.021875, 36.019792, 36.017708, 36.015625, 36.013542,
             36.011458, 36.009375, 36.007292, 36.005208, 36.003125, 36.001042,
             35.998958, 35.996875, 35.994792, 35.992708, 35.990625, 35.988542,
             35.986458, 35.984375, 35.982292, 35.980208, 35.978125, 35.976042,
             35.973958, 35.971875, 35.969792, 35.967708, 35.965625, 35.963542,
             35.961458, 35.959375, 35.957292, 35.955208, 35.953125, 35.951042,
             35.948958, 35.946875, 35.944792, 35.942708, 35.940625, 35.938542,
             35.936458, 35.934375, 35.932292, 35.930208, 35.928125, 35.926042,
             35.923958, 35.921875, 35.919792, 35.917708, 35.915625, 35.913542,
             35.911458, 35.909375, 35.907292, 35.905208, 35.903125, 35.901042,
             35.898958, 35.896875, 35.894792, 35.892708, 35.890625, 35.888542,
             35.886458, 35.884375, 35.882292, 35.880208, 35.878125, 35.876042,
             35.873958, 35.871875, 35.869792, 35.867708, 35.865625, 35.863542,
             35.861458, 35.859375, 35.857292, 35.855208, 35.853125, 35.851042,
             35.848958, 35.846875, 35.844792, 35.842708, 35.840625, 35.838542,
             35.836458, 35.834375, 35.832292, 35.830208, 35.828125, 35.826042,
             35.823958, 35.821875, 35.819792, 35.817708, 35.815625, 35.813542,
             35.811458, 35.809375, 35.807292, 35.805208, 35.803125, 35.801042,
             35.798958, 35.796875, 35.794792, 35.792708, 35.790625, 35.788542,
             35.786458, 35.784375, 35.782292, 35.780208, 35.778125, 35.776042,
             35.773958, 35.771875, 35.769792, 35.767708, 35.765625, 35.763542,
             35.761458, 35.759375, 35.757292, 35.755208, 35.753125, 35.751042,
             35.748958, 35.746875, 35.744792, 35.742708, 35.740625, 35.738542,
             35.736458, 35.734375, 35.732292, 35.730208, 35.728125, 35.726042,
             35.723958, 35.721875, 35.719792, 35.717708, 35.715625, 35.713542,
             35.711458, 35.709375, 35.707292, 35.705208, 35.703125, 35.701042,
             35.698958, 35.696875, 35.694792, 35.692708, 35.690625, 35.688542,
             35.686458, 35.684375, 35.682292, 35.680208, 35.678125, 35.676042,
             35.673958, 35.671875, 35.669792, 35.667708, 35.665625])
    • spatial_ref
      ()
      int64
      0
      crs_wkt :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      semi_major_axis :
      6378137.0
      semi_minor_axis :
      6356752.314245179
      inverse_flattening :
      298.257223563
      reference_ellipsoid_name :
      WGS 84
      longitude_of_prime_meridian :
      0.0
      prime_meridian_name :
      Greenwich
      geographic_crs_name :
      WGS 84
      horizontal_datum_name :
      World Geodetic System 1984
      grid_mapping_name :
      latitude_longitude
      spatial_ref :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      GeoTransform :
      -106.56458332378672 0.0020833333331466974 0.0 36.07499999676821 0.0 -0.0020833333331466974
      array(0)
    • year
      (year)
      int64
      2006 2007 2008 ... 2019 2020 2021
      array([2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
             2018, 2019, 2020, 2021])
    • NDVI
      (year, y, x)
      float32
      0.5589 0.5676 ... 0.259 0.2621
      units :
      NDVI
      AREA_OR_POINT :
      Area
      array([[[0.5589454 , 0.56755453, 0.56755453, ..., 0.43985453,
               0.4537454 , 0.4492636 ],
              [0.53130907, 0.53130907, 0.5363454 , ..., 0.51732725,
               0.5129273 , 0.49119997],
              [0.5329454 , 0.5329454 , 0.5183909 , ..., 0.6086363 ,
               0.6155909 , 0.6155909 ],
              ...,
              [0.4718909 , 0.54034543, 0.5620273 , ..., 0.2841818 ,
               0.2942909 , 0.2966727 ],
              [0.45282727, 0.45915452, 0.46926364, ..., 0.2839    ,
               0.27679998, 0.28475454],
              [0.47922724, 0.4537091 , 0.46587276, ..., 0.2615818 ,
               0.2706    , 0.26988184]],
      
             [[0.63347274, 0.61614543, 0.61614543, ..., 0.46845454,
               0.4482273 , 0.43946362],
              [0.6108909 , 0.6108909 , 0.6035182 , ..., 0.4973818 ,
               0.4869545 , 0.5057636 ],
              [0.56933635, 0.56933635, 0.57164544, ..., 0.6343455 ,
               0.6457546 , 0.6457546 ],
      ...
              [0.33775452, 0.33277273, 0.3565    , ..., 0.27461818,
               0.28416362, 0.28781816],
              [0.3678545 , 0.31406364, 0.32421815, ..., 0.27642727,
               0.28174546, 0.27709997],
              [0.42615452, 0.35505453, 0.36902726, ..., 0.26547274,
               0.27444547, 0.27243635]],
      
             [[0.5786545 , 0.5738    , 0.5738    , ..., 0.4428182 ,
               0.41120002, 0.3969182 ],
              [0.58341813, 0.58341813, 0.5780636 , ..., 0.49165457,
               0.52082723, 0.5162    ],
              [0.5868    , 0.5868    , 0.5499636 , ..., 0.5962727 ,
               0.59586364, 0.59586364],
              ...,
              [0.34611818, 0.3379182 , 0.37029094, ..., 0.25780907,
               0.2665091 , 0.27635452],
              [0.3617909 , 0.3196818 , 0.32499093, ..., 0.26944545,
               0.2681545 , 0.26656362],
              [0.41347268, 0.36121818, 0.3482727 , ..., 0.25144544,
               0.25895455, 0.2620909 ]]], shape=(16, 197, 137), dtype=float32)
    • x
      PandasIndex
      PandasIndex(Index([-106.56354165712014,   -106.561458323787, -106.55937499045385,
              -106.5572916571207, -106.55520832378755,  -106.5531249904544,
             -106.55104165712126, -106.54895832378811, -106.54687499045497,
             -106.54479165712182,
             ...
             -106.29895832381051, -106.29687499047736, -106.29479165714422,
             -106.29270832381107, -106.29062499047792, -106.28854165714478,
             -106.28645832381163, -106.28437499047848, -106.28229165714534,
             -106.28020832381219],
            dtype='float64', name='x', length=137))
    • y
      PandasIndex
      PandasIndex(Index([ 36.07395833010164,  36.07187499676849, 36.069791663435346,
               36.0677083301022,  36.06562499676905, 36.063541663435906,
              36.06145833010276,  36.05937499676961, 36.057291663436466,
              36.05520833010332,
             ...
              35.68437499680321,  35.68229166347006, 35.680208330136914,
              35.67812499680377,  35.67604166347062, 35.673958330137474,
              35.67187499680433,  35.66979166347118,  35.66770833013803,
              35.66562499680489],
            dtype='float64', name='y', length=197))
    • year
      PandasIndex
      PandasIndex(Index([2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
             2018, 2019, 2020, 2021],
            dtype='int64', name='year'))
In [12]:
# Set up a DataArray for visualization with a slider

# Set the first slice of the array to a baseline NDVI
# We'll average the years 2006-2010
ndvi_base_da = ndvi_mean_da.sel(year = slice(2006, 2010)).mean("year")

# Reassign a year coordinate to the DA so we can concatenate later
ndvi_base_da = ndvi_base_da.expand_dims({"year": ["2006-2010"]})


# Grab each year after 2010
ndvi_post_da = ndvi_mean_da.sel(year = slice(2011, 2021))

# Now combine the two DAs
ndvi_vis_da = xr.concat([ndvi_base_da, ndvi_post_da], dim = 'year')

# Check it out
ndvi_vis_da
Out[12]:
<xarray.Dataset> Size: 1MB
Dimensions:      (year: 12, y: 197, x: 137)
Coordinates:
  * year         (year) object 96B '2006-2010' 2011 2012 2013 ... 2019 2020 2021
    band         int64 8B 1
  * x            (x) float64 1kB -106.6 -106.6 -106.6 ... -106.3 -106.3 -106.3
  * y            (y) float64 2kB 36.07 36.07 36.07 36.07 ... 35.67 35.67 35.67
    spatial_ref  int64 8B 0
Data variables:
    NDVI         (year, y, x) float32 1MB 0.5961 0.5952 0.5952 ... 0.259 0.2621
xarray.Dataset
    • year: 12
    • y: 197
    • x: 137
    • year
      (year)
      object
      '2006-2010' 2011 2012 ... 2020 2021
      array(['2006-2010', 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020,
             2021], dtype=object)
    • band
      ()
      int64
      1
      array(1)
    • x
      (x)
      float64
      -106.6 -106.6 ... -106.3 -106.3
      array([-106.563542, -106.561458, -106.559375, -106.557292, -106.555208,
             -106.553125, -106.551042, -106.548958, -106.546875, -106.544792,
             -106.542708, -106.540625, -106.538542, -106.536458, -106.534375,
             -106.532292, -106.530208, -106.528125, -106.526042, -106.523958,
             -106.521875, -106.519792, -106.517708, -106.515625, -106.513542,
             -106.511458, -106.509375, -106.507292, -106.505208, -106.503125,
             -106.501042, -106.498958, -106.496875, -106.494792, -106.492708,
             -106.490625, -106.488542, -106.486458, -106.484375, -106.482292,
             -106.480208, -106.478125, -106.476042, -106.473958, -106.471875,
             -106.469792, -106.467708, -106.465625, -106.463542, -106.461458,
             -106.459375, -106.457292, -106.455208, -106.453125, -106.451042,
             -106.448958, -106.446875, -106.444792, -106.442708, -106.440625,
             -106.438542, -106.436458, -106.434375, -106.432292, -106.430208,
             -106.428125, -106.426042, -106.423958, -106.421875, -106.419792,
             -106.417708, -106.415625, -106.413542, -106.411458, -106.409375,
             -106.407292, -106.405208, -106.403125, -106.401042, -106.398958,
             -106.396875, -106.394792, -106.392708, -106.390625, -106.388542,
             -106.386458, -106.384375, -106.382292, -106.380208, -106.378125,
             -106.376042, -106.373958, -106.371875, -106.369792, -106.367708,
             -106.365625, -106.363542, -106.361458, -106.359375, -106.357292,
             -106.355208, -106.353125, -106.351042, -106.348958, -106.346875,
             -106.344792, -106.342708, -106.340625, -106.338542, -106.336458,
             -106.334375, -106.332292, -106.330208, -106.328125, -106.326042,
             -106.323958, -106.321875, -106.319792, -106.317708, -106.315625,
             -106.313542, -106.311458, -106.309375, -106.307292, -106.305208,
             -106.303125, -106.301042, -106.298958, -106.296875, -106.294792,
             -106.292708, -106.290625, -106.288542, -106.286458, -106.284375,
             -106.282292, -106.280208])
    • y
      (y)
      float64
      36.07 36.07 36.07 ... 35.67 35.67
      array([36.073958, 36.071875, 36.069792, 36.067708, 36.065625, 36.063542,
             36.061458, 36.059375, 36.057292, 36.055208, 36.053125, 36.051042,
             36.048958, 36.046875, 36.044792, 36.042708, 36.040625, 36.038542,
             36.036458, 36.034375, 36.032292, 36.030208, 36.028125, 36.026042,
             36.023958, 36.021875, 36.019792, 36.017708, 36.015625, 36.013542,
             36.011458, 36.009375, 36.007292, 36.005208, 36.003125, 36.001042,
             35.998958, 35.996875, 35.994792, 35.992708, 35.990625, 35.988542,
             35.986458, 35.984375, 35.982292, 35.980208, 35.978125, 35.976042,
             35.973958, 35.971875, 35.969792, 35.967708, 35.965625, 35.963542,
             35.961458, 35.959375, 35.957292, 35.955208, 35.953125, 35.951042,
             35.948958, 35.946875, 35.944792, 35.942708, 35.940625, 35.938542,
             35.936458, 35.934375, 35.932292, 35.930208, 35.928125, 35.926042,
             35.923958, 35.921875, 35.919792, 35.917708, 35.915625, 35.913542,
             35.911458, 35.909375, 35.907292, 35.905208, 35.903125, 35.901042,
             35.898958, 35.896875, 35.894792, 35.892708, 35.890625, 35.888542,
             35.886458, 35.884375, 35.882292, 35.880208, 35.878125, 35.876042,
             35.873958, 35.871875, 35.869792, 35.867708, 35.865625, 35.863542,
             35.861458, 35.859375, 35.857292, 35.855208, 35.853125, 35.851042,
             35.848958, 35.846875, 35.844792, 35.842708, 35.840625, 35.838542,
             35.836458, 35.834375, 35.832292, 35.830208, 35.828125, 35.826042,
             35.823958, 35.821875, 35.819792, 35.817708, 35.815625, 35.813542,
             35.811458, 35.809375, 35.807292, 35.805208, 35.803125, 35.801042,
             35.798958, 35.796875, 35.794792, 35.792708, 35.790625, 35.788542,
             35.786458, 35.784375, 35.782292, 35.780208, 35.778125, 35.776042,
             35.773958, 35.771875, 35.769792, 35.767708, 35.765625, 35.763542,
             35.761458, 35.759375, 35.757292, 35.755208, 35.753125, 35.751042,
             35.748958, 35.746875, 35.744792, 35.742708, 35.740625, 35.738542,
             35.736458, 35.734375, 35.732292, 35.730208, 35.728125, 35.726042,
             35.723958, 35.721875, 35.719792, 35.717708, 35.715625, 35.713542,
             35.711458, 35.709375, 35.707292, 35.705208, 35.703125, 35.701042,
             35.698958, 35.696875, 35.694792, 35.692708, 35.690625, 35.688542,
             35.686458, 35.684375, 35.682292, 35.680208, 35.678125, 35.676042,
             35.673958, 35.671875, 35.669792, 35.667708, 35.665625])
    • spatial_ref
      ()
      int64
      0
      crs_wkt :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      semi_major_axis :
      6378137.0
      semi_minor_axis :
      6356752.314245179
      inverse_flattening :
      298.257223563
      reference_ellipsoid_name :
      WGS 84
      longitude_of_prime_meridian :
      0.0
      prime_meridian_name :
      Greenwich
      geographic_crs_name :
      WGS 84
      horizontal_datum_name :
      World Geodetic System 1984
      grid_mapping_name :
      latitude_longitude
      spatial_ref :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      GeoTransform :
      -106.56458332378672 0.0020833333331466974 0.0 36.07499999676821 0.0 -0.0020833333331466974
      array(0)
    • NDVI
      (year, y, x)
      float32
      0.5961 0.5952 ... 0.259 0.2621
      array([[[0.59606177, 0.5951727 , 0.5951727 , ..., 0.4508891 ,
               0.4489127 , 0.44147086],
              [0.5776182 , 0.5776182 , 0.57492363, ..., 0.5165254 ,
               0.5091545 , 0.50235814],
              [0.5687164 , 0.5687164 , 0.5561891 , ..., 0.6276291 ,
               0.64376366, 0.64376366],
              ...,
              [0.4832763 , 0.5463382 , 0.57022184, ..., 0.27928725,
               0.28491452, 0.28808   ],
              [0.46362725, 0.47274548, 0.5004582 , ..., 0.27439636,
               0.27201453, 0.27212912],
              [0.47089815, 0.45550543, 0.46352   , ..., 0.26085088,
               0.26256725, 0.25905818]],
      
             [[0.5076727 , 0.5600182 , 0.5600182 , ..., 0.4014    ,
               0.40281817, 0.4287636 ],
              [0.5300726 , 0.5300726 , 0.5393363 , ..., 0.48661816,
               0.46719998, 0.43638182],
              [0.54025453, 0.54025453, 0.5135545 , ..., 0.60436356,
               0.6181909 , 0.6181909 ],
      ...
              [0.33775452, 0.33277273, 0.3565    , ..., 0.27461818,
               0.28416362, 0.28781816],
              [0.3678545 , 0.31406364, 0.32421815, ..., 0.27642727,
               0.28174546, 0.27709997],
              [0.42615452, 0.35505453, 0.36902726, ..., 0.26547274,
               0.27444547, 0.27243635]],
      
             [[0.5786545 , 0.5738    , 0.5738    , ..., 0.4428182 ,
               0.41120002, 0.3969182 ],
              [0.58341813, 0.58341813, 0.5780636 , ..., 0.49165457,
               0.52082723, 0.5162    ],
              [0.5868    , 0.5868    , 0.5499636 , ..., 0.5962727 ,
               0.59586364, 0.59586364],
              ...,
              [0.34611818, 0.3379182 , 0.37029094, ..., 0.25780907,
               0.2665091 , 0.27635452],
              [0.3617909 , 0.3196818 , 0.32499093, ..., 0.26944545,
               0.2681545 , 0.26656362],
              [0.41347268, 0.36121818, 0.3482727 , ..., 0.25144544,
               0.25895455, 0.2620909 ]]], shape=(12, 197, 137), dtype=float32)
    • year
      PandasIndex
      PandasIndex(Index(['2006-2010', 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020,
             2021],
            dtype='object', name='year'))
    • x
      PandasIndex
      PandasIndex(Index([-106.56354165712014,   -106.561458323787, -106.55937499045385,
              -106.5572916571207, -106.55520832378755,  -106.5531249904544,
             -106.55104165712126, -106.54895832378811, -106.54687499045497,
             -106.54479165712182,
             ...
             -106.29895832381051, -106.29687499047736, -106.29479165714422,
             -106.29270832381107, -106.29062499047792, -106.28854165714478,
             -106.28645832381163, -106.28437499047848, -106.28229165714534,
             -106.28020832381219],
            dtype='float64', name='x', length=137))
    • y
      PandasIndex
      PandasIndex(Index([ 36.07395833010164,  36.07187499676849, 36.069791663435346,
               36.0677083301022,  36.06562499676905, 36.063541663435906,
              36.06145833010276,  36.05937499676961, 36.057291663436466,
              36.05520833010332,
             ...
              35.68437499680321,  35.68229166347006, 35.680208330136914,
              35.67812499680377,  35.67604166347062, 35.673958330137474,
              35.67187499680433,  35.66979166347118,  35.66770833013803,
              35.66562499680489],
            dtype='float64', name='y', length=197))
In [13]:
ndvi_vis_da.year
Out[13]:
<xarray.DataArray 'year' (year: 12)> Size: 96B
array(['2006-2010', 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020,
       2021], dtype=object)
Coordinates:
  * year         (year) object 96B '2006-2010' 2011 2012 2013 ... 2019 2020 2021
    band         int64 8B 1
    spatial_ref  int64 8B 0
xarray.DataArray
'year'
  • year: 12
  • '2006-2010' 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021
    array(['2006-2010', 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020,
           2021], dtype=object)
    • year
      (year)
      object
      '2006-2010' 2011 2012 ... 2020 2021
      array(['2006-2010', 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020,
             2021], dtype=object)
    • band
      ()
      int64
      1
      array(1)
    • spatial_ref
      ()
      int64
      0
      crs_wkt :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      semi_major_axis :
      6378137.0
      semi_minor_axis :
      6356752.314245179
      inverse_flattening :
      298.257223563
      reference_ellipsoid_name :
      WGS 84
      longitude_of_prime_meridian :
      0.0
      prime_meridian_name :
      Greenwich
      geographic_crs_name :
      WGS 84
      horizontal_datum_name :
      World Geodetic System 1984
      grid_mapping_name :
      latitude_longitude
      spatial_ref :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      GeoTransform :
      -106.56458332378672 0.0020833333331466974 0.0 36.07499999676821 0.0 -0.0020833333331466974
      array(0)
    • year
      PandasIndex
      PandasIndex(Index(['2006-2010', 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020,
             2021],
            dtype='object', name='year'))
In [14]:
ndvi_vis_da.year.values.astype(str)
Out[14]:
array(['2006-2010', '2011', '2012', '2013', '2014', '2015', '2016',
       '2017', '2018', '2019', '2020', '2021'], dtype='<U9')

This DataArray looks like what we need. Now, we'll make a plot with a dynamic slider.

In [15]:
# Set the year coordinate to string so that our slider works
ndvi_vis_da = ndvi_vis_da.assign_coords(
    year=ndvi_vis_da.year.astype(str)
)

# Plot interactive baseline NDVI and post fire years
ndvi_plot = ndvi_vis_da.hvplot(
        x='x', y='y',
        #groupby='year',
        geo=True,
        cmap=plt.cm.PiYG,
        #widget_location = 'bottom',
        title='2006-2010 Baseline and Post-Fire Recovery NDVI',
        xlabel='Longitude',
        ylabel='Latitude'
        )
    
# Overlay the fire boundary
ndvi_int_plot = ndvi_plot * fire_bound_gdf.hvplot(
    geo=True, 
    fill_color=None, 
    line_color='black')

# Save plot to be put on the website
panel_plot = pn.panel(ndvi_int_plot)
panel_plot.save('NDVI_Recovery.html', embed=True)

# This is going to look a bit clunky on the website, 
# but it's the best we can do.
ndvi_int_plot

# I've used ChatGPT to help me troubleshoot this plotting.
                                               
WARNING:bokeh.core.validation.check:W-1005 (FIXED_SIZING_MODE): 'fixed' sizing mode requires width and height to be set: figure(id='p1579', ...)

Out[15]:
BokehModel(combine_events=True, render_bundle={'docs_json': {'60a1d1fc-a1f3-439e-b3ca-bead1fddc5cb': {'version…