{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import folium\n", "import geopandas as gpd\n", "import rasterio\n", "from rasterio.mask import mask\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "counties = gpd.read_file(r'C:\\Users\\i23733\\OneDrive - Verisk Analytics\\__Projects\\dashboard\\fl_counties\\fl_counties.geojson')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# NIFC Wildfire Perimeters - Active\n", "fires = gpd.read_file(r'https://opendata.arcgis.com/datasets/5da472c6d27b4b67970acc7b5044c862_0.geojson')" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Python38\\lib\\site-packages\\numpy\\lib\\function_base.py:2167: RuntimeWarning: invalid value encountered in ? (vectorized)\n", " outputs = ufunc(*inputs)\n" ] } ], "source": [ "# Get the FL county and format the fire names\n", "fires_fl = gpd.sjoin(fires, counties, how=\"inner\", op='intersects')\n", "fires_fl.IncidentName=fires_fl.IncidentName.str.title()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "fires_fl.reset_index(inplace=True)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "fires.to_file(r'C:\\Users\\i23733\\OneDrive - Verisk Analytics\\__Projects\\dashboard\\fires.gpkg', driver=\"GPKG\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "from datetime import date, datetime, timedelta\n", "\n", "today = date.today()\n", "def dateNIFC(datefield):\n", " global dt_string\n", " dt_string = today.strftime(\"%Y-%m-%d %H:%M:%S\")\n", " return dt_string" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "d = datetime.today() - timedelta(days=5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "print(dateNIFC(fires_fl['Date'])),(d)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 2020-07-01T22:37:53\n", "1 2020-07-10T20:24:01\n", "2 2020-08-05T02:37:27\n", "3 2020-07-27T20:20:04\n", "4 2020-07-20T19:34:19\n", " ... \n", "1034 2020-08-27T11:03:23\n", "1035 2020-08-27T11:03:23\n", "1036 2020-08-27T11:03:23\n", "1037 2020-08-27T11:03:23\n", "1038 2020-08-27T11:03:23\n", "Name: CreateDate, Length: 1039, dtype: object" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fires_fl['Date'] = pd.to_datetime(fires_fl['DateCurrent']).astype(str)\n", "fires_fl['CreateDate']" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " IncidentName state GISAcres\n", "455 Lnu Lightning Complex CA 1.851059e+06\n", "222 Del Puerto CA 1.774417e+06\n", "233 Doe CA 4.810496e+05\n", "124 Bush AZ 3.872077e+05\n", "617 Pine Gulch CO 2.714359e+05\n" ] }, { "data": { "text/plain": [ "(None,\n", " state GISAcres\n", " 1 CA 5.347024e+06\n", " 0 AZ 9.699344e+05\n", " 2 CO 3.849826e+05\n", " 6 NV 2.989881e+05\n", " 10 UT 2.987269e+05,\n", " IncidentName state GISAcres Date\n", " 889 Red Salmon Complex CA 21979.779365 2020-08-27 12:46:02\n", " 1000 Red Salmon Complex CA 21979.779365 2020-08-27 12:46:02\n", " 891 Red Salmon Complex CA 21979.779365 2020-08-27 12:46:02\n", " 857 Indian Creek OR 48127.865658 2020-08-27 12:29:14\n", " 1038 Del Puerto CA 354883.499085 2020-08-27 11:03:23\n", " 315 Del Puerto CA 354883.499085 2020-08-27 11:03:23\n", " 1033 Ohlone CA 5922.547882 2020-08-27 11:03:23\n", " 316 Ohlone CA 5922.547882 2020-08-27 11:03:23\n", " 1034 Del Puerto CA 354883.499085 2020-08-27 11:03:23\n", " 1035 Del Puerto CA 354883.499085 2020-08-27 11:03:23)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "state_acres = fires_fl.groupby(['state'])['GISAcres'].sum().reset_index().sort_values(\"GISAcres\", ascending=False)\n", "incident_acres = fires_fl.groupby(['IncidentName','state'])['GISAcres'].sum().reset_index().sort_values(\"GISAcres\", ascending=False)\n", "recent_fires = fires_fl.loc[fires_fl.GISAcres > 50][['IncidentName','state','GISAcres','Date']].sort_values('Date', ascending=False)\n", "#recent_acres_burned = fires_fl.loc[[fires_fl.Date > (d)]]\n", "\n", "print(incident_acres[0:5]),(state_acres[0:5]),(recent_fires[0:10])" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "tile = \"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}\"\n", "attribu = 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'\n", "m = folium.Map([42,-110], zoom_start=5, tiles=tile,attr=attribu)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fires_fl['reported_acres'] = round(fires_fl['GISAcres'],0)\n", "folium.GeoJson(fires_fl,\n", " tooltip=folium.features.GeoJsonTooltip(\n", " fields=['IncidentName','reported_acres','state','Date'],\n", " aliases=['Fire Name:','Reported Acres','State','Last Updated'])\n", " ).add_to(m)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "index int64\n", "OBJECTID int64\n", "IncidentName object\n", "FeatureCategory object\n", "MapMethod object\n", "Comments object\n", "GISAcres float64\n", "Label object\n", "FeatureAccess object\n", "FeatureStatus object\n", "IsVisible object\n", "CreateDate object\n", "DateCurrent object\n", "PolygonDateTime object\n", "ComplexName object\n", "ComplexID object\n", "GACC object\n", "IMTName object\n", "UnitID object\n", "LocalIncidentID object\n", "IRWINID object\n", "GeometryID object\n", "GlobalID object\n", "SHAPE_Length float64\n", "SHAPE_Area float64\n", "geometry geometry\n", "index_right int64\n", "id int64\n", "name object\n", "fl object\n", "state object\n", "Date datetime64[ns]\n", "reported_acres float64\n", "dtype: object" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fires_fl.dtypes" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
indexOBJECTIDIncidentNameFeatureCategoryMapMethodCommentsGISAcresLabelFeatureAccessFeatureStatus...SHAPE_LengthSHAPE_Areageometryindex_rightidnameflstateDatereported_acres
0085633Taylor SpringsWildfire Daily Fire PerimeterGPS-WalkedNone0.009227NonePublicApproved...0.0002453.865364e-09MULTIPOLYGON (((-119.17940 38.67386, -119.1794...761762LyonlyoNV2020-07-10 19:50:160.0
116686952SageWildfire Daily Fire PerimeterPhone/TabletNone1.121013NonePublicApproved...0.0059534.755395e-07MULTIPOLYGON (((-119.27600 39.57148, -119.2760...761762LyonlyoNV2020-07-10 19:51:531.0
23458808310 Mile 2Wildfire Daily Fire PerimeterGPS-DrivenNone305.838568NonePublicApproved...0.0993331.293224e-04MULTIPOLYGON (((-119.46681 39.34448, -119.4668...761762LyonlyoNV2020-07-13 16:13:50306.0
3185639GapWildfire Daily Fire PerimeterMixed MethodsNone0.829251NonePublicApproved...0.0031943.507899e-07MULTIPOLYGON (((-114.91624 39.37364, -114.9162...702703White PinewteNV2020-07-10 19:50:201.0
41785759North CreekWildfire Daily Fire PerimeterGPS-WalkedNone160.802888NonePublicApproved...0.0490906.818068e-05MULTIPOLYGON (((-114.66389 39.53377, -114.6639...702703White PinewteNV2020-07-10 19:49:14161.0
\n", "

5 rows × 34 columns

\n", "
" ], "text/plain": [ " index OBJECTID IncidentName FeatureCategory \\\n", "0 0 85633 Taylor Springs Wildfire Daily Fire Perimeter \n", "1 166 86952 Sage Wildfire Daily Fire Perimeter \n", "2 345 88083 10 Mile 2 Wildfire Daily Fire Perimeter \n", "3 1 85639 Gap Wildfire Daily Fire Perimeter \n", "4 17 85759 North Creek Wildfire Daily Fire Perimeter \n", "\n", " MapMethod Comments GISAcres Label FeatureAccess FeatureStatus ... \\\n", "0 GPS-Walked None 0.009227 None Public Approved ... \n", "1 Phone/Tablet None 1.121013 None Public Approved ... \n", "2 GPS-Driven None 305.838568 None Public Approved ... \n", "3 Mixed Methods None 0.829251 None Public Approved ... \n", "4 GPS-Walked None 160.802888 None Public Approved ... \n", "\n", " SHAPE_Length SHAPE_Area \\\n", "0 0.000245 3.865364e-09 \n", "1 0.005953 4.755395e-07 \n", "2 0.099333 1.293224e-04 \n", "3 0.003194 3.507899e-07 \n", "4 0.049090 6.818068e-05 \n", "\n", " geometry index_right id \\\n", "0 MULTIPOLYGON (((-119.17940 38.67386, -119.1794... 761 762 \n", "1 MULTIPOLYGON (((-119.27600 39.57148, -119.2760... 761 762 \n", "2 MULTIPOLYGON (((-119.46681 39.34448, -119.4668... 761 762 \n", "3 MULTIPOLYGON (((-114.91624 39.37364, -114.9162... 702 703 \n", "4 MULTIPOLYGON (((-114.66389 39.53377, -114.6639... 702 703 \n", "\n", " name fl state Date reported_acres \n", "0 Lyon lyo NV 2020-07-10 19:50:16 0.0 \n", "1 Lyon lyo NV 2020-07-10 19:51:53 1.0 \n", "2 Lyon lyo NV 2020-07-13 16:13:50 306.0 \n", "3 White Pine wte NV 2020-07-10 19:50:20 1.0 \n", "4 White Pine wte NV 2020-07-10 19:49:14 161.0 \n", "\n", "[5 rows x 34 columns]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fires_fl.head()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.3" } }, "nbformat": 4, "nbformat_minor": 4 }