NDVI after the Las Conchas fire in New Mexico¶
This notebook will be used to download NDVI data using the NASA appeeaars api.
In [1]:
# Import Libraries
import pathlib
import os
import earthpy
import hvplot.pandas
import hvplot.xarray
import matplotlib
import geopandas as gpd
import pandas as pd
import panel as pn
import rioxarray as rxr
import xarray as xr
import holoviews as hv
import earthpy.api.appeears as eaapp
In [2]:
# Make a project and a directory
project = earthpy.Project('Las Conchas Vegetation', dirname='fire_boundary')
In [3]:
# Read in Fire Boundary shapefile
fire_bound_gdf = gpd.read_file(project.project_dir / 'nm3581210654120110626_20110624_20120618_burn_bndy.shp')
fire_bound_gdf
Out[3]:
| Event_ID | irwinID | Incid_Name | Incid_Type | Map_ID | Map_Prog | Asmnt_Type | BurnBndAc | BurnBndLat | BurnBndLon | ... | Perim_ID | dNBR_offst | dNBR_stdDv | NoData_T | IncGreen_T | Low_T | Mod_T | High_T | Comment | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | NM3581210654120110626 | None | LAS CONCHAS | Wildfire | 3962 | MTBS | Extended | 150874 | 35.87 | -106.423 | ... | 503403520110928 | -5 | -9999 | -970 | -150 | 5 | 177 | 380 | None | POLYGON ((-917592.246 1492208.61, -917565.51 1... |
1 rows × 23 columns
In [4]:
# Check CRS
fire_bound_gdf.crs # ESRI:102039
# Change CRS to EPSG: 4326
fire_bound_gdf = fire_bound_gdf.to_crs(4326)
print(fire_bound_gdf.crs)
EPSG:4326
In [5]:
# Quick plot to make sure the boundary looks right
fire_bound_plot = fire_bound_gdf.hvplot(
geo=True,
tiles='EsriNatGeo',
frame_width=400,
legend=False,
fill_color='red',
fill_alpha=0.4,
edge_color='white',
title='Boundary of Las Conchas Fire (2011)',
xlabel='Longitude',
ylabel='Latitude'
)
# Save fire boundary plot
panel_plot = pn.panel(fire_bound_plot)
panel_plot.save('Las_Conchas_fire_bound.html', embed=True)
# Show the plot
fire_bound_plot
WARNING:param.main: edge_color option not found for polygons plot with bokeh; similar options include: ['muted_color', 'bgcolor', 'line_color'] WARNING:bokeh.core.validation.check:W-1005 (FIXED_SIZING_MODE): 'fixed' sizing mode requires width and height to be set: figure(id='p1076', ...)
Out[5]:
This looks like what we want, so we're set to download MODIS NDVI data now!
In [6]:
# Initialize AppeearsDownloader for MODIS NDVI data
# set parameters
ndvi_downloader = eaapp.AppeearsDownloader(
# give download a name
download_key = "las-conchas-fire-ndvi",
# put data in the directory we defined
project = project,
# specify MODIS product we want
product = 'MOD13Q1.061',
layer = '_250m_16_days_NDVI',
# choose a start date and end data
start_date = "05-01",
end_date = "09-30",
# recurring means I want those dates over multiple years
recurring = True,
# specify the range of years
year_range = [2006, 2021],
# specify the polygon I want to get NDVI data for
polygon = fire_bound_gdf
)
In [7]:
# download the prepared download - this can take a while!
ndvi_downloader.download_files(cache=True)
Out[7]:
<generator object Path.rglob at 0x7cb8cf2f1140>
In [8]:
# get a sorted list of NDVI file paths and check the file names
ndvi_paths = sorted(list(project.project_dir.rglob('*NDVI*.tif')))
print(len(ndvi_paths))
print(ndvi_paths[:3])
176
[PosixPath('/workspaces/data/fire_boundary/las-conchas-fire-ndvi/MOD13Q1.061_2006106_to_2021273/MOD13Q1.061__250m_16_days_NDVI_doy2006113000000_aid0001.tif'), PosixPath('/workspaces/data/fire_boundary/las-conchas-fire-ndvi/MOD13Q1.061_2006106_to_2021273/MOD13Q1.061__250m_16_days_NDVI_doy2006129000000_aid0001.tif'), PosixPath('/workspaces/data/fire_boundary/las-conchas-fire-ndvi/MOD13Q1.061_2006106_to_2021273/MOD13Q1.061__250m_16_days_NDVI_doy2006145000000_aid0001.tif')]
These results look like what we want - we've successfully downloaded NDVI rasters for the area we're interested in from NASA!
In [9]:
# Store variables to be used in plotting notebooks
%store fire_bound_gdf ndvi_paths project
Stored 'fire_bound_gdf' (GeoDataFrame) Stored 'ndvi_paths' (list) Stored 'project' (Project)