Created
August 15, 2023 02:12
-
-
Save rchardptrsn/736235f065e58658d38450c833ab7ccd to your computer and use it in GitHub Desktop.
analyze NDVI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Extract Year and Month | |
fireNDVI['Year'] = fireNDVI.Date.str.split(pat='-',expand=True)[0] | |
fireNDVI['Month'] = fireNDVI.Date.str.split(pat='-',expand=True)[1] | |
# filter to June, July, August | |
fireNDVI = fireNDVI[fireNDVI.Month.isin(['06','07','08'])] | |
# find average of 3 months for 2021 for object id | |
# then find average of 3 months for 2022 for object id | |
# subtract 2022-2021 | |
# low numbers indicate loss of vegetation | |
# find bottom five lowest | |
# calculate average NDVI for each ObjectID for 2021 | |
fireNDVI2021 = fireNDVI[fireNDVI.Year=='2021'] | |
fireNDVI2021_mean = fireNDVI2021.groupby('OBJECTID')['NDVI'].agg('mean') | |
# calculate average NDVI for each ObjectID for 2022 | |
fireNDVI2022 = fireNDVI[fireNDVI.Year=='2022'] | |
fireNDVI2022_mean = fireNDVI2022.groupby('OBJECTID')['NDVI'].agg('mean') | |
# re-combine the 2021 and 2022 dataframes horizontally | |
fire_mean_2021_2022 = pd.concat([fireNDVI2021_mean,fireNDVI2022_mean],axis=1) | |
fire_mean_2021_2022.columns.values[0] = 'NDVI 2021' | |
fire_mean_2021_2022.columns.values[1] = 'NDVI 2022' | |
# subtract 2022-2021 to find difference | |
fire_mean_2021_2022['difference'] = fire_mean_2021_2022['NDVI 2022'] - fire_mean_2021_2022['NDVI 2021'] | |
fire_mean_2021_2022 = fire_mean_2021_2022.reset_index() | |
# Merge the WFIGS dataframe (gdf) with the NDVI data (fire_mean_2021_2022) | |
ndvi_wfigs_fires = gdf.merge(fire_mean_2021_2022, on='OBJECTID') | |
# filter to fires over 1000 acres in size | |
fires_over_1000_acres = ndvi_wfigs_fires[ndvi_wfigs_fires['poly_GISAcres']> 1000] | |
# sort by difference ascending to find smallest values (largest decreas in vegetation) | |
fires_over_1000_acres = fires_over_1000_acres.sort_values(by='difference', ascending=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment