{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import geopandas as gpd\n", "import os, shutil" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Fire perimeter datasets for the US can be found via GeoMAC at \n", "# https://rmgsc.cr.usgs.gov/outgoing/GeoMAC/current_year_fire_data/current_year_all_states/\n", "# Fire perimeters for Canada can be found at\n", "# https://catalogue.data.gov.bc.ca/dataset/fire-perimeters-current" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Define which state/province we are downloading L8 data for\n", "state = 'WY'\n", "\n", "# Define the filepaths where the shapefile data resides\n", "CA = r'D:\\data\\FirePerimeters\\2018_2019_Canada_perimeters.shp'\n", "US = r'D:\\data\\FirePerimeters\\perimeters_dd83.shp'\n", "stateboundaries = (os.path.join(r'D:\\data\\boundaries',state + '.shp'))\n", "wrsfile = r'D:\\data\\l8\\wrs2_descending.shp'\n", "\n", "# Define where the resultant l8 scenes and metadata files will go\n", "l8out = r'D:\\data\\imagery'\n", "sceneinfo = r'D:\\data\\l8'" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "if state == 'BC' or state == 'AB':\n", " country = 'Canada'\n", " fire = gpd.GeoDataFrame.from_file(CA)\n", " # Used est perimeter data from http://cwfis.cfs.nrcan.gc.ca/downloads/hotspots/ (merged 2019/2018)\n", "else: \n", " country = 'US'\n", " fire = gpd.GeoDataFrame.from_file(US)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# Read the state boundary shapefile and the wrs path/row shapefile\n", "# State files need to be the same projection as the WRS file\n", "bounds = gpd.read_file(stateboundaries)\n", "wrs = gpd.GeoDataFrame.from_file(wrsfile)\n", "\n", "# Select the Landsat path/rows that intersect with the state of interest\n", "wrs_intersection = wrs[wrs.intersects(bounds.geometry[0])]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Select the fires that intersect to later determine the needed imagery date\n", "fires = gpd.sjoin(fire, wrs, how='inner', op='within')###\n", "\n", "# sort dataframe by most recent date, change date format to match AWS's landsat metadata date format\n", "if country == 'Canada':\n", " fires['enddate'] = fires['LASTDATE']+ '.000000'\n", "else:\n", " fires['enddate'] = fires['DATECRNT']+' 00:00:00.000000'\n", "\n", "# empty gdf for most recent fire perimeter date\n", "recent_fire = gpd.GeoDataFrame()\n", "\n", "# select just fires in the state, make lowercase strings for consistent matching of fire names\n", "if country == 'US':\n", " fires = fires.loc[(fires.STATE == state)]\n", " fires.FIRENAME = fires.FIRENAME.str.lower()\n", " fires = fires[['FIRENAME','PATH','ROW','enddate']]\n", "else:\n", " print 'Skipping firename'\n", " fires = fires[['PATH','ROW','enddate']]\n", "\n", "fires['PR'] = fires['PATH'].astype(str)+' '+fires['ROW'].astype(str)\n", "\n", "# for each fire, pick the latest date\n", "if country == 'US':\n", " for firename in fires['FIRENAME']:\n", " rec_fire = fires.loc[(fires.FIRENAME == firename)]\n", " rec_fire['enddate'].sort_values()\n", " rec_fire = rec_fire.tail(1)\n", " recent_fire = recent_fire.append(rec_fire)\n", "else:\n", " rec_fire = fires\n", " recent_fire = recent_fire.append(rec_fire)\n", " \n", "# then find the latest fire date for the path/row\n", "pr_date = gpd.GeoDataFrame()\n", "\n", "for pr in recent_fire['PR'].unique():\n", " prdate = recent_fire.loc[(recent_fire.PR == pr)]\n", " prdate['enddate'].sort_values()\n", " prdate = prdate.tail(1)\n", " pr_date = pr_date.append(prdate)\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\python27\\lib\\site-packages\\folium\\__init__.py:59: UserWarning: This version of folium is the last to support Python 2. Transition to Python 3 to be able to receive updates and fixes. Check out https://python3statement.org/ for more info.\n", " UserWarning\n" ] }, { "data": { "text/html": [ "
\n", " | productId | \n", "entityId | \n", "acquisitionDate | \n", "cloudCover | \n", "processingLevel | \n", "path | \n", "row | \n", "min_lat | \n", "min_lon | \n", "max_lat | \n", "max_lon | \n", "download_url | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|
1698771 | \n", "LC08_L1TP_036029_20190831_20190916_01_T1 | \n", "LC80360292019243LGN00 | \n", "2019-08-31 17:54:50.649040 | \n", "1.11 | \n", "L1TP | \n", "36 | \n", "29 | \n", "43.4775 | \n", "-108.983 | \n", "45.6465 | \n", "-105.894 | \n", "https://s3-us-west-2.amazonaws.com/landsat-pds... | \n", "
1698381 | \n", "LC08_L1TP_036030_20190831_20190916_01_T1 | \n", "LC80360302019243LGN00 | \n", "2019-08-31 17:55:14.535844 | \n", "0.52 | \n", "L1TP | \n", "36 | \n", "30 | \n", "42.0485 | \n", "-109.453 | \n", "44.2195 | \n", "-106.418 | \n", "https://s3-us-west-2.amazonaws.com/landsat-pds... | \n", "
1641340 | \n", "LC08_L1TP_036031_20190714_20190720_01_T1 | \n", "LC80360312019195LGN00 | \n", "2019-07-14 17:55:23.158334 | \n", "1.07 | \n", "L1TP | \n", "36 | \n", "31 | \n", "40.6706 | \n", "-109.78 | \n", "42.8245 | \n", "-107.077 | \n", "https://s3-us-west-2.amazonaws.com/landsat-pds... | \n", "
1641341 | \n", "LC08_L1TP_036032_20190714_20190720_01_T1 | \n", "LC80360322019195LGN00 | \n", "2019-07-14 17:55:47.045136 | \n", "2.04 | \n", "L1TP | \n", "36 | \n", "32 | \n", "39.2485 | \n", "-110.209 | \n", "41.3938 | \n", "-107.557 | \n", "https://s3-us-west-2.amazonaws.com/landsat-pds... | \n", "
1715327 | \n", "LC08_L1TP_034029_20190918_20190926_01_T1 | \n", "LC80340292019261LGN00 | \n", "2019-09-18 17:42:34.829412 | \n", "0 | \n", "L1TP | \n", "34 | \n", "29 | \n", "43.5227 | \n", "-105.811 | \n", "45.6673 | \n", "-102.901 | \n", "https://s3-us-west-2.amazonaws.com/landsat-pds... | \n", "
1715084 | \n", "LC08_L1TP_034030_20190918_20190926_01_T1 | \n", "LC80340302019261LGN00 | \n", "2019-09-18 17:42:58.716216 | \n", "0.01 | \n", "L1TP | \n", "34 | \n", "30 | \n", "42.1046 | \n", "-106.284 | \n", "44.2397 | \n", "-103.42 | \n", "https://s3-us-west-2.amazonaws.com/landsat-pds... | \n", "
1715409 | \n", "LC08_L1TP_034031_20190918_20190926_01_T1 | \n", "LC80340312019261LGN00 | \n", "2019-09-18 17:43:22.611492 | \n", "5.09 | \n", "L1TP | \n", "34 | \n", "31 | \n", "40.6765 | \n", "-106.738 | \n", "42.8102 | \n", "-103.92 | \n", "https://s3-us-west-2.amazonaws.com/landsat-pds... | \n", "
1697556 | \n", "LC08_L1TP_034032_20190902_20190916_01_T1 | \n", "LC80340322019245LGN00 | \n", "2019-09-02 17:43:40.977337 | \n", "7.84 | \n", "L1TP | \n", "34 | \n", "32 | \n", "39.2426 | \n", "-107.169 | \n", "41.379 | \n", "-104.394 | \n", "https://s3-us-west-2.amazonaws.com/landsat-pds... | \n", "
1701659 | \n", "LC08_L1TP_039029_20190905_20190917_01_T1 | \n", "LC80390292019248LGN00 | \n", "2019-09-05 18:13:23.833895 | \n", "14.55 | \n", "L1TP | \n", "39 | \n", "29 | \n", "43.5041 | \n", "-113.579 | \n", "45.6572 | \n", "-110.568 | \n", "https://s3-us-west-2.amazonaws.com/landsat-pds... | \n", "
1712605 | \n", "LC08_L1TP_037029_20190923_20190926_01_T1 | \n", "LC80370292019266LGN00 | \n", "2019-09-23 18:01:08.866094 | \n", "14.89 | \n", "L1TP | \n", "37 | \n", "29 | \n", "43.5178 | \n", "-110.43 | \n", "45.674 | \n", "-107.58 | \n", "https://s3-us-west-2.amazonaws.com/landsat-pds... | \n", "