{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8e73506c",
   "metadata": {},
   "source": [
    "# Analysis of Colorado Spills Data\n",
    "## Attempt 11: Using 2020 as the Year of Analysis for Change and Outlier Removal\n",
    "### Focus on top 3 counties\n",
    "#### [David P. Adams](https://dadams.io)\n",
    "##### [GitHub Repository](https://github.com/dadams-AU/colorado_spills)\n",
    "##### Date: 2025-08-14"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "f476d20e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import geopandas as gpd\n",
    "from sqlalchemy import create_engine\n",
    "from dotenv import load_dotenv\n",
    "\n",
    "# Load environment variables (e.g., DB_USER, DB_PASSWORD)\n",
    "load_dotenv()\n",
    "\n",
    "# Database credentials from .env or shell\n",
    "db_name = 'colorado_spills'\n",
    "user = os.getenv('DB_USER')\n",
    "password = os.getenv('DB_PASSWORD')\n",
    "host = os.getenv('DB_HOST')\n",
    "port = os.getenv('DB_PORT')\n",
    "\n",
    "# SQLAlchemy engine for PostgreSQL/PostGIS\n",
    "engine = create_engine(f'postgresql+psycopg2://{user}:{password}@{host}:{port}/{db_name}')\n",
    "\n",
    "# --- Load data with geometry preserved ---\n",
    "try:\n",
    "    spills = gpd.read_postgis(\n",
    "        sql='SELECT * FROM spills_with_ruca',\n",
    "        con=engine,\n",
    "        geom_col='geometry',\n",
    "        crs='EPSG:4326'\n",
    "    )\n",
    "except Exception as e:\n",
    "    print(\"GeoPandas failed to load geometry. Falling back to plain Pandas.\")\n",
    "    spills = pd.read_sql('SELECT * FROM spills_with_ruca', engine)\n",
    "    # Optional: spills.drop(columns='geometry', inplace=True, errors='ignore')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "03a508ea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Document #</th>\n",
       "      <th>Report</th>\n",
       "      <th>Operator</th>\n",
       "      <th>Operator #</th>\n",
       "      <th>Tracking #</th>\n",
       "      <th>Initial Report Date</th>\n",
       "      <th>Date of Discovery</th>\n",
       "      <th>Spill Type</th>\n",
       "      <th>Qtr Qtr</th>\n",
       "      <th>Section</th>\n",
       "      <th>...</th>\n",
       "      <th>poverty_population</th>\n",
       "      <th>unemployed_population</th>\n",
       "      <th>percent_white</th>\n",
       "      <th>percent_hispanic</th>\n",
       "      <th>percent_poverty</th>\n",
       "      <th>unemployment_rate</th>\n",
       "      <th>geometry</th>\n",
       "      <th>ruca_code</th>\n",
       "      <th>ruca_description</th>\n",
       "      <th>rurality</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>400811665</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>CHEVRON USA INC</td>\n",
       "      <td>16700</td>\n",
       "      <td>400811665</td>\n",
       "      <td>03/19/2015</td>\n",
       "      <td>06/04/2012</td>\n",
       "      <td>Historical</td>\n",
       "      <td>nwne</td>\n",
       "      <td>19</td>\n",
       "      <td>...</td>\n",
       "      <td>249.0</td>\n",
       "      <td>86.0</td>\n",
       "      <td>84.676145</td>\n",
       "      <td>11.650869</td>\n",
       "      <td>9.834123</td>\n",
       "      <td>3.396524</td>\n",
       "      <td>POINT (-108.88214 40.1324)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>400811979</td>\n",
       "      <td>I</td>\n",
       "      <td>WHITING OIL &amp; GAS CORPORATION</td>\n",
       "      <td>96155</td>\n",
       "      <td>400811979</td>\n",
       "      <td>03/19/2015</td>\n",
       "      <td>03/18/2015</td>\n",
       "      <td>Recent</td>\n",
       "      <td>SWSW</td>\n",
       "      <td>33</td>\n",
       "      <td>...</td>\n",
       "      <td>1193.0</td>\n",
       "      <td>253.0</td>\n",
       "      <td>86.064736</td>\n",
       "      <td>14.412266</td>\n",
       "      <td>20.323680</td>\n",
       "      <td>4.310051</td>\n",
       "      <td>POINT (-103.87652 40.78919)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>400812102</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>CHEVRON USA INC</td>\n",
       "      <td>16700</td>\n",
       "      <td>400812102</td>\n",
       "      <td>03/19/2015</td>\n",
       "      <td>07/11/2012</td>\n",
       "      <td>Historical</td>\n",
       "      <td>nese</td>\n",
       "      <td>32</td>\n",
       "      <td>...</td>\n",
       "      <td>249.0</td>\n",
       "      <td>86.0</td>\n",
       "      <td>84.676145</td>\n",
       "      <td>11.650869</td>\n",
       "      <td>9.834123</td>\n",
       "      <td>3.396524</td>\n",
       "      <td>POINT (-108.86143 40.09959)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>400812258</td>\n",
       "      <td>I</td>\n",
       "      <td>KERR MCGEE OIL &amp; GAS ONSHORE LP</td>\n",
       "      <td>47120</td>\n",
       "      <td>400812258</td>\n",
       "      <td>03/20/2015</td>\n",
       "      <td>03/19/2015</td>\n",
       "      <td>Historical</td>\n",
       "      <td>NENW</td>\n",
       "      <td>13</td>\n",
       "      <td>...</td>\n",
       "      <td>25.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>82.352941</td>\n",
       "      <td>18.242740</td>\n",
       "      <td>1.861504</td>\n",
       "      <td>0.744602</td>\n",
       "      <td>POINT (-104.9543 40.0574)</td>\n",
       "      <td>2</td>\n",
       "      <td>Metropolitan high commuting</td>\n",
       "      <td>Urban</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>400812277</td>\n",
       "      <td>I</td>\n",
       "      <td>NOBLE ENERGY INC</td>\n",
       "      <td>100322</td>\n",
       "      <td>400812277</td>\n",
       "      <td>03/20/2015</td>\n",
       "      <td>03/18/2015</td>\n",
       "      <td>Recent</td>\n",
       "      <td>SENE</td>\n",
       "      <td>28</td>\n",
       "      <td>...</td>\n",
       "      <td>268.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>89.013174</td>\n",
       "      <td>15.212528</td>\n",
       "      <td>6.661695</td>\n",
       "      <td>1.541138</td>\n",
       "      <td>POINT (-104.54757 40.2861)</td>\n",
       "      <td>2</td>\n",
       "      <td>Metropolitan high commuting</td>\n",
       "      <td>Urban</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 122 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   Document # Report                         Operator  Operator #  Tracking #  \\\n",
       "0   400811665  I w/S                  CHEVRON USA INC       16700   400811665   \n",
       "1   400811979      I    WHITING OIL & GAS CORPORATION       96155   400811979   \n",
       "2   400812102  I w/S                  CHEVRON USA INC       16700   400812102   \n",
       "3   400812258      I  KERR MCGEE OIL & GAS ONSHORE LP       47120   400812258   \n",
       "4   400812277      I                 NOBLE ENERGY INC      100322   400812277   \n",
       "\n",
       "  Initial Report Date Date of Discovery  Spill Type Qtr Qtr  Section  ...  \\\n",
       "0          03/19/2015        06/04/2012  Historical  nwne         19  ...   \n",
       "1          03/19/2015        03/18/2015      Recent  SWSW         33  ...   \n",
       "2          03/19/2015        07/11/2012  Historical  nese         32  ...   \n",
       "3          03/20/2015        03/19/2015  Historical  NENW         13  ...   \n",
       "4          03/20/2015        03/18/2015      Recent  SENE         28  ...   \n",
       "\n",
       "  poverty_population unemployed_population percent_white  percent_hispanic  \\\n",
       "0              249.0                  86.0     84.676145         11.650869   \n",
       "1             1193.0                 253.0     86.064736         14.412266   \n",
       "2              249.0                  86.0     84.676145         11.650869   \n",
       "3               25.0                  10.0     82.352941         18.242740   \n",
       "4              268.0                  62.0     89.013174         15.212528   \n",
       "\n",
       "   percent_poverty unemployment_rate                     geometry ruca_code  \\\n",
       "0         9.834123          3.396524   POINT (-108.88214 40.1324)        10   \n",
       "1        20.323680          4.310051  POINT (-103.87652 40.78919)        10   \n",
       "2         9.834123          3.396524  POINT (-108.86143 40.09959)        10   \n",
       "3         1.861504          0.744602    POINT (-104.9543 40.0574)         2   \n",
       "4         6.661695          1.541138   POINT (-104.54757 40.2861)         2   \n",
       "\n",
       "              ruca_description rurality  \n",
       "0                   Rural area    Rural  \n",
       "1                   Rural area    Rural  \n",
       "2                   Rural area    Rural  \n",
       "3  Metropolitan high commuting    Urban  \n",
       "4  Metropolitan high commuting    Urban  \n",
       "\n",
       "[5 rows x 122 columns]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# show head\n",
    "spills.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "08bf0d17",
   "metadata": {},
   "outputs": [],
   "source": [
    "# use longitude and latitude to create a GeoDataFrame from spills data\n",
    "spills['geometry'] = gpd.points_from_xy(spills['Longitude'], spills['Latitude'])\n",
    "spills = gpd.GeoDataFrame(spills, geometry='geometry')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "dc5dfab9",
   "metadata": {},
   "outputs": [],
   "source": [
    "spills_gdf = gpd.GeoDataFrame(spills, crs='EPSG:4326') \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "ba3ca567",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# Ensure date columns are in datetime format\n",
    "spills_gdf['Date of Discovery'] = pd.to_datetime(spills_gdf['Date of Discovery'])\n",
    "spills_gdf['Initial Report Date'] = pd.to_datetime(spills_gdf['Initial Report Date'])\n",
    "\n",
    "# create a report year column\n",
    "spills_gdf['Report Year'] = spills_gdf['Initial Report Date'].dt.year\n",
    "\n",
    "# create a discovery year column\n",
    "spills_gdf['Discovery Year'] = spills_gdf['Date of Discovery'].dt.year\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "1c537872",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(Timestamp('2015-03-19 00:00:00'), Timestamp('2025-03-17 00:00:00'))"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "spills_gdf['Initial Report Date'].min(), spills_gdf['Initial Report Date'].max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "ed6768d0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(Timestamp('1994-11-14 00:00:00'), Timestamp('2025-03-16 00:00:00'))"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# show first and last dates\n",
    "spills_gdf['Date of Discovery'].min(), spills_gdf['Date of Discovery'].max()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "faeebec8",
   "metadata": {},
   "outputs": [],
   "source": [
    "def classify_rurality(ruca_code):\n",
    "    if pd.isna(ruca_code):\n",
    "        return 'Unknown'\n",
    "    elif ruca_code <= 3:\n",
    "        return 'Urban'\n",
    "    elif ruca_code <= 6:\n",
    "        return 'Suburban'\n",
    "    else:\n",
    "        return 'Rural'\n",
    "\n",
    "spills_gdf['ruca_code'] = pd.to_numeric(spills_gdf['ruca_code'], errors='coerce')\n",
    "spills_gdf['rurality'] = spills_gdf['ruca_code'].apply(classify_rurality)\n",
    "spills_gdf = spills_gdf[spills_gdf['rurality'] != 'Unknown']  # drop unknowns\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "c53017a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "Discovery Year",
         "rawType": "int32",
         "type": "integer"
        },
        {
         "name": "count",
         "rawType": "int64",
         "type": "integer"
        }
       ],
       "ref": "d506c17f-01c7-436b-bf17-d116e5534ae6",
       "rows": [
        [
         "1994",
         "1"
        ],
        [
         "2004",
         "1"
        ],
        [
         "2009",
         "1"
        ],
        [
         "2011",
         "4"
        ],
        [
         "2012",
         "7"
        ],
        [
         "2013",
         "9"
        ],
        [
         "2014",
         "27"
        ],
        [
         "2015",
         "1192"
        ],
        [
         "2016",
         "1376"
        ],
        [
         "2017",
         "1603"
        ],
        [
         "2018",
         "1584"
        ],
        [
         "2019",
         "1561"
        ],
        [
         "2020",
         "1171"
        ],
        [
         "2021",
         "1794"
        ],
        [
         "2022",
         "2170"
        ],
        [
         "2023",
         "2172"
        ],
        [
         "2024",
         "2700"
        ],
        [
         "2025",
         "447"
        ]
       ],
       "shape": {
        "columns": 1,
        "rows": 18
       }
      },
      "text/plain": [
       "Discovery Year\n",
       "1994       1\n",
       "2004       1\n",
       "2009       1\n",
       "2011       4\n",
       "2012       7\n",
       "2013       9\n",
       "2014      27\n",
       "2015    1192\n",
       "2016    1376\n",
       "2017    1603\n",
       "2018    1584\n",
       "2019    1561\n",
       "2020    1171\n",
       "2021    1794\n",
       "2022    2170\n",
       "2023    2172\n",
       "2024    2700\n",
       "2025     447\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# show frequency of discovery by year\n",
    "spills_gdf['Discovery Year'].value_counts().sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "1ce3eefd",
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "\n",
    "start_date = datetime(2015, 1, 1)\n",
    "end_date = datetime(2024, 12, 31)  # exclusive end date\n",
    "\n",
    "spills_gdf = spills_gdf[\n",
    "    (spills_gdf['Date of Discovery'] >= start_date) &\n",
    "    (spills_gdf['Date of Discovery'] < end_date)\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "21324e82",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 32300 characters]",
      "text/plain": [
       "<Figure size 1200x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot discovery year frequency\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.figure(figsize=(12, 6))\n",
    "spills_gdf['Discovery Year'].value_counts().sort_index().plot(kind='bar')\n",
    "plt.title('Frequency of Discovery by Year')\n",
    "plt.xlabel('Year')\n",
    "plt.ylabel('Frequency')\n",
    "plt.xticks(rotation=45)\n",
    "plt.grid(axis='y')\n",
    "plt.tight_layout()\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "fda5768c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Separate Historical vs. Recent Spills\n",
    "historical_spills = spills_gdf[spills_gdf['Spill Type'] == 'Historical']\n",
    "recent_spills = spills_gdf[spills_gdf['Spill Type'] == 'Recent']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "78d1b001",
   "metadata": {},
   "outputs": [],
   "source": [
    "# only use the top 3 counties by number of spills\n",
    "top_counties = spills_gdf['county'].value_counts().nlargest(3).index.tolist()\n",
    "# filter spills_gdf to only include top counties\n",
    "spills_gdf = spills_gdf[spills_gdf['county'].isin(top_counties)]\n",
    "# filter historical spills to only include top counties\n",
    "historical_spills = historical_spills[historical_spills['county'].isin(top_counties)]\n",
    "# filter recent spills to only include top counties\n",
    "recent_spills = recent_spills[recent_spills['county'].isin(top_counties)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "9d110ce8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 34504 characters]",
      "text/plain": [
       "<Figure size 1200x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 34416 characters]",
      "text/plain": [
       "<Figure size 1200x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot historical spills by county\n",
    "plt.figure(figsize=(12, 6))\n",
    "historical_spills['county'].value_counts().plot(kind='bar')\n",
    "plt.title('Historical Spills by County')\n",
    "plt.xlabel('County')\n",
    "plt.ylabel('Number of Spills')\n",
    "plt.xticks(rotation=45)\n",
    "plt.grid(axis='y')\n",
    "plt.tight_layout()\n",
    "plt.show()\n",
    "\n",
    "# plot recent spills by county\n",
    "plt.figure(figsize=(12, 6))\n",
    "recent_spills['county'].value_counts().plot(kind='bar')\n",
    "plt.title('Recent Spills by County')\n",
    "plt.xlabel('County')\n",
    "plt.ylabel('Number of Spills')\n",
    "plt.xticks(rotation=45)\n",
    "plt.grid(axis='y')\n",
    "plt.tight_layout()\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "5fdfc7fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# create period column for 2020\n",
    "import statsmodels.formula.api as smf\n",
    "\n",
    "# Create 'Period' column\n",
    "spills_gdf['Period'] = spills_gdf['Report Year'].apply(lambda x: 'Before 2020' if x < 2020 else '2020 and After')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "71ce1288",
   "metadata": {},
   "outputs": [],
   "source": [
    "spills_gdf['report_delay'] = (spills_gdf['Initial Report Date'] - spills_gdf['Date of Discovery']).dt.days\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "3940b2ae",
   "metadata": {},
   "outputs": [],
   "source": [
    "spills_gdf = spills_gdf[spills_gdf['report_delay'] >= 0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "d69294c0",
   "metadata": {},
   "outputs": [],
   "source": [
    "spills_gdf = spills_gdf.rename(columns={\n",
    "    'Report Delay (Days)': 'report_delay',\n",
    "    'Spill Type': 'spill_type'\n",
    "})\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "84f17380",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Full mean days: 3.768655023814924 median: 1.0\n",
      "Trimmed mean days: 3.768655023814924 median: 1.0\n",
      "Proportion same-day (0 days): 0.3990322824525592\n",
      "Proportion trimmed (removed): 0.0\n"
     ]
    }
   ],
   "source": [
    "# before trimming: assume delta = Initial Report Date - Date of Discovery\n",
    "\n",
    "delta = spills_gdf['Initial Report Date'] - spills_gdf['Date of Discovery']\n",
    "\n",
    "full_days = delta.dt.days\n",
    "print(\"Full mean days:\", full_days.mean(), \"median:\", full_days.median())\n",
    "# after trimming (if you saved trimmed series as report_delay)\n",
    "print(\"Trimmed mean days:\", spills_gdf['report_delay'].mean(), \"median:\", spills_gdf['report_delay'].median())\n",
    "print(\"Proportion same-day (0 days):\", (full_days==0).mean())\n",
    "print(\"Proportion trimmed (removed):\", 1 - len(spills_gdf)/len(full_days))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "c119005c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "index",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "0",
         "rawType": "int64",
         "type": "integer"
        }
       ],
       "ref": "603116cf-2bef-49f3-a218-c488541ae553",
       "rows": [
        [
         "9403",
         "1329"
        ],
        [
         "17470",
         "925"
        ],
        [
         "15943",
         "655"
        ],
        [
         "15940",
         "655"
        ],
        [
         "14628",
         "648"
        ],
        [
         "15062",
         "541"
        ],
        [
         "11812",
         "462"
        ],
        [
         "17734",
         "452"
        ],
        [
         "17717",
         "434"
        ],
        [
         "17710",
         "431"
        ],
        [
         "14276",
         "428"
        ],
        [
         "16432",
         "428"
        ],
        [
         "17364",
         "417"
        ],
        [
         "15059",
         "414"
        ],
        [
         "17321",
         "412"
        ],
        [
         "7573",
         "395"
        ],
        [
         "7541",
         "395"
        ],
        [
         "12246",
         "365"
        ],
        [
         "15296",
         "365"
        ],
        [
         "12759",
         "365"
        ]
       ],
       "shape": {
        "columns": 1,
        "rows": 20
       }
      },
      "text/plain": [
       "9403     1329\n",
       "17470     925\n",
       "15943     655\n",
       "15940     655\n",
       "14628     648\n",
       "15062     541\n",
       "11812     462\n",
       "17734     452\n",
       "17717     434\n",
       "17710     431\n",
       "14276     428\n",
       "16432     428\n",
       "17364     417\n",
       "15059     414\n",
       "17321     412\n",
       "7573      395\n",
       "7541      395\n",
       "12246     365\n",
       "15296     365\n",
       "12759     365\n",
       "dtype: int64"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "full_days.describe(percentiles=[.5,.75,.9,.95,.99])\n",
    "full_days.sort_values(ascending=False).head(20)  # see extreme values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "f1ca0fe8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Rows total: 13227\n",
      "Rows flagged for removal: 1851 proportion: 0.13994102971195282\n",
      "Full mean days: 3.768655023814924 median: 1.0\n",
      "Trimmed mean days: 0.6633263009845288 median: 1.0\n"
     ]
    }
   ],
   "source": [
    "# reclone original full delays if you still have them, or recompute from dates\n",
    "delta = spills_gdf['Initial Report Date'] - spills_gdf['Date of Discovery']\n",
    "full_days = delta.dt.days\n",
    "\n",
    "# compute IQR bounds the same way you did\n",
    "q1, q3 = full_days.quantile([0.25, 0.75])\n",
    "iqr = q3 - q1\n",
    "lower = max(0, q1 - 1.5 * iqr)\n",
    "upper = q3 + 1.5 * iqr\n",
    "\n",
    "# flag rows that would be removed\n",
    "spills_gdf['report_delay_full'] = full_days\n",
    "spills_gdf['trim_remove'] = ~((spills_gdf['report_delay_full'] >= lower) & (spills_gdf['report_delay_full'] <= upper))\n",
    "\n",
    "# summaries\n",
    "print(\"Rows total:\", len(spills_gdf))\n",
    "print(\"Rows flagged for removal:\", spills_gdf['trim_remove'].sum(), \"proportion:\", spills_gdf['trim_remove'].mean())\n",
    "print(\"Full mean days:\", spills_gdf['report_delay_full'].mean(), \"median:\", spills_gdf['report_delay_full'].median())\n",
    "print(\"Trimmed mean days:\", spills_gdf.loc[~spills_gdf['trim_remove'],'report_delay_full'].mean(),\n",
    "      \"median:\", spills_gdf.loc[~spills_gdf['trim_remove'],'report_delay_full'].median())\n",
    "\n",
    "# save copies if you want\n",
    "spills_gdf.to_parquet('spills_with_trim_flag.parquet')  # or to_csv\n",
    "spills_gdf.loc[~spills_gdf['trim_remove']].to_parquet('spills_trimmed.parquet')\n",
    "spills_gdf.loc[spills_gdf['trim_remove']].to_parquet('spills_trimmed_removed.parquet')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "fb84dc23",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "IQR bounds: Q1=0.0, Q3=1.0, IQR=1.0\n",
      "Keeping report_delay in [0.0, 2.5]\n",
      "Rows before outlier filter: 13227, after: 11376, removed: 1851\n",
      "count    11376.000000\n",
      "mean         0.663326\n",
      "std          0.691330\n",
      "min          0.000000\n",
      "25%          0.000000\n",
      "50%          1.000000\n",
      "75%          1.000000\n",
      "max          2.000000\n",
      "Name: report_delay, dtype: float64\n"
     ]
    }
   ],
   "source": [
    "# Outlier removal using IQR on report_delay (run after report_delay is created)\n",
    "if 'report_delay' not in spills_gdf.columns:\n",
    "    print('report_delay column not found — skipping outlier removal in this cell.')\n",
    "else:\n",
    "    q1 = spills_gdf['report_delay'].quantile(0.25)\n",
    "    q3 = spills_gdf['report_delay'].quantile(0.75)\n",
    "    iqr = q3 - q1\n",
    "    lower = max(0, q1 - 1.5 * iqr)\n",
    "    upper = q3 + 1.5 * iqr\n",
    "    print(f'IQR bounds: Q1={q1:.1f}, Q3={q3:.1f}, IQR={iqr:.1f}')\n",
    "    print(f'Keeping report_delay in [{lower:.1f}, {upper:.1f}]')\n",
    "    before_n = len(spills_gdf)\n",
    "    # keep only rows with report_delay inside bounds\n",
    "    spills_gdf = spills_gdf[(spills_gdf['report_delay'] >= lower) & (spills_gdf['report_delay'] <= upper)].copy()\n",
    "    after_n = len(spills_gdf)\n",
    "    print(f'Rows before outlier filter: {before_n}, after: {after_n}, removed: {before_n - after_n}')\n",
    "    # show a short summary of report_delay after filtering\n",
    "    print(spills_gdf['report_delay'].describe())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "d03aed63",
   "metadata": {},
   "outputs": [],
   "source": [
    "# spill type by rurality\n",
    "spill_type_rurality = spills_gdf.groupby(['rurality', 'spill_type']).size().unstack(fill_value=0)\n",
    "spill_type_rurality = spill_type_rurality.reindex(['Urban', 'Suburban', 'Rural'], fill_value=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "9cecca31",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Axes: xlabel='rurality'>"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 21472 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot spill type by rurality\n",
    "spill_type_rurality.plot(kind='bar', stacked=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "29261e71",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                 Generalized Linear Model Regression Results                  \n",
      "==============================================================================\n",
      "Dep. Variable:           report_delay   No. Observations:                11376\n",
      "Model:                            GLM   Df Residuals:                    11364\n",
      "Model Family:        NegativeBinomial   Df Model:                           11\n",
      "Link Function:                    Log   Scale:                          1.0000\n",
      "Method:                          IRLS   Log-Likelihood:                -12475.\n",
      "Date:                Thu, 14 Aug 2025   Deviance:                       6528.1\n",
      "Time:                        19:52:03   Pearson chi2:                 4.87e+03\n",
      "No. Iterations:                     5   Pseudo R-squ. (CS):            0.04302\n",
      "Covariance Type:            nonrobust                                         \n",
      "============================================================================================================================================\n",
      "                                                                               coef    std err          z      P>|z|      [0.025      0.975]\n",
      "--------------------------------------------------------------------------------------------------------------------------------------------\n",
      "Intercept                                                                   -0.4954      0.069     -7.201      0.000      -0.630      -0.361\n",
      "C(spill_type)[T.Recent]                                                      0.1155      0.077      1.497      0.135      -0.036       0.267\n",
      "C(Period)[T.Before 2020]                                                     0.3768      0.110      3.416      0.001       0.161       0.593\n",
      "C(rurality)[T.Suburban]                                                     -0.3718      0.157     -2.364      0.018      -0.680      -0.064\n",
      "C(rurality)[T.Urban]                                                        -0.5702      0.079     -7.231      0.000      -0.725      -0.416\n",
      "C(spill_type)[T.Recent]:C(Period)[T.Before 2020]                            -0.0985      0.121     -0.812      0.417      -0.336       0.139\n",
      "C(spill_type)[T.Recent]:C(rurality)[T.Suburban]                              0.1757      0.184      0.955      0.339      -0.185       0.536\n",
      "C(spill_type)[T.Recent]:C(rurality)[T.Urban]                                 0.4987      0.098      5.115      0.000       0.308       0.690\n",
      "C(Period)[T.Before 2020]:C(rurality)[T.Suburban]                             0.2468      0.251      0.984      0.325      -0.245       0.738\n",
      "C(Period)[T.Before 2020]:C(rurality)[T.Urban]                                0.4714      0.124      3.790      0.000       0.228       0.715\n",
      "C(spill_type)[T.Recent]:C(Period)[T.Before 2020]:C(rurality)[T.Suburban]    -0.1710      0.290     -0.589      0.556      -0.740       0.398\n",
      "C(spill_type)[T.Recent]:C(Period)[T.Before 2020]:C(rurality)[T.Urban]       -0.3650      0.149     -2.455      0.014      -0.656      -0.074\n",
      "============================================================================================================================================\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/dadams/CSU Fullerton Dropbox/David Adams/Research Projects/colorado_spills_ejproject/github/colorado_spills/.venv/lib/python3.13/site-packages/statsmodels/genmod/families/family.py:1367: ValueWarning: Negative binomial dispersion parameter alpha not set. Using default value alpha=1.0.\n",
      "  warnings.warn(\"Negative binomial dispersion parameter alpha not \"\n"
     ]
    }
   ],
   "source": [
    "import statsmodels.formula.api as smf\n",
    "import statsmodels.api as sm\n",
    "\n",
    "# Make sure spill_type and Period are clean, and report_delay is numeric\n",
    "spills_gdf = spills_gdf.rename(columns={\n",
    "    'Report Delay (Days)': 'report_delay',\n",
    "    'Spill Type': 'spill_type',\n",
    "    'rurality': 'rurality'\n",
    "})\n",
    "\n",
    "# Fit the Negative Binomial model with interaction\n",
    "nb_model = smf.glm(\n",
    "    formula=\"report_delay ~ C(spill_type) * C(Period) * C(rurality)\",\n",
    "    data=spills_gdf,\n",
    "    family=sm.families.NegativeBinomial()\n",
    ").fit()\n",
    "\n",
    "# View the results\n",
    "print(nb_model.summary())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "be634f4e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Pearson chi2: 7807.6, dispersion (chi2/df): 0.687\n"
     ]
    }
   ],
   "source": [
    "# after nb_model = smf.glm(...).fit()\n",
    "# 1) Pearson dispersion\n",
    "pred = nb_model.predict(spills_gdf)\n",
    "pearson_chi2 = ((spills_gdf['report_delay'] - pred)**2 / pred).sum()\n",
    "dispersion = pearson_chi2 / nb_model.df_resid\n",
    "print(f'Pearson chi2: {pearson_chi2:.1f}, dispersion (chi2/df): {dispersion:.3f}')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "258159b7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "spill_type         Period rurality    n\n",
      "Historical    Before 2020 Suburban   74\n",
      "Historical 2020 and After Suburban  169\n",
      "    Recent    Before 2020 Suburban  206\n",
      "Historical    Before 2020    Rural  286\n",
      "    Recent 2020 and After Suburban  354\n",
      "Historical 2020 and After    Rural  558\n",
      "    Recent    Before 2020    Urban 1022\n",
      "Historical    Before 2020    Urban 1233\n",
      "    Recent 2020 and After    Urban 1247\n",
      "    Recent    Before 2020    Rural 1594\n",
      "    Recent 2020 and After    Rural 2006\n",
      "Historical 2020 and After    Urban 2627\n",
      "Summary of cell counts:\n",
      "count      12.00000\n",
      "mean      948.00000\n",
      "std       819.99357\n",
      "min        74.00000\n",
      "25%       266.00000\n",
      "50%       790.00000\n",
      "75%      1333.75000\n",
      "max      2627.00000\n",
      "Name: n, dtype: float64\n",
      "\n",
      "Min count per cell: 74\n",
      "\n",
      "Counts look sufficient for the 3-way interaction (min cell >= 20).\n"
     ]
    }
   ],
   "source": [
    "# (Inserted) Check counts for spill_type × Period × rurality — run this BEFORE relying on the 3-way interaction\n",
    "import pandas as pd\n",
    "\n",
    "group_counts = spills_gdf.groupby(['spill_type','Period','rurality']).size().reset_index(name='n').sort_values('n')\n",
    "# Print smallest groups to inspect sparsity\n",
    "print(group_counts.head(50).to_string(index=False))\n",
    "\n",
    "print('Summary of cell counts:')\n",
    "print(group_counts['n'].describe())\n",
    "min_n = int(group_counts['n'].min())\n",
    "print(f'\\nMin count per cell: {min_n}')\n",
    "if min_n < 20:\n",
    "    print('\\nWarning: many cells have small counts (<20). Consider removing the 3-way interaction or stratifying by rurality.')\n",
    "else:\n",
    "    print('\\nCounts look sufficient for the 3-way interaction (min cell >= 20).')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "97b74c6c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting Poisson GLM:  report_delay ~ C(spill_type) * C(Period) * C(rurality)\n",
      "                 Generalized Linear Model Regression Results                  \n",
      "==============================================================================\n",
      "Dep. Variable:           report_delay   No. Observations:                11376\n",
      "Model:                            GLM   Df Residuals:                    11364\n",
      "Model Family:                 Poisson   Df Model:                           11\n",
      "Link Function:                    Log   Scale:                          1.0000\n",
      "Method:                          IRLS   Log-Likelihood:                -11245.\n",
      "Date:                Thu, 14 Aug 2025   Deviance:                       9405.6\n",
      "Time:                        19:52:03   Pearson chi2:                 7.81e+03\n",
      "No. Iterations:                     5   Pseudo R-squ. (CS):            0.06825\n",
      "Covariance Type:            nonrobust                                         \n",
      "============================================================================================================================================\n",
      "                                                                               coef    std err          z      P>|z|      [0.025      0.975]\n",
      "--------------------------------------------------------------------------------------------------------------------------------------------\n",
      "Intercept                                                                   -0.4954      0.054     -9.135      0.000      -0.602      -0.389\n",
      "C(spill_type)[T.Recent]                                                      0.1155      0.061      1.907      0.056      -0.003       0.234\n",
      "C(Period)[T.Before 2020]                                                     0.3768      0.083      4.543      0.000       0.214       0.539\n",
      "C(rurality)[T.Suburban]                                                     -0.3718      0.130     -2.849      0.004      -0.628      -0.116\n",
      "C(rurality)[T.Urban]                                                        -0.5702      0.064     -8.965      0.000      -0.695      -0.446\n",
      "C(spill_type)[T.Recent]:C(Period)[T.Before 2020]                            -0.0985      0.091     -1.081      0.280      -0.277       0.080\n",
      "C(spill_type)[T.Recent]:C(rurality)[T.Suburban]                              0.1757      0.151      1.164      0.244      -0.120       0.472\n",
      "C(spill_type)[T.Recent]:C(rurality)[T.Urban]                                 0.4987      0.078      6.420      0.000       0.346       0.651\n",
      "C(Period)[T.Before 2020]:C(rurality)[T.Suburban]                             0.2468      0.195      1.263      0.207      -0.136       0.630\n",
      "C(Period)[T.Before 2020]:C(rurality)[T.Urban]                                0.4714      0.095      4.972      0.000       0.286       0.657\n",
      "C(spill_type)[T.Recent]:C(Period)[T.Before 2020]:C(rurality)[T.Suburban]    -0.1710      0.225     -0.760      0.448      -0.612       0.270\n",
      "C(spill_type)[T.Recent]:C(Period)[T.Before 2020]:C(rurality)[T.Urban]       -0.3650      0.113     -3.237      0.001      -0.586      -0.144\n",
      "============================================================================================================================================\n",
      "Pearson chi2: 7807.6, dispersion (chi2/df): 0.687\n",
      "                 Generalized Linear Model Regression Results                  \n",
      "==============================================================================\n",
      "Dep. Variable:           report_delay   No. Observations:                11376\n",
      "Model:                            GLM   Df Residuals:                    11364\n",
      "Model Family:                 Poisson   Df Model:                           11\n",
      "Link Function:                    Log   Scale:                          1.0000\n",
      "Method:                          IRLS   Log-Likelihood:                -11245.\n",
      "Date:                Thu, 14 Aug 2025   Deviance:                       9405.6\n",
      "Time:                        19:52:03   Pearson chi2:                 7.81e+03\n",
      "No. Iterations:                     5   Pseudo R-squ. (CS):            0.06825\n",
      "Covariance Type:            nonrobust                                         \n",
      "============================================================================================================================================\n",
      "                                                                               coef    std err          z      P>|z|      [0.025      0.975]\n",
      "--------------------------------------------------------------------------------------------------------------------------------------------\n",
      "Intercept                                                                   -0.4954      0.054     -9.135      0.000      -0.602      -0.389\n",
      "C(spill_type)[T.Recent]                                                      0.1155      0.061      1.907      0.056      -0.003       0.234\n",
      "C(Period)[T.Before 2020]                                                     0.3768      0.083      4.543      0.000       0.214       0.539\n",
      "C(rurality)[T.Suburban]                                                     -0.3718      0.130     -2.849      0.004      -0.628      -0.116\n",
      "C(rurality)[T.Urban]                                                        -0.5702      0.064     -8.965      0.000      -0.695      -0.446\n",
      "C(spill_type)[T.Recent]:C(Period)[T.Before 2020]                            -0.0985      0.091     -1.081      0.280      -0.277       0.080\n",
      "C(spill_type)[T.Recent]:C(rurality)[T.Suburban]                              0.1757      0.151      1.164      0.244      -0.120       0.472\n",
      "C(spill_type)[T.Recent]:C(rurality)[T.Urban]                                 0.4987      0.078      6.420      0.000       0.346       0.651\n",
      "C(Period)[T.Before 2020]:C(rurality)[T.Suburban]                             0.2468      0.195      1.263      0.207      -0.136       0.630\n",
      "C(Period)[T.Before 2020]:C(rurality)[T.Urban]                                0.4714      0.095      4.972      0.000       0.286       0.657\n",
      "C(spill_type)[T.Recent]:C(Period)[T.Before 2020]:C(rurality)[T.Suburban]    -0.1710      0.225     -0.760      0.448      -0.612       0.270\n",
      "C(spill_type)[T.Recent]:C(Period)[T.Before 2020]:C(rurality)[T.Urban]       -0.3650      0.113     -3.237      0.001      -0.586      -0.144\n",
      "============================================================================================================================================\n",
      "Pearson chi2: 7807.6, dispersion (chi2/df): 0.687\n",
      "Failed to compute HC3 robust covariance: 'GLMResults' object has no attribute 'resid'\n",
      "\n",
      "Predicted group means (Poisson, HC3 CI where available):\n",
      "spill_type         Period rurality  pred_mean  ci_lower  ci_upper    n\n",
      "Historical 2020 and After    Rural   0.609319  0.547874  0.677655  558\n",
      "Historical 2020 and After Suburban   0.420118  0.332928  0.530142  169\n",
      "Historical 2020 and After    Urban   0.344499  0.322770  0.367692 2627\n",
      "Historical    Before 2020    Rural   0.888112  0.785340  1.004333  286\n",
      "Historical    Before 2020 Suburban   0.783784  0.605935  1.013833   74\n",
      "Historical    Before 2020    Urban   0.804542  0.756001  0.856199 1233\n",
      "    Recent 2020 and After    Rural   0.683948  0.648698  0.721114 2006\n",
      "    Recent 2020 and After Suburban   0.562147  0.489225  0.645938  354\n",
      "    Recent 2020 and After    Urban   0.636728  0.593944  0.682594 1247\n",
      "    Recent    Before 2020    Rural   0.903388  0.857912  0.951274 1594\n",
      "    Recent    Before 2020 Suburban   0.800971  0.687622  0.933005  206\n",
      "    Recent    Before 2020    Urban   0.935421  0.877964  0.996638 1022\n",
      "Failed to compute HC3 robust covariance: 'GLMResults' object has no attribute 'resid'\n",
      "\n",
      "Predicted group means (Poisson, HC3 CI where available):\n",
      "spill_type         Period rurality  pred_mean  ci_lower  ci_upper    n\n",
      "Historical 2020 and After    Rural   0.609319  0.547874  0.677655  558\n",
      "Historical 2020 and After Suburban   0.420118  0.332928  0.530142  169\n",
      "Historical 2020 and After    Urban   0.344499  0.322770  0.367692 2627\n",
      "Historical    Before 2020    Rural   0.888112  0.785340  1.004333  286\n",
      "Historical    Before 2020 Suburban   0.783784  0.605935  1.013833   74\n",
      "Historical    Before 2020    Urban   0.804542  0.756001  0.856199 1233\n",
      "    Recent 2020 and After    Rural   0.683948  0.648698  0.721114 2006\n",
      "    Recent 2020 and After Suburban   0.562147  0.489225  0.645938  354\n",
      "    Recent 2020 and After    Urban   0.636728  0.593944  0.682594 1247\n",
      "    Recent    Before 2020    Rural   0.903388  0.857912  0.951274 1594\n",
      "    Recent    Before 2020 Suburban   0.800971  0.687622  0.933005  206\n",
      "    Recent    Before 2020    Urban   0.935421  0.877964  0.996638 1022\n"
     ]
    }
   ],
   "source": [
    "# (Inserted) Fit Poisson GLM, compute HC3 robust covariance (fallback), and produce delta-method CIs for group means\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import patsy\n",
    "import statsmodels.api as sm\n",
    "import statsmodels.formula.api as smf\n",
    "\n",
    "formula = \"report_delay ~ C(spill_type) * C(Period) * C(rurality)\"\n",
    "print('Fitting Poisson GLM: ', formula)\n",
    "poisson = smf.glm(formula=formula, data=spills_gdf, family=sm.families.Poisson()).fit()\n",
    "print(poisson.summary())\n",
    "\n",
    "# Pearson dispersion check\n",
    "pred = poisson.predict(spills_gdf)\n",
    "pearson_chi2 = ((spills_gdf['report_delay'] - pred)**2 / (pred + 1e-12)).sum()\n",
    "dispersion = pearson_chi2 / poisson.df_resid\n",
    "print(f'Pearson chi2: {pearson_chi2:.1f}, dispersion (chi2/df): {dispersion:.3f}')\n",
    "\n",
    "# Robust covariance (HC3) with fallback to sandwich routine if wrapper missing\n",
    "try:\n",
    "    poisson_robust = poisson.get_robustcov_results(cov_type='HC3')\n",
    "    cov = poisson_robust.cov_params()\n",
    "    print('Used get_robustcov_results(cov_type=\"HC3\")')\n",
    "except Exception as e:\n",
    "    from statsmodels.stats.sandwich_covariance import cov_hc3\n",
    "    try:\n",
    "        cov = cov_hc3(poisson)\n",
    "        print('Used cov_hc3() fallback')\n",
    "    except Exception as e2:\n",
    "        print('Failed to compute HC3 robust covariance:', e2)\n",
    "        cov = poisson.cov_params()  # last resort\n",
    "\n",
    "# Prepare group combinations for prediction\n",
    "group_df = (spills_gdf[['spill_type','Period','rurality']]\n",
    "            .drop_duplicates()\n",
    "            .sort_values(['spill_type','Period','rurality'])\n",
    "            .reset_index(drop=True))\n",
    "# Build design matrix for the group_df using the same RHS as the model\n",
    "rhs = '1 + C(spill_type) * C(Period) * C(rurality)'\n",
    "exog = patsy.dmatrix(rhs, group_df, return_type='dataframe')\n",
    "# Align parameter vector and cov matrix to exog columns\n",
    "params = poisson.params.copy()\n",
    "# Ensure cov is a DataFrame indexed by model params\n",
    "if isinstance(cov, np.ndarray):\n",
    "    cov_df = pd.DataFrame(cov, index=poisson.params.index, columns=poisson.params.index)\n",
    "else:\n",
    "    cov_df = cov.copy()\n",
    "# Add missing params to params (zero) so alignment is safe\n",
    "for c in exog.columns:\n",
    "    if c not in params.index:\n",
    "        params.loc[c] = 0.0\n",
    "params = params.reindex(exog.columns)\n",
    "# Ensure cov_df has rows/cols for params (fill missing with 0)\n",
    "cov_df = cov_df.reindex(index=params.index, columns=params.index).fillna(0.0)\n",
    "\n",
    "# Linear predictor and delta-method CIs\n",
    "linpred = exog.values.dot(params.values)\n",
    "# Var(linpred) = row * cov * row.T for each row. Compute diagonal efficiently:\n",
    "linvar = np.einsum('ij,jk,ik->i', exog.values, cov_df.values, exog.values)\n",
    "linse = np.sqrt(np.maximum(0, linvar))\n",
    "crit = 1.96\n",
    "pred_mean = np.exp(linpred)  # inverse link for Poisson with log link\n",
    "lower = np.exp(linpred - crit * linse)\n",
    "upper = np.exp(linpred + crit * linse)\n",
    "\n",
    "poisson_predicted_groups = group_df.copy()\n",
    "poisson_predicted_groups['pred_mean'] = pred_mean\n",
    "poisson_predicted_groups['ci_lower'] = lower\n",
    "poisson_predicted_groups['ci_upper'] = upper\n",
    "\n",
    "# Add counts for reference\n",
    "counts = spills_gdf.groupby(['spill_type','Period','rurality']).size().reset_index(name='n')\n",
    "poisson_predicted_groups = poisson_predicted_groups.merge(counts, on=['spill_type','Period','rurality'], how='left')\n",
    "\n",
    "# Sort and display\n",
    "poisson_predicted_groups = poisson_predicted_groups.sort_values(['spill_type','Period','rurality']).reset_index(drop=True)\n",
    "print('\\nPredicted group means (Poisson, HC3 CI where available):')\n",
    "print(poisson_predicted_groups.to_string(index=False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "b4c26a24",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Parametric bootstrap results (median, 95% CI):\n",
      "spill_type         Period rurality    n  pred_median_boot  ci_lower_boot  ci_upper_boot\n",
      "Historical 2020 and After    Rural  558          0.609319       0.546595       0.673835\n",
      "Historical 2020 and After Suburban  169          0.420118       0.325444       0.520710\n",
      "Historical 2020 and After    Urban 2627          0.343738       0.322602       0.368300\n",
      "Historical    Before 2020    Rural  286          0.888112       0.777885       0.989510\n",
      "Historical    Before 2020 Suburban   74          0.797297       0.594595       0.972973\n",
      "Historical    Before 2020    Urban 1233          0.802920       0.757887       0.856488\n",
      "    Recent 2020 and After    Rural 2006          0.683200       0.647296       0.723330\n",
      "    Recent 2020 and After Suburban  354          0.564972       0.492867       0.639901\n",
      "    Recent 2020 and After    Urban 1247          0.637530       0.586588       0.679230\n",
      "    Recent    Before 2020    Rural 1594          0.903388       0.859112       0.947930\n",
      "    Recent    Before 2020 Suburban  206          0.791262       0.677063       0.934587\n",
      "    Recent    Before 2020    Urban 1022          0.933464       0.879648       0.986815\n"
     ]
    }
   ],
   "source": [
    "# Parametric bootstrap (Poisson) for group mean CIs — Option B\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import statsmodels.formula.api as smf\n",
    "import patsy\n",
    "\n",
    "# Number of bootstrap replications (increase to 1000+ for final results)\n",
    "B = 500\n",
    "n_groups = len(group_df)\n",
    "preds = np.full((n_groups, B), np.nan)\n",
    "failures = 0\n",
    "\n",
    "full_formula = formula  # uses the same formula string defined earlier\n",
    "# Pre-build group design matrix once\n",
    "ex_group = patsy.dmatrix(rhs, group_df, return_type='dataframe')\n",
    "\n",
    "for b in range(B):\n",
    "    # simulate outcome under fitted Poisson mean\n",
    "    y_sim = np.random.poisson(lam=poisson.fittedvalues)\n",
    "    df_sim = spills_gdf.copy()\n",
    "    df_sim['report_delay'] = y_sim\n",
    "    try:\n",
    "        m_sim = smf.glm(formula=full_formula, data=df_sim, family=sm.families.Poisson()).fit(disp=False)\n",
    "        # predict for group_df using analytic prediction from coef vector\n",
    "        p = m_sim.params.reindex(ex_group.columns).fillna(0.0)\n",
    "        lin = ex_group.values.dot(p.values)\n",
    "        preds[:, b] = np.exp(lin)\n",
    "    except Exception:\n",
    "        failures += 1\n",
    "        # leave column as NaN for this replication\n",
    "\n",
    "# Report failures\n",
    "if failures:\n",
    "    print(f'Bootstrap replications with errors: {failures} / {B}')\n",
    "\n",
    "# Compute bootstrap summaries (median and 95% CI)\n",
    "lower = np.nanpercentile(preds, 2.5, axis=1)\n",
    "upper = np.nanpercentile(preds, 97.5, axis=1)\n",
    "median = np.nanmedian(preds, axis=1)\n",
    "\n",
    "poisson_predicted_groups['pred_median_boot'] = median\n",
    "poisson_predicted_groups['ci_lower_boot'] = lower\n",
    "poisson_predicted_groups['ci_upper_boot'] = upper\n",
    "\n",
    "# Show results alongside counts\n",
    "print('\\nParametric bootstrap results (median, 95% CI):')\n",
    "print(poisson_predicted_groups[['spill_type','Period','rurality','n','pred_median_boot','ci_lower_boot','ci_upper_boot']].to_string(index=False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "be3ce0f5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Bootstrap finished — failures: 0 / 2000\n",
      "Updated bootstrap summaries (B=2000):\n",
      "spill_type         Period rurality    n  pred_median_boot  ci_lower_boot  ci_upper_boot\n",
      "Historical 2020 and After    Rural  558          0.609319       0.546595       0.675627\n",
      "Historical 2020 and After Suburban  169          0.420118       0.319527       0.514793\n",
      "Historical 2020 and After    Urban 2627          0.344119       0.322421       0.366959\n",
      "Historical    Before 2020    Rural  286          0.891608       0.779720       0.996503\n",
      "Historical    Before 2020 Suburban   74          0.783784       0.594595       0.972973\n",
      "Historical    Before 2020    Urban 1233          0.804542       0.753447       0.854826\n",
      "    Recent 2020 and After    Rural 2006          0.683450       0.649053       0.720837\n",
      "    Recent 2020 and After Suburban  354          0.562147       0.488701       0.641243\n",
      "    Recent 2020 and After    Urban 1247          0.636327       0.595008       0.680854\n",
      "    Recent    Before 2020    Rural 1594          0.903388       0.858830       0.951694\n",
      "    Recent    Before 2020 Suburban  206          0.800971       0.674757       0.922330\n",
      "    Recent    Before 2020    Urban 1022          0.935421       0.872798       0.992172\n"
     ]
    }
   ],
   "source": [
    "# Re-run parametric bootstrap with more reps (B=2000) and save draws as preds_boot\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import statsmodels.formula.api as smf\n",
    "import patsy\n",
    "\n",
    "B = 2000  # more stable CIs for reporting\n",
    "n_groups = len(group_df)\n",
    "preds_boot = np.full((n_groups, B), np.nan)\n",
    "failures = 0\n",
    "ex_group = patsy.dmatrix(rhs, group_df, return_type='dataframe')\n",
    "full_formula = formula\n",
    "\n",
    "for b in range(B):\n",
    "    y_sim = np.random.poisson(lam=poisson.fittedvalues)\n",
    "    df_sim = spills_gdf.copy()\n",
    "    df_sim['report_delay'] = y_sim\n",
    "    try:\n",
    "        m_sim = smf.glm(formula=full_formula, data=df_sim, family=sm.families.Poisson()).fit(disp=False)\n",
    "        p = m_sim.params.reindex(ex_group.columns).fillna(0.0)\n",
    "        lin = ex_group.values.dot(p.values)\n",
    "        preds_boot[:, b] = np.exp(lin)\n",
    "    except Exception:\n",
    "        failures += 1\n",
    "\n",
    "print(f'Bootstrap finished — failures: {failures} / {B}')\n",
    "\n",
    "# Update poisson_predicted_groups with more precise bootstrap CIs\n",
    "poisson_predicted_groups['pred_median_boot'] = np.nanmedian(preds_boot, axis=1)\n",
    "poisson_predicted_groups['ci_lower_boot'] = np.nanpercentile(preds_boot, 2.5, axis=1)\n",
    "poisson_predicted_groups['ci_upper_boot'] = np.nanpercentile(preds_boot, 97.5, axis=1)\n",
    "\n",
    "print('Updated bootstrap summaries (B=2000):')\n",
    "print(poisson_predicted_groups[['spill_type','Period','rurality','n','pred_median_boot','ci_lower_boot','ci_upper_boot']].to_string(index=False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "4f5ca7db",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Bootstrap contrasts:\n",
      "contrast_type spill_type         Period rurality          comparison   median  ci_lower  ci_upper  p_value\n",
      "       Period Historical                   Rural      Before - After 0.280804  0.156586  0.401350    0.000\n",
      "       Period Historical                Suburban      Before - After 0.362786  0.143191  0.583340    0.002\n",
      "       Period Historical                   Urban      Before - After 0.459794  0.405279  0.513091    0.000\n",
      "       Period     Recent                   Rural      Before - After 0.220381  0.163976  0.278512    0.000\n",
      "       Period     Recent                Suburban      Before - After 0.238207  0.087176  0.380679    0.000\n",
      "       Period     Recent                   Urban      Before - After 0.296537  0.224441  0.369485    0.000\n",
      "    SpillType            2020 and After    Rural Recent - Historical 0.072771  0.000533  0.144294    0.049\n",
      "    SpillType            2020 and After Suburban Recent - Historical 0.143842  0.019373  0.264003    0.022\n",
      "    SpillType            2020 and After    Urban Recent - Historical 0.292168  0.244246  0.342704    0.000\n",
      "    SpillType               Before 2020    Rural Recent - Historical 0.012508 -0.100730  0.124265    0.828\n",
      "    SpillType               Before 2020 Suburban Recent - Historical 0.019286 -0.207068  0.247406    0.862\n",
      "    SpillType               Before 2020    Urban Recent - Historical 0.130557  0.052961  0.208439    0.000\n"
     ]
    }
   ],
   "source": [
    "# Compute bootstrap contrasts using preds_boot\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "# Helper: find row index in group_df matching values\n",
    "def find_idx(spill_type, period, rurality):\n",
    "    mask = (group_df['spill_type'] == spill_type) & (group_df['Period'] == period) & (group_df['rurality'] == rurality)\n",
    "    matches = group_df.index[mask].tolist()\n",
    "    return matches[0] if matches else None\n",
    "\n",
    "contrast_rows = []\n",
    "# Period contrast: Before 2020 - 2020 and After for each spill_type × rurality\n",
    "for st in group_df['spill_type'].unique():\n",
    "    for r in group_df['rurality'].unique():\n",
    "        idx_before = find_idx(st, 'Before 2020', r)\n",
    "        idx_after = find_idx(st, '2020 and After', r)\n",
    "        if idx_before is None or idx_after is None:\n",
    "            continue\n",
    "        diffs = preds_boot[idx_before, :] - preds_boot[idx_after, :]\n",
    "        med = np.nanmedian(diffs)\n",
    "        lo = np.nanpercentile(diffs, 2.5)\n",
    "        hi = np.nanpercentile(diffs, 97.5)\n",
    "        # two-sided p-value: proportion of draws where diff <= 0 (or >=0), convert to two-sided\n",
    "        prop_le0 = np.nanmean(diffs <= 0)\n",
    "        p_two = 2 * min(prop_le0, 1 - prop_le0)\n",
    "        contrast_rows.append({'contrast_type':'Period','spill_type':st,'rurality':r,'comparison':'Before - After','median':med,'ci_lower':lo,'ci_upper':hi,'p_value':p_two})\n",
    "\n",
    "# Spill type contrast: Recent - Historical for each Period × rurality\n",
    "for per in group_df['Period'].unique():\n",
    "    for r in group_df['rurality'].unique():\n",
    "        idx_recent = find_idx('Recent', per, r)\n",
    "        idx_hist = find_idx('Historical', per, r)\n",
    "        if idx_recent is None or idx_hist is None:\n",
    "            continue\n",
    "        diffs = preds_boot[idx_recent, :] - preds_boot[idx_hist, :]\n",
    "        med = np.nanmedian(diffs)\n",
    "        lo = np.nanpercentile(diffs, 2.5)\n",
    "        hi = np.nanpercentile(diffs, 97.5)\n",
    "        prop_le0 = np.nanmean(diffs <= 0)\n",
    "        p_two = 2 * min(prop_le0, 1 - prop_le0)\n",
    "        contrast_rows.append({'contrast_type':'SpillType','Period':per,'rurality':r,'comparison':'Recent - Historical','median':med,'ci_lower':lo,'ci_upper':hi,'p_value':p_two})\n",
    "\n",
    "contrast_df = pd.DataFrame(contrast_rows)\n",
    "# tidy ordering\n",
    "contrast_df = contrast_df[['contrast_type','spill_type','Period','rurality','comparison','median','ci_lower','ci_upper','p_value']].fillna('')\n",
    "print('Bootstrap contrasts:')\n",
    "print(contrast_df.to_string(index=False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "0ba6ac9e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved poisson_predicted_groups_boot_final.csv and poisson_boot_contrasts.csv\n"
     ]
    }
   ],
   "source": [
    "# Save results to CSV for reporting\n",
    "poisson_predicted_groups.to_csv('poisson_predicted_groups_boot_final.csv', index=False)\n",
    "contrast_df.to_csv('poisson_boot_contrasts.csv', index=False)\n",
    "print('Saved poisson_predicted_groups_boot_final.csv and poisson_boot_contrasts.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "71c9cf97",
   "metadata": {},
   "source": [
    "## Short summary of results (for report)\n",
    "The Poisson model with parametric bootstrap shows consistent reductions in predicted reporting delay after 2020 across spill types and ruralities (median reductions ≈ 0.22–0.46 days, ~5–11 hours).\n",
    "Recent spills tend to have longer predicted delays than Historical spills, with the largest and most robust Recent>Historical gap in Urban areas (≈0.29 days post‑2020).\n",
    "These conclusions are based on model‑based inference with parametric and nonparametric bootstrap checks (cells below compute percent changes, run a nonparametric bootstrap for comparison, and plot results)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "d272a930",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Percent-change (Recent vs Historical) by Period × rurality:\n",
      "        Period rurality  median_abs_days  ci_lower_days  ci_upper_days  median_hours  median_pct\n",
      "2020 and After    Rural         0.072771       0.000533       0.144294      1.746502   12.006879\n",
      "2020 and After Suburban         0.143842       0.019373       0.264003      3.452211   34.426108\n",
      "2020 and After    Urban         0.292168       0.244246       0.342704      7.012028   85.000745\n",
      "   Before 2020    Rural         0.012508      -0.100730       0.124265      0.300182    1.405212\n",
      "   Before 2020 Suburban         0.019286      -0.207068       0.247406      0.462871    2.541924\n",
      "   Before 2020    Urban         0.130557       0.052961       0.208439      3.133372   16.184500\n",
      "Period change (Before - After) by Spill Type × rurality (days and hours):\n",
      "spill_type rurality  median_days  ci_lower_days  ci_upper_days  median_hours\n",
      "Historical    Rural     0.280804       0.156586       0.401350      6.739304\n",
      "Historical Suburban     0.362786       0.143191       0.583340      8.706861\n",
      "Historical    Urban     0.459794       0.405279       0.513091     11.035052\n",
      "    Recent    Rural     0.220381       0.163976       0.278512      5.289134\n",
      "    Recent Suburban     0.238207       0.087176       0.380679      5.716966\n",
      "    Recent    Urban     0.296537       0.224441       0.369485      7.116882\n",
      "Saved pct_change_spilltype_boot.csv and pct_change_period_boot.csv\n"
     ]
    }
   ],
   "source": [
    "# Add percent-change columns and an hours table for intuition\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "# Use preds_boot (parametric bootstrap draws) when available\n",
    "if 'preds_boot' not in globals():\n",
    "    print('preds_boot not found; run the B=2000 parametric bootstrap cell first.')\n",
    "else:\n",
    "    # Compute percent change for Recent vs Historical (within each Period × rurality)\n",
    "    pct_rows = []\n",
    "    def idx_for(st, per, r):\n",
    "        mask = (group_df['spill_type'] == st) & (group_df['Period'] == per) & (group_df['rurality'] == r)\n",
    "        res = group_df.index[mask].tolist()\n",
    "        return res[0] if res else None\n",
    "    for per in group_df['Period'].unique():\n",
    "        for r in group_df['rurality'].unique():\n",
    "            idx_rec = idx_for('Recent', per, r)\n",
    "            idx_hist = idx_for('Historical', per, r)\n",
    "            if idx_rec is None or idx_hist is None:\n",
    "                continue\n",
    "            base = preds_boot[idx_hist, :]\n",
    "            diff = preds_boot[idx_rec, :] - base\n",
    "            # relative change = diff / base (avoid divide-by-zero)\n",
    "            rel = diff / np.where(base==0, np.nan, base)\n",
    "            pct_rows.append({'Period': per, 'rurality': r, 'median_abs_days': np.nanmedian(diff), 'ci_lower_days': np.nanpercentile(diff,2.5), 'ci_upper_days': np.nanpercentile(diff,97.5), 'median_hours': 24*np.nanmedian(diff), 'median_pct': 100*np.nanmedian(rel) })\n",
    "    pct_change_spilltype = pd.DataFrame(pct_rows)\n",
    "    print('Percent-change (Recent vs Historical) by Period × rurality:')\n",
    "    print(pct_change_spilltype.to_string(index=False))\n",
    "    # Period change: Before - After (absolute days and hours)\n",
    "    per_rows = []\n",
    "    for st in group_df['spill_type'].unique():\n",
    "        for r in group_df['rurality'].unique():\n",
    "            idx_b = idx_for(st, 'Before 2020', r)\n",
    "            idx_a = idx_for(st, '2020 and After', r)\n",
    "            if idx_b is None or idx_a is None:\n",
    "                continue\n",
    "            diffs = preds_boot[idx_b, :] - preds_boot[idx_a, :]\n",
    "            per_rows.append({'spill_type': st, 'rurality': r, 'median_days': np.nanmedian(diffs), 'ci_lower_days': np.nanpercentile(diffs,2.5), 'ci_upper_days': np.nanpercentile(diffs,97.5), 'median_hours': 24*np.nanmedian(diffs) })\n",
    "    pct_change_period = pd.DataFrame(per_rows)\n",
    "    print('Period change (Before - After) by Spill Type × rurality (days and hours):')\n",
    "    print(pct_change_period.to_string(index=False))\n",
    "    # Save supplemental tables\n",
    "    pct_change_spilltype.to_csv('pct_change_spilltype_boot.csv', index=False)\n",
    "    pct_change_period.to_csv('pct_change_period_boot.csv', index=False)\n",
    "    print('Saved pct_change_spilltype_boot.csv and pct_change_period_boot.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "2ed3ea41",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nonparametric bootstrap summaries (median, 95% CI):\n",
      "spill_type         Period rurality    n  pred_median_npboot  ci_lower_npboot  ci_upper_npboot\n",
      "Historical 2020 and After    Rural  558            0.609401         0.555357         0.666082\n",
      "Historical 2020 and After Suburban  169            0.419667         0.327280         0.502960\n",
      "Historical 2020 and After    Urban 2627            0.343893         0.324574         0.366118\n",
      "Historical    Before 2020    Rural  286            0.888147         0.815597         0.958621\n",
      "Historical    Before 2020 Suburban   74            0.785262         0.606050         0.986125\n",
      "Historical    Before 2020    Urban 1233            0.806253         0.765343         0.845231\n",
      "    Recent 2020 and After    Rural 2006            0.683350         0.652627         0.712609\n",
      "    Recent 2020 and After Suburban  354            0.560903         0.487595         0.630833\n",
      "    Recent 2020 and After    Urban 1247            0.635146         0.598605         0.670400\n",
      "    Recent    Before 2020    Rural 1594            0.904542         0.866832         0.937432\n",
      "    Recent    Before 2020 Suburban  206            0.799065         0.705569         0.895307\n",
      "    Recent    Before 2020    Urban 1022            0.935655         0.889787         0.981434\n",
      "Saved preds_npboot.npy\n"
     ]
    }
   ],
   "source": [
    "# Nonparametric (case) bootstrap: resample rows with replacement and refit Poisson to get group CIs\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import statsmodels.formula.api as smf\n",
    "import patsy\n",
    "B_np = 1000\n",
    "n_groups = len(group_df)\n",
    "preds_np = np.full((n_groups, B_np), np.nan)\n",
    "failures = 0\n",
    "ex_group = patsy.dmatrix(rhs, group_df, return_type='dataframe')\n",
    "full_formula = formula\n",
    "for b in range(B_np):\n",
    "    try:\n",
    "        sample = spills_gdf.sample(frac=1.0, replace=True)\n",
    "        m_sim = smf.glm(formula=full_formula, data=sample, family=sm.families.Poisson()).fit(disp=False)\n",
    "        p = m_sim.params.reindex(ex_group.columns).fillna(0.0)\n",
    "        lin = ex_group.values.dot(p.values)\n",
    "        preds_np[:, b] = np.exp(lin)\n",
    "    except Exception:\n",
    "        failures += 1\n",
    "if failures:\n",
    "    print(f'Nonparametric bootstrap failures: {failures} / {B_np}')\n",
    "# Summaries and attach to poisson_predicted_groups\n",
    "poisson_predicted_groups['pred_median_npboot'] = np.nanmedian(preds_np, axis=1)\n",
    "poisson_predicted_groups['ci_lower_npboot'] = np.nanpercentile(preds_np, 2.5, axis=1)\n",
    "poisson_predicted_groups['ci_upper_npboot'] = np.nanpercentile(preds_np, 97.5, axis=1)\n",
    "print('Nonparametric bootstrap summaries (median, 95% CI):')\n",
    "print(poisson_predicted_groups[['spill_type','Period','rurality','n','pred_median_npboot','ci_lower_npboot','ci_upper_npboot']].to_string(index=False))\n",
    "# Save draws for reproducibility\n",
    "np.save('preds_npboot.npy', preds_np)\n",
    "print('Saved preds_npboot.npy')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "72a5f649",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 88804 characters]",
      "text/plain": [
       "<Figure size 1200x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved predicted_means_boot_CI.png\n",
      "Saved poisson_predicted_groups_boot_all.csv\n"
     ]
    }
   ],
   "source": [
    "# Plot predicted means with parametric bootstrap CIs and save figure\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "# Use poisson_predicted_groups (must exist from previous cells)\n",
    "dfp = poisson_predicted_groups.copy()\n",
    "# Create a label for plotting\n",
    "dfp['label'] = dfp['spill_type'] + ' | ' + dfp['Period'] + ' | ' + dfp['rurality']\n",
    "x = np.arange(len(dfp))\n",
    "y = dfp['pred_median_boot'].values\n",
    "yerr_low = y - dfp['ci_lower_boot'].values\n",
    "yerr_high = dfp['ci_upper_boot'].values - y\n",
    "plt.figure(figsize=(12,6))\n",
    "plt.errorbar(x, y, yerr=[yerr_low, yerr_high], fmt='o', ecolor='gray', capsize=3)\n",
    "plt.xticks(x, dfp['label'], rotation=90)\n",
    "plt.ylabel('Predicted report_delay (days)')\n",
    "plt.title('Predicted group means with parametric bootstrap 95% CI')\n",
    "plt.tight_layout()\n",
    "plt.savefig('predicted_means_boot_CI.png', dpi=150)\n",
    "plt.show()\n",
    "print('Saved predicted_means_boot_CI.png')\n",
    "# Save updated poisson_predicted_groups with all bootstrap summaries\n",
    "poisson_predicted_groups.to_csv('poisson_predicted_groups_boot_all.csv', index=False)\n",
    "print('Saved poisson_predicted_groups_boot_all.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "d3b44df3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 33444 characters]",
      "text/plain": [
       "<Figure size 800x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved bar_by_rurality_spilltype_Historical.png\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 34556 characters]",
      "text/plain": [
       "<Figure size 800x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved bar_by_rurality_spilltype_Recent.png\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 32572 characters]",
      "text/plain": [
       "<Figure size 800x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved bar_by_spilltype_rurality_Urban.png\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 33784 characters]",
      "text/plain": [
       "<Figure size 800x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved bar_by_spilltype_rurality_Suburban.png\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 32812 characters]",
      "text/plain": [
       "<Figure size 800x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved bar_by_spilltype_rurality_Rural.png\n"
     ]
    }
   ],
   "source": [
    "# Create grouped bar charts: (A) for each spill_type show rurality grouped bars (Before vs After),\n",
    "# and (B) for each rurality show spill_type grouped bars (Before vs After).\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "# Verify required data\n",
    "if 'poisson_predicted_groups' not in globals():\n",
    "    print('poisson_predicted_groups not found - run the prediction/bootstrap cells first')\n",
    "else:\n",
    "    df = poisson_predicted_groups.copy()\n",
    "    # Ensure required columns exist\n",
    "    required = {'spill_type','Period','rurality','pred_median_boot','ci_lower_boot','ci_upper_boot'}\n",
    "    if not required.issubset(set(df.columns)):\n",
    "        print('Missing required columns in poisson_predicted_groups:', required - set(df.columns))\n",
    "    else:\n",
    "        period_order = ['Before 2020','2020 and After']\n",
    "        rural_order = ['Urban','Suburban','Rural']\n",
    "        # (A) by spill_type across rurality\n",
    "        for st in sorted(df['spill_type'].unique()):\n",
    "            sub = df[df['spill_type']==st].copy()\n",
    "            # reindex to ensure consistent ordering\n",
    "            idx = pd.MultiIndex.from_product([rural_order, period_order], names=['rurality','Period'])\n",
    "            sub = sub.set_index(['rurality','Period']).reindex(idx).reset_index()\n",
    "            means = sub['pred_median_boot'].values.reshape(len(rural_order), 2)\n",
    "            lower = sub['ci_lower_boot'].values.reshape(len(rural_order), 2)\n",
    "            upper = sub['ci_upper_boot'].values.reshape(len(rural_order), 2)\n",
    "            err_low = means - lower\n",
    "            err_high = upper - means\n",
    "            x = np.arange(len(rural_order))\n",
    "            width = 0.35\n",
    "            fig, ax = plt.subplots(figsize=(8,4))\n",
    "            ax.bar(x - width/2, means[:,0], width, yerr=[err_low[:,0], err_high[:,0]], label='Before 2020', capsize=5, color='#4C72B0')\n",
    "            ax.bar(x + width/2, means[:,1], width, yerr=[err_low[:,1], err_high[:,1]], label='2020 and After', capsize=5, color='#55A868')\n",
    "            ax.set_xticks(x)\n",
    "            ax.set_xticklabels(rural_order)\n",
    "            ax.set_ylabel('Predicted report_delay (days)')\n",
    "            ax.set_title(f'Predicted mean report_delay by rurality – Spill type: {st}')\n",
    "            ax.legend()\n",
    "            plt.tight_layout()\n",
    "            fname = f'bar_by_rurality_spilltype_{st.replace(' ','_')}.png'\n",
    "            plt.savefig(fname, dpi=150)\n",
    "            plt.show()\n",
    "            print(f'Saved {fname}')\n",
    "        # (B) by rurality across spill_type\n",
    "        for r in rural_order:\n",
    "            sub = df[df['rurality']==r].copy()\n",
    "            spill_order = sorted(sub['spill_type'].unique())\n",
    "            idx = pd.MultiIndex.from_product([spill_order, period_order], names=['spill_type','Period'])\n",
    "            sub = sub.set_index(['spill_type','Period']).reindex(idx).reset_index()\n",
    "            means = sub['pred_median_boot'].values.reshape(len(spill_order), 2)\n",
    "            lower = sub['ci_lower_boot'].values.reshape(len(spill_order), 2)\n",
    "            upper = sub['ci_upper_boot'].values.reshape(len(spill_order), 2)\n",
    "            err_low = means - lower\n",
    "            err_high = upper - means\n",
    "            x = np.arange(len(spill_order))\n",
    "            width = 0.35\n",
    "            fig, ax = plt.subplots(figsize=(8,4))\n",
    "            ax.bar(x - width/2, means[:,0], width, yerr=[err_low[:,0], err_high[:,0]], label='Before 2020', capsize=5, color='#4C72B0')\n",
    "            ax.bar(x + width/2, means[:,1], width, yerr=[err_low[:,1], err_high[:,1]], label='2020 and After', capsize=5, color='#55A868')\n",
    "            ax.set_xticks(x)\n",
    "            ax.set_xticklabels(spill_order)\n",
    "            ax.set_ylabel('Predicted report_delay (days)')\n",
    "            ax.set_title(f'Predicted mean report_delay by spill type – Rurality: {r}')\n",
    "            ax.legend()\n",
    "            plt.tight_layout()\n",
    "            fname = f'bar_by_spilltype_rurality_{r}.png'\n",
    "            plt.savefig(fname, dpi=150)\n",
    "            plt.show()\n",
    "            print(f'Saved {fname}')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bcd6ba5b",
   "metadata": {},
   "source": [
    "# Methods\n",
    "\n",
    "## Data and Sample\n",
    "\n",
    "- **Source:** Incident-level Colorado spills dataset (spatial fields preserved).\n",
    "- **Sample restriction:** Analysis limited to discovery dates from 2015–2024 and the three counties with the largest number of spills (top‑3 counties), consistent with study focus.\n",
    "- **Outcome:** `report_delay`, defined as days between Date of Discovery and Initial Report Date (non‑negative).\n",
    "- **Outlier removal:** Used the interquartile range (IQR) rule with lower bound truncated to zero (`lower = max(0, Q1 − 1.5·IQR)`, `upper = Q3 + 1.5·IQR`).\n",
    "- **Key covariates:** \n",
    "    - Spill Type (Historical vs Recent)\n",
    "    - Period (Before 2020 vs 2020 and After)\n",
    "    - Rurality classified from RUCA codes (Urban, Suburban, Rural)\n",
    "- **Exclusions:** Observations with Unknown RUCA were dropped.\n",
    "\n",
    "## Modeling Approach\n",
    "\n",
    "- **Primary model:** Poisson generalized linear model (log link) with full three‑way interaction:\n",
    "    ```\n",
    "    report_delay ~ C(spill_type) * C(Period) * C(rurality)\n",
    "    ```\n",
    "- **Interpretation:** The three‑way interaction allows separate predicted means for each SpillType × Period × rurality cell.\n",
    "\n",
    "## Inference and Contrasts\n",
    "\n",
    "- **Point predictions:** Predicted group means (days) obtained from the fitted Poisson model.\n",
    "- **Primary contrasts:**\n",
    "    - **Period contrasts:** Predicted mean (Before 2020) − predicted mean (2020 and After) within each SpillType × rurality cell (positive → larger delays before 2020).\n",
    "    - **SpillType contrasts:** Predicted mean (Recent) − predicted mean (Historical) within each Period × rurality cell (positive → Recent > Historical).\n",
    "- **Uncertainty:** Parametric (model‑based) bootstrap used as the main uncertainty estimator.\n",
    "    - Simulate outcomes \\( Y_{sim} \\sim \\text{Poisson}(\\hat{\\mu}) \\) under the fitted model.\n",
    "    - Refit the Poisson to each simulated dataset.\n",
    "    - Compute predicted group means and take percentiles of the resulting distribution.\n",
    "    - Final parametric bootstrap used \\( B = 2{,}000 \\) replications.\n",
    "    - Two‑sided bootstrap p‑values: \\( 2 \\cdot \\min\\{\\Pr(\\text{diff} \\leq 0), \\Pr(\\text{diff} \\geq 0)\\} \\) across draws.\n",
    "- **Sensitivity:**\n",
    "    - Negative Binomial attempts: MLE collapsed toward Poisson (\\( \\alpha \\approx 0 \\)), unstable estimates.\n",
    "    - Nonparametric (case) bootstrap (resample rows with replacement, \\( B = 1{,}000 \\)) run to check robustness of group CIs.\n",
    "- **Diagnostics and reporting:** Pearson chi‑square dispersion reported. All model code used Python (`pandas`, `geopandas`, `patsy`, `statsmodels`, `numpy`). Results, bootstrap draws, and figures saved to CSV/PNG for reproducibility.\n",
    "\n",
    "# Results\n",
    "\n",
    "## Sample and Diagnostics\n",
    "\n",
    "- **Final analytic sample:** 11,376 observations (after filtering and outlier removal).\n",
    "- **Model diagnostics:** Poisson fit produced evidence of underdispersion (Pearson χ²/df ≈ 0.69). Negative Binomial MLE attempts did not stabilize (\\( \\alpha \\to 0 \\)), so Poisson specification with bootstrap‑based inference was retained.\n",
    "\n",
    "## Primary Contrasts (Bootstrap Medians, 95% Bootstrap CI, Two‑Sided Bootstrap p)\n",
    "\n",
    "### Period Contrasts (Before 2020 − 2020 and After)\n",
    "*Positive numbers indicate larger predicted delays before 2020 (i.e., delays decreased after 2020).*\n",
    "\n",
    "| Spill Type   | Rurality  | Median (days) | 95% CI         | p-value | Hours (median × 24) |\n",
    "|--------------|-----------|---------------|----------------|---------|---------------------|\n",
    "| Historical   | Urban     | 0.460         | 0.404–0.517    | <0.001  | ≈ 11.0              |\n",
    "| Historical   | Suburban  | 0.359         | 0.142–0.579    | 0.001   | ≈ 8.6               |\n",
    "| Historical   | Rural     | 0.275         | 0.145–0.402    | <0.001  | ≈ 6.6               |\n",
    "| Recent       | Urban     | 0.299         | 0.222–0.375    | <0.001  | ≈ 7.2               |\n",
    "| Recent       | Suburban  | 0.238         | 0.095–0.388    | <0.001  | ≈ 5.7               |\n",
    "| Recent       | Rural     | 0.220         | 0.160–0.277    | <0.001  | ≈ 5.3               |\n",
    "\n",
    "**Interpretation:** Across spill types and ruralities, predicted reporting delay fell after 2020 by roughly 0.22–0.46 days (≈5–11 hours). All Period contrasts are statistically robust by bootstrap p‑values.\n",
    "\n",
    "### SpillType Contrasts (Recent − Historical)\n",
    "*Positive numbers indicate Recent spills have longer predicted delays than Historical spills.*\n",
    "\n",
    "#### 2020 and After\n",
    "| Rurality  | Median (days) | 95% CI         | p-value | Hours |\n",
    "|-----------|---------------|----------------|---------|-------|\n",
    "| Urban     | 0.291         | 0.244–0.341    | <0.001  | ≈ 7.0 |\n",
    "| Suburban  | 0.144         | 0.015–0.262    | 0.029   | ≈ 3.5 |\n",
    "| Rural     | 0.0755        | 0.0019–0.1495  | 0.045   | ≈ 1.8 |\n",
    "\n",
    "#### Before 2020\n",
    "| Rurality  | Median (days) | 95% CI         | p-value | Hours |\n",
    "|-----------|---------------|----------------|---------|-------|\n",
    "| Urban     | 0.129         | 0.050–0.211    | 0.002   | ≈ 3.1 |\n",
    "| Suburban  | 0.0205        | −0.222–0.244   | 0.85    | n.s.  |\n",
    "| Rural     | 0.0194        | −0.0981–0.1334 | 0.753   | n.s.  |\n",
    "\n",
    "**Interpretation:** The Recent vs Historical difference is largest and most consistent in Urban areas (≈3–7 hours depending on period), particularly after 2020. In Suburban and Rural areas the Recent > Historical gap is smaller and often not statistically distinguishable before 2020.\n",
    "\n",
    "## Sensitivity and Robustness\n",
    "\n",
    "- **Nonparametric (case) bootstrap (\\( B = 1{,}000 \\))** produced broadly similar group CIs to the parametric bootstrap, supporting the direction and relative magnitude of the reported contrasts (detailed tables and saved draws are available in the repository).\n",
    "- **Effect size:** Estimated effects are small in absolute units. Although many contrasts are statistically significant under bootstrap inference, practical significance should be judged relative to policy thresholds (e.g., hours of delay important for response operations).\n",
    "\n",
    "## Limitations\n",
    "\n",
    "- **Model dependence:** Inference relies on the fitted model and the bootstrap procedure; the dataset showed underdispersion relative to Poisson assumptions. While bootstrap CIs mitigate reliance on analytic SEs, model misspecification could still bias point estimates and uncertainty.\n",
    "- **Small cell counts:** Several SpillType × Period × rurality cells have small n; estimates and CIs for those cells are less stable and should be interpreted cautiously.\n",
    "- **Multiple comparisons:** Many contrasts were evaluated and reported p‑values are unadjusted; emphasize effect sizes with CIs rather than lone p‑values in policy reporting.\n",
    "\n",
    "## Reproducibility\n",
    "\n",
    "- All code used Python (`pandas`, `geopandas`, `statsmodels`, `patsy`, `numpy`, `matplotlib`).\n",
    "- Key outputs (predicted means, bootstrap draws, contrast tables, and figures) were saved to CSV/PNG in the analysis folder for inclusion in supplementary materials."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1f786261",
   "metadata": {},
   "source": [
    "## Narrative Summary of Reporting Delay Analysis\n",
    "\n",
    "### Analytic Sample and Model\n",
    "\n",
    "- **Sample size:** N = 11,376 (after IQR outlier trimming)\n",
    "- **Model:** Poisson GLM with full interaction: `C(spill_type) × C(Period) × C(rurality)`\n",
    "- **Uncertainty:** Parametric bootstrap (B = 2,000)\n",
    "\n",
    "### Main Findings\n",
    "\n",
    "- **Reporting delays declined after 2020** across spill types and rurality.\n",
    "- **Estimated reduction (Before 2020 − 2020 and After):**  \n",
    "    - Range: **0.22–0.46 days** (≈5–11 hours)\n",
    "    - **Historical spills, Urban:**  \n",
    "        - Median reduction: **0.460 days**  \n",
    "        - 95% bootstrap CI: **0.404–0.517**  \n",
    "        - p < 0.001\n",
    "    - **Recent spills, Urban:**  \n",
    "        - Median reduction: **0.299 days**  \n",
    "        - 95% CI: **0.222–0.375**  \n",
    "        - p < 0.001\n",
    "\n",
    "- **Spill Type Comparison:**  \n",
    "    - Recent spills generally have longer predicted delays than Historical spills.\n",
    "    - **Largest and most robust gap:** Urban settings after 2020\n",
    "        - **Recent − Historical, Urban, 2020 and After:**  \n",
    "            - Difference: **0.291 days** (≈7.0 hours)  \n",
    "            - 95% CI: **0.244–0.341**  \n",
    "            - p < 0.001\n",
    "    - **Suburban and Rural cells before 2020:**  \n",
    "        - Differences smaller and often not statistically significant  \n",
    "        - Example: Suburban, Before 2020: **0.020 days** (95% CI −0.222–0.244, p ≈ 0.85)\n",
    "\n",
    "### Limitations\n",
    "\n",
    "- **Model dependence:** Poisson fit showed underdispersion (Pearson χ²/df ≈ 0.69)\n",
    "- **Bootstrap reliance:** Results rely on bootstrap procedures for uncertainty quantification\n",
    "- **Sensitivity:** Nonparametric case bootstrap (B = 1,000) produced similar group CIs\n",
    "- **Small sample sizes:** Some SpillType × Period × rurality cells have limited precision\n",
    "- **Multiple comparisons:** p-values unadjusted; emphasize effect sizes and bootstrap CIs for policy\n",
    "\n",
    "---\n",
    "\n",
    "### Figure Caption\n",
    "\n",
    "**Figure X.** Predicted reporting delays (days) for each Spill Type × Period × rurality cell with parametric bootstrap (B = 2,000) 95% confidence intervals.  \n",
    "Points show bootstrap medians of the model-predicted group means; vertical bars are 2.5th–97.5th percentiles from the bootstrap distribution."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "5a421918",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitted ITS for Historical / Urban: n_months=117, immediate=-0.626 (p=0.002), slope_change=0.0088 (p=0.023)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 56652 characters]",
      "text/plain": [
       "<Figure size 800x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved its_plot_Historical_Urban.png\n",
      "Fitted ITS for Historical / Suburban: n_months=65, immediate=-1.534 (p=0.006), slope_change=0.0181 (p=0.051)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 52104 characters]",
      "text/plain": [
       "<Figure size 800x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved its_plot_Historical_Suburban.png\n",
      "Fitted ITS for Historical / Rural: n_months=105, immediate=-0.233 (p=0.461), slope_change=0.0001 (p=0.992)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 50388 characters]",
      "text/plain": [
       "<Figure size 800x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved its_plot_Historical_Rural.png\n",
      "Fitted ITS for Recent / Urban: n_months=118, immediate=-0.168 (p=0.388), slope_change=0.0016 (p=0.600)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 55108 characters]",
      "text/plain": [
       "<Figure size 800x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved its_plot_Recent_Urban.png\n",
      "Fitted ITS for Recent / Suburban: n_months=92, immediate=-0.205 (p=0.547), slope_change=-0.0047 (p=0.392)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 51008 characters]",
      "text/plain": [
       "<Figure size 800x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved its_plot_Recent_Suburban.png\n",
      "Fitted ITS for Recent / Rural: n_months=118, immediate=-0.020 (p=0.927), slope_change=-0.0029 (p=0.318)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 49744 characters]",
      "text/plain": [
       "<Figure size 800x400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved its_plot_Recent_Rural.png\n",
      "Saved its_summary.csv\n",
      "ITS analysis complete.\n"
     ]
    }
   ],
   "source": [
    "# Improved Interrupted Time Series (ITS) by Spill Type × Rurality\n",
    "# - Aggregates monthly means, fits separate ITS OLS models,\n",
    "# - Reports coefficients with Newey-West (HAC) standard errors,\n",
    "# - Saves a CSV summary of results and individual ITS plots (PNG).\n",
    "\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import statsmodels.formula.api as smf\n",
    "import statsmodels.api as sm\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# Prepare monthly aggregated dataset\n",
    "spills_gdf['report_month'] = spills_gdf['Initial Report Date'].dt.to_period('M').dt.to_timestamp()\n",
    "monthly = (\n",
    "    spills_gdf\n",
    "    .groupby(['report_month','spill_type','rurality'], observed=True)\n",
    "    ['report_delay']\n",
    "    .mean()\n",
    "    .reset_index()\n",
    "    .sort_values('report_month')\n",
    ")\n",
    "\n",
    "# ITS covariates\n",
    "monthly = monthly.dropna(subset=['report_delay'])\n",
    "monthly['time'] = ((monthly['report_month'] - monthly['report_month'].min()).dt.days/30.0).astype(float)\n",
    "monthly['post_2020'] = (monthly['report_month'] >= pd.Timestamp('2020-01-01')).astype(int)\n",
    "monthly['time_post'] = monthly['time'] * monthly['post_2020']\n",
    "\n",
    "# Storage\n",
    "its_results = {}\n",
    "summary_rows = []\n",
    "\n",
    "# Loop by spill_type × rurality\n",
    "for stype in sorted(monthly['spill_type'].dropna().unique()):\n",
    "    for rur in ['Urban','Suburban','Rural']:\n",
    "        df = monthly[(monthly['spill_type']==stype) & (monthly['rurality']==rur)].copy()\n",
    "        df = df.sort_values('report_month')\n",
    "        n = len(df)\n",
    "        if n < 8:\n",
    "            summary_rows.append({\n",
    "                'spill_type': stype,\n",
    "                'rurality': rur,\n",
    "                'n_months': n,\n",
    "                'status': 'insufficient'\n",
    "            })\n",
    "            print(f\"Skipping {stype} / {rur}: only {n} months (need >=8)\")\n",
    "            continue\n",
    "\n",
    "        # Fit OLS ITS: level and slope change\n",
    "        formula = 'report_delay ~ time + post_2020 + time_post'\n",
    "        model = smf.ols(formula, data=df).fit()\n",
    "\n",
    "        # Newey-West HAC se (lag=3 months default, adjust if needed)\n",
    "        try:\n",
    "            hac_res = model.get_robustcov_results(cov_type='HAC', maxlags=3)\n",
    "            # hac_res attributes may be numpy arrays; coerce to pandas Series/DataFrame keyed by model.param index\n",
    "            raw_params = hac_res.params\n",
    "            raw_bse = getattr(hac_res, 'bse', None)\n",
    "            raw_pvalues = getattr(hac_res, 'pvalues', None)\n",
    "            raw_ci = None\n",
    "            try:\n",
    "                raw_ci = hac_res.conf_int()\n",
    "            except Exception:\n",
    "                raw_ci = None\n",
    "\n",
    "            idx = model.params.index\n",
    "            # params\n",
    "            if isinstance(raw_params, np.ndarray):\n",
    "                params = pd.Series(raw_params, index=idx)\n",
    "            else:\n",
    "                params = pd.Series(raw_params, index=idx)\n",
    "            # bse\n",
    "            if raw_bse is None:\n",
    "                bse = pd.Series(model.bse.values, index=idx)\n",
    "            elif isinstance(raw_bse, np.ndarray):\n",
    "                bse = pd.Series(raw_bse, index=idx)\n",
    "            else:\n",
    "                bse = pd.Series(raw_bse, index=idx)\n",
    "            # pvalues\n",
    "            if raw_pvalues is None:\n",
    "                pvalues = pd.Series(model.pvalues.values, index=idx)\n",
    "            elif isinstance(raw_pvalues, np.ndarray):\n",
    "                pvalues = pd.Series(raw_pvalues, index=idx)\n",
    "            else:\n",
    "                pvalues = pd.Series(raw_pvalues, index=idx)\n",
    "            # conf_int\n",
    "            if raw_ci is None:\n",
    "                conf_int = pd.DataFrame(model.conf_int().values, index=idx, columns=['ci_lower','ci_upper'])\n",
    "            elif isinstance(raw_ci, np.ndarray):\n",
    "                # raw_ci likely shape (k,2)\n",
    "                conf_int = pd.DataFrame(raw_ci, index=idx, columns=['ci_lower','ci_upper'])\n",
    "            else:\n",
    "                try:\n",
    "                    conf_int = pd.DataFrame(raw_ci, index=idx, columns=['ci_lower','ci_upper'])\n",
    "                except Exception:\n",
    "                    conf_int = pd.DataFrame(raw_ci)\n",
    "\n",
    "            cov_type_used = 'HAC(3)'\n",
    "        except Exception as e:\n",
    "            # fallback to OLS se\n",
    "            params = pd.Series(model.params.values, index=model.params.index)\n",
    "            bse = pd.Series(model.bse.values, index=model.params.index)\n",
    "            pvalues = pd.Series(model.pvalues.values, index=model.params.index)\n",
    "            ci = model.conf_int()\n",
    "            conf_int = pd.DataFrame(ci.values, index=model.params.index, columns=['ci_lower','ci_upper'])\n",
    "            cov_type_used = 'OLS'\n",
    "            print(f\"Warning: HAC failed for {stype}/{rur} — using OLS SEs: {e}\")\n",
    "\n",
    "        # store results\n",
    "        its_results[(stype, rur)] = (model, df, params, bse, pvalues, conf_int, cov_type_used)\n",
    "        summary_rows.append({\n",
    "            'spill_type': stype,\n",
    "            'rurality': rur,\n",
    "            'n_months': n,\n",
    "            'status': 'ok',\n",
    "            'cov_type': cov_type_used,\n",
    "            'R_squared': model.rsquared\n",
    "        })\n",
    "\n",
    "        # Key coef extraction: immediate level change (post_2020) and slope change (time_post)\n",
    "        immediate = params.get('post_2020', np.nan)\n",
    "        immediate_se = bse.get('post_2020', np.nan)\n",
    "        immediate_p = pvalues.get('post_2020', np.nan)\n",
    "        slope = params.get('time_post', np.nan)\n",
    "        slope_se = bse.get('time_post', np.nan)\n",
    "        slope_p = pvalues.get('time_post', np.nan)\n",
    "\n",
    "        print(f\"Fitted ITS for {stype} / {rur}: n_months={n}, immediate={immediate:.3f} (p={immediate_p:.3f}), slope_change={slope:.4f} (p={slope_p:.3f})\")\n",
    "\n",
    "        # Plot observed vs fitted trends with vertical intervention line\n",
    "        plt.figure(figsize=(8,4))\n",
    "        plt.scatter(df['report_month'], df['report_delay'], color='gray', alpha=0.7, label='Observed')\n",
    "        df['fitted'] = model.predict(df)\n",
    "        # plot pre and post separately for clarity\n",
    "        pre = df[df['post_2020']==0]\n",
    "        post = df[df['post_2020']==1]\n",
    "        if len(pre)>0:\n",
    "            plt.plot(pre['report_month'], pre['fitted'], color='red', lw=2, label='Fitted (pre)')\n",
    "        if len(post)>0:\n",
    "            plt.plot(post['report_month'], post['fitted'], color='blue', lw=2, label='Fitted (post)')\n",
    "        plt.axvline(pd.Timestamp('2020-01-01'), linestyle='--', color='black', label='2020-01-01')\n",
    "        plt.title(f'ITS: {stype} - {rur} (n={n})')\n",
    "        plt.xlabel('Month')\n",
    "        plt.ylabel('Mean report_delay (days)')\n",
    "        plt.legend()\n",
    "        plt.tight_layout()\n",
    "        fname = f\"its_plot_{stype.replace(' ','_')}_{rur}.png\"\n",
    "        plt.savefig(fname, dpi=150)\n",
    "        plt.show()\n",
    "        print(f'Saved {fname}')\n",
    "\n",
    "# Save summary\n",
    "summary_df = pd.DataFrame(summary_rows)\n",
    "summary_df.to_csv('its_summary.csv', index=False)\n",
    "print('Saved its_summary.csv')\n",
    "print('ITS analysis complete.')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d790e77c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "47248515",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running case bootstrap for 6 ITS models with B=1000 draws...\n",
      "Saved its_coef_bootstrap.csv\n",
      "Saved its_summary_with_boot.csv\n",
      "Building combined ITS figure...\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 170748 characters]",
      "text/plain": [
       "<Figure size 1800x700 with 6 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved its_combined.png\n",
      "Bootstrap + combined figure cell finished.\n"
     ]
    }
   ],
   "source": [
    "# Bootstrap coefficient inference for ITS models and combined multipanel figure\n",
    "# - Case bootstrap (resample months) to get CI and bootstrap p-values for 'post_2020' and 'time_post'\n",
    "# - B = 1000 by default; adjust if you want more precision\n",
    "# - Then build a combined multipanel figure (for manuscript) and save PNG\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import statsmodels.formula.api as smf\n",
    "\n",
    "B = 1000\n",
    "coef_rows = []\n",
    "\n",
    "if 'its_results' not in globals() or len(its_results) == 0:\n",
    "    print('its_results not found or empty — run the ITS cell first to produce models in `its_results`.')\n",
    "else:\n",
    "    print(f'Running case bootstrap for {len(its_results)} ITS models with B={B} draws...')\n",
    "    for (stype, rur), (model, df, params, bse, pvalues, conf_int, cov_used) in its_results.items():\n",
    "        # We'll bootstrap by resampling rows (months) with replacement\n",
    "        coefs_post = np.full(B, np.nan)\n",
    "        coefs_timepost = np.full(B, np.nan)\n",
    "        failures = 0\n",
    "        for b in range(B):\n",
    "            try:\n",
    "                sample = df.sample(frac=1.0, replace=True)\n",
    "                m = smf.ols('report_delay ~ time + post_2020 + time_post', data=sample).fit()\n",
    "                # Ensure coefficients present; if missing, set nan\n",
    "                coefs_post[b] = m.params.get('post_2020', np.nan)\n",
    "                coefs_timepost[b] = m.params.get('time_post', np.nan)\n",
    "            except Exception:\n",
    "                failures += 1\n",
    "                # leave as NaN\n",
    "        if failures:\n",
    "            print(f'  Note: {failures} bootstrap failures for {stype}/{rur} (out of {B})')\n",
    "\n",
    "        # Summaries\n",
    "        med_post = np.nanmedian(coefs_post)\n",
    "        lo_post = np.nanpercentile(coefs_post, 2.5)\n",
    "        hi_post = np.nanpercentile(coefs_post, 97.5)\n",
    "        prop_le0 = np.nanmean(coefs_post <= 0)\n",
    "        p_post = 2 * min(prop_le0, 1 - prop_le0)\n",
    "\n",
    "        med_sp = np.nanmedian(coefs_timepost)\n",
    "        lo_sp = np.nanpercentile(coefs_timepost, 2.5)\n",
    "        hi_sp = np.nanpercentile(coefs_timepost, 97.5)\n",
    "        prop_le0_sp = np.nanmean(coefs_timepost <= 0)\n",
    "        p_sp = 2 * min(prop_le0_sp, 1 - prop_le0_sp)\n",
    "\n",
    "        coef_rows.append({\n",
    "            'spill_type': stype,\n",
    "            'rurality': rur,\n",
    "            'n_months': len(df),\n",
    "            'cov_type_used': cov_used,\n",
    "            # immediate effect (level)\n",
    "            'immediate_median': med_post,\n",
    "            'immediate_ci_lower': lo_post,\n",
    "            'immediate_ci_upper': hi_post,\n",
    "            'immediate_p_boot': p_post,\n",
    "            # slope change\n",
    "            'slope_median': med_sp,\n",
    "            'slope_ci_lower': lo_sp,\n",
    "            'slope_ci_upper': hi_sp,\n",
    "            'slope_p_boot': p_sp\n",
    "        })\n",
    "\n",
    "    coef_df = pd.DataFrame(coef_rows)\n",
    "    coef_df.to_csv('its_coef_bootstrap.csv', index=False)\n",
    "    print('Saved its_coef_bootstrap.csv')\n",
    "\n",
    "    # Merge bootstrap summaries into its_summary if it exists\n",
    "    try:\n",
    "        summary_df = pd.read_csv('its_summary.csv')\n",
    "        merged = summary_df.merge(coef_df, on=['spill_type','rurality','n_months'], how='left')\n",
    "        merged.to_csv('its_summary_with_boot.csv', index=False)\n",
    "        print('Saved its_summary_with_boot.csv')\n",
    "    except Exception:\n",
    "        coef_df.to_csv('its_summary_with_boot.csv', index=False)\n",
    "        print('Saved its_summary_with_boot.csv (no prior its_summary.csv found)')\n",
    "\n",
    "    # Combined multipanel figure for manuscript\n",
    "    print('Building combined ITS figure...')\n",
    "    keys = list(its_results.keys())\n",
    "    n = len(keys)\n",
    "    if n == 0:\n",
    "        print('No ITS models to plot')\n",
    "    else:\n",
    "        cols = min(3, n)\n",
    "        rows = (n + cols - 1) // cols\n",
    "        fig, axes = plt.subplots(rows, cols, figsize=(6*cols, 3.5*rows), sharex=False)\n",
    "        if rows == 1 and cols == 1:\n",
    "            axes = np.array([[axes]])\n",
    "        elif rows == 1:\n",
    "            axes = np.array([axes])\n",
    "        axes_flat = axes.flatten()\n",
    "\n",
    "        for i, key in enumerate(keys):\n",
    "            stype, rur = key\n",
    "            model, df, params, bse, pvalues, conf_int, cov_used = its_results[key]\n",
    "            ax = axes_flat[i]\n",
    "            ax.scatter(df['report_month'], df['report_delay'], color='gray', alpha=0.7, s=25)\n",
    "            df = df.sort_values('report_month')\n",
    "            df['fitted'] = model.predict(df)\n",
    "            pre = df[df['post_2020']==0]\n",
    "            post = df[df['post_2020']==1]\n",
    "            if len(pre) > 0:\n",
    "                ax.plot(pre['report_month'], pre['fitted'], color='#d73027', lw=2)\n",
    "            if len(post) > 0:\n",
    "                ax.plot(post['report_month'], post['fitted'], color='#1a9850', lw=2)\n",
    "            ax.axvline(pd.Timestamp('2020-01-01'), linestyle='--', color='black', alpha=0.8)\n",
    "            ax.set_title(f'{stype} — {rur} (n={len(df)})', fontsize=9)\n",
    "            ax.set_ylabel('Report delay (days)')\n",
    "            ax.tick_params(axis='x', rotation=40)\n",
    "\n",
    "        # Hide any empty subplots\n",
    "        total_axes = axes_flat.size\n",
    "        for j in range(n, total_axes):\n",
    "            axes_flat[j].set_visible(False)\n",
    "\n",
    "        plt.tight_layout()\n",
    "        plt.suptitle('ITS: State Agency Mission Change Impact (by Spill Type × Rurality)', y=1.02, fontsize=12)\n",
    "        outname = 'its_combined.png'\n",
    "        plt.savefig(outname, dpi=200, bbox_inches='tight')\n",
    "        plt.show()\n",
    "        print(f'Saved {outname}')\n",
    "\n",
    "print('Bootstrap + combined figure cell finished.')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "e26940c3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved monthly_full_reindexed.csv\n",
      "Saved its_poisson_summary.csv and its_ols_summary.csv\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 384404 characters]",
      "text/plain": [
       "<Figure size 1800x700 with 12 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved its_combined_reindexed.png\n",
      "Reindex + counts-based ITS finished.\n"
     ]
    }
   ],
   "source": [
    "# Reindex months to include zero-event months and run counts-based Poisson ITS + OLS ITS on mean_delay\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import statsmodels.formula.api as smf\n",
    "import statsmodels.api as sm\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# Build full month index\n",
    "min_month = spills_gdf['Initial Report Date'].min().to_period('M').to_timestamp()\n",
    "max_month = spills_gdf['Initial Report Date'].max().to_period('M').to_timestamp()\n",
    "full_months = pd.date_range(min_month, max_month, freq='MS')\n",
    "\n",
    "# Aggregate counts and mean delay per month × spill_type × rurality\n",
    "agg = (spills_gdf\n",
    "       .groupby(['report_month','spill_type','rurality'], observed=True)\n",
    "       .agg(n_events=('report_delay','size'), mean_delay=('report_delay','mean'))\n",
    "       .reset_index())\n",
    "\n",
    "# Ensure report_month is timestamp\n",
    "agg['report_month'] = pd.to_datetime(agg['report_month'])\n",
    "\n",
    "# Reindex per panel to include all months\n",
    "panels = []\n",
    "for st in sorted(agg['spill_type'].dropna().unique()):\n",
    "    for r in ['Urban','Suburban','Rural']:\n",
    "        sub = agg[(agg['spill_type']==st) & (agg['rurality']==r)].set_index('report_month')\n",
    "        sub = sub.reindex(full_months).rename_axis('report_month').reset_index()\n",
    "        sub['spill_type'] = st\n",
    "        sub['rurality'] = r\n",
    "        # fill n_events=0 where missing; mean_delay remains NaN for months with no events\n",
    "        sub['n_events'] = sub['n_events'].fillna(0).astype(int)\n",
    "        panels.append(sub)\n",
    "monthly_full = pd.concat(panels, ignore_index=True)\n",
    "\n",
    "# Add ITS covariates\n",
    "monthly_full['time'] = ((monthly_full['report_month'] - monthly_full['report_month'].min()).dt.days/30.0).astype(float)\n",
    "monthly_full['post_2020'] = (monthly_full['report_month'] >= pd.Timestamp('2020-01-01')).astype(int)\n",
    "monthly_full['time_post'] = monthly_full['time'] * monthly_full['post_2020']\n",
    "\n",
    "# Save monthly_full for inspection\n",
    "monthly_full.to_csv('monthly_full_reindexed.csv', index=False)\n",
    "print('Saved monthly_full_reindexed.csv')\n",
    "\n",
    "# Fit Poisson ITS on counts and OLS ITS on mean_delay (months with n>0)\n",
    "poisson_results = {}\n",
    "ols_results = {}\n",
    "poisson_rows = []\n",
    "ols_rows = []\n",
    "\n",
    "for st in sorted(monthly_full['spill_type'].unique()):\n",
    "    for r in ['Urban','Suburban','Rural']:\n",
    "        dfp = monthly_full[(monthly_full['spill_type']==st) & (monthly_full['rurality']==r)].copy()\n",
    "        n_months = len(dfp)\n",
    "        # Poisson ITS on counts (uses zeros)\n",
    "        try:\n",
    "            formula_counts = 'n_events ~ time + post_2020 + time_post'\n",
    "            glm = smf.glm(formula=formula_counts, data=dfp, family=sm.families.Poisson()).fit()\n",
    "            try:\n",
    "                glm_hac = glm.get_robustcov_results(cov_type='HAC', maxlags=3)\n",
    "                params_c = pd.Series(glm_hac.params.values, index=glm_hac.params.index)\n",
    "                pvals_c = pd.Series(glm_hac.pvalues.values, index=glm_hac.params.index)\n",
    "                cov_used_c = 'HAC(3)'\n",
    "            except Exception:\n",
    "                params_c = glm.params\n",
    "                pvals_c = glm.pvalues\n",
    "                cov_used_c = 'OLS-GLM'\n",
    "            poisson_results[(st,r)] = (glm, params_c, pvals_c, cov_used_c)\n",
    "            poisson_rows.append({'spill_type':st,'rurality':r,'n_months':n_months,'cov_type':cov_used_c,'coef_post':params_c.get('post_2020',np.nan),'p_post':pvals_c.get('post_2020',np.nan),'coef_timepost':params_c.get('time_post',np.nan),'p_timepost':pvals_c.get('time_post',np.nan)})\n",
    "        except Exception as e:\n",
    "            print(f'Poisson ITS failed for {st}/{r}: {e}')\n",
    "            poisson_rows.append({'spill_type':st,'rurality':r,'n_months':n_months,'cov_type':'failed'})\n",
    "\n",
    "        # OLS ITS on mean_delay: use only months with n>0 but time is continuous\n",
    "        df_mean = dfp[dfp['n_events']>0].copy()\n",
    "        if len(df_mean) < 8:\n",
    "            ols_rows.append({'spill_type':st,'rurality':r,'n_months':len(df_mean),'status':'insufficient'})\n",
    "            print(f'Skipping OLS ITS for {st}/{r}: only {len(df_mean)} months with data')\n",
    "            continue\n",
    "        try:\n",
    "            formula_mean = 'mean_delay ~ time + post_2020 + time_post'\n",
    "            m = smf.ols(formula_mean, data=df_mean).fit()\n",
    "            try:\n",
    "                m_hac = m.get_robustcov_results(cov_type='HAC', maxlags=3)\n",
    "                params_m = pd.Series(m_hac.params.values, index=m_hac.params.index)\n",
    "                pvals_m = pd.Series(m_hac.pvalues.values, index=m_hac.params.index)\n",
    "                cov_used_m = 'HAC(3)'\n",
    "            except Exception:\n",
    "                params_m = m.params\n",
    "                pvals_m = m.pvalues\n",
    "                cov_used_m = 'OLS'\n",
    "            ols_results[(st,r)] = (m, params_m, pvals_m, cov_used_m)\n",
    "            ols_rows.append({'spill_type':st,'rurality':r,'n_months':len(df_mean),'cov_type':cov_used_m,'coef_post':params_m.get('post_2020',np.nan),'p_post':pvals_m.get('post_2020',np.nan),'coef_timepost':params_m.get('time_post',np.nan),'p_timepost':pvals_m.get('time_post',np.nan)})\n",
    "        except Exception as e:\n",
    "            print(f'OLS ITS failed for {st}/{r}: {e}')\n",
    "            ols_rows.append({'spill_type':st,'rurality':r,'n_months':len(df_mean),'status':'failed'})\n",
    "\n",
    "# Save summaries\n",
    "pd.DataFrame(poisson_rows).to_csv('its_poisson_summary.csv', index=False)\n",
    "pd.DataFrame(ols_rows).to_csv('its_ols_summary.csv', index=False)\n",
    "print('Saved its_poisson_summary.csv and its_ols_summary.csv')\n",
    "\n",
    "# Quick combined plot (reuse previous style) — panels for all models where available\n",
    "keys = sorted(list(set(list(poisson_results.keys()) + list(ols_results.keys()))))\n",
    "if len(keys) > 0:\n",
    "    cols = min(3, len(keys))\n",
    "    rows = (len(keys) + cols - 1) // cols\n",
    "    fig, axes = plt.subplots(rows, cols, figsize=(6*cols, 3.5*rows))\n",
    "    axes_flat = axes.flatten() if hasattr(axes, 'flatten') else [axes]\n",
    "    for i, key in enumerate(keys):\n",
    "        st, r = key\n",
    "        ax = axes_flat[i]\n",
    "        # choose df for plotting from monthly_full\n",
    "        dfp = monthly_full[(monthly_full['spill_type']==st) & (monthly_full['rurality']==r)].sort_values('report_month')\n",
    "        ax.scatter(dfp['report_month'], dfp['n_events'], color='gray', alpha=0.6, s=20, label='Counts')\n",
    "        if key in poisson_results:\n",
    "            glm, params_c, pvals_c, cov_used_c = poisson_results[key]\n",
    "            dfp['fitted_counts'] = glm.predict(dfp)\n",
    "            ax.plot(dfp['report_month'], dfp['fitted_counts'], color='#1f77b4', lw=2, label='Fitted counts')\n",
    "        # overlay mean_delay scaled on secondary axis\n",
    "        ax2 = ax.twinx()\n",
    "        ax2.plot(dfp['report_month'], dfp['mean_delay'], color='#ff7f0e', marker='o', linestyle='-', label='Mean delay')\n",
    "        ax.axvline(pd.Timestamp('2020-01-01'), linestyle='--', color='black', alpha=0.8)\n",
    "        ax.set_title(f'{st} — {r}')\n",
    "        ax.set_xlabel('Month')\n",
    "        ax.set_ylabel('Counts')\n",
    "        ax2.set_ylabel('Mean delay (days)')\n",
    "    for j in range(i+1, len(axes_flat)):\n",
    "        axes_flat[j].set_visible(False)\n",
    "    plt.tight_layout()\n",
    "    outname = 'its_combined_reindexed.png'\n",
    "    plt.savefig(outname, dpi=200, bbox_inches='tight')\n",
    "    plt.show()\n",
    "    print(f'Saved {outname}')\n",
    "else:\n",
    "    print('No models to plot')\n",
    "\n",
    "print('Reindex + counts-based ITS finished.')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "112c434a",
   "metadata": {},
   "source": [
    "Figure captions (use with its_combined_reindexed.png, panels ordered by Spill Type × Rurality)\n",
    "Historical — Urban: Monthly mean reporting delay shows a clear immediate drop at the 2020 break (bootstrap median ≈ −0.62 days; 95% bootstrap CI ≈ −0.97 to −0.24) followed by a small positive post‑break slope indicating gradual partial erosion of the initial gain.\n",
    "Historical — Suburban: Immediate reduction at the break is robust (bootstrap median ≈ −1.52 days; 95% CI ≈ −2.76 to −0.43); no consistent post‑break slope detected.\n",
    "Historical — Rural: Bootstrap intervals include zero for both level and slope — no robust ITS effect despite analytic OLS significance.\n",
    "Recent — Urban: No detectable immediate or slope change at the break; reporting delays remain stable.\n",
    "Recent — Suburban: No robust level or slope change (wide bootstrap CIs include zero).\n",
    "Recent — Rural: Analytic coefficients suggest change but bootstrap CIs do not—treat as null for ITS inference."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9a24fc5",
   "metadata": {},
   "source": [
    "# ITS Table Interpretation Guide\n",
    "\n",
    "## Coefficient Types Reported\n",
    "\n",
    "- **Immediate Level Change (`coef_post`, `p_post`):**\n",
    "    - Represents the immediate shift in mean reporting delay at the 2020 break.\n",
    "    - Units: days of mean delay (from OLS ITS).\n",
    "- **Slope Change (`coef_timepost`, `p_timepost`):**\n",
    "    - Indicates the change in monthly trend after the break.\n",
    "    - Units: days per month.\n",
    "\n",
    "## Bootstrap Summaries\n",
    "\n",
    "- **`immediate_median`, `immediate_ci_*`, `slope_median`, `slope_ci_*`, `*_p_boot`:**\n",
    "    - Provide resampling-based medians, 95% percentile confidence intervals, and bootstrap p-values.\n",
    "    - These are the preferred uncertainty quantifiers.\n",
    "\n",
    "- **`n_months`:**\n",
    "    - Number of months in each panel’s time series (typically full span for most panels).\n",
    "\n",
    "---\n",
    "\n",
    "## Panel-by-Panel Interpretation\n",
    "\n",
    "### Historical — Urban\n",
    "\n",
    "- **Analytic:** Immediate drop ≈ −2.26 days (p ≪ 0), post-slope change ≈ +0.030 days/month (p ≪ 0).\n",
    "- **Bootstrap:** Immediate median ≈ −0.62 days, 95% CI [−0.97, −0.24], p ≈ 0.00 (strong evidence of reduction); slope median ≈ +0.0086 days/month, 95% CI [0.0024, 0.0150], p ≈ 0.006 (small upward trend).\n",
    "- **Interpretation:** Statistically robust immediate reduction in mean delay at the 2020 break, followed by a small upward drift.\n",
    "\n",
    "### Historical — Suburban\n",
    "\n",
    "- **Analytic:** Immediate drop ≈ −1.34 days (p ≈ 0.009), slope change ≈ +0.0169 days/month (p ≈ 0.042).\n",
    "- **Bootstrap:** Immediate median ≈ −1.52 days, 95% CI [−2.76, −0.43], p ≈ 0.008; slope median ≈ +0.0182 days/month, 95% CI [−0.0031, 0.0383], p ≈ 0.102.\n",
    "- **Interpretation:** Clear immediate reduction; slope change not robust under bootstrap.\n",
    "\n",
    "### Historical — Rural\n",
    "\n",
    "- **Analytic:** Immediate drop ≈ −2.72 days (p ≪ 0), slope change ≈ +0.0437 days/month (p ≪ 0).\n",
    "- **Bootstrap:** Immediate median ≈ −0.23 days, 95% CI [−0.82, 0.43], p ≈ 0.472; slope median ≈ +0.00023 days/month, 95% CI [−0.0114, 0.0101], p ≈ 0.984.\n",
    "- **Interpretation:** No robust immediate or slope change under bootstrap; analytic SEs may be optimistic.\n",
    "\n",
    "### Recent — Urban\n",
    "\n",
    "- **Analytic:** Immediate change ≈ −0.24 days (p ≈ 0.143), slope ≈ +0.0009 days/month (p ≈ 0.714).\n",
    "- **Bootstrap:** Immediate median ≈ −0.16 days, 95% CI [−0.57, 0.22], p ≈ 0.396; slope median ≈ +0.00155 days/month, 95% CI [−0.0054, 0.0091], p ≈ 0.706.\n",
    "- **Interpretation:** No evidence of ITS effect.\n",
    "\n",
    "### Recent — Suburban\n",
    "\n",
    "- **Analytic:** Immediate ≈ +0.43 days (p ≈ 0.165), slope ≈ −0.00082 days/month (p ≈ 0.872).\n",
    "- **Bootstrap:** Immediate median ≈ −0.19 days, 95% CI [−1.25, 0.71], p ≈ 0.702; slope median ≈ −0.00486 days/month, 95% CI [−0.0178, 0.0106], p ≈ 0.50.\n",
    "- **Interpretation:** No robust ITS signal.\n",
    "\n",
    "### Recent — Rural\n",
    "\n",
    "- **Analytic:** Immediate ≈ +0.73 days (p ≪ 0), slope ≈ −0.0113 days/month (p ≪ 0).\n",
    "- **Bootstrap:** Immediate median ≈ −0.02 days, 95% CI [−0.36, 0.36], p ≈ 0.914; slope median ≈ −0.00279 days/month, 95% CI [−0.00806, 0.00208], p ≈ 0.286.\n",
    "- **Interpretation:** No robust ITS effect under bootstrap.\n",
    "\n",
    "---\n",
    "\n",
    "## Cross-Panel Summary\n",
    "\n",
    "- **Historical spill types (Urban, Suburban):** Credible immediate reduction in delay at the 2020 break (bootstrap inference).\n",
    "- **Urban Historical:** Small post-break upward trend, but immediate reduction is dominant.\n",
    "- **Recent spill types:** No consistent ITS-level or slope changes; reporting behavior unchanged at the break.\n",
    "\n",
    "---\n",
    "\n",
    "## Statistical Strength and Diagnostics\n",
    "\n",
    "- Most panels have ~100+ months; one panel (Historical–Suburban) has 65 months—verify time span.\n",
    "- R-squared values vary; strongest fit for Historical–Urban (R² ≈ 0.45).\n",
    "- **Bootstrap CIs and p-values are preferred**; trust bootstrap where analytic and bootstrap diverge.\n",
    "\n",
    "---\n",
    "\n",
    "## Policy Implications\n",
    "\n",
    "- **Reporting delays decreased after 2020** for Historical spill types in Urban and Suburban areas.\n",
    "- **Small upward slope** after Urban improvement suggests need for monitoring to prevent backsliding.\n",
    "- **Recent spill types:** Lack of ITS signal suggests reporting practices were already aligned or unchanged.\n",
    "\n",
    "---\n",
    "\n",
    "## Limitations and Next Steps\n",
    "\n",
    "- Use bootstrap-based inference for final reporting.\n",
    "- Avoid overinterpreting analytic p-values where they conflict with bootstrap results.\n",
    "- Verify panel month counts and reindexing consistency.\n",
    "- Visualize ITS plots with pointwise bootstrap CIs.\n",
    "- Consider pooled or hierarchical ITS models for power.\n",
    "- Adjust for confounders if stronger causal claims are needed.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "72a76363",
   "metadata": {},
   "source": [
    "# Overview — Summary of Analyses\n",
    "\n",
    "## Analytical Approach\n",
    "\n",
    "- **Objective:** Estimate how reporting delay (days between spill occurrence and reporting) varies by spill type, period (before vs. 2020 and after), and rurality.\n",
    "- **Primary Model:** Poisson GLM (log link) with three-way interaction: `C(spill_type) * C(Period) * C(rurality)`.\n",
    "- **Negative Binomial:** Attempted but collapsed to Poisson; not used for inference.\n",
    "- **Uncertainty Quantification:** \n",
    "    - Parametric bootstrap (recommended B = 2,000) for robust CIs.\n",
    "    - Nonparametric (case) bootstrap (B = 1,000) for sensitivity.\n",
    "- **Interrupted Time Series (ITS):** Monthly aggregation, reindexed to include zero-event months. Both counts-based Poisson ITS and OLS ITS on monthly mean delay. Coefficient uncertainty reported with Newey–West (HAC) SEs and bootstrap CIs.\n",
    "\n",
    "---\n",
    "\n",
    "## Data and Preprocessing\n",
    "\n",
    "- **Sample Size:** 11,376 spill records after filtering and cleaning.\n",
    "- **Key Variables:**\n",
    "    - `report_delay`: Nonnegative days between event and report; outliers removed via IQR rule (lower bound clipped at 0).\n",
    "    - `Period`: \"Before 2020\" vs \"2020 and After\".\n",
    "    - `rurality`: RUCA-derived categories (Urban / Suburban / Rural); Unknown dropped.\n",
    "- **ITS Aggregation:** Monthly panels for each SpillType × Rurality, reindexed to include all months (zero-event months included).\n",
    "\n",
    "---\n",
    "\n",
    "## Modeling and Inference\n",
    "\n",
    "- **Exploratory Fits:** Included OLS and log1p-transformed OLS.\n",
    "- **Primary Estimation:** Poisson GLM for `report_delay`.\n",
    "- **Negative Binomial:** Not used (collapsed to Poisson).\n",
    "- **Robust Covariance:** Analytic HC3 attempts unreliable; inference emphasizes bootstrap.\n",
    "    - **Parametric Bootstrap:** Simulate Y ~ Poisson(fitted μ), refit; B = 2,000 recommended.\n",
    "    - **Nonparametric Bootstrap:** B = 1,000 for sensitivity.\n",
    "- **ITS OLS:** Newey–West (HAC) SEs and bootstrap CIs/p-values.\n",
    "- **Diagnostics:** Pearson χ² ≈ 7,807.6 → dispersion ≈ 0.687 (underdispersion).\n",
    "\n",
    "---\n",
    "\n",
    "## ITS Results — Panel Summary & Interpretation\n",
    "\n",
    "**ITS panels report:**\n",
    "- Immediate level change at 2020 break (`coef_post` / immediate).\n",
    "- Post-break slope change (`coef_timepost` / slope).\n",
    "- Bootstrap medians, 95% CIs, and bootstrap p-values are preferred.\n",
    "\n",
    "### Panel-Level Summary (Bootstrap Interpretation)\n",
    "\n",
    "#### Historical — Urban (n_months ≈ 117–118; R² ≈ 0.45)\n",
    "- Immediate: robust reduction (median ≈ −0.62 days; 95% CI [−0.97, −0.24]; p_boot ≈ 0.00).\n",
    "- Slope: small positive post-break trend (median ≈ +0.0086 days/month; 95% CI [0.0024, 0.0150]; p_boot ≈ 0.006).\n",
    "- **Interpretation:** Clear immediate improvement, slow upward drift post-break.\n",
    "\n",
    "#### Historical — Suburban (n_months ≈ 117 in some outputs)\n",
    "- Immediate: robust reduction (median ≈ −1.52 days; 95% CI [−2.76, −0.43]; p_boot ≈ 0.008).\n",
    "- Slope: bootstrap CI includes zero (not robust; p_boot ≈ 0.10).\n",
    "- **Interpretation:** Immediate improvement credible; slope change weak.\n",
    "\n",
    "#### Historical — Rural (n_months ≈ 105–118; R² ≈ 0.08)\n",
    "- Analytic coefficients large/significant, but bootstrap shows no robust effect (immediate median ≈ −0.23 days; 95% CI includes 0; p_boot ≈ 0.47).\n",
    "- **Interpretation:** Prefer bootstrap — no clear ITS change.\n",
    "\n",
    "#### Recent — Urban (n_months ≈ 118; R² ≈ 0.20)\n",
    "- No robust immediate or slope change (bootstrap medians near zero; 95% CIs include zero; p_boot ≈ 0.4–0.7).\n",
    "- **Interpretation:** No ITS signal at 2020 break.\n",
    "\n",
    "#### Recent — Suburban (n_months ≈ 92–118; R² low)\n",
    "- No robust immediate or slope change (bootstrap CI includes zero; p_boot ≈ 0.5–0.7).\n",
    "\n",
    "#### Recent — Rural (n_months ≈ 118; R² ≈ 0.17)\n",
    "- Analytic significance not supported by bootstrap; no robust effect.\n",
    "- **Interpretation:** No reliable ITS signal.\n",
    "\n",
    "---\n",
    "\n",
    "## Cross-Panel Takeaway\n",
    "\n",
    "- **ITS evidence of immediate post-2020 improvement is strongest for Historical spill types in Urban and Suburban areas (bootstrap-confirmed).**\n",
    "- **Analytic OLS p-values (especially Rural panels) not confirmed by bootstrap — prefer bootstrap interpretation.**\n",
    "- **Recent spill types show little ITS change, suggesting reporting patterns were unchanged or already similar post-2020.**\n",
    "\n",
    "---\n",
    "\n",
    "## Main Findings (with ITS Nuance)\n",
    "\n",
    "- **Cross-sectional Poisson GLM:** Predicted group means and bootstrap CIs show general reductions in reporting delay after 2020.\n",
    "- **ITS:** Supports cross-sectional result mainly for Historical–Urban and Historical–Suburban panels (robust immediate reductions). Other panels: bootstrap uncertainty tempers analytic significance.\n",
    "- **Percent-change tables and contrasts:** Useful for communication; ITS plots illustrate timing and change type (level vs. slope).\n",
    "\n",
    "---\n",
    "\n",
    "## Files and Artifacts Produced\n",
    "\n",
    "- **ITS summaries and reindexed monthly data:**\n",
    "    - `monthly_full_reindexed.csv`\n",
    "    - `its_poisson_summary.csv`\n",
    "    - `its_ols_summary.csv`\n",
    "    - `its_coef_bootstrap.csv`\n",
    "    - `its_summary_with_boot.csv`\n",
    "- **Figures:**\n",
    "    - `its_combined.png`\n",
    "    - `its_combined_reindexed.png` (use with panel-specific captions)\n",
    "\n",
    "---\n",
    "\n",
    "## Interpretation and Policy Implications\n",
    "\n",
    "- **Reporting delays fell after 2020 for Historical spill types in Urban and Suburban areas (bootstrap-confirmed).**\n",
    "- **Small positive post-break slope in Historical–Urban:** Monitoring needed to preserve gains.\n",
    "- **Lack of ITS signal for Recent spill types:** No change required or already aligned practices.\n",
    "- **Policy briefs:** Emphasize bootstrap-based effect sizes (days saved, percent reductions) and show ITS plots with bootstrap CIs for Urban/Suburban Historical panels.\n",
    "\n",
    "---\n",
    "\n",
    "## Limitations (ITS-Specific Notes)\n",
    "\n",
    "- **Discrepancies between analytic OLS significance and bootstrap results:** Prefer bootstrap inference.\n",
    "- **Panel n_months:** One export showed abbreviated n_months (65) for Historical–Suburban — verify consistency.\n",
    "- **Modest R² in some panels:** Sensitive to small-sample behavior.\n",
    "- **ITS limitations:** Causal interpretation threatened by concurrent interventions, measurement changes."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f5650265",
   "metadata": {},
   "source": [
    "# "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "3a696afe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "IQR bounds: Q1=0.0, Q3=2.0, IQR=2.0\n",
      "Keeping report_delay in [0.0, 5.0]\n",
      "Rows total: 17820\n",
      "Rows flagged for removal by IQR rule: 1219 (proportion: 0.068)\n",
      "\n",
      "Full summary (days)\n",
      "count    17820.000000\n",
      "mean         9.984568\n",
      "std        127.082215\n",
      "min          0.000000\n",
      "25%          0.000000\n",
      "50%          1.000000\n",
      "75%          2.000000\n",
      "max       9261.000000\n",
      "dtype: float64\n",
      "\n",
      "Trimmed summary (days)\n",
      "count    16601.000000\n",
      "mean         0.986567\n",
      "std          1.087719\n",
      "min          0.000000\n",
      "25%          0.000000\n",
      "50%          1.000000\n",
      "75%          1.000000\n",
      "max          5.000000\n",
      "dtype: float64\n",
      "\n",
      "Top 20 extreme delays (days)\n",
      "7402     9261\n",
      "6370     5681\n",
      "15283    4642\n",
      "15697    4642\n",
      "5451     3632\n",
      "17072    2772\n",
      "17012    2772\n",
      "11808    2501\n",
      "6825     2291\n",
      "6967     2291\n",
      "6254     2232\n",
      "12159    2150\n",
      "16352    2150\n",
      "12134    1950\n",
      "12466    1950\n",
      "6255     1900\n",
      "1156     1822\n",
      "1161     1822\n",
      "5904     1795\n",
      "5609     1795\n",
      "dtype: int64\n",
      "\n",
      "Proportion same-day (0 days): 0.36840628507295176\n",
      "\n",
      "Saved: spills_with_trim_flag.csv, spills_trimmed.csv, spills_trimmed_removed.csv\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 30712 characters]",
      "text/plain": [
       "<Figure size 1000x400 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "## Diagnostic: compute full-day delays from `spills`, evaluate IQR trimming, and save flags\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# Defensive checks\n",
    "if 'spills' not in globals():\n",
    "    print(\"Variable `spills` not found in the current kernel. Please ensure the full dataset is loaded as `spills`.\")\n",
    "else:\n",
    "    try:\n",
    "        # ensure datetime\n",
    "        spills['Initial Report Date'] = pd.to_datetime(spills['Initial Report Date'])\n",
    "        spills['Date of Discovery'] = pd.to_datetime(spills['Date of Discovery'])\n",
    "\n",
    "        # compute full-day differences\n",
    "        delta = spills['Initial Report Date'] - spills['Date of Discovery']\n",
    "        full_days = delta.dt.days\n",
    "\n",
    "        # compute IQR bounds (lower clipped at 0, matching your procedure)\n",
    "        q1 = full_days.quantile(0.25)\n",
    "        q3 = full_days.quantile(0.75)\n",
    "        iqr = q3 - q1\n",
    "        lower = max(0, q1 - 1.5 * iqr)\n",
    "        upper = q3 + 1.5 * iqr\n",
    "\n",
    "        remove_mask = (full_days < lower) | (full_days > upper)\n",
    "\n",
    "        # Print diagnostics\n",
    "        print(f\"IQR bounds: Q1={q1:.1f}, Q3={q3:.1f}, IQR={iqr:.1f}\")\n",
    "        print(f\"Keeping report_delay in [{lower:.1f}, {upper:.1f}]\")\n",
    "        print(f\"Rows total: {len(spills)}\")\n",
    "        print(f\"Rows flagged for removal by IQR rule: {int(remove_mask.sum())} (proportion: {remove_mask.mean():.3f})\")\n",
    "        print('\\nFull summary (days)')\n",
    "        print(full_days.describe())\n",
    "        print('\\nTrimmed summary (days)')\n",
    "        print(full_days[~remove_mask].describe())\n",
    "        print('\\nTop 20 extreme delays (days)')\n",
    "        print(full_days.sort_values(ascending=False).head(20))\n",
    "        print('\\nProportion same-day (0 days):', (full_days==0).mean())\n",
    "\n",
    "        # Attach flags to a copy and save\n",
    "        out = spills.copy()\n",
    "        out['report_delay_full_days'] = full_days\n",
    "        out['trim_remove'] = remove_mask\n",
    "\n",
    "        try:\n",
    "            out.to_csv('spills_with_trim_flag.csv', index=False)\n",
    "            out.loc[~out['trim_remove']].to_csv('spills_trimmed.csv', index=False)\n",
    "            out.loc[out['trim_remove']].to_csv('spills_trimmed_removed.csv', index=False)\n",
    "            print('\\nSaved: spills_with_trim_flag.csv, spills_trimmed.csv, spills_trimmed_removed.csv')\n",
    "        except Exception as e:\n",
    "            print('\\nFailed to save CSVs:', e)\n",
    "\n",
    "        # Plot histograms before/after trimming\n",
    "        plt.figure(figsize=(10,4))\n",
    "        plt.subplot(1,2,1)\n",
    "        plt.hist(full_days.clip(upper=30), bins=30, color='C0', alpha=0.8)\n",
    "        plt.title('Full delays (days), clipped to 30')\n",
    "        plt.xlabel('days')\n",
    "        plt.ylabel('count')\n",
    "\n",
    "        plt.subplot(1,2,2)\n",
    "        plt.hist(full_days[~remove_mask].clip(upper=30), bins=30, color='C1', alpha=0.8)\n",
    "        plt.title('Trimmed delays (days), clipped to 30')\n",
    "        plt.xlabel('days')\n",
    "\n",
    "        plt.tight_layout()\n",
    "        plt.show()\n",
    "\n",
    "    except Exception as e:\n",
    "        print('Error while running diagnostic cell:', e)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "25c5c652",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "index",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Document #",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Report",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Operator",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Operator #",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Tracking #",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Initial Report Date",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Date of Discovery",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Spill Type",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Qtr Qtr",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Section",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Township",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "range",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "meridian",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Latitude",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Longitude",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Municipality",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "county",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Facility Type",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Facility ID",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "API County Code",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "API Sequence Number",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Spilled outside of berms",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "More than five barrels spilled",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Oil Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Condensate Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Flow Back Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Produced Water Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "E&P Waste Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Other Waste",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Drilling Fluid Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Current Land Use",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Other Land Use",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Weather Conditions",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Surface Owner",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Surface Owner Other",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Waters of the State",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Residence / Occupied Structure",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "livestock",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Public Byway",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water Supply Area",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Spill Description",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Supplemental Report Date",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Oil BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Oil BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Oil Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Condensate BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Condensate BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Condensate Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Produced Water BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Produced Water BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Produced Water Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Drilling Fluid BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Drilling Fluid BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Drilling Fluid Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Flow Back Fluid BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Flow Back Fluid BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Flow Back Fluid Unkown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste BBLS Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste BBLS Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Spill Contained within Berm",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Emergency Pit Constructed",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "soil",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "groundwater",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Dry Drainage Feature",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Area Length",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Area Width",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Depth of Impact in Feet",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Depth of Impact in Inches",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Area Depth Determined",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Geology Description",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Depth to Groundwater",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Water wells in area",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Water Wells",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Water Wells None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water Near",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Wetlands",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Wetlands None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Springs",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Springs None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Livestock Near",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Livestock None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Occupied Buildings",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Occupied Buildings None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Additional Spill Details",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Supplemental Report Date CA",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Human Error",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Equipment Failure",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Historical Unkown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other Description",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Root Cause",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Preventative Measures",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Soil Excavated",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Offsite Disposal",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Onsite Treatment",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other Disposition",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other Disposition Description",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Ground Water Removed",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water Removed",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Corrective Actions Completed",
         "rawType": "bool",
         "type": "boolean"
        },
        {
         "name": "Approved Form 27",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Form 27 Project Number",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "GEOID",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "TRACT_NAME",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "total_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "white_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "hispanic_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "median_household_income",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "poverty_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "unemployed_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "percent_white",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "percent_hispanic",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "percent_poverty",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "unemployment_rate",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "geometry",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "ruca_code",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "ruca_description",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "rurality",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "report_delay_full_days",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "report_delay_winsor99",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "report_delay_winsor99_int",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Period",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "spill_type",
         "rawType": "object",
         "type": "string"
        }
       ],
       "ref": "333100b2-0371-4e3a-8997-01300cb7ed00",
       "rows": [
        [
         "44",
         "402349927",
         "I w/S",
         "ANADARKO DJ GAS PROCESSING LLC",
         "10719",
         "402349927",
         "2020-03-23",
         "1994-11-14",
         "Historical",
         "SENE  ",
         "32",
         "3S    ",
         "65W    ",
         "6",
         "39.748143",
         "-104.680174",
         null,
         "ADAMS          ",
         "GAS PROCESSING PLANT",
         "255983.0",
         "   ",
         "     ",
         "Y",
         "N",
         "0",
         "0",
         "0",
         "0",
         "Unknown",
         "Water and soil impacted by a mix of E&P and non-E&P materials",
         "0",
         "CROP LAND                          ",
         null,
         "Unknown, historical release        ",
         "OTHER (SPECIFY)",
         "DJ Gas Processing LLC",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "Two Flare Fluid Storage Pits (#1 and #2) were historically operated at the Wattenberg Gas Plant. During decommissioning of the former Flare Fluid Storage Pits, initial investigation activities indicated that hydrocarbon impacts to soil and groundwater were present at the site. The COGCC had previously issued Remediation Project No. 1688 for the release from the former Flare Fluid Storage Pits, however this Remediation Project was inadvertently closed prior to achieving No Further Action (NFA) criteria. As a result, a Form 27-Initial was re-filed with the COGCC on January 6, 2020 (COGCC Document No. 402274364) and Remediation Project No. 14874 was issued. This Form 19 is being submitted to establish a new Spill/Release Point ID for the release from the former Flare Fluid Storage Pits, as noted in the Form 27-Initial. A topographic Site Location Map showing the geographic setting of the release is provided as Figure 1.",
         "04/06/2020",
         null,
         null,
         "1.0",
         null,
         null,
         "1.0",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         "1.0",
         "Water and soil impacted by a mix of E&P and non-E&P materials",
         "0.0",
         "0.0",
         "1.0",
         "1.0",
         "0.0",
         "0.0",
         "150.0",
         "120.0",
         "15.0",
         null,
         "Reference Form 27-Initial (Document No. 402274364).",
         "Clay with sand",
         "12.0",
         "4.0",
         "550.0",
         "0.0",
         "300.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         "2730.0",
         "0.0",
         "380.0",
         "0.0",
         null,
         "2020-04-06",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "Historical impacts were discovered during decommissioning of the former Flare Fluid Storage Pits.",
         "The former Flare Fluid Storage Pits were removed and replaced with an engineered above ground storage tank in a lined berm.",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         null,
         "False",
         "1.0",
         "14874.0",
         "8001008354",
         "83.54",
         "4211.0",
         "1204.0",
         "992.0",
         "101250.0",
         "453.0",
         "16.0",
         "28.59178342436476",
         "23.55734979814771",
         "10.757539776775111",
         "0.379957254808834",
         "POINT (-104.680174 39.748143)",
         "1",
         "Metropolitan core",
         "Urban",
         "9261",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "41",
         "402116460",
         "I w/S",
         "NGL WATER SOLUTIONS DJ LLC",
         "10373",
         "402116460",
         "2019-07-22",
         "2004-01-01",
         "Historical",
         "SESE  ",
         "28",
         "1N    ",
         "67W    ",
         "6",
         "40.016567",
         "-104.887064",
         null,
         "WELD           ",
         "PRODUCED WATER TRANSFER SYSTEM",
         null,
         "123",
         "18763",
         "N",
         "N",
         "0",
         "0",
         "0",
         ">0 and <1",
         "0",
         null,
         "0",
         "CROP LAND                          ",
         null,
         "Overcast                           ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "Minor spill near wellhead",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "1.0",
         "1837.0",
         "8123002006",
         "20.06",
         "408.0",
         "323.0",
         "44.0",
         "143646.0",
         "17.0",
         "0.0",
         "79.16666666666666",
         "10.784313725490197",
         "4.166666666666666",
         "0.0",
         "POINT (-104.887064 40.016567)",
         "10",
         "Rural area",
         "Rural",
         "5681",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Historical"
        ],
        [
         "65",
         "403791618",
         "I",
         "MAGPIE OPERATING INC",
         "52530",
         "403791618",
         "2024-05-15",
         "2011-08-30",
         "Historical",
         "NENE  ",
         "36",
         "9N    ",
         "55W    ",
         "6",
         "40.714817",
         "-103.462663",
         null,
         "LOGAN          ",
         "PIT",
         "116333.0",
         "   ",
         "     ",
         null,
         "N",
         "0",
         "0",
         "0",
         "Unknown",
         "Unknown",
         "Three historic evaporation pits",
         "0",
         "NON-CROP LAND                      ",
         null,
         "Unknown at time of discovery       ",
         "OTHER (SPECIFY)",
         "CO State Land Board",
         null,
         null,
         null,
         null,
         null,
         "An Initial Form 27 was submitted on 8/30/2011 (Document 1761290) to complete administrative pit closure on three unlined pits at the Site (pit closure occurred in 1997). Subsequent Form 27 Supplementals have documented sample collection and analysis. Inspection performed on 01/03/2024 (Document 709100202) referenced salt scarring and need for additional sampling/analysis for full Table 915-1 parameters. Approved Form 27 Supplemental (Document 403738665) was completed to outline next assessment action; this Document included a COA to complete a Form 19 to document historic release. Upon approval of this Form 19, a Form 19 Supplemental will be submitted requesting closure with additional Site Investigation to continue under Remediation Project #6103.",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "0.0",
         null,
         "8075966000",
         "9660.0",
         "2214.0",
         "2011.0",
         "310.0",
         "61339.0",
         "259.0",
         "77.0",
         "90.83107497741643",
         "14.001806684733516",
         "11.698283649503162",
         "3.477868112014453",
         "POINT (-103.462663 40.714817)",
         "5",
         "Micropolitan high commuting",
         "Suburban",
         "4642",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "66",
         "403846130",
         "S",
         "MAGPIE OPERATING INC",
         "52530",
         "403791618",
         "2024-05-15",
         "2011-08-30",
         "Historical",
         "NENE  ",
         "36",
         "9N    ",
         "55W    ",
         "6",
         "40.714817",
         "-103.462663",
         null,
         "LOGAN          ",
         "PIT",
         "116333.0",
         "   ",
         "     ",
         null,
         "N",
         "0",
         "0",
         "0",
         "Unknown",
         "Unknown",
         "Three historic evaporation pits",
         "0",
         "NON-CROP LAND                      ",
         null,
         "Unknown at time of discovery       ",
         "OTHER (SPECIFY)",
         "CO State Land Board",
         null,
         null,
         null,
         null,
         null,
         "An Initial Form 27 was submitted on 8/30/2011 (Document 1761290) to complete administrative pit closure on three unlined pits at the Site (pit closure occurred in 1997). Subsequent Form 27 Supplementals have documented sample collection and analysis. Inspection performed on 01/03/2024 (Document 709100202) referenced salt scarring and need for additional sampling/analysis for full Table 915-1 parameters. Approved Form 27 Supplemental (Document 403738665) was completed to outline next assessment action; this Document included a COA to complete a Form 19 to document historic release. \n\nThis Form 19 Supplemental requests closure with additional Site Investigation to continue under Remediation Project #6103.",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "1.0",
         "6103.0",
         "8075966000",
         "9660.0",
         "2214.0",
         "2011.0",
         "310.0",
         "61339.0",
         "259.0",
         "77.0",
         "90.83107497741643",
         "14.001806684733516",
         "11.698283649503162",
         "3.477868112014453",
         "POINT (-103.462663 40.714817)",
         "5",
         "Micropolitan high commuting",
         "Suburban",
         "4642",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "35",
         "401893556",
         "I w/S",
         "BONANZA CREEK ENERGY OPERATING COMPANY LLC",
         "8960",
         "401893556",
         "2019-01-04",
         "2009-01-24",
         "Historical",
         "SESW  ",
         "14",
         "4N    ",
         "64W    ",
         "6",
         "40.30657",
         "-104.520309",
         null,
         "WELD           ",
         "TANK BATTERY",
         "323325.0",
         "   ",
         "     ",
         "N",
         "Y",
         "Unknown",
         "0",
         "0",
         "0",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "Cold, Snow                         ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "This is a historic release that as initially reported back in 2009, but was never closed.  A loadline froze overnight and failed at the production tank. The release was contained to the earthen containment berm. The oil was vac'd up and the impacted soil was removed.",
         "01/04/2019",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         null,
         null,
         "This is an NFA request for a release that occurred in 2009 with limited documented details. The dimensions of the surface area impact are currently unknown, but assumed to be a portion of the erathen containment area behind the tank.",
         "Dacono clay loam, 0-1 percent slopes.",
         "30.0",
         "9.0",
         "814.0",
         "0.0",
         "1700.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         null,
         "1.0",
         "70.0",
         "0.0",
         "This is a historic release. BCEI originally submitted an initial Form 19 and notification back in 2009. However, supplemental forms were never filed on behalf of BCEI. The original release footprint is currently unknown. Two confirmation soil samples were collected around the release point and analyzed for TPH and BTEX. Analytical results indicate compliance with COGCC Table 910-1. BCEI respectfully requests an NFA determination.",
         "2019-01-04",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "A loadline froze and ruptured releasing and unknown amount of oil.",
         "Heat tape and insulation are used to help prevent future freezes.",
         null,
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "True",
         "0.0",
         null,
         "8123001600",
         "16.0",
         "4023.0",
         "3581.0",
         "612.0",
         "82865.0",
         "268.0",
         "62.0",
         "89.01317424807358",
         "15.212527964205815",
         "6.661695252299279",
         "1.5411384538901318",
         "POINT (-104.520309 40.30657)",
         "2",
         "Metropolitan high commuting",
         "Urban",
         "3632",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Historical"
        ],
        [
         "76",
         "404029999",
         "I",
         "IMPETRO RESOURCES LLC",
         "10690",
         "404029999",
         "2024-12-16",
         "2017-05-15",
         "Historical",
         "SESW  ",
         "14",
         "1S    ",
         "55W    ",
         "6",
         "39.958799",
         "-103.509319",
         null,
         "WASHINGTON     ",
         "PIT",
         "101966.0",
         "   ",
         "     ",
         null,
         "N",
         "Unknown",
         "0",
         "0",
         "Unknown",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "unknown                            ",
         "FEE",
         null,
         null,
         null,
         null,
         null,
         null,
         "The Gettman 14-14 well and associated tank battery were acquired by Impetro Resources, LLC in July 2023. Impetro has been unable to determine or identify detailed investigation and/or remediation activities that were performed by the previous operator (#94300) beyond the historical information submitted in the documents uploaded to the ECMC database. This Form 19 is being submitted to comply with the COAs from the previously submitted Form 27 (#403930289), Operator shall submit a Form 19, per Rule 912.b.(1).E.: \" The discovery of 10 cubic yards or more of impacted material resulting from a current or historic Spill or Release. Discovery and reporting will not be contingent upon confirmation samples demonstrating exceedance of Table 915-1 standards.\" since the Remedial Action Plan documents 52 cubic yards of impacted material from this historic spill/release. A waste manifest was submitted from 2017 documenting the removal of 54.23 tons of impacted soil from the site.",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "0.0",
         null,
         "8121924100",
         "9241.0",
         "2081.0",
         "1968.0",
         "196.0",
         "56875.0",
         "220.0",
         "40.0",
         "94.56991830850554",
         "9.418548774627585",
         "10.571840461316674",
         "1.9221528111484865",
         "POINT (-103.509319 39.958799)",
         "10",
         "Rural area",
         "Rural",
         "2772",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "77",
         "404037262",
         "S",
         "IMPETRO RESOURCES LLC",
         "10690",
         "404029999",
         "2024-12-16",
         "2017-05-15",
         "Historical",
         "SESW  ",
         "14",
         "1S    ",
         "55W    ",
         "6",
         "39.958799",
         "-103.509319",
         null,
         "WASHINGTON     ",
         "PIT",
         "101966.0",
         "   ",
         "     ",
         null,
         "N",
         "Unknown",
         "0",
         "0",
         "Unknown",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "unknown                            ",
         "FEE",
         null,
         null,
         null,
         null,
         null,
         null,
         "The Gettman 14-14 well and associated tank battery were acquired by Impetro Resources, LLC in July 2023. Impetro has been unable to determine or identify detailed investigation and/or remediation activities that were performed by the previous operator (#94300) beyond the historical information submitted in the documents uploaded to the ECMC database. This Form 19 is being submitted to comply with the COAs from the previously submitted Form 27 (#403930289), Operator shall submit a Form 19, per Rule 912.b.(1).E.: \" The discovery of 10 cubic yards or more of impacted material resulting from a current or historic Spill or Release. Discovery and reporting will not be contingent upon confirmation samples demonstrating exceedance of Table 915-1 standards.\" since the Remedial Action Plan documents 52 cubic yards of impacted material from this historic spill/release. A waste manifest was submitted from 2017 documenting the removal of 54.23 tons of impacted soil from the site.",
         "12/20/2024",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "1.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "20.0",
         "20.0",
         "1.0",
         null,
         "The estimated surface area impacted has been determined by aerial photographs of the former skim pit . No soil samples have been collected to date. Impacts were previously determined visually. A waste manifest was submitted from 2017 documenting the removal of 54.23 tons of impacted soil from the site.",
         "Keith-Kuma Complex",
         "28.0",
         "2.0",
         "2218.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         null,
         "1.0",
         null,
         "1.0",
         "1800.0",
         "0.0",
         "\"DUG UP SKIM PIT, STOCKPILE SOIL, TEST AND BACKFILL. THE ORIGINAL SKIM PIT WAS ACTUALLY A CULVERT WITH A CONCRETE BOTTOM. REPLACED IT WITH A TANK. THERE WAS NO STAINING. CURRENTLY, THE LEASE IS BEING EVALUATED FOR P&A. IF WE DECIDE TO CONTINUE PUMPING WE CAN EXCAVATE THE SIDE OF THE TANK, OTHERWISE, WE WILL BE DIGGING IT OUT. WILL MAKE A DECISION BY JULY 21.\" This description was provided by the previous operator, Alfred Ward & Son (Operator #94300), on the most recent Form 27-S (Doc #402658626) for the remediation project. The Gettman 14-14 well and associated tank battery were acquired by Impetro Resources, LLC (Operator #10690) in July 2023, who will be putting the lease back into production. Impetro has been unable to determine or identify detailed investigation and/or remediation activities that were performed by the previous operator, beyond the historical information submitted in the documents uploaded to the ECMC database.",
         "2024-12-20",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "Historical impacts from skim pit\n",
         "Pit (vertical culvert with concrete bottom) was excavated and removed. This description was provided by the previous operator. However, Impetro has been unable to determine or identify any confirmation soil sampling was performed.",
         "200.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "False",
         "1.0",
         "8067.0",
         "8121924100",
         "9241.0",
         "2081.0",
         "1968.0",
         "196.0",
         "56875.0",
         "220.0",
         "40.0",
         "94.56991830850554",
         "9.418548774627585",
         "10.571840461316674",
         "1.9221528111484865",
         "POINT (-103.509319 39.958799)",
         "10",
         "Rural area",
         "Rural",
         "2772",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "50",
         "403208400",
         "I w/S",
         "KP KAUFFMAN COMPANY INC",
         "46290",
         "403208400",
         "2022-10-26",
         "2015-12-21",
         "Historical",
         "SESE  ",
         "29",
         "2N    ",
         "58W    ",
         "6",
         "40.10257",
         "-103.89023",
         null,
         "MORGAN         ",
         "PIT",
         "102705.0",
         "   ",
         "     ",
         null,
         "N",
         "0",
         "0",
         "0",
         "Unknown",
         "0",
         "Earthen evaporation pit",
         "0",
         "NON-CROP LAND                      ",
         "reclaimed pit used as rangeland",
         "Variable                           ",
         "FEE",
         null,
         null,
         null,
         null,
         null,
         null,
         "Facility #102705 was closed and reclaimed in 2012.  The landowner notification was provided in 2012.  Site investigation activities conducted in 2015 identified elevated levels of SAR and EC in soil samples collected from within the pit extent at 3 feet bgs.  No previous spill report was filed as Operator reported in 2018 that it has been unable to access the site to conduct further investigation.  Correspondence from Operator to COGCC dated 2018 is attached.",
         "10/26/2022",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "1.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "150.0",
         "150.0",
         "3.0",
         null,
         "Post-reclamation soil sampling",
         "sand to silty sand (SP-SM) with some clay (CL) layers",
         "25.0",
         "2.0",
         "2000.0",
         "0.0",
         "1800.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         null,
         "1.0",
         "2500.0",
         "0.0",
         "Depth to groundwater is inferred based on topo map data.  ",
         "2022-10-26",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "Unlined earthen pit operated from approximately1973 until 2012.  ",
         "Pit has been properly reclaimed.",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "False",
         "1.0",
         "9363.0",
         "8087000600",
         "6.0",
         "6245.0",
         "3713.0",
         "3332.0",
         "64961.0",
         "919.0",
         "81.0",
         "59.45556445156125",
         "53.3546837469976",
         "14.715772618094476",
         "1.2970376301040831",
         "POINT (-103.89023 40.10257)",
         "4",
         "Micropolitan core",
         "Suburban",
         "2501",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "43",
         "402253095",
         "S",
         "DCP OPERATING COMPANY LP",
         "4680",
         "402226829",
         "2019-10-30",
         "2013-07-22",
         "Historical",
         "SWSW  ",
         "17",
         "2N    ",
         "66W    ",
         "6",
         "40.13091",
         "-104.806776",
         null,
         "WELD           ",
         "PIPELINE",
         null,
         "   ",
         "     ",
         "Y",
         "N",
         "0",
         "Unknown",
         "0",
         "0",
         "0",
         null,
         "0",
         "CROP LAND                          ",
         "Roadway, Industrial",
         "Sunny 80's                         ",
         "STATE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "In July 2013, a leak was identified within a six-inch DCP gas gathering pipeline and resulted in a hydrocarbon release to soils at CR 20 and Highway (Hwy) 85 pipeline release (Site), located approximately 0.2 miles east on CR 20 from the intersection with Hwy 85, in Ft. Lupton, CO.  At the time of the release, the pipeline was isolated and blown down while repairs were completed. DCP contracted a third-party environmental contractor to delineate and remove impacted soils in the area of the release.  Analytical results from soil excavation and boring sample locations determined that soil impacts remained in place and required additional remediation. Beginning June 4, 2014 additional investigation activities were performed and included groundwater delineation activities, groundwater remediation and continued quarterly groundwater monitoring activities.",
         "12/04/2019",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "60.0",
         "18.0",
         "10.0",
         null,
         "During the July 2013 remediation efforts, approximately 400 cubic yard (CY) of impacted soils were removed by excavation methods and transported for off-site disposal. Confirmation soil samples were collected from the excavation sidewalls and base of excavation at locations illustrated on the attached Figure 2. Analytical results indicated soil impacts remained in place, however the extent of the excavation was limited at the time due to buried fiber optic utilities to the south and agricultural ditch to the north. Soil analytical data was provided in the Table 1 and analytical reports were provided in approved eForm19I/S (Document # 402226829). Additional soil boings were advanced and completed as monitoring wells to evaluate impacts to groundwater in June 2014. Between June 2014 and September 2015, six soil borings were advanced to approximately 18-feet bgs and completed as one-inch monitoring wells at locations illustrated on the attached Figure 3. Following monitoring well installation, ongoing groundwater monitoring has been performed at the Site on a quarterly basis through the third quarter 2019. Additionally, mobile vacuum enhanced fluid recovery (EFR) groundwater remediation efforts were conducted from the third quarter 2015 through the fourth quarter 2016 at which point light non-aqueous phase liquid (LNAPL) was no longer observed at the site. Historical soil excavation and boring analytical data is provided as an attachment to this submittal. Quarterly groundwater reports prepared from the second quarter 2015 through the third quarter 2019 were provided as attachments in approved eForm 27 (Dcoument # 402247877).",
         "Altvan Loam, 0 to 1 percent slopes, Silty Sands",
         "14.0",
         "15.0",
         "256.0",
         "0.0",
         "20.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         "615.0",
         "0.0",
         "418.0",
         "0.0",
         null,
         "2019-12-04",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "In July 2013, a leak was identified within a six-inch DCP gas gathering pipeline and resulted in a hydrocarbon release to soils at the site. The affected section of pipeline was removed, and a new section welded in place. The pipeline repair was inspected and pressure tested prior to being returned to service",
         "The affected section of pipeline was removed, and a new section welded in place. The pipeline repair was inspected and pressure tested prior to being returned to service.",
         "400.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "307.0",
         "0.0",
         "False",
         "1.0",
         "14694.0",
         "8123001906",
         "19.06",
         "1656.0",
         "993.0",
         "951.0",
         "62500.0",
         "309.0",
         "2.0",
         "59.96376811594203",
         "57.427536231884055",
         "18.65942028985507",
         "0.1207729468599033",
         "POINT (-104.806776 40.13091)",
         "2",
         "Metropolitan high commuting",
         "Urban",
         "2291",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Historical"
        ],
        [
         "42",
         "402226829",
         "I w/S",
         "DCP OPERATING COMPANY LP",
         "4680",
         "402226829",
         "2019-10-30",
         "2013-07-22",
         "Historical",
         "SWSW  ",
         "17",
         "2N    ",
         "66W    ",
         "6",
         "40.13091",
         "-104.806776",
         null,
         "WELD           ",
         "PIPELINE",
         null,
         "   ",
         "     ",
         "Y",
         "N",
         "0",
         "Unknown",
         "0",
         "0",
         "0",
         null,
         "0",
         "CROP LAND                          ",
         "Roadway, Industrial",
         "Sunny 80's                         ",
         "STATE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "In July 2013, a leak was identified within a six-inch DCP gas gathering pipeline and resulted in a hydrocarbon release to soils at CR 20 and Highway (Hwy) 85 pipeline release (Site), located approximately 0.2 miles east on CR 20 from the intersection with Hwy 85, in Ft. Lupton, CO.  At the time of the release, the pipeline was isolated and blown down while repairs were completed. DCP contracted a third-party environmental contractor to delineate and remove impacted soils in the area of the release.  Analytical results from soil excavation and boring sample locations determined that soil impacts remained in place and required additional remediation. Beginning June 4, 2014 additional investigation activities were performed and included groundwater delineation activities, groundwater remediation and continued quarterly groundwater monitoring activities.",
         "10/30/2019",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "60.0",
         "18.0",
         "10.0",
         null,
         "During the July 2013 remediation efforts, approximately 400 cubic yard (CY) of impacted soils were removed by excavation methods and transported for off-site disposal. Confirmation soil samples were collected from the excavation sidewalls and base of excavation at locations illustrated on the attached Figure 2. Analytical results indicated soil impacts remained in place, however the extent of the excavation was limited at the time due to buried fiber optic utilities to the south and agricultural ditch to the north. Soil analytical data is provided in the attached Table 1 and analytical reports are also attached for reference. Additional soil boings were advanced and completed as monitoring wells to evaluate impacts to groundwater in June 2014. Between June 2014 and September 2015, six soil borings were advanced to approximately 18-feet bgs and completed as one-inch monitoring wells at locations illustrated on the attached Figure 3. Following monitoring well installation, ongoing groundwater monitoring has been performed at the Site on a quarterly basis through the third quarter 2019. Additionally, mobile vacuum enhanced fluid recovery (EFR) groundwater remediation efforts were conducted from the third quarter 2015 through the fourth quarter 2016 at which point light non-aqueous phase liquid (LNAPL) was no longer observed at the site. Historical soil excavation and boring analytical data is provided as an attachment to this submittal. Quarterly groundwater reports prepared from the second quarter 2015 through the third quarter 2019 will be provided as attachments in a subsequent eForm 27 submittal. ",
         "Altvan Loam, 0 to 1 percent slopes, Silty Sands",
         "14.0",
         "15.0",
         "256.0",
         "0.0",
         "20.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         "615.0",
         "0.0",
         "418.0",
         "0.0",
         null,
         "2019-10-30",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "In July 2013, a leak was identified within a six-inch DCP gas gathering pipeline and resulted in a hydrocarbon release to soils at the site. The affected section of pipeline was removed, and a new section welded in place. The pipeline repair was inspected and pressure tested prior to being returned to service. ",
         "The affected section of pipeline was removed, and a new section welded in place. The pipeline repair was inspected and pressure tested prior to being returned to service.",
         "400.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "307.0",
         "0.0",
         "False",
         "0.0",
         null,
         "8123001906",
         "19.06",
         "1656.0",
         "993.0",
         "951.0",
         "62500.0",
         "309.0",
         "2.0",
         "59.96376811594203",
         "57.427536231884055",
         "18.65942028985507",
         "0.1207729468599033",
         "POINT (-104.806776 40.13091)",
         "2",
         "Metropolitan high commuting",
         "Urban",
         "2291",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Historical"
        ],
        [
         "39",
         "402081663",
         "I w/S",
         "KERR MCGEE GATHERING LLC",
         "47121",
         "402081663",
         "2019-06-20",
         "2013-05-10",
         "Recent",
         "SESE  ",
         "15",
         "1S    ",
         "65W    ",
         "6",
         "39.95913",
         "-104.640812",
         null,
         "ADAMS          ",
         "PIPELINE",
         null,
         "   ",
         "     ",
         "Y",
         "N",
         "Unknown",
         "0",
         "0",
         "Unknown",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "Sunny, 60°F                        ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "On May 10, 2013, a corrosion hole on the 53-4” pipeline resulted in the release of oil and produced water to the subsurface. The volume of the release is unknown. The petroleum hydrocarbon impacted soil was excavated. The release was reported to the Colorado Oil and Gas Conservation Commission (COGCC) based on the volume of soil excavated. The assessment details and analytical results are summarized below. The topographic Site Location Map showing the geographic setting of the release is provided as Figure 1.",
         "06/21/2019",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "40.0",
         "30.0",
         "20.0",
         null,
         "Between May 8 and 11, 2013, fourteen soil samples were collected from the base and sidewalls of the excavation and submitted for laboratory analysis of TPH and BTEX. Laboratory analytical results indicated that TPH and BTEX concentrations were in full compliance with COGCC Table 910-1 allowable levels at the extent of the excavation. Approximately 890 cubic yards of impacted soil were excavated and transported to Buffalo Ridge Landfill in Keenesburg, Colorado, for disposal. The general site layout, excavation dimensions, and soil sample locations are depicted on the Excavation Site Map provided as Figure 2. The soil sample analytical results are summarized in Table 1, and the laboratory analytical reports are attached.",
         "Sand and Clayey Sand (SC) ",
         "20.0",
         "38.0",
         "430.0",
         "0.0",
         "4800.0",
         "0.0",
         "4800.0",
         "0.0",
         null,
         "1.0",
         "1250.0",
         "0.0",
         "280.0",
         "0.0",
         "No further action is required. Laboratory analytical results for the soil samples indicated that TPH and BTEX concentrations were in full compliance with COGCC Table 910-1 allowable levels at the extent of the excavation. Based on the soil sample analytical results, Kerr-McGee is requesting a No Further Action status for this site. The original Form 19 NFA Status Request, submitted to the COGCC on May 16, 2013, is included as an attachment.",
         "2019-06-21",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "On May 10, 2013, a corrosion hole on the 53-4” pipeline resulted in the release of oil and produced water to the subsurface. The volume of the release is unknown. ",
         "The corroded portion of the pipeline was replaced and cathodic protection was installed.",
         "890.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "True",
         "0.0",
         null,
         "8001008553",
         "85.53",
         "5096.0",
         "4324.0",
         "834.0",
         "130163.0",
         "397.0",
         "124.0",
         "84.850863422292",
         "16.36577708006279",
         "7.790423861852433",
         "2.4332810047095763",
         "POINT (-104.640812 39.95913)",
         "2",
         "Metropolitan high commuting",
         "Urban",
         "2232",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Recent"
        ],
        [
         "70",
         "403944915",
         "S",
         "WESTERN OPERATING COMPANY",
         "95620",
         "403276008",
         "2022-12-30",
         "2017-02-09",
         "Historical",
         "NESE  ",
         "27",
         "11N   ",
         "53W    ",
         "6",
         "40.895966",
         "-103.269374",
         null,
         "LOGAN          ",
         "OTHER",
         "483654.0",
         "   ",
         "     ",
         null,
         "N",
         "Unknown",
         "0",
         "0",
         "Unknown",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "Clear, 45 degrees fahreneit        ",
         "FEE",
         null,
         null,
         null,
         null,
         null,
         null,
         "This form is being submitted to satisfy the requirement in COGCC inspection report document number 690900217.  An approximately 38,000 square foot area exists with stressed vegetation downgradient of the pit.  The progress of reclamation efforts to date have not met COGCC standards.",
         "10/03/2024",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "570.0",
         "450.0",
         "7.0",
         null,
         "The initial extents were determined from the extents of visibly stressed vegetation, as reported initially under COGCC Inspection Form 690900217. On 3/30/2023 and 10/16/2023, fifty-six (56) soil samples were collected from various depths and submitted for analysis of full Table 915-1 to further delineate the extents of impacts. Additional sampling is needed to determine final extents, and a comprehensive sampling plan will be proposed for approval under Remediation Project 27157.",
         "Peetz gravelly hills and Kim loamy plains",
         "80.0",
         "1.0",
         "2100.0",
         "0.0",
         "1000.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         "500.0",
         "0.0",
         null,
         "1.0",
         null,
         "2024-10-03",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "Based on a virtual meeting between Western Operating and ECMC (formerly COGCC) on 11/17/2022 and Inspection Form 690900217 submitted on 12/05/2022, Western Operating submitted Spill/Release ID 483654 to document the release of produced water and oil from Production Pit ID 256303 and/or 100311, resulting in stressed and barren vegetation to the south and west of the former pit(s). It is suspected that a release from the production pit berms, either from an overflow event(s) or berm soil materials insufficient to contain fluids, resulted in produced water and oil spreading into the adjacent grassland. ",
         "Western Operating is decommissioning the pit and production facility at the Propst B-2 to prevent reoccurrence at this location, and is evaluating all owned locations for unused production pits and stressed vegetation for decommissioning and/or remediation. ",
         null,
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         null,
         "False",
         "1.0",
         "27157.0",
         "8075965900",
         "9659.0",
         "967.0",
         "909.0",
         "94.0",
         "57500.0",
         "83.0",
         "49.0",
         "94.0020682523268",
         "9.720785935884178",
         "8.583247156153051",
         "5.067218200620475",
         "POINT (-103.269374 40.895966)",
         "10",
         "Rural area",
         "Rural",
         "2150",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "54",
         "403276008",
         "I",
         "WESTERN OPERATING COMPANY",
         "95620",
         "403276008",
         "2022-12-30",
         "2017-02-09",
         "Historical",
         "NESE  ",
         "27",
         "11N   ",
         "53W    ",
         "6",
         "40.895966",
         "-103.269374",
         null,
         "LOGAN          ",
         "OTHER",
         null,
         "   ",
         "     ",
         null,
         "N",
         "Unknown",
         "0",
         "0",
         "Unknown",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "Clear, 45 degrees fahreneit        ",
         "FEE",
         null,
         null,
         null,
         null,
         null,
         null,
         "This form is being submitted to satisfy the requirement in COGCC inspection report document number 690900217.  An approximately 38,000 square foot area exists with stressed vegetation downgradient of the pit.  The progress of reclamation efforts to date have not met COGCC standards.",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "0.0",
         null,
         "8075965900",
         "9659.0",
         "967.0",
         "909.0",
         "94.0",
         "57500.0",
         "83.0",
         "49.0",
         "94.0020682523268",
         "9.720785935884178",
         "8.583247156153051",
         "5.067218200620475",
         "POINT (-103.269374 40.895966)",
         "10",
         "Rural area",
         "Rural",
         "2150",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "57",
         "403332304",
         "S",
         "WESTERN OPERATING COMPANY",
         "95620",
         "403272313",
         "2022-12-27",
         "2017-08-25",
         "Historical",
         "SWSW  ",
         "26",
         "11N   ",
         "53W    ",
         "6",
         "40.892679",
         "-103.265038",
         null,
         "LOGAN          ",
         "OTHER",
         null,
         "   ",
         "     ",
         null,
         "N",
         "Unknown",
         "0",
         "0",
         "Unknown",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "Clear, 45 degrees fahrenheit       ",
         "FEE",
         null,
         null,
         null,
         null,
         null,
         null,
         "This form is being filed to satisfy the requirement  in COGCC inspection document number 690900222.  An approximately 16,200 square foot area exists with stressed vegetation downgradient of the pit.  The progress of reclamation efforts to date have not met COGCC standards.",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "1.0",
         "27153.0",
         "8075965900",
         "9659.0",
         "967.0",
         "909.0",
         "94.0",
         "57500.0",
         "83.0",
         "49.0",
         "94.0020682523268",
         "9.720785935884178",
         "8.583247156153051",
         "5.067218200620475",
         "POINT (-103.265038 40.892679)",
         "10",
         "Rural area",
         "Rural",
         "1950",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "53",
         "403272313",
         "I",
         "WESTERN OPERATING COMPANY",
         "95620",
         "403272313",
         "2022-12-27",
         "2017-08-25",
         "Historical",
         "SWSW  ",
         "26",
         "11N   ",
         "53W    ",
         "6",
         "40.892679",
         "-103.265038",
         null,
         "LOGAN          ",
         "OTHER",
         null,
         "   ",
         "     ",
         null,
         "N",
         "Unknown",
         "0",
         "0",
         "Unknown",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "Clear, 45 degrees fahrenheit       ",
         "FEE",
         null,
         null,
         null,
         null,
         null,
         null,
         "This form is being filed to satisfy the requirement  in COGCC inspection document number 690900222.  An approximately 16,200 square foot area exists with stressed vegetation downgradient of the pit.  The progress of reclamation efforts to date have not met COGCC standards.",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "0.0",
         null,
         "8075965900",
         "9659.0",
         "967.0",
         "909.0",
         "94.0",
         "57500.0",
         "83.0",
         "49.0",
         "94.0020682523268",
         "9.720785935884178",
         "8.583247156153051",
         "5.067218200620475",
         "POINT (-103.265038 40.892679)",
         "10",
         "Rural area",
         "Rural",
         "1950",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "40",
         "402081722",
         "I w/S",
         "KERR MCGEE GATHERING LLC",
         "47121",
         "402081722",
         "2019-06-20",
         "2014-04-07",
         "Recent",
         "SWSE  ",
         "28",
         "2N    ",
         "67W    ",
         "6",
         "40.10293",
         "-104.893234",
         null,
         "WELD           ",
         "PIPELINE",
         null,
         "   ",
         "     ",
         "Y",
         "N",
         ">=1 and <5",
         "0",
         "0",
         "0",
         "0",
         null,
         "0",
         "CROP LAND                          ",
         null,
         "Sunny, 55°F                        ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "On April 7, 2014, a contractor struck the Kerr-McGee 14-83-1196-4\" pipeline while conducting excavation activities for DCP Midstream. Approximately 1.5 barrels of condensate were released from the damaged Kerr-McGee pipeline. The condensate released into the open DCP Midstream excavation and sprayed onto the surrounding land south of the excavation. The petroleum hydrocarbon impacted soil was excavated. The assessment details and analytical results are summarized below. The topographic Site Location Map showing the geographic setting of the release is provided as Figure 1.",
         "06/21/2019",
         "1.0",
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "180.0",
         "90.0",
         null,
         null,
         "On April 11, 2014, following the removal of impacted soil from the spray release area, three soil samples SS01@6” through SS03@6”) were collected from the base of the shallow excavation and submitted for laboratory analysis of TPH and BTEX. Laboratory analytical results indicated that TPH and BTEX concentrations were in full compliance with COGCC Table 910-1 allowable levels at the extent of the excavation. Approximately 300 cubic yards of impacted soil were excavated and transported to Front Range Landfill in Erie, Colorado, for disposal. The general site layout, excavation dimensions, and soil sample locations are depicted on the Excavation Site Map provided as Figure 2. The soil sample analytical results are summarized in Table 1, and the laboratory analytical report is attached.",
         "Sandy Clay (SC) ",
         "20.0",
         "9.0",
         "1195.0",
         "0.0",
         "2250.0",
         "0.0",
         "3800.0",
         "0.0",
         null,
         "1.0",
         "1610.0",
         "0.0",
         "330.0",
         "0.0",
         "No further action is required. Laboratory analytical results for the soil samples indicated that TPH and BTEX concentrations were in full compliance with COGCC Table 910-1 allowable levels at the extent of the shallow excavation. Based on the soil sample analytical results, Kerr-McGee is requesting a No Further Action status for this site. The original Form 19 NFA Status Request, submitted to the COGCC on April 17, 2014, is included as an attachment.",
         "2019-06-21",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "On April 7, 2014, a contractor struck the Kerr-McGee 14-83-1196-4\" pipeline while conducting excavation activities for DCP Midstream. Approximately 1.5 barrels of condensate were released from the damaged Kerr-McGee pipeline. ",
         "All Kerr-McGee utilities will be properly marked prior to excavation activities.",
         "300.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "True",
         "0.0",
         null,
         "8123002016",
         "20.16",
         "3135.0",
         "2631.0",
         "813.0",
         "82625.0",
         "157.0",
         "109.0",
         "83.92344497607655",
         "25.933014354066984",
         "5.007974481658692",
         "3.476874003189793",
         "POINT (-104.893234 40.10293)",
         "4",
         "Micropolitan core",
         "Suburban",
         "1900",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Recent"
        ],
        [
         "24",
         "400978919",
         "I",
         "PICEANCE ENERGY LLC DBA LARAMIE ENERGY COMPANY",
         "10433",
         "400978919",
         "2016-01-27",
         "2011-01-31",
         "Historical",
         "NESE  ",
         "13",
         "7S    ",
         "94W    ",
         "6",
         "39.43559",
         "-107.8291",
         null,
         "GARFIELD       ",
         "WELL",
         null,
         "045",
         "17611",
         "N",
         "Y",
         "0",
         "0",
         "0",
         ">=5 and <100",
         "0",
         "Approx 40-50 bbl spilled",
         "0",
         "OTHER                              ",
         "Rangeland (Summer)",
         "Cold, snowing                      ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "CONTRACTOR WAS TRANSFERRING PRODUCED WATER WHEN THE FITTING (STAINLESS STEEL BAND) ON A 3\" HOSE GAVE WAY. WATER WAS RELEASED ON LOCATION UNTIL VALVE AND HOSE COULD BE ISOLATED. DISTANCE TO SURFACE WATER BASED ON DRAINAGE PATTERN AND WATER FLOW ROUTE. CLOSEST WATER WELL UP GRADIENT OF PAD.",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "0.0",
         null,
         "8045952003",
         "9520.03",
         "2376.0",
         "2025.0",
         "973.0",
         "108364.0",
         "52.0",
         "49.0",
         "85.22727272727273",
         "40.95117845117845",
         "2.1885521885521886",
         "2.0622895622895623",
         "POINT (-107.8291 39.43559)",
         "5",
         "Micropolitan high commuting",
         "Suburban",
         "1822",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Historical"
        ],
        [
         "25",
         "400979944",
         "S",
         "PICEANCE ENERGY LLC DBA LARAMIE ENERGY COMPANY",
         "10433",
         "400978919",
         "2016-01-27",
         "2011-01-31",
         "Historical",
         "NESE  ",
         "13",
         "7S    ",
         "94W    ",
         "6",
         "39.43559",
         "-107.8291",
         null,
         "GARFIELD       ",
         "WELL",
         null,
         "045",
         "17611",
         "N",
         "Y",
         "0",
         "0",
         "0",
         ">=5 and <100",
         "0",
         "Approx 40-50 bbl spilled",
         "0",
         "OTHER                              ",
         "Rangeland (Summer)",
         "Cold, snowing                      ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "CONTRACTOR WAS TRANSFERRING PRODUCED WATER WHEN THE FITTING (STAINLESS STEEL BAND) ON A 3\" HOSE GAVE WAY. WATER WAS RELEASED ON LOCATION UNTIL VALVE AND HOSE COULD BE ISOLATED. DISTANCE TO SURFACE WATER BASED ON DRAINAGE PATTERN AND WATER FLOW ROUTE. CLOSEST WATER WELL UP GRADIENT OF PAD.",
         "01/28/2016",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "55.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "1.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "150.0",
         "90.0",
         "0.0",
         null,
         "Visual observation of surface, fluid volumes pumped from spill. Fluid spill was on location. Site was surveyed to ensure no water went beyond berms on site. No spilled fluids migrated outside the bermed containment of the pad.",
         "Compacted Cimarron Loam, 2-2 1/2% slopes, Map Unit 16",
         "50.0",
         "0.0",
         "4195.0",
         "0.0",
         "1848.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         null,
         "1.0",
         null,
         "1.0",
         "No remediation required, spill was fully contained and fluids did not migrate into soils because the ground was frozen.",
         "2016-01-28",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "Contractor was transferring produced water when the fitting (stainless steel band) on a 3\" hose gave way.  Water was released on location until valve and hose could be isolated. *Distance to surface water based on drainage pattern and water flow route. Closest water well up gradient of pad. Valve to hose was closed. Water contained on location. Water truck on location sucked up all standing water onsite including melted snow (~55bbls). Environmental contractor (Olosn and Associates) investigated site 2/3/2011 and gathered soil sampes for anlaysis. No emergency pits required. Water stayed on location. See Photo (attachment) included with Initial F19 submittal. No remediation required, spill was fully contained and fluids did not migrate into soils because the ground was frozen.",
         "Laramie consulted with contractor to review exisitng fluid transfer protocols and to assure the contractor's staff adhere to protocols in the future. Additionally, contractors will inspect all hose fittings for signs of wear or damage. Any hoses found to have worn or damaged clamps will be replaced.",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "True",
         "0.0",
         null,
         "8045952003",
         "9520.03",
         "2376.0",
         "2025.0",
         "973.0",
         "108364.0",
         "52.0",
         "49.0",
         "85.22727272727273",
         "40.95117845117845",
         "2.1885521885521886",
         "2.0622895622895623",
         "POINT (-107.8291 39.43559)",
         "5",
         "Micropolitan high commuting",
         "Suburban",
         "1822",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Historical"
        ],
        [
         "37",
         "401991720",
         "S",
         "KERR MCGEE OIL & GAS ONSHORE LP",
         "47120",
         "401924669",
         "2019-01-31",
         "2014-03-03",
         "Recent",
         "SWNE  ",
         "23",
         "3N    ",
         "66W    ",
         "6",
         "40.212433",
         "-104.736178",
         null,
         "WELD           ",
         "TANK BATTERY",
         null,
         "   ",
         "     ",
         "N",
         "Y",
         "0",
         ">=5 and <100",
         "0",
         "0",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "40 degrees F.                      ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "On March 9, 2014, approximately 30 barrels of condensate were released inside secondary containment at the Sarchet 41-23, Sarchet UPRR 42-23 3X production facility when a motor valve seat and trim failed at the wellhead. Approximately 25 barrels of condensate were recovered via vacuum truck and transferred to a licensed injection facility for disposal. Excavation activities were guided in the field by screening soil for volatile organic compound (VOC) concentrations using a photoionization detector (PID). A topographic Site Location Map showing the geographic setting of the release is provided as Figure 1.",
         "04/01/2019",
         "0.0",
         "0.0",
         "0.0",
         "30.0",
         "25.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "41.0",
         "36.0",
         "6.0",
         null,
         "Reference Initial-Supplemental Form 19 (Document No. 401924669) and Initial eForm 27 (Document No. 401962387).",
         "Sandy silt",
         "20.0",
         "23.0",
         "390.0",
         "0.0",
         "1450.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         "975.0",
         "0.0",
         "1630.0",
         "0.0",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "1.0",
         "12741.0",
         "8123001800",
         "18.0",
         "4681.0",
         "3690.0",
         "1658.0",
         "85561.0",
         "273.0",
         "186.0",
         "78.82930997650075",
         "35.41978209784234",
         "5.832087160863064",
         "3.9735099337748343",
         "POINT (-104.736178 40.212433)",
         "3",
         "Metropolitan low commuting",
         "Urban",
         "1795",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Recent"
        ],
        [
         "36",
         "401924669",
         "I w/S",
         "KERR MCGEE OIL & GAS ONSHORE LP",
         "47120",
         "401924669",
         "2019-01-31",
         "2014-03-03",
         "Recent",
         "SWNE  ",
         "23",
         "3N    ",
         "66W    ",
         "6",
         "40.212433",
         "-104.736178",
         null,
         "WELD           ",
         "TANK BATTERY",
         null,
         "   ",
         "     ",
         "N",
         "Y",
         "0",
         ">=5 and <100",
         "0",
         "0",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "40 degrees F.                      ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "On March 9, 2014, approximately 30 barrels of condensate were released inside secondary containment at the Sarchet 41-23, Sarchet UPRR 42-23 3X production facility when a motor valve seat and trim failed at the wellhead. Approximately 25 barrels of condensate were recovered via vacuum truck and transferred to a licensed injection facility for disposal. Excavation activities were guided in the field by screening soil for volatile organic compound (VOC) concentrations using a photoionization detector (PID). A topographic Site Location Map showing the geographic setting of the release is provided as Figure 1.",
         "01/31/2019",
         "0.0",
         "0.0",
         "0.0",
         "30.0",
         "25.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "41.0",
         "36.0",
         "6.0",
         null,
         "On March 9, 2014, approximately 30 barrels of condensate were released inside secondary containment at the Sarchet 41-23, Sarchet UPRR 42-23 3X production facility. Approximately 160 cubic yards of impacted material were removed and transported to the Buffalo Ridge Landfill in Keenesburg, Colorado for disposal. Eight (8) confirmation soil samples were collected from the sidewalls and base of the final extent of the excavation area at depths ranging from approximately 4 feet to 6 feet below ground surface (bgs). The soil samples were submitted to eAnalytics Laboratory for analysis of benzene, toluene, ethylbenzene, total xylenes (BTEX), total petroleum hydrocarbons (TPH) - gasoline range organics (GRO) by USEPA Method 8260C, TPH - diesel and oil range organics (DRO and ORO) by USEPA Method 8015. Laboratory analytical results indicated that constituent concentrations in the soil samples collected from the final extent of the excavation area were in full compliance with COGCC standards. A topographic Site Location Map showing the geographic setting of the release is provided as Figure 1. Soil sample locations are illustrated on Figure 2. Soil analytical results are summarized in Table 1 and the laboratory analytical reports are provided as Attachment A. A Form 27 Site Investigation and Remediation Workplan - Produced Water Vessel Closure Report will be prepared for this release. ",
         "Sandy silt",
         "20.0",
         "23.0",
         "390.0",
         "0.0",
         "1450.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         "975.0",
         "0.0",
         "1630.0",
         "0.0",
         null,
         "2019-01-31",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "A release occurred from the production tank when a motor valve seat and trim failed at the wellhead.",
         "The production facility was rebuilt and the motor valve seat and trim were replaced at the wellhead.",
         "160.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         null,
         null,
         "False",
         "0.0",
         null,
         "8123001800",
         "18.0",
         "4681.0",
         "3690.0",
         "1658.0",
         "85561.0",
         "273.0",
         "186.0",
         "78.82930997650075",
         "35.41978209784234",
         "5.832087160863064",
         "3.9735099337748343",
         "POINT (-104.736178 40.212433)",
         "3",
         "Metropolitan low commuting",
         "Urban",
         "1795",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Recent"
        ]
       ],
       "shape": {
        "columns": 127,
        "rows": 20
       }
      },
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Document #</th>\n",
       "      <th>Report</th>\n",
       "      <th>Operator</th>\n",
       "      <th>Operator #</th>\n",
       "      <th>Tracking #</th>\n",
       "      <th>Initial Report Date</th>\n",
       "      <th>Date of Discovery</th>\n",
       "      <th>Spill Type</th>\n",
       "      <th>Qtr Qtr</th>\n",
       "      <th>Section</th>\n",
       "      <th>...</th>\n",
       "      <th>unemployment_rate</th>\n",
       "      <th>geometry</th>\n",
       "      <th>ruca_code</th>\n",
       "      <th>ruca_description</th>\n",
       "      <th>rurality</th>\n",
       "      <th>report_delay_full_days</th>\n",
       "      <th>report_delay_winsor99</th>\n",
       "      <th>report_delay_winsor99_int</th>\n",
       "      <th>Period</th>\n",
       "      <th>spill_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>402349927</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>ANADARKO DJ GAS PROCESSING LLC</td>\n",
       "      <td>10719</td>\n",
       "      <td>402349927</td>\n",
       "      <td>2020-03-23</td>\n",
       "      <td>1994-11-14</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SENE</td>\n",
       "      <td>32</td>\n",
       "      <td>...</td>\n",
       "      <td>0.379957</td>\n",
       "      <td>POINT (-104.680174 39.748143)</td>\n",
       "      <td>1</td>\n",
       "      <td>Metropolitan core</td>\n",
       "      <td>Urban</td>\n",
       "      <td>9261</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>402116460</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>NGL WATER SOLUTIONS DJ LLC</td>\n",
       "      <td>10373</td>\n",
       "      <td>402116460</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2004-01-01</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SESE</td>\n",
       "      <td>28</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>POINT (-104.887064 40.016567)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "      <td>5681</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>403791618</td>\n",
       "      <td>I</td>\n",
       "      <td>MAGPIE OPERATING INC</td>\n",
       "      <td>52530</td>\n",
       "      <td>403791618</td>\n",
       "      <td>2024-05-15</td>\n",
       "      <td>2011-08-30</td>\n",
       "      <td>Historical</td>\n",
       "      <td>NENE</td>\n",
       "      <td>36</td>\n",
       "      <td>...</td>\n",
       "      <td>3.477868</td>\n",
       "      <td>POINT (-103.462663 40.714817)</td>\n",
       "      <td>5</td>\n",
       "      <td>Micropolitan high commuting</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>4642</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>403846130</td>\n",
       "      <td>S</td>\n",
       "      <td>MAGPIE OPERATING INC</td>\n",
       "      <td>52530</td>\n",
       "      <td>403791618</td>\n",
       "      <td>2024-05-15</td>\n",
       "      <td>2011-08-30</td>\n",
       "      <td>Historical</td>\n",
       "      <td>NENE</td>\n",
       "      <td>36</td>\n",
       "      <td>...</td>\n",
       "      <td>3.477868</td>\n",
       "      <td>POINT (-103.462663 40.714817)</td>\n",
       "      <td>5</td>\n",
       "      <td>Micropolitan high commuting</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>4642</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>401893556</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>BONANZA CREEK ENERGY OPERATING COMPANY LLC</td>\n",
       "      <td>8960</td>\n",
       "      <td>401893556</td>\n",
       "      <td>2019-01-04</td>\n",
       "      <td>2009-01-24</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SESW</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>1.541138</td>\n",
       "      <td>POINT (-104.520309 40.30657)</td>\n",
       "      <td>2</td>\n",
       "      <td>Metropolitan high commuting</td>\n",
       "      <td>Urban</td>\n",
       "      <td>3632</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>404029999</td>\n",
       "      <td>I</td>\n",
       "      <td>IMPETRO RESOURCES LLC</td>\n",
       "      <td>10690</td>\n",
       "      <td>404029999</td>\n",
       "      <td>2024-12-16</td>\n",
       "      <td>2017-05-15</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SESW</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>1.922153</td>\n",
       "      <td>POINT (-103.509319 39.958799)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "      <td>2772</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>404037262</td>\n",
       "      <td>S</td>\n",
       "      <td>IMPETRO RESOURCES LLC</td>\n",
       "      <td>10690</td>\n",
       "      <td>404029999</td>\n",
       "      <td>2024-12-16</td>\n",
       "      <td>2017-05-15</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SESW</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>1.922153</td>\n",
       "      <td>POINT (-103.509319 39.958799)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "      <td>2772</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>403208400</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>KP KAUFFMAN COMPANY INC</td>\n",
       "      <td>46290</td>\n",
       "      <td>403208400</td>\n",
       "      <td>2022-10-26</td>\n",
       "      <td>2015-12-21</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SESE</td>\n",
       "      <td>29</td>\n",
       "      <td>...</td>\n",
       "      <td>1.297038</td>\n",
       "      <td>POINT (-103.89023 40.10257)</td>\n",
       "      <td>4</td>\n",
       "      <td>Micropolitan core</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>2501</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>402253095</td>\n",
       "      <td>S</td>\n",
       "      <td>DCP OPERATING COMPANY LP</td>\n",
       "      <td>4680</td>\n",
       "      <td>402226829</td>\n",
       "      <td>2019-10-30</td>\n",
       "      <td>2013-07-22</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SWSW</td>\n",
       "      <td>17</td>\n",
       "      <td>...</td>\n",
       "      <td>0.120773</td>\n",
       "      <td>POINT (-104.806776 40.13091)</td>\n",
       "      <td>2</td>\n",
       "      <td>Metropolitan high commuting</td>\n",
       "      <td>Urban</td>\n",
       "      <td>2291</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>402226829</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>DCP OPERATING COMPANY LP</td>\n",
       "      <td>4680</td>\n",
       "      <td>402226829</td>\n",
       "      <td>2019-10-30</td>\n",
       "      <td>2013-07-22</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SWSW</td>\n",
       "      <td>17</td>\n",
       "      <td>...</td>\n",
       "      <td>0.120773</td>\n",
       "      <td>POINT (-104.806776 40.13091)</td>\n",
       "      <td>2</td>\n",
       "      <td>Metropolitan high commuting</td>\n",
       "      <td>Urban</td>\n",
       "      <td>2291</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>402081663</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>KERR MCGEE GATHERING LLC</td>\n",
       "      <td>47121</td>\n",
       "      <td>402081663</td>\n",
       "      <td>2019-06-20</td>\n",
       "      <td>2013-05-10</td>\n",
       "      <td>Recent</td>\n",
       "      <td>SESE</td>\n",
       "      <td>15</td>\n",
       "      <td>...</td>\n",
       "      <td>2.433281</td>\n",
       "      <td>POINT (-104.640812 39.95913)</td>\n",
       "      <td>2</td>\n",
       "      <td>Metropolitan high commuting</td>\n",
       "      <td>Urban</td>\n",
       "      <td>2232</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Recent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>403944915</td>\n",
       "      <td>S</td>\n",
       "      <td>WESTERN OPERATING COMPANY</td>\n",
       "      <td>95620</td>\n",
       "      <td>403276008</td>\n",
       "      <td>2022-12-30</td>\n",
       "      <td>2017-02-09</td>\n",
       "      <td>Historical</td>\n",
       "      <td>NESE</td>\n",
       "      <td>27</td>\n",
       "      <td>...</td>\n",
       "      <td>5.067218</td>\n",
       "      <td>POINT (-103.269374 40.895966)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "      <td>2150</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>403276008</td>\n",
       "      <td>I</td>\n",
       "      <td>WESTERN OPERATING COMPANY</td>\n",
       "      <td>95620</td>\n",
       "      <td>403276008</td>\n",
       "      <td>2022-12-30</td>\n",
       "      <td>2017-02-09</td>\n",
       "      <td>Historical</td>\n",
       "      <td>NESE</td>\n",
       "      <td>27</td>\n",
       "      <td>...</td>\n",
       "      <td>5.067218</td>\n",
       "      <td>POINT (-103.269374 40.895966)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "      <td>2150</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>57</th>\n",
       "      <td>403332304</td>\n",
       "      <td>S</td>\n",
       "      <td>WESTERN OPERATING COMPANY</td>\n",
       "      <td>95620</td>\n",
       "      <td>403272313</td>\n",
       "      <td>2022-12-27</td>\n",
       "      <td>2017-08-25</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SWSW</td>\n",
       "      <td>26</td>\n",
       "      <td>...</td>\n",
       "      <td>5.067218</td>\n",
       "      <td>POINT (-103.265038 40.892679)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "      <td>1950</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>403272313</td>\n",
       "      <td>I</td>\n",
       "      <td>WESTERN OPERATING COMPANY</td>\n",
       "      <td>95620</td>\n",
       "      <td>403272313</td>\n",
       "      <td>2022-12-27</td>\n",
       "      <td>2017-08-25</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SWSW</td>\n",
       "      <td>26</td>\n",
       "      <td>...</td>\n",
       "      <td>5.067218</td>\n",
       "      <td>POINT (-103.265038 40.892679)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "      <td>1950</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>402081722</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>KERR MCGEE GATHERING LLC</td>\n",
       "      <td>47121</td>\n",
       "      <td>402081722</td>\n",
       "      <td>2019-06-20</td>\n",
       "      <td>2014-04-07</td>\n",
       "      <td>Recent</td>\n",
       "      <td>SWSE</td>\n",
       "      <td>28</td>\n",
       "      <td>...</td>\n",
       "      <td>3.476874</td>\n",
       "      <td>POINT (-104.893234 40.10293)</td>\n",
       "      <td>4</td>\n",
       "      <td>Micropolitan core</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>1900</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Recent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>400978919</td>\n",
       "      <td>I</td>\n",
       "      <td>PICEANCE ENERGY LLC DBA LARAMIE ENERGY COMPANY</td>\n",
       "      <td>10433</td>\n",
       "      <td>400978919</td>\n",
       "      <td>2016-01-27</td>\n",
       "      <td>2011-01-31</td>\n",
       "      <td>Historical</td>\n",
       "      <td>NESE</td>\n",
       "      <td>13</td>\n",
       "      <td>...</td>\n",
       "      <td>2.062290</td>\n",
       "      <td>POINT (-107.8291 39.43559)</td>\n",
       "      <td>5</td>\n",
       "      <td>Micropolitan high commuting</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>1822</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>400979944</td>\n",
       "      <td>S</td>\n",
       "      <td>PICEANCE ENERGY LLC DBA LARAMIE ENERGY COMPANY</td>\n",
       "      <td>10433</td>\n",
       "      <td>400978919</td>\n",
       "      <td>2016-01-27</td>\n",
       "      <td>2011-01-31</td>\n",
       "      <td>Historical</td>\n",
       "      <td>NESE</td>\n",
       "      <td>13</td>\n",
       "      <td>...</td>\n",
       "      <td>2.062290</td>\n",
       "      <td>POINT (-107.8291 39.43559)</td>\n",
       "      <td>5</td>\n",
       "      <td>Micropolitan high commuting</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>1822</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>401991720</td>\n",
       "      <td>S</td>\n",
       "      <td>KERR MCGEE OIL &amp; GAS ONSHORE LP</td>\n",
       "      <td>47120</td>\n",
       "      <td>401924669</td>\n",
       "      <td>2019-01-31</td>\n",
       "      <td>2014-03-03</td>\n",
       "      <td>Recent</td>\n",
       "      <td>SWNE</td>\n",
       "      <td>23</td>\n",
       "      <td>...</td>\n",
       "      <td>3.973510</td>\n",
       "      <td>POINT (-104.736178 40.212433)</td>\n",
       "      <td>3</td>\n",
       "      <td>Metropolitan low commuting</td>\n",
       "      <td>Urban</td>\n",
       "      <td>1795</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Recent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>401924669</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>KERR MCGEE OIL &amp; GAS ONSHORE LP</td>\n",
       "      <td>47120</td>\n",
       "      <td>401924669</td>\n",
       "      <td>2019-01-31</td>\n",
       "      <td>2014-03-03</td>\n",
       "      <td>Recent</td>\n",
       "      <td>SWNE</td>\n",
       "      <td>23</td>\n",
       "      <td>...</td>\n",
       "      <td>3.973510</td>\n",
       "      <td>POINT (-104.736178 40.212433)</td>\n",
       "      <td>3</td>\n",
       "      <td>Metropolitan low commuting</td>\n",
       "      <td>Urban</td>\n",
       "      <td>1795</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Recent</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>20 rows × 127 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Document # Report                                        Operator  \\\n",
       "44   402349927  I w/S                  ANADARKO DJ GAS PROCESSING LLC   \n",
       "41   402116460  I w/S                      NGL WATER SOLUTIONS DJ LLC   \n",
       "65   403791618      I                            MAGPIE OPERATING INC   \n",
       "66   403846130      S                            MAGPIE OPERATING INC   \n",
       "35   401893556  I w/S      BONANZA CREEK ENERGY OPERATING COMPANY LLC   \n",
       "76   404029999      I                           IMPETRO RESOURCES LLC   \n",
       "77   404037262      S                           IMPETRO RESOURCES LLC   \n",
       "50   403208400  I w/S                         KP KAUFFMAN COMPANY INC   \n",
       "43   402253095      S                        DCP OPERATING COMPANY LP   \n",
       "42   402226829  I w/S                        DCP OPERATING COMPANY LP   \n",
       "39   402081663  I w/S                        KERR MCGEE GATHERING LLC   \n",
       "70   403944915      S                       WESTERN OPERATING COMPANY   \n",
       "54   403276008      I                       WESTERN OPERATING COMPANY   \n",
       "57   403332304      S                       WESTERN OPERATING COMPANY   \n",
       "53   403272313      I                       WESTERN OPERATING COMPANY   \n",
       "40   402081722  I w/S                        KERR MCGEE GATHERING LLC   \n",
       "24   400978919      I  PICEANCE ENERGY LLC DBA LARAMIE ENERGY COMPANY   \n",
       "25   400979944      S  PICEANCE ENERGY LLC DBA LARAMIE ENERGY COMPANY   \n",
       "37   401991720      S                 KERR MCGEE OIL & GAS ONSHORE LP   \n",
       "36   401924669  I w/S                 KERR MCGEE OIL & GAS ONSHORE LP   \n",
       "\n",
       "    Operator #  Tracking # Initial Report Date Date of Discovery  Spill Type  \\\n",
       "44       10719   402349927          2020-03-23        1994-11-14  Historical   \n",
       "41       10373   402116460          2019-07-22        2004-01-01  Historical   \n",
       "65       52530   403791618          2024-05-15        2011-08-30  Historical   \n",
       "66       52530   403791618          2024-05-15        2011-08-30  Historical   \n",
       "35        8960   401893556          2019-01-04        2009-01-24  Historical   \n",
       "76       10690   404029999          2024-12-16        2017-05-15  Historical   \n",
       "77       10690   404029999          2024-12-16        2017-05-15  Historical   \n",
       "50       46290   403208400          2022-10-26        2015-12-21  Historical   \n",
       "43        4680   402226829          2019-10-30        2013-07-22  Historical   \n",
       "42        4680   402226829          2019-10-30        2013-07-22  Historical   \n",
       "39       47121   402081663          2019-06-20        2013-05-10      Recent   \n",
       "70       95620   403276008          2022-12-30        2017-02-09  Historical   \n",
       "54       95620   403276008          2022-12-30        2017-02-09  Historical   \n",
       "57       95620   403272313          2022-12-27        2017-08-25  Historical   \n",
       "53       95620   403272313          2022-12-27        2017-08-25  Historical   \n",
       "40       47121   402081722          2019-06-20        2014-04-07      Recent   \n",
       "24       10433   400978919          2016-01-27        2011-01-31  Historical   \n",
       "25       10433   400978919          2016-01-27        2011-01-31  Historical   \n",
       "37       47120   401924669          2019-01-31        2014-03-03      Recent   \n",
       "36       47120   401924669          2019-01-31        2014-03-03      Recent   \n",
       "\n",
       "   Qtr Qtr  Section  ... unemployment_rate                       geometry  \\\n",
       "44  SENE         32  ...          0.379957  POINT (-104.680174 39.748143)   \n",
       "41  SESE         28  ...          0.000000  POINT (-104.887064 40.016567)   \n",
       "65  NENE         36  ...          3.477868  POINT (-103.462663 40.714817)   \n",
       "66  NENE         36  ...          3.477868  POINT (-103.462663 40.714817)   \n",
       "35  SESW         14  ...          1.541138   POINT (-104.520309 40.30657)   \n",
       "76  SESW         14  ...          1.922153  POINT (-103.509319 39.958799)   \n",
       "77  SESW         14  ...          1.922153  POINT (-103.509319 39.958799)   \n",
       "50  SESE         29  ...          1.297038    POINT (-103.89023 40.10257)   \n",
       "43  SWSW         17  ...          0.120773   POINT (-104.806776 40.13091)   \n",
       "42  SWSW         17  ...          0.120773   POINT (-104.806776 40.13091)   \n",
       "39  SESE         15  ...          2.433281   POINT (-104.640812 39.95913)   \n",
       "70  NESE         27  ...          5.067218  POINT (-103.269374 40.895966)   \n",
       "54  NESE         27  ...          5.067218  POINT (-103.269374 40.895966)   \n",
       "57  SWSW         26  ...          5.067218  POINT (-103.265038 40.892679)   \n",
       "53  SWSW         26  ...          5.067218  POINT (-103.265038 40.892679)   \n",
       "40  SWSE         28  ...          3.476874   POINT (-104.893234 40.10293)   \n",
       "24  NESE         13  ...          2.062290     POINT (-107.8291 39.43559)   \n",
       "25  NESE         13  ...          2.062290     POINT (-107.8291 39.43559)   \n",
       "37  SWNE         23  ...          3.973510  POINT (-104.736178 40.212433)   \n",
       "36  SWNE         23  ...          3.973510  POINT (-104.736178 40.212433)   \n",
       "\n",
       "   ruca_code             ruca_description  rurality report_delay_full_days  \\\n",
       "44         1            Metropolitan core     Urban                   9261   \n",
       "41        10                   Rural area     Rural                   5681   \n",
       "65         5  Micropolitan high commuting  Suburban                   4642   \n",
       "66         5  Micropolitan high commuting  Suburban                   4642   \n",
       "35         2  Metropolitan high commuting     Urban                   3632   \n",
       "76        10                   Rural area     Rural                   2772   \n",
       "77        10                   Rural area     Rural                   2772   \n",
       "50         4            Micropolitan core  Suburban                   2501   \n",
       "43         2  Metropolitan high commuting     Urban                   2291   \n",
       "42         2  Metropolitan high commuting     Urban                   2291   \n",
       "39         2  Metropolitan high commuting     Urban                   2232   \n",
       "70        10                   Rural area     Rural                   2150   \n",
       "54        10                   Rural area     Rural                   2150   \n",
       "57        10                   Rural area     Rural                   1950   \n",
       "53        10                   Rural area     Rural                   1950   \n",
       "40         4            Micropolitan core  Suburban                   1900   \n",
       "24         5  Micropolitan high commuting  Suburban                   1822   \n",
       "25         5  Micropolitan high commuting  Suburban                   1822   \n",
       "37         3   Metropolitan low commuting     Urban                   1795   \n",
       "36         3   Metropolitan low commuting     Urban                   1795   \n",
       "\n",
       "   report_delay_winsor99 report_delay_winsor99_int          Period  spill_type  \n",
       "44                173.43                       173  2020 and After  Historical  \n",
       "41                173.43                       173     Before 2020  Historical  \n",
       "65                173.43                       173  2020 and After  Historical  \n",
       "66                173.43                       173  2020 and After  Historical  \n",
       "35                173.43                       173     Before 2020  Historical  \n",
       "76                173.43                       173  2020 and After  Historical  \n",
       "77                173.43                       173  2020 and After  Historical  \n",
       "50                173.43                       173  2020 and After  Historical  \n",
       "43                173.43                       173     Before 2020  Historical  \n",
       "42                173.43                       173     Before 2020  Historical  \n",
       "39                173.43                       173     Before 2020      Recent  \n",
       "70                173.43                       173  2020 and After  Historical  \n",
       "54                173.43                       173  2020 and After  Historical  \n",
       "57                173.43                       173  2020 and After  Historical  \n",
       "53                173.43                       173  2020 and After  Historical  \n",
       "40                173.43                       173     Before 2020      Recent  \n",
       "24                173.43                       173     Before 2020  Historical  \n",
       "25                173.43                       173     Before 2020  Historical  \n",
       "37                173.43                       173     Before 2020      Recent  \n",
       "36                173.43                       173     Before 2020      Recent  \n",
       "\n",
       "[20 rows x 127 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "index",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Document #",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Report",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Operator",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Operator #",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Tracking #",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Initial Report Date",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Date of Discovery",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Spill Type",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Qtr Qtr",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Section",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Township",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "range",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "meridian",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Latitude",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Longitude",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Municipality",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "county",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Facility Type",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Facility ID",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "API County Code",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "API Sequence Number",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Spilled outside of berms",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "More than five barrels spilled",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Oil Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Condensate Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Flow Back Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Produced Water Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "E&P Waste Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Other Waste",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Drilling Fluid Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Current Land Use",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Other Land Use",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Weather Conditions",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Surface Owner",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Surface Owner Other",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Waters of the State",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Residence / Occupied Structure",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "livestock",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Public Byway",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water Supply Area",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Spill Description",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Supplemental Report Date",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Oil BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Oil BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Oil Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Condensate BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Condensate BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Condensate Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Produced Water BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Produced Water BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Produced Water Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Drilling Fluid BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Drilling Fluid BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Drilling Fluid Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Flow Back Fluid BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Flow Back Fluid BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Flow Back Fluid Unkown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste BBLS Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste BBLS Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Spill Contained within Berm",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Emergency Pit Constructed",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "soil",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "groundwater",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Dry Drainage Feature",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Area Length",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Area Width",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Depth of Impact in Feet",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Depth of Impact in Inches",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Area Depth Determined",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Geology Description",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Depth to Groundwater",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Water wells in area",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Water Wells",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Water Wells None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water Near",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Wetlands",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Wetlands None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Springs",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Springs None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Livestock Near",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Livestock None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Occupied Buildings",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Occupied Buildings None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Additional Spill Details",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Supplemental Report Date CA",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Human Error",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Equipment Failure",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Historical Unkown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other Description",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Root Cause",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Preventative Measures",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Soil Excavated",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Offsite Disposal",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Onsite Treatment",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other Disposition",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other Disposition Description",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Ground Water Removed",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water Removed",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Corrective Actions Completed",
         "rawType": "bool",
         "type": "boolean"
        },
        {
         "name": "Approved Form 27",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Form 27 Project Number",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "GEOID",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "TRACT_NAME",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "total_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "white_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "hispanic_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "median_household_income",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "poverty_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "unemployed_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "percent_white",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "percent_hispanic",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "percent_poverty",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "unemployment_rate",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "geometry",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "ruca_code",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "ruca_description",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "rurality",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "report_delay_full_days",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "report_delay_winsor99",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "report_delay_winsor99_int",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Period",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "spill_type",
         "rawType": "object",
         "type": "string"
        }
       ],
       "ref": "26e920eb-4b87-4df8-8cd4-653ccf564e43",
       "rows": [],
       "shape": {
        "columns": 127,
        "rows": 0
       }
      },
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Document #</th>\n",
       "      <th>Report</th>\n",
       "      <th>Operator</th>\n",
       "      <th>Operator #</th>\n",
       "      <th>Tracking #</th>\n",
       "      <th>Initial Report Date</th>\n",
       "      <th>Date of Discovery</th>\n",
       "      <th>Spill Type</th>\n",
       "      <th>Qtr Qtr</th>\n",
       "      <th>Section</th>\n",
       "      <th>...</th>\n",
       "      <th>unemployment_rate</th>\n",
       "      <th>geometry</th>\n",
       "      <th>ruca_code</th>\n",
       "      <th>ruca_description</th>\n",
       "      <th>rurality</th>\n",
       "      <th>report_delay_full_days</th>\n",
       "      <th>report_delay_winsor99</th>\n",
       "      <th>report_delay_winsor99_int</th>\n",
       "      <th>Period</th>\n",
       "      <th>spill_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>0 rows × 127 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [Document #, Report, Operator, Operator #, Tracking #, Initial Report Date, Date of Discovery, Spill Type, Qtr Qtr, Section, Township, range, meridian, Latitude, Longitude, Municipality, county, Facility Type, Facility ID, API County Code, API Sequence Number, Spilled outside of berms, More than five barrels spilled, Oil Spill Volume, Condensate Spill Volume, Flow Back Spill Volume, Produced Water Spill Volume, E&P Waste Spill Volume, Other Waste, Drilling Fluid Spill Volume, Current Land Use, Other Land Use, Weather Conditions, Surface Owner, Surface Owner Other, Waters of the State, Residence / Occupied Structure, livestock, Public Byway, Surface Water Supply Area, Spill Description, Supplemental Report Date, Oil BBLs Spilled, Oil BBLs Recovered, Oil Unknown, Condensate BBLs Spilled, Condensate BBLs Recovered, Condensate Unknown, Produced Water BBLs Spilled, Produced Water BBLs Recovered, Produced Water Unknown, Drilling Fluid BBLs Spilled, Drilling Fluid BBLs Recovered, Drilling Fluid Unknown, Flow Back Fluid BBLs Spilled, Flow Back Fluid BBLs Recovered, Flow Back Fluid Unkown, Other E&P Waste BBLS Spilled, Other E&P Waste BBLS Recovered, Other E&P Waste Unknown, Other E&P Waste, Spill Contained within Berm, Emergency Pit Constructed, soil, groundwater, Surface Water, Dry Drainage Feature, Surface Area Length, Surface Area Width, Depth of Impact in Feet, Depth of Impact in Inches, Area Depth Determined, Geology Description, Depth to Groundwater, Water wells in area, Water Wells, Water Wells None, Surface Water Near, Surface Water None, Wetlands, Wetlands None, Springs, Springs None, Livestock Near, Livestock None, Occupied Buildings, Occupied Buildings None, Additional Spill Details, Supplemental Report Date CA, Human Error, Equipment Failure, Historical Unkown, Other, Other Description, Root Cause, Preventative Measures, Soil Excavated, Offsite Disposal, Onsite Treatment, Other Disposition, ...]\n",
       "Index: []\n",
       "\n",
       "[0 rows x 127 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "index",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Document #",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Report",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Operator",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Operator #",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Tracking #",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Initial Report Date",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Date of Discovery",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Spill Type",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Qtr Qtr",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Section",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Township",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "range",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "meridian",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Latitude",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Longitude",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Municipality",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "county",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Facility Type",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Facility ID",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "API County Code",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "API Sequence Number",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Spilled outside of berms",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "More than five barrels spilled",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Oil Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Condensate Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Flow Back Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Produced Water Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "E&P Waste Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Other Waste",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Drilling Fluid Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Current Land Use",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Other Land Use",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Weather Conditions",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Surface Owner",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Surface Owner Other",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Waters of the State",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Residence / Occupied Structure",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "livestock",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Public Byway",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water Supply Area",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Spill Description",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Supplemental Report Date",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Oil BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Oil BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Oil Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Condensate BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Condensate BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Condensate Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Produced Water BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Produced Water BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Produced Water Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Drilling Fluid BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Drilling Fluid BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Drilling Fluid Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Flow Back Fluid BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Flow Back Fluid BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Flow Back Fluid Unkown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste BBLS Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste BBLS Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Spill Contained within Berm",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Emergency Pit Constructed",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "soil",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "groundwater",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Dry Drainage Feature",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Area Length",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Area Width",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Depth of Impact in Feet",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Depth of Impact in Inches",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Area Depth Determined",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Geology Description",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Depth to Groundwater",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Water wells in area",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Water Wells",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Water Wells None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water Near",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Wetlands",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Wetlands None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Springs",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Springs None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Livestock Near",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Livestock None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Occupied Buildings",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Occupied Buildings None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Additional Spill Details",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Supplemental Report Date CA",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Human Error",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Equipment Failure",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Historical Unkown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other Description",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Root Cause",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Preventative Measures",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "Soil Excavated",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Offsite Disposal",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Onsite Treatment",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other Disposition",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other Disposition Description",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Ground Water Removed",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water Removed",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Corrective Actions Completed",
         "rawType": "bool",
         "type": "boolean"
        },
        {
         "name": "Approved Form 27",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Form 27 Project Number",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "GEOID",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "TRACT_NAME",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "total_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "white_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "hispanic_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "median_household_income",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "poverty_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "unemployed_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "percent_white",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "percent_hispanic",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "percent_poverty",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "unemployment_rate",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "geometry",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "ruca_code",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "ruca_description",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "rurality",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "report_delay_full_days",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "report_delay_winsor99",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "report_delay_winsor99_int",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Period",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "spill_type",
         "rawType": "object",
         "type": "string"
        }
       ],
       "ref": "333100b2-0371-4e3a-8997-01300cb7ed00",
       "rows": [
        [
         "44",
         "402349927",
         "I w/S",
         "ANADARKO DJ GAS PROCESSING LLC",
         "10719",
         "402349927",
         "2020-03-23",
         "1994-11-14",
         "Historical",
         "SENE  ",
         "32",
         "3S    ",
         "65W    ",
         "6",
         "39.748143",
         "-104.680174",
         null,
         "ADAMS          ",
         "GAS PROCESSING PLANT",
         "255983.0",
         "   ",
         "     ",
         "Y",
         "N",
         "0",
         "0",
         "0",
         "0",
         "Unknown",
         "Water and soil impacted by a mix of E&P and non-E&P materials",
         "0",
         "CROP LAND                          ",
         null,
         "Unknown, historical release        ",
         "OTHER (SPECIFY)",
         "DJ Gas Processing LLC",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "Two Flare Fluid Storage Pits (#1 and #2) were historically operated at the Wattenberg Gas Plant. During decommissioning of the former Flare Fluid Storage Pits, initial investigation activities indicated that hydrocarbon impacts to soil and groundwater were present at the site. The COGCC had previously issued Remediation Project No. 1688 for the release from the former Flare Fluid Storage Pits, however this Remediation Project was inadvertently closed prior to achieving No Further Action (NFA) criteria. As a result, a Form 27-Initial was re-filed with the COGCC on January 6, 2020 (COGCC Document No. 402274364) and Remediation Project No. 14874 was issued. This Form 19 is being submitted to establish a new Spill/Release Point ID for the release from the former Flare Fluid Storage Pits, as noted in the Form 27-Initial. A topographic Site Location Map showing the geographic setting of the release is provided as Figure 1.",
         "04/06/2020",
         null,
         null,
         "1.0",
         null,
         null,
         "1.0",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         "1.0",
         "Water and soil impacted by a mix of E&P and non-E&P materials",
         "0.0",
         "0.0",
         "1.0",
         "1.0",
         "0.0",
         "0.0",
         "150.0",
         "120.0",
         "15.0",
         null,
         "Reference Form 27-Initial (Document No. 402274364).",
         "Clay with sand",
         "12.0",
         "4.0",
         "550.0",
         "0.0",
         "300.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         "2730.0",
         "0.0",
         "380.0",
         "0.0",
         null,
         "2020-04-06",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "Historical impacts were discovered during decommissioning of the former Flare Fluid Storage Pits.",
         "The former Flare Fluid Storage Pits were removed and replaced with an engineered above ground storage tank in a lined berm.",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         null,
         "False",
         "1.0",
         "14874.0",
         "8001008354",
         "83.54",
         "4211.0",
         "1204.0",
         "992.0",
         "101250.0",
         "453.0",
         "16.0",
         "28.59178342436476",
         "23.55734979814771",
         "10.757539776775111",
         "0.379957254808834",
         "POINT (-104.680174 39.748143)",
         "1",
         "Metropolitan core",
         "Urban",
         "9261",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "41",
         "402116460",
         "I w/S",
         "NGL WATER SOLUTIONS DJ LLC",
         "10373",
         "402116460",
         "2019-07-22",
         "2004-01-01",
         "Historical",
         "SESE  ",
         "28",
         "1N    ",
         "67W    ",
         "6",
         "40.016567",
         "-104.887064",
         null,
         "WELD           ",
         "PRODUCED WATER TRANSFER SYSTEM",
         null,
         "123",
         "18763",
         "N",
         "N",
         "0",
         "0",
         "0",
         ">0 and <1",
         "0",
         null,
         "0",
         "CROP LAND                          ",
         null,
         "Overcast                           ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "Minor spill near wellhead",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "1.0",
         "1837.0",
         "8123002006",
         "20.06",
         "408.0",
         "323.0",
         "44.0",
         "143646.0",
         "17.0",
         "0.0",
         "79.16666666666666",
         "10.784313725490197",
         "4.166666666666666",
         "0.0",
         "POINT (-104.887064 40.016567)",
         "10",
         "Rural area",
         "Rural",
         "5681",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Historical"
        ],
        [
         "65",
         "403791618",
         "I",
         "MAGPIE OPERATING INC",
         "52530",
         "403791618",
         "2024-05-15",
         "2011-08-30",
         "Historical",
         "NENE  ",
         "36",
         "9N    ",
         "55W    ",
         "6",
         "40.714817",
         "-103.462663",
         null,
         "LOGAN          ",
         "PIT",
         "116333.0",
         "   ",
         "     ",
         null,
         "N",
         "0",
         "0",
         "0",
         "Unknown",
         "Unknown",
         "Three historic evaporation pits",
         "0",
         "NON-CROP LAND                      ",
         null,
         "Unknown at time of discovery       ",
         "OTHER (SPECIFY)",
         "CO State Land Board",
         null,
         null,
         null,
         null,
         null,
         "An Initial Form 27 was submitted on 8/30/2011 (Document 1761290) to complete administrative pit closure on three unlined pits at the Site (pit closure occurred in 1997). Subsequent Form 27 Supplementals have documented sample collection and analysis. Inspection performed on 01/03/2024 (Document 709100202) referenced salt scarring and need for additional sampling/analysis for full Table 915-1 parameters. Approved Form 27 Supplemental (Document 403738665) was completed to outline next assessment action; this Document included a COA to complete a Form 19 to document historic release. Upon approval of this Form 19, a Form 19 Supplemental will be submitted requesting closure with additional Site Investigation to continue under Remediation Project #6103.",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "0.0",
         null,
         "8075966000",
         "9660.0",
         "2214.0",
         "2011.0",
         "310.0",
         "61339.0",
         "259.0",
         "77.0",
         "90.83107497741643",
         "14.001806684733516",
         "11.698283649503162",
         "3.477868112014453",
         "POINT (-103.462663 40.714817)",
         "5",
         "Micropolitan high commuting",
         "Suburban",
         "4642",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "66",
         "403846130",
         "S",
         "MAGPIE OPERATING INC",
         "52530",
         "403791618",
         "2024-05-15",
         "2011-08-30",
         "Historical",
         "NENE  ",
         "36",
         "9N    ",
         "55W    ",
         "6",
         "40.714817",
         "-103.462663",
         null,
         "LOGAN          ",
         "PIT",
         "116333.0",
         "   ",
         "     ",
         null,
         "N",
         "0",
         "0",
         "0",
         "Unknown",
         "Unknown",
         "Three historic evaporation pits",
         "0",
         "NON-CROP LAND                      ",
         null,
         "Unknown at time of discovery       ",
         "OTHER (SPECIFY)",
         "CO State Land Board",
         null,
         null,
         null,
         null,
         null,
         "An Initial Form 27 was submitted on 8/30/2011 (Document 1761290) to complete administrative pit closure on three unlined pits at the Site (pit closure occurred in 1997). Subsequent Form 27 Supplementals have documented sample collection and analysis. Inspection performed on 01/03/2024 (Document 709100202) referenced salt scarring and need for additional sampling/analysis for full Table 915-1 parameters. Approved Form 27 Supplemental (Document 403738665) was completed to outline next assessment action; this Document included a COA to complete a Form 19 to document historic release. \n\nThis Form 19 Supplemental requests closure with additional Site Investigation to continue under Remediation Project #6103.",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "1.0",
         "6103.0",
         "8075966000",
         "9660.0",
         "2214.0",
         "2011.0",
         "310.0",
         "61339.0",
         "259.0",
         "77.0",
         "90.83107497741643",
         "14.001806684733516",
         "11.698283649503162",
         "3.477868112014453",
         "POINT (-103.462663 40.714817)",
         "5",
         "Micropolitan high commuting",
         "Suburban",
         "4642",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "35",
         "401893556",
         "I w/S",
         "BONANZA CREEK ENERGY OPERATING COMPANY LLC",
         "8960",
         "401893556",
         "2019-01-04",
         "2009-01-24",
         "Historical",
         "SESW  ",
         "14",
         "4N    ",
         "64W    ",
         "6",
         "40.30657",
         "-104.520309",
         null,
         "WELD           ",
         "TANK BATTERY",
         "323325.0",
         "   ",
         "     ",
         "N",
         "Y",
         "Unknown",
         "0",
         "0",
         "0",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "Cold, Snow                         ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "This is a historic release that as initially reported back in 2009, but was never closed.  A loadline froze overnight and failed at the production tank. The release was contained to the earthen containment berm. The oil was vac'd up and the impacted soil was removed.",
         "01/04/2019",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         null,
         null,
         "This is an NFA request for a release that occurred in 2009 with limited documented details. The dimensions of the surface area impact are currently unknown, but assumed to be a portion of the erathen containment area behind the tank.",
         "Dacono clay loam, 0-1 percent slopes.",
         "30.0",
         "9.0",
         "814.0",
         "0.0",
         "1700.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         null,
         "1.0",
         "70.0",
         "0.0",
         "This is a historic release. BCEI originally submitted an initial Form 19 and notification back in 2009. However, supplemental forms were never filed on behalf of BCEI. The original release footprint is currently unknown. Two confirmation soil samples were collected around the release point and analyzed for TPH and BTEX. Analytical results indicate compliance with COGCC Table 910-1. BCEI respectfully requests an NFA determination.",
         "2019-01-04",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "A loadline froze and ruptured releasing and unknown amount of oil.",
         "Heat tape and insulation are used to help prevent future freezes.",
         null,
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "True",
         "0.0",
         null,
         "8123001600",
         "16.0",
         "4023.0",
         "3581.0",
         "612.0",
         "82865.0",
         "268.0",
         "62.0",
         "89.01317424807358",
         "15.212527964205815",
         "6.661695252299279",
         "1.5411384538901318",
         "POINT (-104.520309 40.30657)",
         "2",
         "Metropolitan high commuting",
         "Urban",
         "3632",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Historical"
        ],
        [
         "76",
         "404029999",
         "I",
         "IMPETRO RESOURCES LLC",
         "10690",
         "404029999",
         "2024-12-16",
         "2017-05-15",
         "Historical",
         "SESW  ",
         "14",
         "1S    ",
         "55W    ",
         "6",
         "39.958799",
         "-103.509319",
         null,
         "WASHINGTON     ",
         "PIT",
         "101966.0",
         "   ",
         "     ",
         null,
         "N",
         "Unknown",
         "0",
         "0",
         "Unknown",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "unknown                            ",
         "FEE",
         null,
         null,
         null,
         null,
         null,
         null,
         "The Gettman 14-14 well and associated tank battery were acquired by Impetro Resources, LLC in July 2023. Impetro has been unable to determine or identify detailed investigation and/or remediation activities that were performed by the previous operator (#94300) beyond the historical information submitted in the documents uploaded to the ECMC database. This Form 19 is being submitted to comply with the COAs from the previously submitted Form 27 (#403930289), Operator shall submit a Form 19, per Rule 912.b.(1).E.: \" The discovery of 10 cubic yards or more of impacted material resulting from a current or historic Spill or Release. Discovery and reporting will not be contingent upon confirmation samples demonstrating exceedance of Table 915-1 standards.\" since the Remedial Action Plan documents 52 cubic yards of impacted material from this historic spill/release. A waste manifest was submitted from 2017 documenting the removal of 54.23 tons of impacted soil from the site.",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "0.0",
         null,
         "8121924100",
         "9241.0",
         "2081.0",
         "1968.0",
         "196.0",
         "56875.0",
         "220.0",
         "40.0",
         "94.56991830850554",
         "9.418548774627585",
         "10.571840461316674",
         "1.9221528111484865",
         "POINT (-103.509319 39.958799)",
         "10",
         "Rural area",
         "Rural",
         "2772",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "77",
         "404037262",
         "S",
         "IMPETRO RESOURCES LLC",
         "10690",
         "404029999",
         "2024-12-16",
         "2017-05-15",
         "Historical",
         "SESW  ",
         "14",
         "1S    ",
         "55W    ",
         "6",
         "39.958799",
         "-103.509319",
         null,
         "WASHINGTON     ",
         "PIT",
         "101966.0",
         "   ",
         "     ",
         null,
         "N",
         "Unknown",
         "0",
         "0",
         "Unknown",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "unknown                            ",
         "FEE",
         null,
         null,
         null,
         null,
         null,
         null,
         "The Gettman 14-14 well and associated tank battery were acquired by Impetro Resources, LLC in July 2023. Impetro has been unable to determine or identify detailed investigation and/or remediation activities that were performed by the previous operator (#94300) beyond the historical information submitted in the documents uploaded to the ECMC database. This Form 19 is being submitted to comply with the COAs from the previously submitted Form 27 (#403930289), Operator shall submit a Form 19, per Rule 912.b.(1).E.: \" The discovery of 10 cubic yards or more of impacted material resulting from a current or historic Spill or Release. Discovery and reporting will not be contingent upon confirmation samples demonstrating exceedance of Table 915-1 standards.\" since the Remedial Action Plan documents 52 cubic yards of impacted material from this historic spill/release. A waste manifest was submitted from 2017 documenting the removal of 54.23 tons of impacted soil from the site.",
         "12/20/2024",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "1.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "20.0",
         "20.0",
         "1.0",
         null,
         "The estimated surface area impacted has been determined by aerial photographs of the former skim pit . No soil samples have been collected to date. Impacts were previously determined visually. A waste manifest was submitted from 2017 documenting the removal of 54.23 tons of impacted soil from the site.",
         "Keith-Kuma Complex",
         "28.0",
         "2.0",
         "2218.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         null,
         "1.0",
         null,
         "1.0",
         "1800.0",
         "0.0",
         "\"DUG UP SKIM PIT, STOCKPILE SOIL, TEST AND BACKFILL. THE ORIGINAL SKIM PIT WAS ACTUALLY A CULVERT WITH A CONCRETE BOTTOM. REPLACED IT WITH A TANK. THERE WAS NO STAINING. CURRENTLY, THE LEASE IS BEING EVALUATED FOR P&A. IF WE DECIDE TO CONTINUE PUMPING WE CAN EXCAVATE THE SIDE OF THE TANK, OTHERWISE, WE WILL BE DIGGING IT OUT. WILL MAKE A DECISION BY JULY 21.\" This description was provided by the previous operator, Alfred Ward & Son (Operator #94300), on the most recent Form 27-S (Doc #402658626) for the remediation project. The Gettman 14-14 well and associated tank battery were acquired by Impetro Resources, LLC (Operator #10690) in July 2023, who will be putting the lease back into production. Impetro has been unable to determine or identify detailed investigation and/or remediation activities that were performed by the previous operator, beyond the historical information submitted in the documents uploaded to the ECMC database.",
         "2024-12-20",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "Historical impacts from skim pit\n",
         "Pit (vertical culvert with concrete bottom) was excavated and removed. This description was provided by the previous operator. However, Impetro has been unable to determine or identify any confirmation soil sampling was performed.",
         "200.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "False",
         "1.0",
         "8067.0",
         "8121924100",
         "9241.0",
         "2081.0",
         "1968.0",
         "196.0",
         "56875.0",
         "220.0",
         "40.0",
         "94.56991830850554",
         "9.418548774627585",
         "10.571840461316674",
         "1.9221528111484865",
         "POINT (-103.509319 39.958799)",
         "10",
         "Rural area",
         "Rural",
         "2772",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "50",
         "403208400",
         "I w/S",
         "KP KAUFFMAN COMPANY INC",
         "46290",
         "403208400",
         "2022-10-26",
         "2015-12-21",
         "Historical",
         "SESE  ",
         "29",
         "2N    ",
         "58W    ",
         "6",
         "40.10257",
         "-103.89023",
         null,
         "MORGAN         ",
         "PIT",
         "102705.0",
         "   ",
         "     ",
         null,
         "N",
         "0",
         "0",
         "0",
         "Unknown",
         "0",
         "Earthen evaporation pit",
         "0",
         "NON-CROP LAND                      ",
         "reclaimed pit used as rangeland",
         "Variable                           ",
         "FEE",
         null,
         null,
         null,
         null,
         null,
         null,
         "Facility #102705 was closed and reclaimed in 2012.  The landowner notification was provided in 2012.  Site investigation activities conducted in 2015 identified elevated levels of SAR and EC in soil samples collected from within the pit extent at 3 feet bgs.  No previous spill report was filed as Operator reported in 2018 that it has been unable to access the site to conduct further investigation.  Correspondence from Operator to COGCC dated 2018 is attached.",
         "10/26/2022",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "1.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "150.0",
         "150.0",
         "3.0",
         null,
         "Post-reclamation soil sampling",
         "sand to silty sand (SP-SM) with some clay (CL) layers",
         "25.0",
         "2.0",
         "2000.0",
         "0.0",
         "1800.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         null,
         "1.0",
         "2500.0",
         "0.0",
         "Depth to groundwater is inferred based on topo map data.  ",
         "2022-10-26",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "Unlined earthen pit operated from approximately1973 until 2012.  ",
         "Pit has been properly reclaimed.",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "False",
         "1.0",
         "9363.0",
         "8087000600",
         "6.0",
         "6245.0",
         "3713.0",
         "3332.0",
         "64961.0",
         "919.0",
         "81.0",
         "59.45556445156125",
         "53.3546837469976",
         "14.715772618094476",
         "1.2970376301040831",
         "POINT (-103.89023 40.10257)",
         "4",
         "Micropolitan core",
         "Suburban",
         "2501",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "43",
         "402253095",
         "S",
         "DCP OPERATING COMPANY LP",
         "4680",
         "402226829",
         "2019-10-30",
         "2013-07-22",
         "Historical",
         "SWSW  ",
         "17",
         "2N    ",
         "66W    ",
         "6",
         "40.13091",
         "-104.806776",
         null,
         "WELD           ",
         "PIPELINE",
         null,
         "   ",
         "     ",
         "Y",
         "N",
         "0",
         "Unknown",
         "0",
         "0",
         "0",
         null,
         "0",
         "CROP LAND                          ",
         "Roadway, Industrial",
         "Sunny 80's                         ",
         "STATE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "In July 2013, a leak was identified within a six-inch DCP gas gathering pipeline and resulted in a hydrocarbon release to soils at CR 20 and Highway (Hwy) 85 pipeline release (Site), located approximately 0.2 miles east on CR 20 from the intersection with Hwy 85, in Ft. Lupton, CO.  At the time of the release, the pipeline was isolated and blown down while repairs were completed. DCP contracted a third-party environmental contractor to delineate and remove impacted soils in the area of the release.  Analytical results from soil excavation and boring sample locations determined that soil impacts remained in place and required additional remediation. Beginning June 4, 2014 additional investigation activities were performed and included groundwater delineation activities, groundwater remediation and continued quarterly groundwater monitoring activities.",
         "12/04/2019",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "60.0",
         "18.0",
         "10.0",
         null,
         "During the July 2013 remediation efforts, approximately 400 cubic yard (CY) of impacted soils were removed by excavation methods and transported for off-site disposal. Confirmation soil samples were collected from the excavation sidewalls and base of excavation at locations illustrated on the attached Figure 2. Analytical results indicated soil impacts remained in place, however the extent of the excavation was limited at the time due to buried fiber optic utilities to the south and agricultural ditch to the north. Soil analytical data was provided in the Table 1 and analytical reports were provided in approved eForm19I/S (Document # 402226829). Additional soil boings were advanced and completed as monitoring wells to evaluate impacts to groundwater in June 2014. Between June 2014 and September 2015, six soil borings were advanced to approximately 18-feet bgs and completed as one-inch monitoring wells at locations illustrated on the attached Figure 3. Following monitoring well installation, ongoing groundwater monitoring has been performed at the Site on a quarterly basis through the third quarter 2019. Additionally, mobile vacuum enhanced fluid recovery (EFR) groundwater remediation efforts were conducted from the third quarter 2015 through the fourth quarter 2016 at which point light non-aqueous phase liquid (LNAPL) was no longer observed at the site. Historical soil excavation and boring analytical data is provided as an attachment to this submittal. Quarterly groundwater reports prepared from the second quarter 2015 through the third quarter 2019 were provided as attachments in approved eForm 27 (Dcoument # 402247877).",
         "Altvan Loam, 0 to 1 percent slopes, Silty Sands",
         "14.0",
         "15.0",
         "256.0",
         "0.0",
         "20.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         "615.0",
         "0.0",
         "418.0",
         "0.0",
         null,
         "2019-12-04",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "In July 2013, a leak was identified within a six-inch DCP gas gathering pipeline and resulted in a hydrocarbon release to soils at the site. The affected section of pipeline was removed, and a new section welded in place. The pipeline repair was inspected and pressure tested prior to being returned to service",
         "The affected section of pipeline was removed, and a new section welded in place. The pipeline repair was inspected and pressure tested prior to being returned to service.",
         "400.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "307.0",
         "0.0",
         "False",
         "1.0",
         "14694.0",
         "8123001906",
         "19.06",
         "1656.0",
         "993.0",
         "951.0",
         "62500.0",
         "309.0",
         "2.0",
         "59.96376811594203",
         "57.427536231884055",
         "18.65942028985507",
         "0.1207729468599033",
         "POINT (-104.806776 40.13091)",
         "2",
         "Metropolitan high commuting",
         "Urban",
         "2291",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Historical"
        ],
        [
         "42",
         "402226829",
         "I w/S",
         "DCP OPERATING COMPANY LP",
         "4680",
         "402226829",
         "2019-10-30",
         "2013-07-22",
         "Historical",
         "SWSW  ",
         "17",
         "2N    ",
         "66W    ",
         "6",
         "40.13091",
         "-104.806776",
         null,
         "WELD           ",
         "PIPELINE",
         null,
         "   ",
         "     ",
         "Y",
         "N",
         "0",
         "Unknown",
         "0",
         "0",
         "0",
         null,
         "0",
         "CROP LAND                          ",
         "Roadway, Industrial",
         "Sunny 80's                         ",
         "STATE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "In July 2013, a leak was identified within a six-inch DCP gas gathering pipeline and resulted in a hydrocarbon release to soils at CR 20 and Highway (Hwy) 85 pipeline release (Site), located approximately 0.2 miles east on CR 20 from the intersection with Hwy 85, in Ft. Lupton, CO.  At the time of the release, the pipeline was isolated and blown down while repairs were completed. DCP contracted a third-party environmental contractor to delineate and remove impacted soils in the area of the release.  Analytical results from soil excavation and boring sample locations determined that soil impacts remained in place and required additional remediation. Beginning June 4, 2014 additional investigation activities were performed and included groundwater delineation activities, groundwater remediation and continued quarterly groundwater monitoring activities.",
         "10/30/2019",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "60.0",
         "18.0",
         "10.0",
         null,
         "During the July 2013 remediation efforts, approximately 400 cubic yard (CY) of impacted soils were removed by excavation methods and transported for off-site disposal. Confirmation soil samples were collected from the excavation sidewalls and base of excavation at locations illustrated on the attached Figure 2. Analytical results indicated soil impacts remained in place, however the extent of the excavation was limited at the time due to buried fiber optic utilities to the south and agricultural ditch to the north. Soil analytical data is provided in the attached Table 1 and analytical reports are also attached for reference. Additional soil boings were advanced and completed as monitoring wells to evaluate impacts to groundwater in June 2014. Between June 2014 and September 2015, six soil borings were advanced to approximately 18-feet bgs and completed as one-inch monitoring wells at locations illustrated on the attached Figure 3. Following monitoring well installation, ongoing groundwater monitoring has been performed at the Site on a quarterly basis through the third quarter 2019. Additionally, mobile vacuum enhanced fluid recovery (EFR) groundwater remediation efforts were conducted from the third quarter 2015 through the fourth quarter 2016 at which point light non-aqueous phase liquid (LNAPL) was no longer observed at the site. Historical soil excavation and boring analytical data is provided as an attachment to this submittal. Quarterly groundwater reports prepared from the second quarter 2015 through the third quarter 2019 will be provided as attachments in a subsequent eForm 27 submittal. ",
         "Altvan Loam, 0 to 1 percent slopes, Silty Sands",
         "14.0",
         "15.0",
         "256.0",
         "0.0",
         "20.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         "615.0",
         "0.0",
         "418.0",
         "0.0",
         null,
         "2019-10-30",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "In July 2013, a leak was identified within a six-inch DCP gas gathering pipeline and resulted in a hydrocarbon release to soils at the site. The affected section of pipeline was removed, and a new section welded in place. The pipeline repair was inspected and pressure tested prior to being returned to service. ",
         "The affected section of pipeline was removed, and a new section welded in place. The pipeline repair was inspected and pressure tested prior to being returned to service.",
         "400.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "307.0",
         "0.0",
         "False",
         "0.0",
         null,
         "8123001906",
         "19.06",
         "1656.0",
         "993.0",
         "951.0",
         "62500.0",
         "309.0",
         "2.0",
         "59.96376811594203",
         "57.427536231884055",
         "18.65942028985507",
         "0.1207729468599033",
         "POINT (-104.806776 40.13091)",
         "2",
         "Metropolitan high commuting",
         "Urban",
         "2291",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Historical"
        ],
        [
         "39",
         "402081663",
         "I w/S",
         "KERR MCGEE GATHERING LLC",
         "47121",
         "402081663",
         "2019-06-20",
         "2013-05-10",
         "Recent",
         "SESE  ",
         "15",
         "1S    ",
         "65W    ",
         "6",
         "39.95913",
         "-104.640812",
         null,
         "ADAMS          ",
         "PIPELINE",
         null,
         "   ",
         "     ",
         "Y",
         "N",
         "Unknown",
         "0",
         "0",
         "Unknown",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "Sunny, 60°F                        ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "On May 10, 2013, a corrosion hole on the 53-4” pipeline resulted in the release of oil and produced water to the subsurface. The volume of the release is unknown. The petroleum hydrocarbon impacted soil was excavated. The release was reported to the Colorado Oil and Gas Conservation Commission (COGCC) based on the volume of soil excavated. The assessment details and analytical results are summarized below. The topographic Site Location Map showing the geographic setting of the release is provided as Figure 1.",
         "06/21/2019",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "40.0",
         "30.0",
         "20.0",
         null,
         "Between May 8 and 11, 2013, fourteen soil samples were collected from the base and sidewalls of the excavation and submitted for laboratory analysis of TPH and BTEX. Laboratory analytical results indicated that TPH and BTEX concentrations were in full compliance with COGCC Table 910-1 allowable levels at the extent of the excavation. Approximately 890 cubic yards of impacted soil were excavated and transported to Buffalo Ridge Landfill in Keenesburg, Colorado, for disposal. The general site layout, excavation dimensions, and soil sample locations are depicted on the Excavation Site Map provided as Figure 2. The soil sample analytical results are summarized in Table 1, and the laboratory analytical reports are attached.",
         "Sand and Clayey Sand (SC) ",
         "20.0",
         "38.0",
         "430.0",
         "0.0",
         "4800.0",
         "0.0",
         "4800.0",
         "0.0",
         null,
         "1.0",
         "1250.0",
         "0.0",
         "280.0",
         "0.0",
         "No further action is required. Laboratory analytical results for the soil samples indicated that TPH and BTEX concentrations were in full compliance with COGCC Table 910-1 allowable levels at the extent of the excavation. Based on the soil sample analytical results, Kerr-McGee is requesting a No Further Action status for this site. The original Form 19 NFA Status Request, submitted to the COGCC on May 16, 2013, is included as an attachment.",
         "2019-06-21",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "On May 10, 2013, a corrosion hole on the 53-4” pipeline resulted in the release of oil and produced water to the subsurface. The volume of the release is unknown. ",
         "The corroded portion of the pipeline was replaced and cathodic protection was installed.",
         "890.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "True",
         "0.0",
         null,
         "8001008553",
         "85.53",
         "5096.0",
         "4324.0",
         "834.0",
         "130163.0",
         "397.0",
         "124.0",
         "84.850863422292",
         "16.36577708006279",
         "7.790423861852433",
         "2.4332810047095763",
         "POINT (-104.640812 39.95913)",
         "2",
         "Metropolitan high commuting",
         "Urban",
         "2232",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Recent"
        ],
        [
         "70",
         "403944915",
         "S",
         "WESTERN OPERATING COMPANY",
         "95620",
         "403276008",
         "2022-12-30",
         "2017-02-09",
         "Historical",
         "NESE  ",
         "27",
         "11N   ",
         "53W    ",
         "6",
         "40.895966",
         "-103.269374",
         null,
         "LOGAN          ",
         "OTHER",
         "483654.0",
         "   ",
         "     ",
         null,
         "N",
         "Unknown",
         "0",
         "0",
         "Unknown",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "Clear, 45 degrees fahreneit        ",
         "FEE",
         null,
         null,
         null,
         null,
         null,
         null,
         "This form is being submitted to satisfy the requirement in COGCC inspection report document number 690900217.  An approximately 38,000 square foot area exists with stressed vegetation downgradient of the pit.  The progress of reclamation efforts to date have not met COGCC standards.",
         "10/03/2024",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "570.0",
         "450.0",
         "7.0",
         null,
         "The initial extents were determined from the extents of visibly stressed vegetation, as reported initially under COGCC Inspection Form 690900217. On 3/30/2023 and 10/16/2023, fifty-six (56) soil samples were collected from various depths and submitted for analysis of full Table 915-1 to further delineate the extents of impacts. Additional sampling is needed to determine final extents, and a comprehensive sampling plan will be proposed for approval under Remediation Project 27157.",
         "Peetz gravelly hills and Kim loamy plains",
         "80.0",
         "1.0",
         "2100.0",
         "0.0",
         "1000.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         "500.0",
         "0.0",
         null,
         "1.0",
         null,
         "2024-10-03",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "Based on a virtual meeting between Western Operating and ECMC (formerly COGCC) on 11/17/2022 and Inspection Form 690900217 submitted on 12/05/2022, Western Operating submitted Spill/Release ID 483654 to document the release of produced water and oil from Production Pit ID 256303 and/or 100311, resulting in stressed and barren vegetation to the south and west of the former pit(s). It is suspected that a release from the production pit berms, either from an overflow event(s) or berm soil materials insufficient to contain fluids, resulted in produced water and oil spreading into the adjacent grassland. ",
         "Western Operating is decommissioning the pit and production facility at the Propst B-2 to prevent reoccurrence at this location, and is evaluating all owned locations for unused production pits and stressed vegetation for decommissioning and/or remediation. ",
         null,
         "0.0",
         "0.0",
         "0.0",
         null,
         null,
         null,
         "False",
         "1.0",
         "27157.0",
         "8075965900",
         "9659.0",
         "967.0",
         "909.0",
         "94.0",
         "57500.0",
         "83.0",
         "49.0",
         "94.0020682523268",
         "9.720785935884178",
         "8.583247156153051",
         "5.067218200620475",
         "POINT (-103.269374 40.895966)",
         "10",
         "Rural area",
         "Rural",
         "2150",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "54",
         "403276008",
         "I",
         "WESTERN OPERATING COMPANY",
         "95620",
         "403276008",
         "2022-12-30",
         "2017-02-09",
         "Historical",
         "NESE  ",
         "27",
         "11N   ",
         "53W    ",
         "6",
         "40.895966",
         "-103.269374",
         null,
         "LOGAN          ",
         "OTHER",
         null,
         "   ",
         "     ",
         null,
         "N",
         "Unknown",
         "0",
         "0",
         "Unknown",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "Clear, 45 degrees fahreneit        ",
         "FEE",
         null,
         null,
         null,
         null,
         null,
         null,
         "This form is being submitted to satisfy the requirement in COGCC inspection report document number 690900217.  An approximately 38,000 square foot area exists with stressed vegetation downgradient of the pit.  The progress of reclamation efforts to date have not met COGCC standards.",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "0.0",
         null,
         "8075965900",
         "9659.0",
         "967.0",
         "909.0",
         "94.0",
         "57500.0",
         "83.0",
         "49.0",
         "94.0020682523268",
         "9.720785935884178",
         "8.583247156153051",
         "5.067218200620475",
         "POINT (-103.269374 40.895966)",
         "10",
         "Rural area",
         "Rural",
         "2150",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "57",
         "403332304",
         "S",
         "WESTERN OPERATING COMPANY",
         "95620",
         "403272313",
         "2022-12-27",
         "2017-08-25",
         "Historical",
         "SWSW  ",
         "26",
         "11N   ",
         "53W    ",
         "6",
         "40.892679",
         "-103.265038",
         null,
         "LOGAN          ",
         "OTHER",
         null,
         "   ",
         "     ",
         null,
         "N",
         "Unknown",
         "0",
         "0",
         "Unknown",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "Clear, 45 degrees fahrenheit       ",
         "FEE",
         null,
         null,
         null,
         null,
         null,
         null,
         "This form is being filed to satisfy the requirement  in COGCC inspection document number 690900222.  An approximately 16,200 square foot area exists with stressed vegetation downgradient of the pit.  The progress of reclamation efforts to date have not met COGCC standards.",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "1.0",
         "27153.0",
         "8075965900",
         "9659.0",
         "967.0",
         "909.0",
         "94.0",
         "57500.0",
         "83.0",
         "49.0",
         "94.0020682523268",
         "9.720785935884178",
         "8.583247156153051",
         "5.067218200620475",
         "POINT (-103.265038 40.892679)",
         "10",
         "Rural area",
         "Rural",
         "1950",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "53",
         "403272313",
         "I",
         "WESTERN OPERATING COMPANY",
         "95620",
         "403272313",
         "2022-12-27",
         "2017-08-25",
         "Historical",
         "SWSW  ",
         "26",
         "11N   ",
         "53W    ",
         "6",
         "40.892679",
         "-103.265038",
         null,
         "LOGAN          ",
         "OTHER",
         null,
         "   ",
         "     ",
         null,
         "N",
         "Unknown",
         "0",
         "0",
         "Unknown",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "Clear, 45 degrees fahrenheit       ",
         "FEE",
         null,
         null,
         null,
         null,
         null,
         null,
         "This form is being filed to satisfy the requirement  in COGCC inspection document number 690900222.  An approximately 16,200 square foot area exists with stressed vegetation downgradient of the pit.  The progress of reclamation efforts to date have not met COGCC standards.",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "0.0",
         null,
         "8075965900",
         "9659.0",
         "967.0",
         "909.0",
         "94.0",
         "57500.0",
         "83.0",
         "49.0",
         "94.0020682523268",
         "9.720785935884178",
         "8.583247156153051",
         "5.067218200620475",
         "POINT (-103.265038 40.892679)",
         "10",
         "Rural area",
         "Rural",
         "1950",
         "173.43000000000393",
         "173",
         "2020 and After",
         "Historical"
        ],
        [
         "40",
         "402081722",
         "I w/S",
         "KERR MCGEE GATHERING LLC",
         "47121",
         "402081722",
         "2019-06-20",
         "2014-04-07",
         "Recent",
         "SWSE  ",
         "28",
         "2N    ",
         "67W    ",
         "6",
         "40.10293",
         "-104.893234",
         null,
         "WELD           ",
         "PIPELINE",
         null,
         "   ",
         "     ",
         "Y",
         "N",
         ">=1 and <5",
         "0",
         "0",
         "0",
         "0",
         null,
         "0",
         "CROP LAND                          ",
         null,
         "Sunny, 55°F                        ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "On April 7, 2014, a contractor struck the Kerr-McGee 14-83-1196-4\" pipeline while conducting excavation activities for DCP Midstream. Approximately 1.5 barrels of condensate were released from the damaged Kerr-McGee pipeline. The condensate released into the open DCP Midstream excavation and sprayed onto the surrounding land south of the excavation. The petroleum hydrocarbon impacted soil was excavated. The assessment details and analytical results are summarized below. The topographic Site Location Map showing the geographic setting of the release is provided as Figure 1.",
         "06/21/2019",
         "1.0",
         null,
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "180.0",
         "90.0",
         null,
         null,
         "On April 11, 2014, following the removal of impacted soil from the spray release area, three soil samples SS01@6” through SS03@6”) were collected from the base of the shallow excavation and submitted for laboratory analysis of TPH and BTEX. Laboratory analytical results indicated that TPH and BTEX concentrations were in full compliance with COGCC Table 910-1 allowable levels at the extent of the excavation. Approximately 300 cubic yards of impacted soil were excavated and transported to Front Range Landfill in Erie, Colorado, for disposal. The general site layout, excavation dimensions, and soil sample locations are depicted on the Excavation Site Map provided as Figure 2. The soil sample analytical results are summarized in Table 1, and the laboratory analytical report is attached.",
         "Sandy Clay (SC) ",
         "20.0",
         "9.0",
         "1195.0",
         "0.0",
         "2250.0",
         "0.0",
         "3800.0",
         "0.0",
         null,
         "1.0",
         "1610.0",
         "0.0",
         "330.0",
         "0.0",
         "No further action is required. Laboratory analytical results for the soil samples indicated that TPH and BTEX concentrations were in full compliance with COGCC Table 910-1 allowable levels at the extent of the shallow excavation. Based on the soil sample analytical results, Kerr-McGee is requesting a No Further Action status for this site. The original Form 19 NFA Status Request, submitted to the COGCC on April 17, 2014, is included as an attachment.",
         "2019-06-21",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "On April 7, 2014, a contractor struck the Kerr-McGee 14-83-1196-4\" pipeline while conducting excavation activities for DCP Midstream. Approximately 1.5 barrels of condensate were released from the damaged Kerr-McGee pipeline. ",
         "All Kerr-McGee utilities will be properly marked prior to excavation activities.",
         "300.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "True",
         "0.0",
         null,
         "8123002016",
         "20.16",
         "3135.0",
         "2631.0",
         "813.0",
         "82625.0",
         "157.0",
         "109.0",
         "83.92344497607655",
         "25.933014354066984",
         "5.007974481658692",
         "3.476874003189793",
         "POINT (-104.893234 40.10293)",
         "4",
         "Micropolitan core",
         "Suburban",
         "1900",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Recent"
        ],
        [
         "24",
         "400978919",
         "I",
         "PICEANCE ENERGY LLC DBA LARAMIE ENERGY COMPANY",
         "10433",
         "400978919",
         "2016-01-27",
         "2011-01-31",
         "Historical",
         "NESE  ",
         "13",
         "7S    ",
         "94W    ",
         "6",
         "39.43559",
         "-107.8291",
         null,
         "GARFIELD       ",
         "WELL",
         null,
         "045",
         "17611",
         "N",
         "Y",
         "0",
         "0",
         "0",
         ">=5 and <100",
         "0",
         "Approx 40-50 bbl spilled",
         "0",
         "OTHER                              ",
         "Rangeland (Summer)",
         "Cold, snowing                      ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "CONTRACTOR WAS TRANSFERRING PRODUCED WATER WHEN THE FITTING (STAINLESS STEEL BAND) ON A 3\" HOSE GAVE WAY. WATER WAS RELEASED ON LOCATION UNTIL VALVE AND HOSE COULD BE ISOLATED. DISTANCE TO SURFACE WATER BASED ON DRAINAGE PATTERN AND WATER FLOW ROUTE. CLOSEST WATER WELL UP GRADIENT OF PAD.",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "0.0",
         null,
         "8045952003",
         "9520.03",
         "2376.0",
         "2025.0",
         "973.0",
         "108364.0",
         "52.0",
         "49.0",
         "85.22727272727273",
         "40.95117845117845",
         "2.1885521885521886",
         "2.0622895622895623",
         "POINT (-107.8291 39.43559)",
         "5",
         "Micropolitan high commuting",
         "Suburban",
         "1822",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Historical"
        ],
        [
         "25",
         "400979944",
         "S",
         "PICEANCE ENERGY LLC DBA LARAMIE ENERGY COMPANY",
         "10433",
         "400978919",
         "2016-01-27",
         "2011-01-31",
         "Historical",
         "NESE  ",
         "13",
         "7S    ",
         "94W    ",
         "6",
         "39.43559",
         "-107.8291",
         null,
         "GARFIELD       ",
         "WELL",
         null,
         "045",
         "17611",
         "N",
         "Y",
         "0",
         "0",
         "0",
         ">=5 and <100",
         "0",
         "Approx 40-50 bbl spilled",
         "0",
         "OTHER                              ",
         "Rangeland (Summer)",
         "Cold, snowing                      ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "CONTRACTOR WAS TRANSFERRING PRODUCED WATER WHEN THE FITTING (STAINLESS STEEL BAND) ON A 3\" HOSE GAVE WAY. WATER WAS RELEASED ON LOCATION UNTIL VALVE AND HOSE COULD BE ISOLATED. DISTANCE TO SURFACE WATER BASED ON DRAINAGE PATTERN AND WATER FLOW ROUTE. CLOSEST WATER WELL UP GRADIENT OF PAD.",
         "01/28/2016",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "55.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "1.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "150.0",
         "90.0",
         "0.0",
         null,
         "Visual observation of surface, fluid volumes pumped from spill. Fluid spill was on location. Site was surveyed to ensure no water went beyond berms on site. No spilled fluids migrated outside the bermed containment of the pad.",
         "Compacted Cimarron Loam, 2-2 1/2% slopes, Map Unit 16",
         "50.0",
         "0.0",
         "4195.0",
         "0.0",
         "1848.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         null,
         "1.0",
         null,
         "1.0",
         "No remediation required, spill was fully contained and fluids did not migrate into soils because the ground was frozen.",
         "2016-01-28",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "Contractor was transferring produced water when the fitting (stainless steel band) on a 3\" hose gave way.  Water was released on location until valve and hose could be isolated. *Distance to surface water based on drainage pattern and water flow route. Closest water well up gradient of pad. Valve to hose was closed. Water contained on location. Water truck on location sucked up all standing water onsite including melted snow (~55bbls). Environmental contractor (Olosn and Associates) investigated site 2/3/2011 and gathered soil sampes for anlaysis. No emergency pits required. Water stayed on location. See Photo (attachment) included with Initial F19 submittal. No remediation required, spill was fully contained and fluids did not migrate into soils because the ground was frozen.",
         "Laramie consulted with contractor to review exisitng fluid transfer protocols and to assure the contractor's staff adhere to protocols in the future. Additionally, contractors will inspect all hose fittings for signs of wear or damage. Any hoses found to have worn or damaged clamps will be replaced.",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "True",
         "0.0",
         null,
         "8045952003",
         "9520.03",
         "2376.0",
         "2025.0",
         "973.0",
         "108364.0",
         "52.0",
         "49.0",
         "85.22727272727273",
         "40.95117845117845",
         "2.1885521885521886",
         "2.0622895622895623",
         "POINT (-107.8291 39.43559)",
         "5",
         "Micropolitan high commuting",
         "Suburban",
         "1822",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Historical"
        ],
        [
         "37",
         "401991720",
         "S",
         "KERR MCGEE OIL & GAS ONSHORE LP",
         "47120",
         "401924669",
         "2019-01-31",
         "2014-03-03",
         "Recent",
         "SWNE  ",
         "23",
         "3N    ",
         "66W    ",
         "6",
         "40.212433",
         "-104.736178",
         null,
         "WELD           ",
         "TANK BATTERY",
         null,
         "   ",
         "     ",
         "N",
         "Y",
         "0",
         ">=5 and <100",
         "0",
         "0",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "40 degrees F.                      ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "On March 9, 2014, approximately 30 barrels of condensate were released inside secondary containment at the Sarchet 41-23, Sarchet UPRR 42-23 3X production facility when a motor valve seat and trim failed at the wellhead. Approximately 25 barrels of condensate were recovered via vacuum truck and transferred to a licensed injection facility for disposal. Excavation activities were guided in the field by screening soil for volatile organic compound (VOC) concentrations using a photoionization detector (PID). A topographic Site Location Map showing the geographic setting of the release is provided as Figure 1.",
         "04/01/2019",
         "0.0",
         "0.0",
         "0.0",
         "30.0",
         "25.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "41.0",
         "36.0",
         "6.0",
         null,
         "Reference Initial-Supplemental Form 19 (Document No. 401924669) and Initial eForm 27 (Document No. 401962387).",
         "Sandy silt",
         "20.0",
         "23.0",
         "390.0",
         "0.0",
         "1450.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         "975.0",
         "0.0",
         "1630.0",
         "0.0",
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         "False",
         "1.0",
         "12741.0",
         "8123001800",
         "18.0",
         "4681.0",
         "3690.0",
         "1658.0",
         "85561.0",
         "273.0",
         "186.0",
         "78.82930997650075",
         "35.41978209784234",
         "5.832087160863064",
         "3.9735099337748343",
         "POINT (-104.736178 40.212433)",
         "3",
         "Metropolitan low commuting",
         "Urban",
         "1795",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Recent"
        ],
        [
         "36",
         "401924669",
         "I w/S",
         "KERR MCGEE OIL & GAS ONSHORE LP",
         "47120",
         "401924669",
         "2019-01-31",
         "2014-03-03",
         "Recent",
         "SWNE  ",
         "23",
         "3N    ",
         "66W    ",
         "6",
         "40.212433",
         "-104.736178",
         null,
         "WELD           ",
         "TANK BATTERY",
         null,
         "   ",
         "     ",
         "N",
         "Y",
         "0",
         ">=5 and <100",
         "0",
         "0",
         "0",
         null,
         "0",
         "NON-CROP LAND                      ",
         null,
         "40 degrees F.                      ",
         "FEE",
         null,
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "On March 9, 2014, approximately 30 barrels of condensate were released inside secondary containment at the Sarchet 41-23, Sarchet UPRR 42-23 3X production facility when a motor valve seat and trim failed at the wellhead. Approximately 25 barrels of condensate were recovered via vacuum truck and transferred to a licensed injection facility for disposal. Excavation activities were guided in the field by screening soil for volatile organic compound (VOC) concentrations using a photoionization detector (PID). A topographic Site Location Map showing the geographic setting of the release is provided as Figure 1.",
         "01/31/2019",
         "0.0",
         "0.0",
         "0.0",
         "30.0",
         "25.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         "0.0",
         null,
         "0.0",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         "0.0",
         "41.0",
         "36.0",
         "6.0",
         null,
         "On March 9, 2014, approximately 30 barrels of condensate were released inside secondary containment at the Sarchet 41-23, Sarchet UPRR 42-23 3X production facility. Approximately 160 cubic yards of impacted material were removed and transported to the Buffalo Ridge Landfill in Keenesburg, Colorado for disposal. Eight (8) confirmation soil samples were collected from the sidewalls and base of the final extent of the excavation area at depths ranging from approximately 4 feet to 6 feet below ground surface (bgs). The soil samples were submitted to eAnalytics Laboratory for analysis of benzene, toluene, ethylbenzene, total xylenes (BTEX), total petroleum hydrocarbons (TPH) - gasoline range organics (GRO) by USEPA Method 8260C, TPH - diesel and oil range organics (DRO and ORO) by USEPA Method 8015. Laboratory analytical results indicated that constituent concentrations in the soil samples collected from the final extent of the excavation area were in full compliance with COGCC standards. A topographic Site Location Map showing the geographic setting of the release is provided as Figure 1. Soil sample locations are illustrated on Figure 2. Soil analytical results are summarized in Table 1 and the laboratory analytical reports are provided as Attachment A. A Form 27 Site Investigation and Remediation Workplan - Produced Water Vessel Closure Report will be prepared for this release. ",
         "Sandy silt",
         "20.0",
         "23.0",
         "390.0",
         "0.0",
         "1450.0",
         "0.0",
         null,
         "1.0",
         null,
         "1.0",
         "975.0",
         "0.0",
         "1630.0",
         "0.0",
         null,
         "2019-01-31",
         "0.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         "A release occurred from the production tank when a motor valve seat and trim failed at the wellhead.",
         "The production facility was rebuilt and the motor valve seat and trim were replaced at the wellhead.",
         "160.0",
         "1.0",
         "0.0",
         "0.0",
         null,
         null,
         null,
         "False",
         "0.0",
         null,
         "8123001800",
         "18.0",
         "4681.0",
         "3690.0",
         "1658.0",
         "85561.0",
         "273.0",
         "186.0",
         "78.82930997650075",
         "35.41978209784234",
         "5.832087160863064",
         "3.9735099337748343",
         "POINT (-104.736178 40.212433)",
         "3",
         "Metropolitan low commuting",
         "Urban",
         "1795",
         "173.43000000000393",
         "173",
         "Before 2020",
         "Recent"
        ]
       ],
       "shape": {
        "columns": 127,
        "rows": 20
       }
      },
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Document #</th>\n",
       "      <th>Report</th>\n",
       "      <th>Operator</th>\n",
       "      <th>Operator #</th>\n",
       "      <th>Tracking #</th>\n",
       "      <th>Initial Report Date</th>\n",
       "      <th>Date of Discovery</th>\n",
       "      <th>Spill Type</th>\n",
       "      <th>Qtr Qtr</th>\n",
       "      <th>Section</th>\n",
       "      <th>...</th>\n",
       "      <th>unemployment_rate</th>\n",
       "      <th>geometry</th>\n",
       "      <th>ruca_code</th>\n",
       "      <th>ruca_description</th>\n",
       "      <th>rurality</th>\n",
       "      <th>report_delay_full_days</th>\n",
       "      <th>report_delay_winsor99</th>\n",
       "      <th>report_delay_winsor99_int</th>\n",
       "      <th>Period</th>\n",
       "      <th>spill_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>402349927</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>ANADARKO DJ GAS PROCESSING LLC</td>\n",
       "      <td>10719</td>\n",
       "      <td>402349927</td>\n",
       "      <td>2020-03-23</td>\n",
       "      <td>1994-11-14</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SENE</td>\n",
       "      <td>32</td>\n",
       "      <td>...</td>\n",
       "      <td>0.379957</td>\n",
       "      <td>POINT (-104.680174 39.748143)</td>\n",
       "      <td>1</td>\n",
       "      <td>Metropolitan core</td>\n",
       "      <td>Urban</td>\n",
       "      <td>9261</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>402116460</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>NGL WATER SOLUTIONS DJ LLC</td>\n",
       "      <td>10373</td>\n",
       "      <td>402116460</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2004-01-01</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SESE</td>\n",
       "      <td>28</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>POINT (-104.887064 40.016567)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "      <td>5681</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>403791618</td>\n",
       "      <td>I</td>\n",
       "      <td>MAGPIE OPERATING INC</td>\n",
       "      <td>52530</td>\n",
       "      <td>403791618</td>\n",
       "      <td>2024-05-15</td>\n",
       "      <td>2011-08-30</td>\n",
       "      <td>Historical</td>\n",
       "      <td>NENE</td>\n",
       "      <td>36</td>\n",
       "      <td>...</td>\n",
       "      <td>3.477868</td>\n",
       "      <td>POINT (-103.462663 40.714817)</td>\n",
       "      <td>5</td>\n",
       "      <td>Micropolitan high commuting</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>4642</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>403846130</td>\n",
       "      <td>S</td>\n",
       "      <td>MAGPIE OPERATING INC</td>\n",
       "      <td>52530</td>\n",
       "      <td>403791618</td>\n",
       "      <td>2024-05-15</td>\n",
       "      <td>2011-08-30</td>\n",
       "      <td>Historical</td>\n",
       "      <td>NENE</td>\n",
       "      <td>36</td>\n",
       "      <td>...</td>\n",
       "      <td>3.477868</td>\n",
       "      <td>POINT (-103.462663 40.714817)</td>\n",
       "      <td>5</td>\n",
       "      <td>Micropolitan high commuting</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>4642</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>401893556</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>BONANZA CREEK ENERGY OPERATING COMPANY LLC</td>\n",
       "      <td>8960</td>\n",
       "      <td>401893556</td>\n",
       "      <td>2019-01-04</td>\n",
       "      <td>2009-01-24</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SESW</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>1.541138</td>\n",
       "      <td>POINT (-104.520309 40.30657)</td>\n",
       "      <td>2</td>\n",
       "      <td>Metropolitan high commuting</td>\n",
       "      <td>Urban</td>\n",
       "      <td>3632</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>404029999</td>\n",
       "      <td>I</td>\n",
       "      <td>IMPETRO RESOURCES LLC</td>\n",
       "      <td>10690</td>\n",
       "      <td>404029999</td>\n",
       "      <td>2024-12-16</td>\n",
       "      <td>2017-05-15</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SESW</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>1.922153</td>\n",
       "      <td>POINT (-103.509319 39.958799)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "      <td>2772</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>404037262</td>\n",
       "      <td>S</td>\n",
       "      <td>IMPETRO RESOURCES LLC</td>\n",
       "      <td>10690</td>\n",
       "      <td>404029999</td>\n",
       "      <td>2024-12-16</td>\n",
       "      <td>2017-05-15</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SESW</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>1.922153</td>\n",
       "      <td>POINT (-103.509319 39.958799)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "      <td>2772</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>403208400</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>KP KAUFFMAN COMPANY INC</td>\n",
       "      <td>46290</td>\n",
       "      <td>403208400</td>\n",
       "      <td>2022-10-26</td>\n",
       "      <td>2015-12-21</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SESE</td>\n",
       "      <td>29</td>\n",
       "      <td>...</td>\n",
       "      <td>1.297038</td>\n",
       "      <td>POINT (-103.89023 40.10257)</td>\n",
       "      <td>4</td>\n",
       "      <td>Micropolitan core</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>2501</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>402253095</td>\n",
       "      <td>S</td>\n",
       "      <td>DCP OPERATING COMPANY LP</td>\n",
       "      <td>4680</td>\n",
       "      <td>402226829</td>\n",
       "      <td>2019-10-30</td>\n",
       "      <td>2013-07-22</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SWSW</td>\n",
       "      <td>17</td>\n",
       "      <td>...</td>\n",
       "      <td>0.120773</td>\n",
       "      <td>POINT (-104.806776 40.13091)</td>\n",
       "      <td>2</td>\n",
       "      <td>Metropolitan high commuting</td>\n",
       "      <td>Urban</td>\n",
       "      <td>2291</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>402226829</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>DCP OPERATING COMPANY LP</td>\n",
       "      <td>4680</td>\n",
       "      <td>402226829</td>\n",
       "      <td>2019-10-30</td>\n",
       "      <td>2013-07-22</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SWSW</td>\n",
       "      <td>17</td>\n",
       "      <td>...</td>\n",
       "      <td>0.120773</td>\n",
       "      <td>POINT (-104.806776 40.13091)</td>\n",
       "      <td>2</td>\n",
       "      <td>Metropolitan high commuting</td>\n",
       "      <td>Urban</td>\n",
       "      <td>2291</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>402081663</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>KERR MCGEE GATHERING LLC</td>\n",
       "      <td>47121</td>\n",
       "      <td>402081663</td>\n",
       "      <td>2019-06-20</td>\n",
       "      <td>2013-05-10</td>\n",
       "      <td>Recent</td>\n",
       "      <td>SESE</td>\n",
       "      <td>15</td>\n",
       "      <td>...</td>\n",
       "      <td>2.433281</td>\n",
       "      <td>POINT (-104.640812 39.95913)</td>\n",
       "      <td>2</td>\n",
       "      <td>Metropolitan high commuting</td>\n",
       "      <td>Urban</td>\n",
       "      <td>2232</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Recent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>403944915</td>\n",
       "      <td>S</td>\n",
       "      <td>WESTERN OPERATING COMPANY</td>\n",
       "      <td>95620</td>\n",
       "      <td>403276008</td>\n",
       "      <td>2022-12-30</td>\n",
       "      <td>2017-02-09</td>\n",
       "      <td>Historical</td>\n",
       "      <td>NESE</td>\n",
       "      <td>27</td>\n",
       "      <td>...</td>\n",
       "      <td>5.067218</td>\n",
       "      <td>POINT (-103.269374 40.895966)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "      <td>2150</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>403276008</td>\n",
       "      <td>I</td>\n",
       "      <td>WESTERN OPERATING COMPANY</td>\n",
       "      <td>95620</td>\n",
       "      <td>403276008</td>\n",
       "      <td>2022-12-30</td>\n",
       "      <td>2017-02-09</td>\n",
       "      <td>Historical</td>\n",
       "      <td>NESE</td>\n",
       "      <td>27</td>\n",
       "      <td>...</td>\n",
       "      <td>5.067218</td>\n",
       "      <td>POINT (-103.269374 40.895966)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "      <td>2150</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>57</th>\n",
       "      <td>403332304</td>\n",
       "      <td>S</td>\n",
       "      <td>WESTERN OPERATING COMPANY</td>\n",
       "      <td>95620</td>\n",
       "      <td>403272313</td>\n",
       "      <td>2022-12-27</td>\n",
       "      <td>2017-08-25</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SWSW</td>\n",
       "      <td>26</td>\n",
       "      <td>...</td>\n",
       "      <td>5.067218</td>\n",
       "      <td>POINT (-103.265038 40.892679)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "      <td>1950</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>403272313</td>\n",
       "      <td>I</td>\n",
       "      <td>WESTERN OPERATING COMPANY</td>\n",
       "      <td>95620</td>\n",
       "      <td>403272313</td>\n",
       "      <td>2022-12-27</td>\n",
       "      <td>2017-08-25</td>\n",
       "      <td>Historical</td>\n",
       "      <td>SWSW</td>\n",
       "      <td>26</td>\n",
       "      <td>...</td>\n",
       "      <td>5.067218</td>\n",
       "      <td>POINT (-103.265038 40.892679)</td>\n",
       "      <td>10</td>\n",
       "      <td>Rural area</td>\n",
       "      <td>Rural</td>\n",
       "      <td>1950</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>2020 and After</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>402081722</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>KERR MCGEE GATHERING LLC</td>\n",
       "      <td>47121</td>\n",
       "      <td>402081722</td>\n",
       "      <td>2019-06-20</td>\n",
       "      <td>2014-04-07</td>\n",
       "      <td>Recent</td>\n",
       "      <td>SWSE</td>\n",
       "      <td>28</td>\n",
       "      <td>...</td>\n",
       "      <td>3.476874</td>\n",
       "      <td>POINT (-104.893234 40.10293)</td>\n",
       "      <td>4</td>\n",
       "      <td>Micropolitan core</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>1900</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Recent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>400978919</td>\n",
       "      <td>I</td>\n",
       "      <td>PICEANCE ENERGY LLC DBA LARAMIE ENERGY COMPANY</td>\n",
       "      <td>10433</td>\n",
       "      <td>400978919</td>\n",
       "      <td>2016-01-27</td>\n",
       "      <td>2011-01-31</td>\n",
       "      <td>Historical</td>\n",
       "      <td>NESE</td>\n",
       "      <td>13</td>\n",
       "      <td>...</td>\n",
       "      <td>2.062290</td>\n",
       "      <td>POINT (-107.8291 39.43559)</td>\n",
       "      <td>5</td>\n",
       "      <td>Micropolitan high commuting</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>1822</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>400979944</td>\n",
       "      <td>S</td>\n",
       "      <td>PICEANCE ENERGY LLC DBA LARAMIE ENERGY COMPANY</td>\n",
       "      <td>10433</td>\n",
       "      <td>400978919</td>\n",
       "      <td>2016-01-27</td>\n",
       "      <td>2011-01-31</td>\n",
       "      <td>Historical</td>\n",
       "      <td>NESE</td>\n",
       "      <td>13</td>\n",
       "      <td>...</td>\n",
       "      <td>2.062290</td>\n",
       "      <td>POINT (-107.8291 39.43559)</td>\n",
       "      <td>5</td>\n",
       "      <td>Micropolitan high commuting</td>\n",
       "      <td>Suburban</td>\n",
       "      <td>1822</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Historical</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>401991720</td>\n",
       "      <td>S</td>\n",
       "      <td>KERR MCGEE OIL &amp; GAS ONSHORE LP</td>\n",
       "      <td>47120</td>\n",
       "      <td>401924669</td>\n",
       "      <td>2019-01-31</td>\n",
       "      <td>2014-03-03</td>\n",
       "      <td>Recent</td>\n",
       "      <td>SWNE</td>\n",
       "      <td>23</td>\n",
       "      <td>...</td>\n",
       "      <td>3.973510</td>\n",
       "      <td>POINT (-104.736178 40.212433)</td>\n",
       "      <td>3</td>\n",
       "      <td>Metropolitan low commuting</td>\n",
       "      <td>Urban</td>\n",
       "      <td>1795</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Recent</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>401924669</td>\n",
       "      <td>I w/S</td>\n",
       "      <td>KERR MCGEE OIL &amp; GAS ONSHORE LP</td>\n",
       "      <td>47120</td>\n",
       "      <td>401924669</td>\n",
       "      <td>2019-01-31</td>\n",
       "      <td>2014-03-03</td>\n",
       "      <td>Recent</td>\n",
       "      <td>SWNE</td>\n",
       "      <td>23</td>\n",
       "      <td>...</td>\n",
       "      <td>3.973510</td>\n",
       "      <td>POINT (-104.736178 40.212433)</td>\n",
       "      <td>3</td>\n",
       "      <td>Metropolitan low commuting</td>\n",
       "      <td>Urban</td>\n",
       "      <td>1795</td>\n",
       "      <td>173.43</td>\n",
       "      <td>173</td>\n",
       "      <td>Before 2020</td>\n",
       "      <td>Recent</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>20 rows × 127 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Document # Report                                        Operator  \\\n",
       "44   402349927  I w/S                  ANADARKO DJ GAS PROCESSING LLC   \n",
       "41   402116460  I w/S                      NGL WATER SOLUTIONS DJ LLC   \n",
       "65   403791618      I                            MAGPIE OPERATING INC   \n",
       "66   403846130      S                            MAGPIE OPERATING INC   \n",
       "35   401893556  I w/S      BONANZA CREEK ENERGY OPERATING COMPANY LLC   \n",
       "76   404029999      I                           IMPETRO RESOURCES LLC   \n",
       "77   404037262      S                           IMPETRO RESOURCES LLC   \n",
       "50   403208400  I w/S                         KP KAUFFMAN COMPANY INC   \n",
       "43   402253095      S                        DCP OPERATING COMPANY LP   \n",
       "42   402226829  I w/S                        DCP OPERATING COMPANY LP   \n",
       "39   402081663  I w/S                        KERR MCGEE GATHERING LLC   \n",
       "70   403944915      S                       WESTERN OPERATING COMPANY   \n",
       "54   403276008      I                       WESTERN OPERATING COMPANY   \n",
       "57   403332304      S                       WESTERN OPERATING COMPANY   \n",
       "53   403272313      I                       WESTERN OPERATING COMPANY   \n",
       "40   402081722  I w/S                        KERR MCGEE GATHERING LLC   \n",
       "24   400978919      I  PICEANCE ENERGY LLC DBA LARAMIE ENERGY COMPANY   \n",
       "25   400979944      S  PICEANCE ENERGY LLC DBA LARAMIE ENERGY COMPANY   \n",
       "37   401991720      S                 KERR MCGEE OIL & GAS ONSHORE LP   \n",
       "36   401924669  I w/S                 KERR MCGEE OIL & GAS ONSHORE LP   \n",
       "\n",
       "    Operator #  Tracking # Initial Report Date Date of Discovery  Spill Type  \\\n",
       "44       10719   402349927          2020-03-23        1994-11-14  Historical   \n",
       "41       10373   402116460          2019-07-22        2004-01-01  Historical   \n",
       "65       52530   403791618          2024-05-15        2011-08-30  Historical   \n",
       "66       52530   403791618          2024-05-15        2011-08-30  Historical   \n",
       "35        8960   401893556          2019-01-04        2009-01-24  Historical   \n",
       "76       10690   404029999          2024-12-16        2017-05-15  Historical   \n",
       "77       10690   404029999          2024-12-16        2017-05-15  Historical   \n",
       "50       46290   403208400          2022-10-26        2015-12-21  Historical   \n",
       "43        4680   402226829          2019-10-30        2013-07-22  Historical   \n",
       "42        4680   402226829          2019-10-30        2013-07-22  Historical   \n",
       "39       47121   402081663          2019-06-20        2013-05-10      Recent   \n",
       "70       95620   403276008          2022-12-30        2017-02-09  Historical   \n",
       "54       95620   403276008          2022-12-30        2017-02-09  Historical   \n",
       "57       95620   403272313          2022-12-27        2017-08-25  Historical   \n",
       "53       95620   403272313          2022-12-27        2017-08-25  Historical   \n",
       "40       47121   402081722          2019-06-20        2014-04-07      Recent   \n",
       "24       10433   400978919          2016-01-27        2011-01-31  Historical   \n",
       "25       10433   400978919          2016-01-27        2011-01-31  Historical   \n",
       "37       47120   401924669          2019-01-31        2014-03-03      Recent   \n",
       "36       47120   401924669          2019-01-31        2014-03-03      Recent   \n",
       "\n",
       "   Qtr Qtr  Section  ... unemployment_rate                       geometry  \\\n",
       "44  SENE         32  ...          0.379957  POINT (-104.680174 39.748143)   \n",
       "41  SESE         28  ...          0.000000  POINT (-104.887064 40.016567)   \n",
       "65  NENE         36  ...          3.477868  POINT (-103.462663 40.714817)   \n",
       "66  NENE         36  ...          3.477868  POINT (-103.462663 40.714817)   \n",
       "35  SESW         14  ...          1.541138   POINT (-104.520309 40.30657)   \n",
       "76  SESW         14  ...          1.922153  POINT (-103.509319 39.958799)   \n",
       "77  SESW         14  ...          1.922153  POINT (-103.509319 39.958799)   \n",
       "50  SESE         29  ...          1.297038    POINT (-103.89023 40.10257)   \n",
       "43  SWSW         17  ...          0.120773   POINT (-104.806776 40.13091)   \n",
       "42  SWSW         17  ...          0.120773   POINT (-104.806776 40.13091)   \n",
       "39  SESE         15  ...          2.433281   POINT (-104.640812 39.95913)   \n",
       "70  NESE         27  ...          5.067218  POINT (-103.269374 40.895966)   \n",
       "54  NESE         27  ...          5.067218  POINT (-103.269374 40.895966)   \n",
       "57  SWSW         26  ...          5.067218  POINT (-103.265038 40.892679)   \n",
       "53  SWSW         26  ...          5.067218  POINT (-103.265038 40.892679)   \n",
       "40  SWSE         28  ...          3.476874   POINT (-104.893234 40.10293)   \n",
       "24  NESE         13  ...          2.062290     POINT (-107.8291 39.43559)   \n",
       "25  NESE         13  ...          2.062290     POINT (-107.8291 39.43559)   \n",
       "37  SWNE         23  ...          3.973510  POINT (-104.736178 40.212433)   \n",
       "36  SWNE         23  ...          3.973510  POINT (-104.736178 40.212433)   \n",
       "\n",
       "   ruca_code             ruca_description  rurality report_delay_full_days  \\\n",
       "44         1            Metropolitan core     Urban                   9261   \n",
       "41        10                   Rural area     Rural                   5681   \n",
       "65         5  Micropolitan high commuting  Suburban                   4642   \n",
       "66         5  Micropolitan high commuting  Suburban                   4642   \n",
       "35         2  Metropolitan high commuting     Urban                   3632   \n",
       "76        10                   Rural area     Rural                   2772   \n",
       "77        10                   Rural area     Rural                   2772   \n",
       "50         4            Micropolitan core  Suburban                   2501   \n",
       "43         2  Metropolitan high commuting     Urban                   2291   \n",
       "42         2  Metropolitan high commuting     Urban                   2291   \n",
       "39         2  Metropolitan high commuting     Urban                   2232   \n",
       "70        10                   Rural area     Rural                   2150   \n",
       "54        10                   Rural area     Rural                   2150   \n",
       "57        10                   Rural area     Rural                   1950   \n",
       "53        10                   Rural area     Rural                   1950   \n",
       "40         4            Micropolitan core  Suburban                   1900   \n",
       "24         5  Micropolitan high commuting  Suburban                   1822   \n",
       "25         5  Micropolitan high commuting  Suburban                   1822   \n",
       "37         3   Metropolitan low commuting     Urban                   1795   \n",
       "36         3   Metropolitan low commuting     Urban                   1795   \n",
       "\n",
       "   report_delay_winsor99 report_delay_winsor99_int          Period  spill_type  \n",
       "44                173.43                       173  2020 and After  Historical  \n",
       "41                173.43                       173     Before 2020  Historical  \n",
       "65                173.43                       173  2020 and After  Historical  \n",
       "66                173.43                       173  2020 and After  Historical  \n",
       "35                173.43                       173     Before 2020  Historical  \n",
       "76                173.43                       173  2020 and After  Historical  \n",
       "77                173.43                       173  2020 and After  Historical  \n",
       "50                173.43                       173  2020 and After  Historical  \n",
       "43                173.43                       173     Before 2020  Historical  \n",
       "42                173.43                       173     Before 2020  Historical  \n",
       "39                173.43                       173     Before 2020      Recent  \n",
       "70                173.43                       173  2020 and After  Historical  \n",
       "54                173.43                       173  2020 and After  Historical  \n",
       "57                173.43                       173  2020 and After  Historical  \n",
       "53                173.43                       173  2020 and After  Historical  \n",
       "40                173.43                       173     Before 2020      Recent  \n",
       "24                173.43                       173     Before 2020  Historical  \n",
       "25                173.43                       173     Before 2020  Historical  \n",
       "37                173.43                       173     Before 2020      Recent  \n",
       "36                173.43                       173     Before 2020      Recent  \n",
       "\n",
       "[20 rows x 127 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "index",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Document #",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Report",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Operator",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Operator #",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Tracking #",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Initial Report Date",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Date of Discovery",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Spill Type",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Qtr Qtr",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Section",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Township",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "range",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "meridian",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Latitude",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Longitude",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Municipality",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "county",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Facility Type",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Facility ID",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "API County Code",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "API Sequence Number",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Spilled outside of berms",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "More than five barrels spilled",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Oil Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Condensate Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Flow Back Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Produced Water Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "E&P Waste Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Other Waste",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Drilling Fluid Spill Volume",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Current Land Use",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Other Land Use",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Weather Conditions",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Surface Owner",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Surface Owner Other",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Waters of the State",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Residence / Occupied Structure",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "livestock",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Public Byway",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water Supply Area",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Spill Description",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Supplemental Report Date",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Oil BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Oil BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Oil Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Condensate BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Condensate BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Condensate Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Produced Water BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Produced Water BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Produced Water Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Drilling Fluid BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Drilling Fluid BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Drilling Fluid Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Flow Back Fluid BBLs Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Flow Back Fluid BBLs Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Flow Back Fluid Unkown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste BBLS Spilled",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste BBLS Recovered",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste Unknown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other E&P Waste",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Spill Contained within Berm",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Emergency Pit Constructed",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "soil",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "groundwater",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Dry Drainage Feature",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Area Length",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Area Width",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Depth of Impact in Feet",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Depth of Impact in Inches",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Area Depth Determined",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Geology Description",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Depth to Groundwater",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Water wells in area",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Water Wells",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Water Wells None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water Near",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Wetlands",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Wetlands None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Springs",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Springs None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Livestock Near",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Livestock None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Occupied Buildings",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Occupied Buildings None",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Additional Spill Details",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Supplemental Report Date CA",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Human Error",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Equipment Failure",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Historical Unkown",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other Description",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Root Cause",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Preventative Measures",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "Soil Excavated",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Offsite Disposal",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Onsite Treatment",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other Disposition",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Other Disposition Description",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Ground Water Removed",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Surface Water Removed",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Corrective Actions Completed",
         "rawType": "bool",
         "type": "boolean"
        },
        {
         "name": "Approved Form 27",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "Form 27 Project Number",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "GEOID",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "TRACT_NAME",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "total_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "white_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "hispanic_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "median_household_income",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "poverty_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "unemployed_population",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "percent_white",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "percent_hispanic",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "percent_poverty",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "unemployment_rate",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "geometry",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "ruca_code",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "ruca_description",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "rurality",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "report_delay_full_days",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "report_delay_winsor99",
         "rawType": "float64",
         "type": "float"
        },
        {
         "name": "report_delay_winsor99_int",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "Period",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "spill_type",
         "rawType": "object",
         "type": "string"
        }
       ],
       "ref": "26e920eb-4b87-4df8-8cd4-653ccf564e43",
       "rows": [],
       "shape": {
        "columns": 127,
        "rows": 0
       }
      },
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Document #</th>\n",
       "      <th>Report</th>\n",
       "      <th>Operator</th>\n",
       "      <th>Operator #</th>\n",
       "      <th>Tracking #</th>\n",
       "      <th>Initial Report Date</th>\n",
       "      <th>Date of Discovery</th>\n",
       "      <th>Spill Type</th>\n",
       "      <th>Qtr Qtr</th>\n",
       "      <th>Section</th>\n",
       "      <th>...</th>\n",
       "      <th>unemployment_rate</th>\n",
       "      <th>geometry</th>\n",
       "      <th>ruca_code</th>\n",
       "      <th>ruca_description</th>\n",
       "      <th>rurality</th>\n",
       "      <th>report_delay_full_days</th>\n",
       "      <th>report_delay_winsor99</th>\n",
       "      <th>report_delay_winsor99_int</th>\n",
       "      <th>Period</th>\n",
       "      <th>spill_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>0 rows × 127 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [Document #, Report, Operator, Operator #, Tracking #, Initial Report Date, Date of Discovery, Spill Type, Qtr Qtr, Section, Township, range, meridian, Latitude, Longitude, Municipality, county, Facility Type, Facility ID, API County Code, API Sequence Number, Spilled outside of berms, More than five barrels spilled, Oil Spill Volume, Condensate Spill Volume, Flow Back Spill Volume, Produced Water Spill Volume, E&P Waste Spill Volume, Other Waste, Drilling Fluid Spill Volume, Current Land Use, Other Land Use, Weather Conditions, Surface Owner, Surface Owner Other, Waters of the State, Residence / Occupied Structure, livestock, Public Byway, Surface Water Supply Area, Spill Description, Supplemental Report Date, Oil BBLs Spilled, Oil BBLs Recovered, Oil Unknown, Condensate BBLs Spilled, Condensate BBLs Recovered, Condensate Unknown, Produced Water BBLs Spilled, Produced Water BBLs Recovered, Produced Water Unknown, Drilling Fluid BBLs Spilled, Drilling Fluid BBLs Recovered, Drilling Fluid Unknown, Flow Back Fluid BBLs Spilled, Flow Back Fluid BBLs Recovered, Flow Back Fluid Unkown, Other E&P Waste BBLS Spilled, Other E&P Waste BBLS Recovered, Other E&P Waste Unknown, Other E&P Waste, Spill Contained within Berm, Emergency Pit Constructed, soil, groundwater, Surface Water, Dry Drainage Feature, Surface Area Length, Surface Area Width, Depth of Impact in Feet, Depth of Impact in Inches, Area Depth Determined, Geology Description, Depth to Groundwater, Water wells in area, Water Wells, Water Wells None, Surface Water Near, Surface Water None, Wetlands, Wetlands None, Springs, Springs None, Livestock Near, Livestock None, Occupied Buildings, Occupied Buildings None, Additional Spill Details, Supplemental Report Date CA, Human Error, Equipment Failure, Historical Unkown, Other, Other Description, Root Cause, Preventative Measures, Soil Excavated, Offsite Disposal, Onsite Treatment, Other Disposition, ...]\n",
       "Index: []\n",
       "\n",
       "[0 rows x 127 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "index",
         "rawType": "int64",
         "type": "integer"
        },
        {
         "name": "disc_year",
         "rawType": "int32",
         "type": "integer"
        },
        {
         "name": "report_year",
         "rawType": "int32",
         "type": "integer"
        },
        {
         "name": "report_delay_full_days",
         "rawType": "int64",
         "type": "integer"
        }
       ],
       "ref": "f08a04fb-fe72-452b-9206-63a12a2dbb97",
       "rows": [
        [
         "0",
         "2012",
         "2015",
         "1018"
        ],
        [
         "1",
         "2012",
         "2015",
         "981"
        ],
        [
         "2",
         "2012",
         "2015",
         "864"
        ],
        [
         "3",
         "2012",
         "2015",
         "1018"
        ],
        [
         "4",
         "2012",
         "2015",
         "1018"
        ],
        [
         "5",
         "2013",
         "2015",
         "752"
        ],
        [
         "6",
         "2014",
         "2015",
         "404"
        ],
        [
         "7",
         "2014",
         "2015",
         "493"
        ],
        [
         "8",
         "2012",
         "2015",
         "1079"
        ],
        [
         "9",
         "2014",
         "2015",
         "443"
        ],
        [
         "10",
         "2014",
         "2015",
         "512"
        ],
        [
         "11",
         "2014",
         "2015",
         "580"
        ],
        [
         "12",
         "2014",
         "2015",
         "443"
        ],
        [
         "13",
         "2014",
         "2015",
         "591"
        ],
        [
         "14",
         "2013",
         "2015",
         "1022"
        ],
        [
         "15",
         "2014",
         "2015",
         "585"
        ],
        [
         "16",
         "2014",
         "2015",
         "603"
        ],
        [
         "17",
         "2014",
         "2015",
         "603"
        ],
        [
         "18",
         "2014",
         "2015",
         "603"
        ],
        [
         "19",
         "2014",
         "2015",
         "578"
        ]
       ],
       "shape": {
        "columns": 3,
        "rows": 20
       }
      },
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>disc_year</th>\n",
       "      <th>report_year</th>\n",
       "      <th>report_delay_full_days</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2012</td>\n",
       "      <td>2015</td>\n",
       "      <td>1018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2012</td>\n",
       "      <td>2015</td>\n",
       "      <td>981</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2012</td>\n",
       "      <td>2015</td>\n",
       "      <td>864</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2012</td>\n",
       "      <td>2015</td>\n",
       "      <td>1018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2012</td>\n",
       "      <td>2015</td>\n",
       "      <td>1018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2013</td>\n",
       "      <td>2015</td>\n",
       "      <td>752</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2014</td>\n",
       "      <td>2015</td>\n",
       "      <td>404</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2014</td>\n",
       "      <td>2015</td>\n",
       "      <td>493</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2012</td>\n",
       "      <td>2015</td>\n",
       "      <td>1079</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2014</td>\n",
       "      <td>2015</td>\n",
       "      <td>443</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2014</td>\n",
       "      <td>2015</td>\n",
       "      <td>512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2014</td>\n",
       "      <td>2015</td>\n",
       "      <td>580</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2014</td>\n",
       "      <td>2015</td>\n",
       "      <td>443</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2014</td>\n",
       "      <td>2015</td>\n",
       "      <td>591</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2013</td>\n",
       "      <td>2015</td>\n",
       "      <td>1022</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2014</td>\n",
       "      <td>2015</td>\n",
       "      <td>585</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2014</td>\n",
       "      <td>2015</td>\n",
       "      <td>603</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2014</td>\n",
       "      <td>2015</td>\n",
       "      <td>603</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2014</td>\n",
       "      <td>2015</td>\n",
       "      <td>603</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>2014</td>\n",
       "      <td>2015</td>\n",
       "      <td>578</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    disc_year  report_year  report_delay_full_days\n",
       "0        2012         2015                    1018\n",
       "1        2012         2015                     981\n",
       "2        2012         2015                     864\n",
       "3        2012         2015                    1018\n",
       "4        2012         2015                    1018\n",
       "5        2013         2015                     752\n",
       "6        2014         2015                     404\n",
       "7        2014         2015                     493\n",
       "8        2012         2015                    1079\n",
       "9        2014         2015                     443\n",
       "10       2014         2015                     512\n",
       "11       2014         2015                     580\n",
       "12       2014         2015                     443\n",
       "13       2014         2015                     591\n",
       "14       2013         2015                    1022\n",
       "15       2014         2015                     585\n",
       "16       2014         2015                     603\n",
       "17       2014         2015                     603\n",
       "18       2014         2015                     603\n",
       "19       2014         2015                     578"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Counts by delay buckets: report_delay_full_days\n",
      "1     48\n",
      "2     16\n",
      "3      6\n",
      "4      4\n",
      "5      5\n",
      "6      4\n",
      "7      2\n",
      "9      1\n",
      "12     2\n",
      "15     1\n",
      "25     1\n",
      "Name: count, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "sus = pd.read_csv('spills_suspect_delays.csv')  # file saved by earlier cell\n",
    "# show top 20 suspects\n",
    "display(sus.sort_values('report_delay_full_days', ascending=False).head(20))\n",
    "# inspect negative delays\n",
    "display(sus[sus['report_delay_full_days'] < 0].head(20))\n",
    "# year anomalies\n",
    "sus['disc_year'] = pd.to_datetime(sus['Date of Discovery'], errors='coerce').dt.year\n",
    "sus['report_year'] = pd.to_datetime(sus['Initial Report Date'], errors='coerce').dt.year\n",
    "display(sus[['disc_year','report_year','report_delay_full_days']].head(20))\n",
    "# frequency of long delays by reason\n",
    "print(\"Counts by delay buckets:\", (sus['report_delay_full_days'] // 365).value_counts().sort_index())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "27fa7224",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mean: 4.495566778900113 var: 418.98482797999503 var/mean: 93.19955604852656\n"
     ]
    }
   ],
   "source": [
    "y = spills['report_delay_winsor99_int']\n",
    "print(\"mean:\", y.mean(), \"var:\", y.var(), \"var/mean:\", y.var()/y.mean())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "3dac9cf1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                     Generalized Linear Model Regression Results                     \n",
      "=====================================================================================\n",
      "Dep. Variable:     report_delay_winsor99_int   No. Observations:                17820\n",
      "Model:                                   GLM   Df Residuals:                    17808\n",
      "Model Family:               NegativeBinomial   Df Model:                           11\n",
      "Link Function:                           Log   Scale:                          1.0000\n",
      "Method:                                 IRLS   Log-Likelihood:                -43581.\n",
      "Date:                       Thu, 14 Aug 2025   Deviance:                       43285.\n",
      "Time:                               20:18:23   Pearson chi2:                 2.82e+05\n",
      "No. Iterations:                            9   Pseudo R-squ. (CS):             0.2757\n",
      "Covariance Type:                   nonrobust                                         \n",
      "============================================================================================================================================\n",
      "                                                                               coef    std err          z      P>|z|      [0.025      0.975]\n",
      "--------------------------------------------------------------------------------------------------------------------------------------------\n",
      "Intercept                                                                    2.8101      0.032     88.183      0.000       2.748       2.873\n",
      "C(spill_type)[T.Recent]                                                     -1.8599      0.038    -49.090      0.000      -1.934      -1.786\n",
      "C(Period)[T.Before 2020]                                                    -0.2839      0.058     -4.925      0.000      -0.397      -0.171\n",
      "C(rurality)[T.Suburban]                                                     -0.3858      0.076     -5.098      0.000      -0.534      -0.237\n",
      "C(rurality)[T.Urban]                                                        -1.1969      0.037    -32.466      0.000      -1.269      -1.125\n",
      "C(spill_type)[T.Recent]:C(Period)[T.Before 2020]                             0.2451      0.065      3.796      0.000       0.119       0.372\n",
      "C(spill_type)[T.Recent]:C(rurality)[T.Suburban]                              0.7640      0.090      8.491      0.000       0.588       0.940\n",
      "C(spill_type)[T.Recent]:C(rurality)[T.Urban]                                 1.0083      0.051     19.732      0.000       0.908       1.108\n",
      "C(Period)[T.Before 2020]:C(rurality)[T.Suburban]                             0.2293      0.135      1.702      0.089      -0.035       0.493\n",
      "C(Period)[T.Before 2020]:C(rurality)[T.Urban]                                0.1770      0.067      2.658      0.008       0.046       0.308\n",
      "C(spill_type)[T.Recent]:C(Period)[T.Before 2020]:C(rurality)[T.Suburban]    -0.4002      0.155     -2.586      0.010      -0.704      -0.097\n",
      "C(spill_type)[T.Recent]:C(Period)[T.Before 2020]:C(rurality)[T.Urban]        0.1573      0.084      1.874      0.061      -0.007       0.322\n",
      "============================================================================================================================================\n"
     ]
    }
   ],
   "source": [
    "import statsmodels.api as sm\n",
    "import statsmodels.formula.api as smf\n",
    "\n",
    "formula = 'report_delay_winsor99_int ~ C(spill_type) * C(Period) * C(rurality)'\n",
    "nb = smf.glm(formula=formula, data=spills, family=sm.families.NegativeBinomial()).fit()\n",
    "print(nb.summary())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "e3964204",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "empirical alpha: 20.5089948794141\n",
      "                     Generalized Linear Model Regression Results                     \n",
      "=====================================================================================\n",
      "Dep. Variable:     report_delay_winsor99_int   No. Observations:                17820\n",
      "Model:                                   GLM   Df Residuals:                    17808\n",
      "Model Family:               NegativeBinomial   Df Model:                           11\n",
      "Link Function:                           Log   Scale:                          1.0000\n",
      "Method:                                 IRLS   Log-Likelihood:                -45737.\n",
      "Date:                       Thu, 14 Aug 2025   Deviance:                       4105.5\n",
      "Time:                               20:18:28   Pearson chi2:                 1.78e+04\n",
      "No. Iterations:                           10   Pseudo R-squ. (CS):            0.01859\n",
      "Covariance Type:                   nonrobust                                         \n",
      "============================================================================================================================================\n",
      "                                                                               coef    std err          z      P>|z|      [0.025      0.975]\n",
      "--------------------------------------------------------------------------------------------------------------------------------------------\n",
      "Intercept                                                                    2.8101      0.140     20.020      0.000       2.535       3.085\n",
      "C(spill_type)[T.Recent]                                                     -1.8599      0.161    -11.528      0.000      -2.176      -1.544\n",
      "C(Period)[T.Before 2020]                                                    -0.2839      0.252     -1.125      0.261      -0.779       0.211\n",
      "C(rurality)[T.Suburban]                                                     -0.3858      0.330     -1.169      0.242      -1.033       0.261\n",
      "C(rurality)[T.Urban]                                                        -1.1969      0.160     -7.475      0.000      -1.511      -0.883\n",
      "C(spill_type)[T.Recent]:C(Period)[T.Before 2020]                             0.2451      0.276      0.887      0.375      -0.297       0.787\n",
      "C(spill_type)[T.Recent]:C(rurality)[T.Suburban]                              0.7640      0.384      1.991      0.046       0.012       1.516\n",
      "C(spill_type)[T.Recent]:C(rurality)[T.Urban]                                 1.0083      0.209      4.814      0.000       0.598       1.419\n",
      "C(Period)[T.Before 2020]:C(rurality)[T.Suburban]                             0.2293      0.586      0.391      0.696      -0.920       1.378\n",
      "C(Period)[T.Before 2020]:C(rurality)[T.Urban]                                0.1770      0.288      0.616      0.538      -0.387       0.741\n",
      "C(spill_type)[T.Recent]:C(Period)[T.Before 2020]:C(rurality)[T.Suburban]    -0.4002      0.660     -0.607      0.544      -1.693       0.893\n",
      "C(spill_type)[T.Recent]:C(Period)[T.Before 2020]:C(rurality)[T.Urban]        0.1573      0.349      0.451      0.652      -0.526       0.841\n",
      "============================================================================================================================================\n",
      "Pearson chi2: 17756.94, dispersion: 0.997\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import statsmodels.api as sm\n",
    "import statsmodels.formula.api as smf\n",
    "\n",
    "y = spills['report_delay_winsor99_int'].dropna()\n",
    "mean_y = y.mean()\n",
    "var_y  = y.var()\n",
    "alpha_emp = max(1e-8, (var_y - mean_y) / (mean_y**2))  # NB2 alpha estimate\n",
    "print(\"empirical alpha:\", alpha_emp)\n",
    "\n",
    "fam = sm.families.NegativeBinomial(alpha=alpha_emp)\n",
    "formula = 'report_delay_winsor99_int ~ C(spill_type) * C(Period) * C(rurality)'\n",
    "nb_glm = smf.glm(formula=formula, data=spills, family=fam).fit()\n",
    "print(nb_glm.summary())\n",
    "\n",
    "pearson_chi2 = ((nb_glm.resid_pearson)**2).sum()\n",
    "dispersion = pearson_chi2 / nb_glm.df_resid\n",
    "print(f\"Pearson chi2: {pearson_chi2:.2f}, dispersion: {dispersion:.3f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3cbe2363",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "bdde238b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Winsorize 99th percentile = 173.43000000000393\n",
      "Empirical alpha (NB2 MOM) = 20.5089948794141\n",
      "Discrete NB MLE on observed data succeeded\n",
      "Appended NB parametric bootstrap finished in 127.6s — successes=2000, failures=0, requested=2000\n",
      "Saved nb_parametric_boot_predicted_means_appended.csv\n"
     ]
    }
   ],
   "source": [
    "# APPENDED: Improved NB parametric bootstrap (safe append)\n",
    "# - Non-destructive append so your manual edits aren't overwritten\n",
    "# - Run this cell (start with B=100 for a smoke test) to produce a CSV: nb_parametric_boot_predicted_means_appended.csv\n",
    "import time\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import patsy\n",
    "import statsmodels.api as sm\n",
    "import statsmodels.formula.api as smf\n",
    "\n",
    "# Adjustable draws: use small B for smoke tests (e.g., 100), increase to 500-2000 for final runs\n",
    "B = 2000  # change to 500 or 2000 for final\n",
    "RNG_SEED = 12345\n",
    "rng = np.random.default_rng(RNG_SEED)\n",
    "\n",
    "if 'spills' not in globals():\n",
    "    print('`spills` not found in kernel. Load the dataset into variable `spills` and re-run this cell.')\n",
    "else:\n",
    "    t0 = time.time()\n",
    "    # Ensure required columns and dtypes\n",
    "    if 'Spill Type' in spills.columns and 'spill_type' not in spills.columns:\n",
    "        spills['spill_type'] = spills['Spill Type']\n",
    "    if 'Rurality' in spills.columns and 'rurality' not in spills.columns:\n",
    "        spills['rurality'] = spills['Rurality']\n",
    "    if 'Period' not in spills.columns:\n",
    "        spills['Initial Report Date'] = pd.to_datetime(spills['Initial Report Date'])\n",
    "        spills['Period'] = np.where(spills['Initial Report Date'].dt.year < 2020, 'Before 2020', '2020 and After')\n",
    "    for c in ['spill_type','Period','rurality']:\n",
    "        if c in spills.columns:\n",
    "            spills[c] = spills[c].astype('category')\n",
    "\n",
    "    # Prepare winsorized integer outcome used for NB sensitivity (99th percentile)\n",
    "    if 'report_delay_full_days' not in spills.columns:\n",
    "        spills['Date of Discovery'] = pd.to_datetime(spills['Date of Discovery'])\n",
    "        spills['Initial Report Date'] = pd.to_datetime(spills['Initial Report Date'])\n",
    "        spills['report_delay_full_days'] = (spills['Initial Report Date'] - spills['Date of Discovery']).dt.days\n",
    "    p99 = np.nanpercentile(spills['report_delay_full_days'].dropna(), 99)\n",
    "    spills['report_delay_winsor99_int'] = spills['report_delay_full_days'].clip(upper=p99).round().astype(int)\n",
    "    print('Winsorize 99th percentile =', p99)\n",
    "\n",
    "    # Modeling formula (matches previous cells)\n",
    "    formula = 'report_delay_winsor99_int ~ C(spill_type) * C(Period) * C(rurality)'\n",
    "\n",
    "    # Empirical NB2 alpha (MOM) with safe floor\n",
    "    y_obs = spills['report_delay_winsor99_int'].dropna()\n",
    "    mean_y = y_obs.mean()\n",
    "    var_y = y_obs.var()\n",
    "    alpha_emp = max(1e-8, (var_y - mean_y) / (mean_y**2))\n",
    "    print('Empirical alpha (NB2 MOM) =', alpha_emp)\n",
    "\n",
    "    # Build design matrices once (response and exog for full sample)\n",
    "    y_mat, X_mat = patsy.dmatrices(formula, data=spills, return_type='dataframe')\n",
    "\n",
    "    # Try discrete NB MLE on observed data (preferred). If fail, fall back to GLM NB (empirical alpha).\n",
    "    res_nb_mle = None\n",
    "    try:\n",
    "        nb_model = sm.NegativeBinomial(y_mat, X_mat)\n",
    "        res_nb_mle = nb_model.fit(disp=0)\n",
    "        print('Discrete NB MLE on observed data succeeded')\n",
    "    except Exception as e:\n",
    "        print('Discrete NB MLE failed on observed data — falling back to GLM-NB (empirical alpha):', e)\n",
    "        fam_emp = sm.families.NegativeBinomial(alpha=alpha_emp)\n",
    "        res_glm_emp = smf.glm(formula=formula, data=spills, family=fam_emp).fit()\n",
    "        print('GLM NB (empirical alpha) fit complete')\n",
    "\n",
    "    # Choose baseline mu_hat for simulation\n",
    "    if res_nb_mle is not None:\n",
    "        try:\n",
    "            mu_hat_obs = res_nb_mle.predict(X_mat)\n",
    "        except Exception:\n",
    "            # fallback via linear predictor and exp\n",
    "            mu_hat_obs = np.exp(X_mat.values.dot(res_nb_mle.params.reindex(X_mat.columns).fillna(0).values))\n",
    "    else:\n",
    "        mu_hat_obs = res_glm_emp.predict(spills)\n",
    "\n",
    "    # Prepare prediction grid for group combinations\n",
    "    groups = spills.groupby(['spill_type','Period','rurality'], observed=True).size().reset_index(name='n')\n",
    "    preds_df = groups[['spill_type','Period','rurality']].copy().reset_index(drop=True)\n",
    "    Xp = patsy.dmatrix('1 + C(spill_type) * C(Period) * C(rurality)', preds_df, return_type='dataframe')\n",
    "\n",
    "    # Use empirical alpha to simulate NB2 (alpha_used); extracting alpha from discrete MLE is often unstable\n",
    "    alpha_used = alpha_emp\n",
    "    successes = 0\n",
    "    fail_count = 0\n",
    "    boot_preds = []\n",
    "\n",
    "    for b in range(int(B)):\n",
    "        try:\n",
    "            # gamma-poisson representation: lam_i ~ Gamma(shape=1/alpha, scale=alpha * mu_i) so E[lam]=mu_i\n",
    "            k = 1.0 / alpha_used\n",
    "            # ensure mu_hat_obs is non-negative\n",
    "            if np.any(mu_hat_obs < 0):\n",
    "                raise ValueError('Negative mu_hat encountered')\n",
    "            lam = rng.gamma(shape=k, scale=alpha_used * mu_hat_obs)\n",
    "            y_sim = rng.poisson(lam)\n",
    "            # Attempt discrete NB fit on simulated outcome using same X_mat (X doesn't change)\n",
    "            try:\n",
    "                nb_sim = sm.NegativeBinomial(y_sim, X_mat)\n",
    "                res_sim = nb_sim.fit(disp=0, maxiter=100)\n",
    "                params_sim = res_sim.params.reindex(Xp.columns).fillna(0.0)\n",
    "                lin = Xp.values.dot(params_sim.values)\n",
    "                mu_group = np.exp(lin)\n",
    "                boot_preds.append(mu_group)\n",
    "                successes += 1\n",
    "            except Exception:\n",
    "                # fallback: GLM NB on simulated dataset\n",
    "                try:\n",
    "                    sim_df = spills.copy()\n",
    "                    sim_df['report_delay_winsor99_int'] = y_sim\n",
    "                    fam_emp = sm.families.NegativeBinomial(alpha=alpha_used)\n",
    "                    res_glm_sim = smf.glm(formula=formula, data=sim_df, family=fam_emp).fit(disp=False)\n",
    "                    params_glm = res_glm_sim.params.reindex(Xp.columns).fillna(0.0)\n",
    "                    lin = Xp.values.dot(params_glm.values)\n",
    "                    mu_group = np.exp(lin)\n",
    "                    boot_preds.append(mu_group)\n",
    "                    successes += 1\n",
    "                except Exception:\n",
    "                    fail_count += 1\n",
    "                    continue\n",
    "        except Exception:\n",
    "            fail_count += 1\n",
    "            continue\n",
    "\n",
    "    t1 = time.time()\n",
    "    print(f'Appended NB parametric bootstrap finished in {t1 - t0:.1f}s — successes={successes}, failures={fail_count}, requested={B}')\n",
    "\n",
    "    if successes > 0:\n",
    "        boot_arr = np.vstack(boot_preds)  # shape (successes, n_groups)\n",
    "        out = preds_df.copy().reset_index(drop=True)\n",
    "        out['pred_median'] = np.median(boot_arr, axis=0)\n",
    "        out['ci_lower'] = np.percentile(boot_arr, 2.5, axis=0)\n",
    "        out['ci_upper'] = np.percentile(boot_arr, 97.5, axis=0)\n",
    "        out.to_csv('nb_parametric_boot_predicted_means_appended.csv', index=False)\n",
    "        print('Saved nb_parametric_boot_predicted_means_appended.csv')\n",
    "    else:\n",
    "        print('No successful bootstrap draws; try reducing B or inspect errors; consider nonparametric (case) bootstrap as fallback.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "4aa7c91b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Found 12 groups in nb_parametric_boot_predicted_means_appended.csv\n",
      "No bootstrap draws found — using approximate normal simulation from summary CI (conservative).\n",
      "Generated 5000 approximate draws from normals\n",
      "Saved nb_contrasts_period.csv and nb_contrasts_spilltype.csv\n",
      "Saved nb_contrasts_period.png\n",
      "Saved nb_contrasts_spilltype.png\n",
      "Contrast computation complete.\n"
     ]
    }
   ],
   "source": [
    "# APPENDED: compute contrasts from NB parametric bootstrap draws (or approximate from summary CSV)\n",
    "import os\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# Filenames to look for (ordered)\n",
    "boot_files = ['nb_boot_arr.npy', 'nb_boot_arr_appended.npy', 'nb_parametric_boot_arr.npy', 'nb_boot_arr.npy']\n",
    "summary_file = 'nb_parametric_boot_predicted_means_appended.csv'\n",
    "\n",
    "boot_arr = None\n",
    "for f in boot_files:\n",
    "    if os.path.exists(f):\n",
    "        try:\n",
    "            boot_arr = np.load(f)\n",
    "            print('Loaded bootstrap draws from', f)\n",
    "            break\n",
    "        except Exception as e:\n",
    "            print('Found', f, 'but failed to load:', e)\n",
    "\n",
    "# Read group summary CSV to get group order and baseline medians/CI\n",
    "if not os.path.exists(summary_file):\n",
    "    raise FileNotFoundError(f'Summary CSV {summary_file} not found. Run NB bootstrap cell first.')\n",
    "preds_df = pd.read_csv(summary_file)\n",
    "groups = list(zip(preds_df['spill_type'], preds_df['Period'], preds_df['rurality']))\n",
    "n_groups = len(groups)\n",
    "print(f'Found {n_groups} groups in {summary_file}')\n",
    "\n",
    "# If boot_arr exists, ensure shape is (n_draws, n_groups)\n",
    "if boot_arr is not None:\n",
    "    if boot_arr.ndim != 2:\n",
    "        raise ValueError('boot_arr must be 2-dimensional (draws x groups)')\n",
    "    # common shapes: (n_draws, n_groups) or (n_groups, n_draws)\n",
    "    if boot_arr.shape[1] == n_groups:\n",
    "        draws = boot_arr\n",
    "    elif boot_arr.shape[0] == n_groups:\n",
    "        draws = boot_arr.T\n",
    "    else:\n",
    "        # ambiguous; attempt transpose if dims match otherwise error\n",
    "        raise ValueError(f'boot_arr shape {boot_arr.shape} not compatible with n_groups={n_groups}')\n",
    "    print('Using exact bootstrap draws (n_draws=', draws.shape[0], ', n_groups=', draws.shape[1], ')')\n",
    "else:\n",
    "    # Fallback: approximate draws per group from median + CI assuming approx normality\n",
    "    print('No bootstrap draws found — using approximate normal simulation from summary CI (conservative).')\n",
    "    med = preds_df['pred_median'].values\n",
    "    lo = preds_df['ci_lower'].values\n",
    "    hi = preds_df['ci_upper'].values\n",
    "    # approximate sd from 95% CI width: sd = (hi - lo) / (2*1.96)\n",
    "    sd = (hi - lo) / (2.0 * 1.96)\n",
    "    sd[sd <= 0] = 1e-6\n",
    "    Nsim = 5000\n",
    "    rng = np.random.default_rng(12345)\n",
    "    draws = rng.normal(loc=med.reshape(1, -1), scale=sd.reshape(1, -1), size=(Nsim, n_groups))\n",
    "    # clip to non-negative delays\n",
    "    draws = np.clip(draws, 0, None)\n",
    "    print(f'Generated {Nsim} approximate draws from normals')\n",
    "\n",
    "# helper to find index for a group tuple\n",
    "group_to_idx = {g: i for i, g in enumerate(groups)}\n",
    "\n",
    "period_rows = []\n",
    "spilltype_rows = []\n",
    "# Period contrasts: Before 2020 - 2020 and After (for each spill_type × rurality)\n",
    "spill_types = sorted(set(preds_df['spill_type']))\n",
    "rurals = sorted(set(preds_df['rurality']))\n",
    "periods = ['Before 2020', '2020 and After']\n",
    "for st in spill_types:\n",
    "    for r in rurals:\n",
    "        key_before = (st, 'Before 2020', r)\n",
    "        key_after = (st, '2020 and After', r)\n",
    "        if key_before not in group_to_idx or key_after not in group_to_idx:\n",
    "            print('Skipping Period contrast missing group for', st, r)\n",
    "            continue\n",
    "        i_b = group_to_idx[key_before]\n",
    "        i_a = group_to_idx[key_after]\n",
    "        diffs = draws[:, i_b] - draws[:, i_a]\n",
    "        med = np.median(diffs)\n",
    "        lo = np.percentile(diffs, 2.5)\n",
    "        hi = np.percentile(diffs, 97.5)\n",
    "        p_two = 2.0 * min(np.mean(diffs <= 0), np.mean(diffs >= 0))\n",
    "        period_rows.append({'spill_type': st, 'rurality': r, 'median_days': med, 'ci_lower': lo, 'ci_upper': hi, 'p_value_boot': p_two})\n",
    "\n",
    "# SpillType contrasts: Recent - Historical (for each Period × rurality)\n",
    "for per in periods:\n",
    "    for r in rurals:\n",
    "        key_rec = ('Recent', per, r)\n",
    "        key_hist = ('Historical', per, r)\n",
    "        if key_rec not in group_to_idx or key_hist not in group_to_idx:\n",
    "            print('Skipping SpillType contrast missing group for', per, r)\n",
    "            continue\n",
    "        i_rec = group_to_idx[key_rec]\n",
    "        i_hist = group_to_idx[key_hist]\n",
    "        diffs = draws[:, i_rec] - draws[:, i_hist]\n",
    "        med = np.median(diffs)\n",
    "        lo = np.percentile(diffs, 2.5)\n",
    "        hi = np.percentile(diffs, 97.5)\n",
    "        p_two = 2.0 * min(np.mean(diffs <= 0), np.mean(diffs >= 0))\n",
    "        spilltype_rows.append({'Period': per, 'rurality': r, 'median_days': med, 'ci_lower': lo, 'ci_upper': hi, 'p_value_boot': p_two})\n",
    "\n",
    "# Save CSVs\n",
    "pd.DataFrame(period_rows).to_csv('nb_contrasts_period.csv', index=False)\n",
    "pd.DataFrame(spilltype_rows).to_csv('nb_contrasts_spilltype.csv', index=False)\n",
    "print('Saved nb_contrasts_period.csv and nb_contrasts_spilltype.csv')\n",
    "\n",
    "# Plotting: Period contrasts by spill_type (one subplot per spill_type)\n",
    "period_df = pd.DataFrame(period_rows)\n",
    "if not period_df.empty:\n",
    "    spill_types_plot = sorted(period_df['spill_type'].unique())\n",
    "    n = len(spill_types_plot)\n",
    "    fig, axes = plt.subplots(1, n, figsize=(5*n, 4), squeeze=False)\n",
    "    for i, st in enumerate(spill_types_plot):\n",
    "        ax = axes[0, i]\n",
    "        sub = period_df[period_df['spill_type']==st].sort_values('rurality')\n",
    "        x = np.arange(len(sub))\n",
    "        y = sub['median_days'].values\n",
    "        yerr_low = y - sub['ci_lower'].values\n",
    "        yerr_high = sub['ci_upper'].values - y\n",
    "        ax.bar(x, y, color='#4C72B0')\n",
    "        ax.errorbar(x, y, yerr=[yerr_low, yerr_high], fmt='none', ecolor='black', capsize=5)\n",
    "        ax.set_xticks(x)\n",
    "        ax.set_xticklabels(sub['rurality'].values, rotation=45)\n",
    "        ax.set_title(f'Period contrast (Before - After): {st}')\n",
    "        ax.axhline(0, color='gray', linewidth=0.8)\n",
    "    plt.tight_layout()\n",
    "    plt.savefig('nb_contrasts_period.png', dpi=150)\n",
    "    plt.close(fig)\n",
    "    print('Saved nb_contrasts_period.png')\n",
    "\n",
    "# Plotting: SpillType contrasts by Period (one subplot per Period)\n",
    "spill_df = pd.DataFrame(spilltype_rows)\n",
    "if not spill_df.empty:\n",
    "    periods_plot = sorted(spill_df['Period'].unique())\n",
    "    n = len(periods_plot)\n",
    "    fig, axes = plt.subplots(1, n, figsize=(5*n, 4), squeeze=False)\n",
    "    for i, per in enumerate(periods_plot):\n",
    "        ax = axes[0, i]\n",
    "        sub = spill_df[spill_df['Period']==per].sort_values('rurality')\n",
    "        x = np.arange(len(sub))\n",
    "        y = sub['median_days'].values\n",
    "        yerr_low = y - sub['ci_lower'].values\n",
    "        yerr_high = sub['ci_upper'].values - y\n",
    "        ax.bar(x, y, color='#55A868')\n",
    "        ax.errorbar(x, y, yerr=[yerr_low, yerr_high], fmt='none', ecolor='black', capsize=5)\n",
    "        ax.set_xticks(x)\n",
    "        ax.set_xticklabels(sub['rurality'].values, rotation=45)\n",
    "        ax.set_title(f'SpillType contrast (Recent - Historical): {per}')\n",
    "        ax.axhline(0, color='gray', linewidth=0.8)\n",
    "    plt.tight_layout()\n",
    "    plt.savefig('nb_contrasts_spilltype.png', dpi=150)\n",
    "    plt.close(fig)\n",
    "    print('Saved nb_contrasts_spilltype.png')\n",
    "\n",
    "print('Contrast computation complete.')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a8884c9",
   "metadata": {},
   "source": [
    "# Key Statistically Significant Contrasts (NB Parametric Bootstrap, p < 0.05)\n",
    "\n",
    "## Period Contrasts (Before 2020 − 2020 and After)\n",
    "\n",
    "| Period           | Rurality   | Median (days) | 95% CI                | p-value   | Interpretation                                      |\n",
    "|------------------|------------|---------------|-----------------------|-----------|-----------------------------------------------------|\n",
    "| Before 2020      | Rural      | −9.83         | [−14.87, −4.51]       | 0.0004    | Significant: After > Before by ≈ 9.8 days           |\n",
    "| Before 2020      | Urban      | −1.64         | [−2.86, −0.46]        | 0.008     | Significant: After > Before by ≈ 1.64 days          |\n",
    "| 2020 and After   | Rural      | −13.92        | [−18.48, −9.26]       | ≈ 0.0     | Significant: Large negative Recent−Historical gap   |\n",
    "| 2020 and After   | Suburban   | −7.23         | [−13.89, −0.40]       | 0.0368    | Significant                                         |\n",
    "| 2020 and After   | Urban      | −2.87         | [−3.73, −2.01]        | ≈ 0.0     | Significant                                         |\n",
    "| Before 2020      | Suburban   | −7.10         | [−15.48, 1.48]        | 0.1072    | Not significant at α=0.05                           |\n",
    "\n",
    "## SpillType Contrasts (Recent − Historical)\n",
    "\n",
    "- None of the listed per-row p-values are < 0.05 (all p ≥ 0.0784).\n",
    "- Recent − Historical contrasts are not statistically significant at conventional levels, though some medians are meaningful in size.\n",
    "\n",
    "---\n",
    "\n",
    "## Concise Interpretation\n",
    "\n",
    "- **Dominant signal:** Large negative Period contrasts (Before − After < 0) in several rurality strata, especially Rural and Urban. Predicted delays are larger after 2020 in those cells (Rural: ≈ 10–14 days).\n",
    "- **SpillType contrasts:** Recent − Historical differences are relatively small and not statistically significant at α=0.05 in these NB results.\n",
    "- **Model sensitivity:** NB (with winsorization) produces larger predicted means and different sign/magnitude for Period contrasts compared to Poisson + bootstrap output (which showed small reductions after 2020).\n",
    "\n",
    "---\n",
    "\n",
    "## Limitations and Important Caveats\n",
    "\n",
    "- Results reflect the NB parametric bootstrap and winsorized NB specification; sensitive to outcome transformation and NB dispersion.\n",
    "- Contrasts and p-values are valid for the bootstrap draws used; ensure group ordering matches when computing contrasts.\n",
    "- Small cell counts (some SpillType × Period × rurality cells) can inflate uncertainty and make NB fits unstable; check sample sizes.\n",
    "- NB median differences (several days) are larger than Poisson results (hours); report both as sensitivity analyses and emphasize effect sizes + CIs rather than p-values."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "ef8a34b6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved contrast_comparison_period.csv\n",
      "Saved contrast_comparison_spilltype.csv\n",
      "Saved contrast_comparison_period.png\n",
      "Saved contrast_comparison_spilltype.png\n",
      "Poisson vs NB contrast comparison complete.\n",
      "Saved contrast_comparison_spilltype.png\n",
      "Poisson vs NB contrast comparison complete.\n"
     ]
    }
   ],
   "source": [
    "# APPENDED: Compare Poisson vs NB contrasts and save CSV + PNG outputs\n",
    "import os\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# Filenames (change if your Poisson outputs use different names)\n",
    "poisson_file = 'poisson_predicted_groups_boot_final.csv'\n",
    "poisson_contrast_file = 'poisson_boot_contrasts.csv'\n",
    "nb_period_file = 'nb_contrasts_period.csv'\n",
    "nb_spill_file = 'nb_contrasts_spilltype.csv'\n",
    "out_period_cmp = 'contrast_comparison_period.csv'\n",
    "out_spill_cmp = 'contrast_comparison_spilltype.csv'\n",
    "\n",
    "# Load NB contrasts (must exist)\n",
    "if not os.path.exists(nb_period_file) or not os.path.exists(nb_spill_file):\n",
    "    raise FileNotFoundError('NB contrast files not found. Run previous contrast cell first.')\n",
    "nb_period = pd.read_csv(nb_period_file)\n",
    "nb_spill = pd.read_csv(nb_spill_file)\n",
    "\n",
    "# Load Poisson contrasts if available (bootstrap contrasts produced earlier)\n",
    "if os.path.exists(poisson_contrast_file):\n",
    "    poisson_contrasts = pd.read_csv(poisson_contrast_file)\n",
    "    # poisson_contrasts has columns like contrast_type, spill_type, Period, rurality, median, ci_lower, ci_upper, p_value\n",
    "else:\n",
    "    print('Poisson contrasts file not found:', poisson_contrast_file)\n",
    "    poisson_contrasts = None\n",
    "\n",
    "# Normalize column names for merging and comparison\n",
    "# NB period: columns = spill_type,rurality,median_days,ci_lower,ci_upper,p_value_boot\n",
    "nb_period = nb_period.rename(columns={'median_days':'nb_median','ci_lower':'nb_ci_lower','ci_upper':'nb_ci_upper','p_value_boot':'nb_p'})\n",
    "nb_spill = nb_spill.rename(columns={'median_days':'nb_median','ci_lower':'nb_ci_lower','ci_upper':'nb_ci_upper','p_value_boot':'nb_p'})\n",
    "\n",
    "# Build poisson period table from poisson_contrasts if possible\n",
    "if poisson_contrasts is not None and 'contrast_type' in poisson_contrasts.columns:\n",
    "    # Extract Period contrasts rows (contrast_type=='Period')\n",
    "    p_period = poisson_contrasts[poisson_contrasts['contrast_type']=='Period'].copy()\n",
    "    # columns: contrast_type, spill_type, rurality, comparison, median, ci_lower, ci_upper, p_value\n",
    "    p_period = p_period.rename(columns={'median':'poisson_median','ci_lower':'poisson_ci_lower','ci_upper':'poisson_ci_upper','p_value':'poisson_p'})\n",
    "    # Keep spill_type, rurality for merge\n",
    "    p_period = p_period[['spill_type','rurality','poisson_median','poisson_ci_lower','poisson_ci_upper','poisson_p']]\n",
    "    # Merge with NB period on spill_type + rurality\n",
    "    period_cmp = nb_period.merge(p_period, on=['spill_type','rurality'], how='left')\n",
    "else:\n",
    "    # If poisson contrasts not available, set NaNs for poisson columns\n",
    "    period_cmp = nb_period.copy()\n",
    "    period_cmp[['poisson_median','poisson_ci_lower','poisson_ci_upper','poisson_p']] = np.nan\n",
    "\n",
    "period_cmp.to_csv(out_period_cmp, index=False)\n",
    "print('Saved', out_period_cmp)\n",
    "\n",
    "# Build poisson spilltype table from poisson_contrasts if possible\n",
    "if poisson_contrasts is not None and 'contrast_type' in poisson_contrasts.columns:\n",
    "    p_spill = poisson_contrasts[poisson_contrasts['contrast_type']=='SpillType'].copy()\n",
    "    p_spill = p_spill.rename(columns={'median':'poisson_median','ci_lower':'poisson_ci_lower','ci_upper':'poisson_ci_upper','p_value':'poisson_p'})\n",
    "    # expected columns: contrast_type, Period, rurality, comparison, median, ci_lower, ci_upper, p_value\n",
    "    # We keep Period and rurality to merge with nb_spill (which has Period column)\n",
    "    p_spill = p_spill[['Period','rurality','poisson_median','poisson_ci_lower','poisson_ci_upper','poisson_p']]\n",
    "    spill_cmp = nb_spill.merge(p_spill, on=['Period','rurality'], how='left')\n",
    "else:\n",
    "    spill_cmp = nb_spill.copy()\n",
    "    spill_cmp[['poisson_median','poisson_ci_lower','poisson_ci_upper','poisson_p']] = np.nan\n",
    "\n",
    "spill_cmp.to_csv(out_spill_cmp, index=False)\n",
    "print('Saved', out_spill_cmp)\n",
    "\n",
    "# Plots: Side-by-side Poisson vs NB for Period contrasts (by spill_type)\n",
    "try:\n",
    "    df = period_cmp.copy()\n",
    "    spill_types = sorted(df['spill_type'].unique())\n",
    "    n = len(spill_types)\n",
    "    fig, axes = plt.subplots(1, n, figsize=(5*n,4), squeeze=False)\n",
    "    for i, st in enumerate(spill_types):\n",
    "        ax = axes[0, i]\n",
    "        sub = df[df['spill_type']==st].sort_values('rurality')\n",
    "        x = np.arange(len(sub))\n",
    "        # NB bars\n",
    "        y_nb = sub['nb_median'].values\n",
    "        err_nb_low = y_nb - sub['nb_ci_lower'].values\n",
    "        err_nb_high = sub['nb_ci_upper'].values - y_nb\n",
    "        ax.bar(x - 0.15, y_nb, width=0.3, color='#4C72B0', label='NB')\n",
    "        ax.errorbar(x - 0.15, y_nb, yerr=[err_nb_low, err_nb_high], fmt='none', ecolor='black', capsize=4)\n",
    "        # Poisson bars if available\n",
    "        if 'poisson_median' in sub.columns and not sub['poisson_median'].isna().all():\n",
    "            y_p = sub['poisson_median'].values\n",
    "            err_p_low = y_p - sub['poisson_ci_lower'].values\n",
    "            err_p_high = sub['poisson_ci_upper'].values - y_p\n",
    "            ax.bar(x + 0.15, y_p, width=0.3, color='#55A868', label='Poisson')\n",
    "            ax.errorbar(x + 0.15, y_p, yerr=[err_p_low, err_p_high], fmt='none', ecolor='black', capsize=4)\n",
    "        ax.set_xticks(x)\n",
    "        ax.set_xticklabels(sub['rurality'].values, rotation=45)\n",
    "        ax.axhline(0, color='gray', linewidth=0.8)\n",
    "        ax.set_title(f'Period contrast (Before - After): {st}')\n",
    "        if i == 0:\n",
    "            ax.legend()\n",
    "    plt.tight_layout()\n",
    "    plt.savefig('contrast_comparison_period.png', dpi=150)\n",
    "    plt.close(fig)\n",
    "    print('Saved contrast_comparison_period.png')\n",
    "except Exception as e:\n",
    "    print('Failed to build period comparison plot:', e)\n",
    "\n",
    "# Plots: SpillType contrasts by Period (NB vs Poisson)\n",
    "try:\n",
    "    df2 = spill_cmp.copy()\n",
    "    periods = sorted(df2['Period'].unique())\n",
    "    n = len(periods)\n",
    "    fig, axes = plt.subplots(1, n, figsize=(5*n,4), squeeze=False)\n",
    "    for i, per in enumerate(periods):\n",
    "        ax = axes[0, i]\n",
    "        sub = df2[df2['Period']==per].sort_values('rurality')\n",
    "        x = np.arange(len(sub))\n",
    "        y_nb = sub['nb_median'].values\n",
    "        err_nb_low = y_nb - sub['nb_ci_lower'].values\n",
    "        err_nb_high = sub['nb_ci_upper'].values - y_nb\n",
    "        ax.bar(x - 0.15, y_nb, width=0.3, color='#4C72B0', label='NB')\n",
    "        ax.errorbar(x - 0.15, y_nb, yerr=[err_nb_low, err_nb_high], fmt='none', ecolor='black', capsize=4)\n",
    "        if 'poisson_median' in sub.columns and not sub['poisson_median'].isna().all():\n",
    "            y_p = sub['poisson_median'].values\n",
    "            err_p_low = y_p - sub['poisson_ci_lower'].values\n",
    "            err_p_high = sub['poisson_ci_upper'].values - y_p\n",
    "            ax.bar(x + 0.15, y_p, width=0.3, color='#55A868', label='Poisson')\n",
    "            ax.errorbar(x + 0.15, y_p, yerr=[err_p_low, err_p_high], fmt='none', ecolor='black', capsize=4)\n",
    "        ax.set_xticks(x)\n",
    "        ax.set_xticklabels(sub['rurality'].values, rotation=45)\n",
    "        ax.axhline(0, color='gray', linewidth=0.8)\n",
    "        ax.set_title(f'SpillType contrast (Recent - Historical): {per}')\n",
    "        if i == 0:\n",
    "            ax.legend()\n",
    "    plt.tight_layout()\n",
    "    plt.savefig('contrast_comparison_spilltype.png', dpi=150)\n",
    "    plt.close(fig)\n",
    "    print('Saved contrast_comparison_spilltype.png')\n",
    "except Exception as e:\n",
    "    print('Failed to build spilltype comparison plot:', e)\n",
    "\n",
    "print('Poisson vs NB contrast comparison complete.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "8c68de82",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved enhanced CSVs: contrast_comparison_period_enhanced_nb.csv and contrast_comparison_spilltype_enhanced_nb.csv\n",
      "Saved contrast_comparison_period_with_pct.png\n",
      "Saved contrast_comparison_spilltype_with_pct.png\n",
      "Enhanced contrast tables and plots complete.\n",
      "Saved contrast_comparison_spilltype_with_pct.png\n",
      "Enhanced contrast tables and plots complete.\n"
     ]
    }
   ],
   "source": [
    "# APPENDED: add percent-change and hours columns to contrast comparison tables and save enhanced CSVs + PNGs\n",
    "import os\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# Files produced by prior cells\n",
    "period_cmp_file = 'contrast_comparison_period.csv'\n",
    "spill_cmp_file = 'contrast_comparison_spilltype.csv'\n",
    "nb_preds_file = 'nb_parametric_boot_predicted_means_appended.csv'\n",
    "poisson_preds_file_candidates = ['poisson_predicted_groups_boot_all.csv', 'poisson_predicted_groups_boot_final.csv']\n",
    "\n",
    "# Load comparison tables\n",
    "if not os.path.exists(period_cmp_file) or not os.path.exists(spill_cmp_file):\n",
    "    raise FileNotFoundError('Run comparison cell first: missing comparison CSVs.')\n",
    "period = pd.read_csv(period_cmp_file)\n",
    "spill = pd.read_csv(spill_cmp_file)\n",
    "\n",
    "# Load NB predicted group means (to form denominators for percent-change)\n",
    "if not os.path.exists(nb_preds_file):\n",
    "    print('NB predicted-means CSV not found:', nb_preds_file, '— percent-change columns will be NA where denominator missing')\n",
    "    nb_preds = None\n",
    "else:\n",
    "    nb_preds = pd.read_csv(nb_preds_file)\n",
    "    nb_preds = nb_preds.rename(columns={col: col.strip() for col in nb_preds.columns})\n",
    "\n",
    "# Load Poisson predicted group means if available (for Poisson percent-change denominator)\n",
    "poisson_preds = None\n",
    "for cand in poisson_preds_file_candidates:\n",
    "    if os.path.exists(cand):\n",
    "        try:\n",
    "            poisson_preds = pd.read_csv(cand)\n",
    "            break\n",
    "        except Exception as e:\n",
    "            print('Failed to read', cand, e)\n",
    "\n",
    "# Helper: find predicted mean for a given spill_type, Period, rurality in preds DataFrame\n",
    "def find_pred(preds_df, st, per, rur):\n",
    "    if preds_df is None:\n",
    "        return np.nan\n",
    "    df = preds_df.copy()\n",
    "    # attempt common name variants\n",
    "    for cname in ['spill_type','Spill Type','spill_type ']:\n",
    "        if cname in df.columns:\n",
    "            df = df.rename(columns={cname:'spill_type'})\n",
    "            break\n",
    "    for cname in ['Period','period']:\n",
    "        if cname in df.columns:\n",
    "            df = df.rename(columns={cname:'Period'})\n",
    "            break\n",
    "    for cname in ['rurality','Rurality']:\n",
    "        if cname in df.columns:\n",
    "            df = df.rename(columns={cname:'rurality'})\n",
    "            break\n",
    "    for cname in ['pred_median','pred_median_boot','pred_mean','pred_median_boot']:\n",
    "        if cname in df.columns:\n",
    "            df = df.rename(columns={cname:'pred_median'})\n",
    "            break\n",
    "    try:\n",
    "        row = df[(df['spill_type']==st) & (df['Period']==per) & (df['rurality']==rur)]\n",
    "        if len(row)==0:\n",
    "            return np.nan\n",
    "        return float(row['pred_median'].iloc[0])\n",
    "    except Exception:\n",
    "        return np.nan\n",
    "\n",
    "# Add hours columns (multiply days by 24) and percent-change columns where denominator available\n",
    "def enhance_df(df, nb_preds, poisson_preds, is_period=True):\n",
    "    df = df.copy()\n",
    "    # days -> hours for NB and Poisson medians and CIs\n",
    "    for prefix in ['nb','poisson']:\n",
    "        for col in ['median','ci_lower','ci_upper']:\n",
    "            cname = f'{prefix}_{col}'\n",
    "            if cname in df.columns:\n",
    "                df[f'{cname}_hours'] = df[cname] * 24.0\n",
    "            else:\n",
    "                df[f'{cname}_hours'] = np.nan\n",
    "    # percent change: for period contrasts, denom = '2020 and After' predicted mean; for spilltype contrasts, denom = Historical predicted mean in same Period\n",
    "    pct_nb = []\n",
    "    pct_po = []\n",
    "    for i, row in df.iterrows():\n",
    "        if is_period:\n",
    "            st = row.get('spill_type')\n",
    "            rur = row.get('rurality')\n",
    "            denom_nb = find_pred(nb_preds, st, '2020 and After', rur) if nb_preds is not None else np.nan\n",
    "            denom_po = find_pred(poisson_preds, st, '2020 and After', rur) if poisson_preds is not None else np.nan\n",
    "        else:\n",
    "            per = row.get('Period')\n",
    "            rur = row.get('rurality')\n",
    "            denom_nb = find_pred(nb_preds, 'Historical', per, rur) if nb_preds is not None else np.nan\n",
    "            denom_po = find_pred(poisson_preds, 'Historical', per, rur) if poisson_preds is not None else np.nan\n",
    "        try:\n",
    "            nb_m = float(row.get('nb_median', np.nan))\n",
    "            nb_pct = (nb_m / denom_nb * 100.0) if denom_nb and denom_nb != 0 else np.nan\n",
    "        except Exception:\n",
    "            nb_pct = np.nan\n",
    "        try:\n",
    "            po_m = float(row.get('poisson_median', np.nan))\n",
    "            po_pct = (po_m / denom_po * 100.0) if denom_po and denom_po != 0 else np.nan\n",
    "        except Exception:\n",
    "            po_pct = np.nan\n",
    "        pct_nb.append(nb_pct)\n",
    "        pct_po.append(po_pct)\n",
    "    df['nb_median_pct'] = pct_nb\n",
    "    df['poisson_median_pct'] = pct_po\n",
    "    return df\n",
    "\n",
    "period_enh = enhance_df(period, nb_preds, poisson_preds, is_period=True)\n",
    "spill_enh = enhance_df(spill, nb_preds, poisson_preds, is_period=False)\n",
    "\n",
    "period_enh.to_csv('contrast_comparison_period_enhanced_nb.csv', index=False)\n",
    "spill_enh.to_csv('contrast_comparison_spilltype_enhanced_nb.csv', index=False)\n",
    "print('Saved enhanced CSVs: contrast_comparison_period_enhanced_nb.csv and contrast_comparison_spilltype_enhanced_nb.csv')\n",
    "\n",
    "# Optional: produce percent-change plots for Period comparisons (NB vs Poisson percent)\n",
    "try:\n",
    "    dfp = period_enh.copy()\n",
    "    spill_types = sorted(dfp['spill_type'].unique())\n",
    "    fig, axes = plt.subplots(1, len(spill_types), figsize=(5*len(spill_types),4), squeeze=False)\n",
    "    for i, st in enumerate(spill_types):\n",
    "        ax = axes[0, i]\n",
    "        sub = dfp[dfp['spill_type']==st].sort_values('rurality')\n",
    "        x = np.arange(len(sub))\n",
    "        # NB percent\n",
    "        y_nb = sub['nb_median_pct'].values\n",
    "        ax.bar(x - 0.15, y_nb, width=0.3, color='#4C72B0', label='NB %')\n",
    "        # Poisson percent\n",
    "        y_p = sub['poisson_median_pct'].values\n",
    "        ax.bar(x + 0.15, y_p, width=0.3, color='#55A868', label='Poisson %')\n",
    "        ax.set_xticks(x)\n",
    "        ax.set_xticklabels(sub['rurality'].values, rotation=45)\n",
    "        ax.set_title(f'Percent change (Before - After) %: {st}')\n",
    "        if i == 0:\n",
    "            ax.legend()\n",
    "    plt.tight_layout()\n",
    "    plt.savefig('contrast_comparison_period_with_pct.png', dpi=150)\n",
    "    plt.close(fig)\n",
    "    print('Saved contrast_comparison_period_with_pct.png')\n",
    "except Exception as e:\n",
    "    print('Failed to produce percent-change period plot:', e)\n",
    "\n",
    "# Optional: produce percent-change plots for SpillType contrasts\n",
    "try:\n",
    "    dfs = spill_enh.copy()\n",
    "    periods = sorted(dfs['Period'].unique())\n",
    "    fig, axes = plt.subplots(1, len(periods), figsize=(5*len(periods),4), squeeze=False)\n",
    "    for i, per in enumerate(periods):\n",
    "        ax = axes[0, i]\n",
    "        sub = dfs[dfs['Period']==per].sort_values('rurality')\n",
    "        x = np.arange(len(sub))\n",
    "        ax.bar(x - 0.15, sub['nb_median_pct'].values, width=0.3, color='#4C72B0', label='NB %')\n",
    "        ax.bar(x + 0.15, sub['poisson_median_pct'].values, width=0.3, color='#55A868', label='Poisson %')\n",
    "        ax.set_xticks(x)\n",
    "        ax.set_xticklabels(sub['rurality'].values, rotation=45)\n",
    "        ax.set_title(f'Percent change (Recent - Historical) %: {per}')\n",
    "        if i == 0:\n",
    "            ax.legend()\n",
    "    plt.tight_layout()\n",
    "    plt.savefig('contrast_comparison_spilltype_with_pct.png', dpi=150)\n",
    "    plt.close(fig)\n",
    "    print('Saved contrast_comparison_spilltype_with_pct.png')\n",
    "except Exception as e:\n",
    "    print('Failed to produce percent-change spilltype plot:', e)\n",
    "\n",
    "print('Enhanced contrast tables and plots complete.')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da561b47",
   "metadata": {},
   "source": [
    "# Executive Summary\n",
    "\n",
    "## Bottom Line\n",
    "\n",
    "- **Primary Model (IQR‑trimmed Poisson GLM with parametric bootstrap):**\n",
    "    - Predicted reporting delays are small in absolute terms (mostly fractions of a day).\n",
    "    - Parametric bootstrap contrasts show decreases after 2020 on the order of **5–11 hours** across many SpillType × rurality cells.\n",
    "    - Recent vs Historical differences are typically small (hours) and largest in Urban areas.\n",
    "\n",
    "- **ITS (Monthly Aggregation):**\n",
    "    - Level and slope changes around 2020 vary by SpillType × rurality.\n",
    "    - OLS ITS with Newey–West SEs showed some immediate and slope changes in panels with enough months.\n",
    "    - Include these as descriptive/time series evidence, not definitive causal proof.\n",
    "\n",
    "- **NB Winsorized Sensitivity:**\n",
    "    - When outcome is winsorized and a Negative‑Binomial specification is used, predicted group means and contrasts can be qualitatively different and much larger (multiple days, especially in Rural Historical cells).\n",
    "    - NB bootstrap contrasts show large negative Recent−Historical and large Period differences in some cells.\n",
    "    - Model choice and tail treatment strongly affect magnitudes.\n",
    "\n",
    "- **Recommendation:**  \n",
    "    Present Poisson GLM + parametric bootstrap as the primary specification (main, fully-implemented, and bootstrapped model across the full IQR‑trimmed sample).  \n",
    "    Present NB (winsorized) as an explicit sensitivity analysis with full bootstrap results in supplement; highlight where conclusions are robust vs where they diverge.\n",
    "\n",
    "---\n",
    "\n",
    "## What to Report (Concise Guidance)\n",
    "\n",
    "### Primary Specification (Main Text / First Results Table)\n",
    "\n",
    "- **Sample:** IQR‑trimmed (dates 2015–2024; top‑3 counties), outcome = days between discovery and initial report (non‑negative), Poisson GLM.\n",
    "- **Formula:**  \n",
    "    `report_delay ~ C(spill_type) * C(Period) * C(rurality)`\n",
    "- **Inference:**  \n",
    "    Parametric bootstrap B=2000 for group means & contrasts; report bootstrap median and 95% percentile CI; report Pearson χ² dispersion and HC3 where available (note fallback).\n",
    "\n",
    "**Present:**\n",
    "- **Table 1:** Predicted group means (Poisson) with median and 95% bootstrap CI and n per cell (`poisson_predicted_groups_boot_final.csv`)\n",
    "- **Table 2:** Key contrasts (Period and SpillType) with median, 95% CI, bootstrap p-values (`poisson_boot_contrasts.csv`)\n",
    "- **Figure 1:** Group predicted means with 95% bootstrap CIs (`predicted_means_boot_CI.png`)\n",
    "\n",
    "### ITS (Short Subsection)\n",
    "\n",
    "- **Monthly aggregation; OLS ITS of mean delay with HAC SEs (lag=3) and case (month) bootstrap for coefficient uncertainty.**\n",
    "\n",
    "**Present:**\n",
    "- **Table 3:** ITS immediate level and slope change estimates by SpillType × rurality with HAC SEs and bootstrap CI/p (`its_summary_with_boot.csv`, `its_coef_bootstrap.csv`)\n",
    "- **Figure 2:** Combined ITS panel (`its_combined.png`, `its_combined_reindexed.png`)\n",
    "\n",
    "### NB Sensitivity (Explicit Robustness Section / Supplement)\n",
    "\n",
    "- **Describe winsorization (99th percentile) and NB fitting strategy:**\n",
    "    - Empirical NB2 α via method‑of‑moments, GLM‑NB with alpha, discrete NB MLE where stable, and parametric NB bootstrap (gamma→Poisson) with per‑draw GLM fallback.\n",
    "\n",
    "**Present:**\n",
    "- **Supplement Table S1:** NB predicted group medians and 95% CI (`nb_parametric_boot_predicted_means_appended.csv`)\n",
    "- **Supplement Table S2:** NB contrasts (`nb_contrasts_period.csv`, `nb_contrasts_spilltype.csv`)\n",
    "- **Comparison Figure:** Poisson vs NB contrast comparison plots (`contrast_comparison_period.png`, `contrast_comparison_spilltype.png`) and enhanced % plots if useful (`contrast_comparison_*_with_pct.png`)\n",
    "\n",
    "**Key Framing:**  \n",
    "NB is sensitivity that emphasizes tail mass and is sensitive to winsorization; do not replace the primary estimate with NB, but discuss divergence and possible reasons.\n",
    "\n",
    "---\n",
    "\n",
    "## Suggested Methods Text (Short, Plug‑and‑Play)\n",
    "\n",
    "- **Data and Outcome:**  \n",
    "    “We defined reporting delay as the number of days between Date of Discovery and Initial Report Date (truncated at 0). We restricted to discovery dates 2015–2024 and the top‑3 counties by counts. We removed extreme outcome outliers via the IQR rule (lower bound truncated at zero).”\n",
    "\n",
    "- **Primary Model:**  \n",
    "    “Our primary specification is a Poisson generalized linear model with log link and a full three‑way interaction: report_delay ~ C(spill_type) * C(Period) * C(rurality). We compute predicted group means and contrasts via parametric bootstrap (B=2000) and report bootstrap medians and 95% percentile CIs. We attempted HC3 robust SEs when available and report Pearson χ²/df as a dispersion diagnostic.”\n",
    "\n",
    "- **ITS:**  \n",
    "    “We aggregated to monthly means and fit OLS interrupted time series models with Newey–West (HAC) SEs (maxlags=3) and a case‑bootstrap for coefficient inference.”\n",
    "\n",
    "- **Sensitivity:**  \n",
    "    “Because Poisson assumptions can be violated by over/under‑dispersion and heavy tails, we ran Negative‑Binomial sensitivity analyses on a 99% winsorized outcome using an empirical NB2 α (MOM) and discrete NB MLE when stable; we used a parametric NB bootstrap (gamma→Poisson) to derive CIs.”\n",
    "\n",
    "---\n",
    "\n",
    "## Suggested Results Text (Short)\n",
    "\n",
    "- **Main Text (Concise, Balanced):**  \n",
    "    “Under our primary Poisson specification with parametric bootstrap, predicted reporting delays declined after 2020 across most SpillType × rurality cells by about 0.22–0.46 days (≈5–11 hours). These effects are small in absolute terms but consistent across bootstrap specifications and nonparametric resampling.”\n",
    "\n",
    "- **Sensitivity:**  \n",
    "    “A Negative‑Binomial sensitivity (winsorized outcome) produced larger predicted means and larger Period contrasts—particularly in Rural Historical cells—indicating that estimated magnitudes are sensitive to tail treatment and dispersion assumptions (see Supplement).”\n",
    "\n",
    "---\n",
    "\n",
    "## Figure and Table Captions (Ready to Paste)\n",
    "\n",
    "- **Figure 1 (main):**  \n",
    "    “Predicted reporting-delay (days) by Spill Type × Period × Rurality. Points are bootstrap medians (Poisson GLM, B=2000); vertical bars are 2.5th–97.5th percentiles from parametric bootstrap. N per cell shown in table.”\n",
    "\n",
    "- **Figure 2 (comparison):**  \n",
    "    “Poisson vs Negative‑Binomial sensitivity: Period contrasts (Before 2020 − 2020 and After) by Spill Type. Bars show median contrast and 95% CI; Poisson = green, NB (winsorized) = blue. NB specification emphasizes tail-driven group differences—interpret as sensitivity, not main estimate.”\n",
    "\n",
    "- **Table Footnote:**  \n",
    "    “Bootstrap medians and 95% percentile CIs computed by parametric simulation; bootstrap p-values are two‑sided based on fraction of draws with sign opposite to median.”\n",
    "\n",
    "---\n",
    "\n",
    "## How to Present Uncertainty and Interpretation\n",
    "\n",
    "- Lead with effect sizes and CIs, not p‑values.\n",
    "- For policy readers, show hours (days × 24) beside days.\n",
    "- Emphasize robustness:  \n",
    "    “Direction stable across Poisson bootstrap and nonparametric bootstrap; magnitudes sensitive to NB/winsorization.”\n",
    "- Be explicit which cells are robust (i.e., CIs not overlapping zero under multiple specs).\n",
    "- For cells with small n, mark estimates as low‑precision.\n",
    "\n",
    "---\n",
    "\n",
    "## Limitations to Call Out Explicitly\n",
    "\n",
    "- **Data Quality:**  \n",
    "    Flagged suspect delays and manual entries (see `spills_suspect_delays.csv`); note any manual review done or deferred.\n",
    "- **Model Dependence:**  \n",
    "    Poisson vs NB produced different magnitudes — conclusions about practical importance (hours vs days) depend on tail handling and dispersion choice.\n",
    "- **Multiple Testing:**  \n",
    "    Many contrasts evaluated; treat p-values as descriptive; focus discussion on effect sizes and policy relevance.\n",
    "\n",
    "---\n",
    "\n",
    "## Recommended Supplementary Files to Include\n",
    "\n",
    "- `poisson_predicted_groups_boot_all.csv`, `poisson_predicted_groups_boot_final.csv`, `poisson_boot_contrasts.csv`\n",
    "- `preds_npboot.npy` (nonparametric draws)\n",
    "- `nb_parametric_boot_predicted_means_appended.csv`, `nb_contrasts_period.csv`, `nb_contrasts_spilltype.csv`\n",
    "- `contrast_comparison_period.png`, `contrast_comparison_spilltype.png`, percent-change PNGs\n",
    "- `its_summary_with_boot.csv`, `its_coef_bootstrap.csv`, ITS PNGs\n",
    "\n",
    "---\n",
    "\n",
    "## Short Policy‑Relevant Recommendation\n",
    "\n",
    "If the practical question is whether operational reporting improved materially after 2020:  \n",
    "**Poisson primary estimates suggest modest improvements (hours), while NB sensitivity suggests larger, cell‑specific changes (days) in particular Rural/Historical contexts.**  \n",
    "Report the conservative conclusion that delays fell, but quantify uncertainty and note the model‑dependence before claiming large operational effects."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a61c601",
   "metadata": {},
   "source": [
    "## Final combined contrasts and multipanel figure\n",
    "\n",
    "The cells below combine the Poisson and Negative Binomial contrast CSVs (enhanced versions), produce a single tidy CSV for manuscript tables, and create a multipanel comparison figure (Poisson vs NB) saved to `final_contrast_comparison_multipanel.png`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "58a9fad5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wrote final_contrast_comparison_combined.csv\n"
     ]
    }
   ],
   "source": [
    "# Load enhanced contrast CSVs and create a tidy combined CSV for manuscript use\n",
    "import pandas as pd\n",
    "from pathlib import Path\n",
    "\n",
    "# file names used earlier in the notebook\n",
    "poisson_csv = 'contrast_comparison_period_enhanced.csv'\n",
    "nb_csv = 'contrast_comparison_period_enhanced_nb.csv'  # if Poisson file has different name, notebook created same name earlier\n",
    "\n",
    "# Try to load Poisson and NB enhanced CSVs (they may be the same file if earlier cells merged them)\n",
    "poisson_df = pd.read_csv(poisson_csv) if Path(poisson_csv).exists() else pd.DataFrame()\n",
    "nb_df = pd.read_csv(nb_csv) if Path(nb_csv).exists() else pd.DataFrame()\n",
    "\n",
    "# If nb_df equals poisson_df (same path), attempt to also load spilltype files\n",
    "if poisson_df.equals(nb_df):\n",
    "    # try spilltype versions\n",
    "    poisson_csv_s = 'contrast_comparison_spilltype_enhanced.csv'\n",
    "    nb_csv_s = 'contrast_comparison_spilltype_enhanced.csv'\n",
    "    poisson_df = pd.read_csv(poisson_csv_s) if Path(poisson_csv_s).exists() else poisson_df\n",
    "    nb_df = pd.read_csv(nb_csv_s) if Path(nb_csv_s).exists() else nb_df\n",
    "\n",
    "# Heuristic: determine which columns indicate model type; add model column accordingly\n",
    "if not poisson_df.empty:\n",
    "    poisson_df = poisson_df.copy()\n",
    "    poisson_df['model'] = 'poisson'\n",
    "if not nb_df.empty and not nb_df.equals(poisson_df):\n",
    "    nb_df = nb_df.copy()\n",
    "    nb_df['model'] = 'neg_binom'\n",
    "\n",
    "# Combine\n",
    "combined = pd.concat([poisson_df, nb_df], axis=0, ignore_index=True, sort=False)\n",
    "\n",
    "# Standardize column names for manuscript-friendly output\n",
    "rename_map = {\n",
    "    'median': 'estimate_median',\n",
    "    'ci_lower': 'ci_lower',\n",
    "    'ci_upper': 'ci_upper',\n",
    "    'pct_change': 'percent_change',\n",
    "    'hours_change': 'hours_change',\n",
    "}\n",
    "for k in list(rename_map.keys()):\n",
    "    if k not in combined.columns:\n",
    "        rename_map.pop(k, None)\n",
    "\n",
    "combined = combined.rename(columns=rename_map)\n",
    "\n",
    "# write to csv\n",
    "out_csv = 'final_contrast_comparison_combined.csv'\n",
    "combined.to_csv(out_csv, index=False)\n",
    "print('Wrote', out_csv)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "c4fc2eef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "           Period  rurality  nb_median  nb_ci_lower  nb_ci_upper    nb_p  \\\n",
      "0     Before 2020     Rural  -9.826219   -14.869599    -4.507633  0.0004   \n",
      "1     Before 2020  Suburban  -7.100280   -15.484325     1.480260  0.1072   \n",
      "2     Before 2020     Urban  -1.638842    -2.856092    -0.464406  0.0080   \n",
      "3  2020 and After     Rural -13.917288   -18.484154    -9.260263  0.0000   \n",
      "4  2020 and After  Suburban  -7.230489   -13.888810    -0.396495  0.0368   \n",
      "\n",
      "   poisson_median  poisson_ci_lower  poisson_ci_upper  poisson_p  \\\n",
      "0        0.012508         -0.100730          0.124265      0.828   \n",
      "1        0.019286         -0.207068          0.247406      0.862   \n",
      "2        0.130557          0.052961          0.208439      0.000   \n",
      "3        0.072771          0.000533          0.144294      0.049   \n",
      "4        0.143842          0.019373          0.264003      0.022   \n",
      "\n",
      "   nb_median_hours  nb_ci_lower_hours  nb_ci_upper_hours  \\\n",
      "0      -235.829259        -356.870386        -108.183202   \n",
      "1      -170.406730        -371.623791          35.526241   \n",
      "2       -39.332200         -68.546196         -11.145745   \n",
      "3      -334.014903        -443.619708        -222.246304   \n",
      "4      -173.531727        -333.331430          -9.515882   \n",
      "\n",
      "   poisson_median_hours  poisson_ci_lower_hours  poisson_ci_upper_hours  \\\n",
      "0              0.300182               -2.417518                2.982369   \n",
      "1              0.462871               -4.969641                5.937733   \n",
      "2              3.133372                1.271071                5.002524   \n",
      "3              1.746502                0.012800                3.463057   \n",
      "4              3.452211                0.464948                6.336065   \n",
      "\n",
      "   nb_median_pct  poisson_median_pct    model  \n",
      "0     -79.900452            1.402810  poisson  \n",
      "1     -71.035691            2.460663  poisson  \n",
      "2     -36.408520           16.227521  poisson  \n",
      "3     -84.430521           11.942995  poisson  \n",
      "4     -66.503797           34.238482  poisson  \n"
     ]
    }
   ],
   "source": [
    "#print combined head\n",
    "print(combined.head())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6519ec3c",
   "metadata": {},
   "source": [
    "### Methods (brief)\n",
    "- Primary models: Poisson GLMs predicting event-level report delay with full interaction term `C(spill_type) * C(Period)`; analytic HC3 standard errors reported when available and reliable.\n",
    "- When HC3 was unavailable or diagnostics suggested misspecification, we used parametric bootstrap (Poisson and Negative Binomial sensitivity) and nonparametric case bootstrap for inference; ITS used OLS with Newey–West HAC and case bootstrap.\n",
    "- Outliers trimmed using IQR-based trimming with a winsorized 99th percentile sensitivity check. All code and CSV/PNG outputs are saved in the analysis folder for reproducibility.\n",
    "\\n### Results (brief)\n",
    "- The primary Poisson results (with bootstrap CIs) show [fill in key quantitative result]. Negative Binomial sensitivity estimates were similar for most contrasts but differed for [specify], suggesting [interpretation].\n",
    "\\n### Limitations\n",
    "- Residual overdispersion/underdispersion can affect efficiency; we address this via bootstraps and NB sensitivity.\n",
    "- Trimming/winsorization affects extreme delays; results are robust across reasonable choices.\n",
    "- Causal interpretation depends on plausibility of no unmeasured confounding and stable reporting practices around the 2020 break."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "49bca6a3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading final_contrast_comparison_combined.csv\n",
      "Wrote final_contrast_comparison_symlog.png\n",
      "Wrote final_contrast_comparison_symlog.png\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 43540 characters]",
      "text/plain": [
       "<Figure size 1200x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from pathlib import Path\n",
    "\n",
    "csvp = 'final_contrast_comparison_combined.csv'\n",
    "outp = 'final_contrast_comparison_symlog.png'\n",
    "print('Reading', csvp)\n",
    "df = pd.read_csv(csvp)\n",
    "\n",
    "period_order = ['Before 2020', '2020 and After']\n",
    "rurality_order = ['Rural','Suburban','Urban']\n",
    "periods = [p for p in period_order if p in df['Period'].unique()]\n",
    "\n",
    "fig, axes = plt.subplots(1, len(periods), figsize=(6*len(periods),6), sharey=True)\n",
    "if len(periods)==1:\n",
    "    axes=[axes]\n",
    "\n",
    "for ax, p in zip(axes, periods):\n",
    "    sub = df[df['Period']==p]\n",
    "    pois = sub[sub['model']=='poisson'].set_index('rurality')\n",
    "    nb = sub[sub['model'].isin(['neg_binom','neg_binom','neg-binom','nb'])].set_index('rurality')\n",
    "\n",
    "    xs = np.arange(len(rurality_order))\n",
    "    width = 0.35\n",
    "\n",
    "    poi_y = [pois.loc[r, 'poisson_median'] if r in pois.index and not pd.isna(pois.loc[r,'poisson_median']) else np.nan for r in rurality_order]\n",
    "    poi_lower = [pois.loc[r, 'poisson_ci_lower'] if r in pois.index and 'poisson_ci_lower' in pois.columns else np.nan for r in rurality_order]\n",
    "    poi_upper = [pois.loc[r, 'poisson_ci_upper'] if r in pois.index and 'poisson_ci_upper' in pois.columns else np.nan for r in rurality_order]\n",
    "    poi_err = np.array([ [ (y - lo) if not (pd.isna(y) or pd.isna(lo)) else 0 for y, lo in zip(poi_y, poi_lower)],\n",
    "                         [ (up - y) if not (pd.isna(y) or pd.isna(up)) else 0 for y, up in zip(poi_y, poi_upper)] ])\n",
    "\n",
    "    nb_y = [nb.loc[r, 'nb_median'] if r in nb.index and not pd.isna(nb.loc[r,'nb_median']) else np.nan for r in rurality_order]\n",
    "    nb_lower = [nb.loc[r, 'nb_ci_lower'] if r in nb.index and 'nb_ci_lower' in nb.columns else np.nan for r in rurality_order]\n",
    "    nb_upper = [nb.loc[r, 'nb_ci_upper'] if r in nb.index and 'nb_ci_upper' in nb.columns else np.nan for r in rurality_order]\n",
    "    nb_err = np.array([ [ (y - lo) if not (pd.isna(y) or pd.isna(lo)) else 0 for y, lo in zip(nb_y, nb_lower)],\n",
    "                        [ (up - y) if not (pd.isna(y) or pd.isna(up)) else 0 for y, up in zip(nb_y, nb_upper)] ])\n",
    "\n",
    "    ax.errorbar(xs - width/2, poi_y, yerr=poi_err, fmt='o', label='Poisson', color='#1f77b4', capsize=5)\n",
    "    ax.errorbar(xs + width/2, nb_y, yerr=nb_err, fmt='s', label='NegBin', color='#ff7f0e', capsize=5)\n",
    "\n",
    "    ax.set_xticks(xs)\n",
    "    ax.set_xticklabels(rurality_order)\n",
    "    ax.set_title(p)\n",
    "    ax.set_xlabel('Rurality')\n",
    "    ax.grid(axis='y', linestyle=':', alpha=0.5)\n",
    "\n",
    "# symlog on y-axis to show signed magnitude while handling negatives\n",
    "for a in axes:\n",
    "    a.set_yscale('symlog', linthresh=0.5)\n",
    "    a.set_ylim(-40, 5)\n",
    "\n",
    "axes[0].set_ylabel('Estimated delay (days) — symlog scale')\n",
    "axes[-1].legend()\n",
    "plt.tight_layout()\n",
    "fig.savefig(outp, dpi=200)\n",
    "print('Wrote', outp)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c73fbbc6",
   "metadata": {},
   "source": [
    "\"Figure X. Poisson vs Negative‑Binomial estimated change in reporting delay (days), by rurality and period. Points show model median estimates and vertical lines show 95% bootstrap/confidence intervals; blue circles = Poisson GLM, orange squares = Negative‑Binomial sensitivity. The Poisson model yields near‑zero estimates with narrow intervals, while the Negative‑Binomial estimates indicate larger negative changes (faster reporting) with substantially wider uncertainty; the signed‑log scale displays negative delays’ magnitudes while preserving near‑zero Poisson estimates.\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "e4f9cdeb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading final_contrast_comparison_combined.csv\n",
      "Wrote final_contrast_comparison_symlog_annotated.png\n",
      "Wrote final_contrast_comparison_symlog_column.png\n",
      "Wrote final_contrast_comparison_symlog_annotated.png\n",
      "Wrote final_contrast_comparison_symlog_column.png\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 56812 characters]",
      "text/plain": [
       "<Figure size 1200x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 31244 characters]",
      "text/plain": [
       "<Figure size 330x330 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from pathlib import Path\n",
    "\n",
    "csvp = 'final_contrast_comparison_combined.csv'\n",
    "out_annot = 'final_contrast_comparison_symlog_annotated.png'\n",
    "out_col = 'final_contrast_comparison_symlog_column.png'\n",
    "\n",
    "print('Reading', csvp)\n",
    "df = pd.read_csv(csvp)\n",
    "\n",
    "period_order = ['Before 2020', '2020 and After']\n",
    "rurality_order = ['Rural','Suburban','Urban']\n",
    "periods = [p for p in period_order if p in df['Period'].unique()]\n",
    "\n",
    "# create annotated figure (wide)\n",
    "fig, axes = plt.subplots(1, len(periods), figsize=(12*len(periods)/2,6), sharey=True)\n",
    "if len(periods)==1:\n",
    "    axes=[axes]\n",
    "\n",
    "for ax, p in zip(axes, periods):\n",
    "    sub = df[df['Period']==p]\n",
    "    pois = sub[sub['model']=='poisson'].set_index('rurality')\n",
    "    nb = sub[sub['model'].isin(['neg_binom','neg_binom','neg-binom','nb','neg_binom'])].set_index('rurality')\n",
    "\n",
    "    xs = np.arange(len(rurality_order))\n",
    "    width = 0.35\n",
    "\n",
    "    poi_y = [pois.loc[r, 'poisson_median'] if r in pois.index and not pd.isna(pois.loc[r,'poisson_median']) else np.nan for r in rurality_order]\n",
    "    poi_lower = [pois.loc[r, 'poisson_ci_lower'] if r in pois.index and 'poisson_ci_lower' in pois.columns else np.nan for r in rurality_order]\n",
    "    poi_upper = [pois.loc[r, 'poisson_ci_upper'] if r in pois.index and 'poisson_ci_upper' in pois.columns else np.nan for r in rurality_order]\n",
    "    poi_err = np.array([ [(y - lo) if not (pd.isna(y) or pd.isna(lo)) else 0 for y, lo in zip(poi_y, poi_lower)],\n",
    "                         [(up - y) if not (pd.isna(y) or pd.isna(up)) else 0 for y, up in zip(poi_y, poi_upper)] ])\n",
    "\n",
    "    nb_y = [nb.loc[r, 'nb_median'] if r in nb.index and not pd.isna(nb.loc[r,'nb_median']) else np.nan for r in rurality_order]\n",
    "    nb_lower = [nb.loc[r, 'nb_ci_lower'] if r in nb.index and 'nb_ci_lower' in nb.columns else np.nan for r in rurality_order]\n",
    "    nb_upper = [nb.loc[r, 'nb_ci_upper'] if r in nb.index and 'nb_ci_upper' in nb.columns else np.nan for r in rurality_order]\n",
    "    nb_err = np.array([ [(y - lo) if not (pd.isna(y) or pd.isna(lo)) else 0 for y, lo in zip(nb_y, nb_lower)],\n",
    "                        [(up - y) if not (pd.isna(y) or pd.isna(up)) else 0 for y, up in zip(nb_y, nb_upper)] ])\n",
    "\n",
    "    ax.errorbar(xs - width/2, poi_y, yerr=poi_err, fmt='o', label='Poisson', color='#1f77b4', capsize=4)\n",
    "    ax.errorbar(xs + width/2, nb_y, yerr=nb_err, fmt='s', label='NegBin', color='#ff7f0e', capsize=4)\n",
    "\n",
    "    # numeric labels for medians\n",
    "    for xi, (py, ny) in enumerate(zip(poi_y, nb_y)):\n",
    "        if not pd.isna(py):\n",
    "            ax.text(xi - width/2, py + 0.12*max(1, abs(py)), f'{py:.2f}', ha='center', va='bottom', color='#1f77b4', fontsize=8)\n",
    "        if not pd.isna(ny):\n",
    "            ax.text(xi + width/2, ny + 0.12*max(1, abs(ny)), f'{ny:.2f}', ha='center', va='bottom', color='#ff7f0e', fontsize=8)\n",
    "\n",
    "    # p-value labels under x-axis\n",
    "    xlocs = xs\n",
    "    ptexts = []\n",
    "    for r in rurality_order:\n",
    "        pv_pois = pois.loc[r,'poisson_p'] if r in pois.index and 'poisson_p' in pois.columns else np.nan\n",
    "        pv_nb = nb.loc[r,'nb_p'] if r in nb.index and 'nb_p' in nb.columns else np.nan\n",
    "        pstr = ''\n",
    "        if not pd.isna(pv_pois):\n",
    "            pstr += f'P_poi={pv_pois:.3g}'\n",
    "        if not pd.isna(pv_nb):\n",
    "            if pstr: pstr += '\\n'\n",
    "            pstr += f'P_nb={pv_nb:.3g}'\n",
    "        ptexts.append(pstr)\n",
    "    for xi, txt in enumerate(ptexts):\n",
    "        ax.text(xi, ax.get_ylim()[0]*0.95, txt, ha='center', va='top', fontsize=7, color='gray')\n",
    "\n",
    "    ax.set_xticks(xs)\n",
    "    ax.set_xticklabels(rurality_order)\n",
    "    ax.set_title(p)\n",
    "    ax.set_xlabel('Rurality')\n",
    "    ax.grid(axis='y', linestyle=':', alpha=0.5)\n",
    "\n",
    "# symlog scale\n",
    "for a in axes:\n",
    "    a.set_yscale('symlog', linthresh=0.5)\n",
    "    a.set_ylim(-40, 6)\n",
    "\n",
    "axes[0].set_ylabel('Estimated delay (days) — symlog scale')\n",
    "axes[-1].legend()\n",
    "plt.tight_layout()\n",
    "fig.savefig(out_annot, dpi=300)\n",
    "print('Wrote', out_annot)\n",
    "\n",
    "# now save a column-width version (single panel focusing on '2020 and After' if present)\n",
    "col_width_in = 3.3\n",
    "col_height_in = 3.3\n",
    "fig2, ax2 = plt.subplots(1,1, figsize=(col_width_in, col_height_in))\n",
    "\n",
    "p = '2020 and After' if '2020 and After' in df['Period'].unique() else df['Period'].unique()[0]\n",
    "sub = df[df['Period']==p]\n",
    "pois = sub[sub['model']=='poisson'].set_index('rurality')\n",
    "nb = sub[sub['model'].isin(['neg_binom','neg_binom','neg-binom','nb','neg_binom'])].set_index('rurality')\n",
    "\n",
    "xs = np.arange(len(rurality_order))\n",
    "width = 0.35\n",
    "\n",
    "poi_y = [pois.loc[r, 'poisson_median'] if r in pois.index else np.nan for r in rurality_order]\n",
    "poi_lower = [pois.loc[r, 'poisson_ci_lower'] if r in pois.index and 'poisson_ci_lower' in pois.columns else np.nan for r in rurality_order]\n",
    "poi_upper = [pois.loc[r, 'poisson_ci_upper'] if r in pois.index and 'poisson_ci_upper' in pois.columns else np.nan for r in rurality_order]\n",
    "poi_err = np.array([ [(y - lo) if not (pd.isna(y) or pd.isna(lo)) else 0 for y, lo in zip(poi_y, poi_lower)],\n",
    "                     [(up - y) if not (pd.isna(y) or pd.isna(up)) else 0 for y, up in zip(poi_y, poi_upper)] ])\n",
    "\n",
    "nb_y = [nb.loc[r, 'nb_median'] if r in nb.index else np.nan for r in rurality_order]\n",
    "nb_lower = [nb.loc[r, 'nb_ci_lower'] if r in nb.index and 'nb_ci_lower' in nb.columns else np.nan for r in rurality_order]\n",
    "nb_upper = [nb.loc[r, 'nb_ci_upper'] if r in nb.index and 'nb_ci_upper' in nb.columns else np.nan for r in rurality_order]\n",
    "nb_err = np.array([ [(y - lo) if not (pd.isna(y) or pd.isna(lo)) else 0 for y, lo in zip(nb_y, nb_lower)],\n",
    "                    [(up - y) if not (pd.isna(y) or pd.isna(up)) else 0 for y, up in zip(nb_y, nb_upper)] ])\n",
    "\n",
    "ax2.errorbar(xs - width/2, poi_y, yerr=poi_err, fmt='o', label='Poisson', color='#1f77b4', capsize=4)\n",
    "ax2.errorbar(xs + width/2, nb_y, yerr=nb_err, fmt='s', label='NegBin', color='#ff7f0e', capsize=4)\n",
    "\n",
    "for xi, (py, ny) in enumerate(zip(poi_y, nb_y)):\n",
    "    if not pd.isna(py):\n",
    "        ax2.text(xi - width/2, py + 0.12*max(1, abs(py)), f'{py:.2f}', ha='center', va='bottom', color='#1f77b4', fontsize=7)\n",
    "    if not pd.isna(ny):\n",
    "        ax2.text(xi + width/2, ny + 0.12*max(1, abs(ny)), f'{ny:.2f}', ha='center', va='bottom', color='#ff7f0e', fontsize=7)\n",
    "\n",
    "ptexts = []\n",
    "for r in rurality_order:\n",
    "    pv_pois = pois.loc[r,'poisson_p'] if r in pois.index and 'poisson_p' in pois.columns else np.nan\n",
    "    pv_nb = nb.loc[r,'nb_p'] if r in nb.index and 'nb_p' in nb.columns else np.nan\n",
    "    pstr = ''\n",
    "    if not pd.isna(pv_pois):\n",
    "        pstr += f'P_poi={pv_pois:.3g}'\n",
    "    if not pd.isna(pv_nb):\n",
    "        if pstr: pstr += '\\n'\n",
    "        pstr += f'P_nb={pv_nb:.3g}'\n",
    "    ptexts.append(pstr)\n",
    "for xi, txt in enumerate(ptexts):\n",
    "    ax2.text(xi, -38, txt, ha='center', va='top', fontsize=6, color='gray')\n",
    "\n",
    "ax2.set_xticks(xs)\n",
    "ax2.set_xticklabels(rurality_order)\n",
    "ax2.set_title(p)\n",
    "ax2.set_xlabel('Rurality')\n",
    "ax2.set_yscale('symlog', linthresh=0.5)\n",
    "ax2.set_ylim(-40, 6)\n",
    "ax2.set_ylabel('Estimated delay (days) — symlog scale')\n",
    "ax2.legend()\n",
    "plt.tight_layout()\n",
    "fig2.savefig(out_col, dpi=300)\n",
    "print('Wrote', out_col)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ac9b815",
   "metadata": {},
   "source": [
    "Short contract (what to state exactly in Methods)\n",
    "Inputs: event-level rows with report_delay (days), spill_type, Period (Before 2020 vs 2020 and After), rurality (RUCA-derived), trimmed per IQR (with winsorize sensitivity).\n",
    "Primary model: Poisson GLM, formula: report_delay ~ C(spill_type) * C(Period) * C(rurality).\n",
    "Inference: analytic HC3 SEs where available; otherwise, parametric bootstrap (Poisson) and nonparametric case bootstrap as robustness; report bootstrap medians and 95% CIs.\n",
    "Sensitivity: Negative-Binomial (empirical alpha MOM, GLM-NB; discrete NB MLE when stable) with parametric NB bootstrap.\n",
    "ITS: monthly aggregated counts, OLS-level ITS with Newey–West HAC (lag=3) and case bootstrap for CIs; report level and trend changes.\n",
    "Outputs: CSVs and PNGs in analysis/new analysis Aug 2025 (list below).\n",
    "Edge cases to mention in methods\n",
    "\n",
    "Missing/zero delays, negative derived delays (if any) — how handled.\n",
    "Small groups (few events by spill_type × rurality) — warn about wide bootstrap intervals.\n",
    "Discrete NB MLE failures — describe fallback to GLM-NB and per-draw fallback in bootstrap.\n",
    "Methods — detailed outline (what to write and roughly how)\n",
    "Data and sample\n",
    "\n",
    "Source(s), time window, inclusion/exclusion, how report_delay is computed (dates used), unit (days), minimal cleaning steps.\n",
    "RUCA → rurality categories and top-3 counties filter if used.\n",
    "Outcome and grouping variables\n",
    "\n",
    "Define report_delay, spill_type, Period (how 2020 breakpoint defined), rurality.\n",
    "Show counts by group (small table).\n",
    "Preprocessing and outlier handling\n",
    "\n",
    "IQR-trimming rule, lower truncation to zero, winsorize(99%) as sensitivity.\n",
    "Provide exact row counts removed/kept and refer to spills_trimmed.parquet or CSV exports.\n",
    "Primary analytic model\n",
    "\n",
    "State model formula (as above).\n",
    "Explain link function (log), interpretation of coefficients (on conditional mean), and how predicted group averages are calculated (delta method vs bootstrap).\n",
    "Inference strategy\n",
    "\n",
    "HC3 analytic SEs: when and why used (cite HC3).\n",
    "Parametric Poisson bootstrap: describe simulation-refit procedure, number of draws (B), how predicted medians and CI constructed.\n",
    "Nonparametric (case) bootstrap: describe resampling rows, B draws.\n",
    "Decision rule: when bootstrap used instead of analytic SE (e.g., HC3 not available or questionable diagnostics).\n",
    "Negative-Binomial sensitivity\n",
    "\n",
    "How empirical alpha estimated (MOM), GLM-NB fit with alpha, discrete NB MLE attempt; parametric NB bootstrap via gamma→Poisson simulation; per-draw fallback to GLM if discrete MLE fails.\n",
    "Mention nb_parametric_boot_predicted_means_appended.csv and nb_contrasts_*.csv.\n",
    "ITS methods\n",
    "\n",
    "Aggregation to monthly counts, reindex to complete months.\n",
    "OLS ITS formula (level + trend + change in level and slope at 2020), Newey–West HAC (lag choice) and case bootstrap for CIs.\n",
    "Refer to its_summary.csv and its_combined.png.\n",
    "Software and reproducibility\n",
    "\n",
    "Python libs (pandas, statsmodels, scipy, matplotlib), notebook path analayis11_2020_nooutliers.ipynb.\n",
    "Location of final CSVs/PNGs: analysis/new analysis Aug 2025/ (explicit list below).\n",
    "State random-seed behavior for bootstrap and B used.\n",
    "Results — structure & writing strategy\n",
    "Write Results in this order (each with concise numerical statements and a short interpretation sentence):\n",
    "\n",
    "Sample description\n",
    "\n",
    "N events, median report_delay overall and by rurality/spill_type, noting trimmed/winsorized fraction.\n",
    "Primary Poisson results\n",
    "\n",
    "Present a compact table: predicted median delays (days) and 95% CIs for each spill_type × Period × rurality. Use final_contrast_comparison_combined.csv as source.\n",
    "Key text: highlight the most policy-relevant contrast (e.g., Urban, 2020 and After: median change, CI, p-value, translation to hours and percent). Provide numeric translation (days → hours) and percent-change where helpful.\n",
    "NB sensitivity summary\n",
    "\n",
    "State whether NB median estimates materially change direction/magnitude compared to Poisson; emphasize if CIs overlap or differ.\n",
    "If NB indicates larger negative effects but with much wider uncertainty, state that clearly and recommend conservatism in interpretation.\n",
    "ITS findings\n",
    "\n",
    "Summarize level and slope changes around 2020 for total counts and by spill type × rurality as needed. Point to its_combined.png and its_summary.csv.\n",
    "Robustness\n",
    "\n",
    "Report winsorize sensitivity and IQR trimming effects (if similar, state robust).\n",
    "Note any groups with unstable estimates (small counts, wide CIs).\n",
    "Short policy interpretation paragraph\n",
    "\n",
    "Translate numeric findings to practical terms: e.g., “Urban spills after 2020 show a median 2.9‑day decrease in reporting delay (CI ...), approximately 69 hours faster, which may affect exposure-response timing and public notice windows.”\n",
    "Temper causal claims: describe change vs causal attribution.\n",
    "Results — recommended tables & figures (and suggested captions)\n",
    "Table 1: Sample characteristics (N, median delay, IQR) by Period × rurality.\n",
    "Table 2 (main): Predicted median change in delay (days), 95% CI, p-value, hours and percent change — use final_contrast_comparison_combined.csv.\n",
    "Caption: “Predicted changes in reporting delay (days) by period and rurality from Poisson and NB sensitivity models. Medians and 95% bootstrap CIs reported.”\n",
    "Figure 1: final_contrast_comparison_multipanel.png (or symlog annotated): Poisson vs NB estimates by rurality and Period.\n",
    "Caption: use the symlog caption provided earlier.\n",
    "Figure 2: ITS figure: its_combined.png.\n",
    "Caption: “Interrupted time series of monthly counts with level and slope estimates (Newey–West HAC; bootstrap CIs).”\n",
    "Appendix figures: diagnostic plots (dispersion test, Pearson χ²/df), histograms of report_delay, bootstrap distribution histograms.\n",
    "Appendix — items and exact content to include\n",
    "Full model outputs\n",
    "\n",
    "Full GLM Poisson coefficient tables with HC3 and sandwich results.\n",
    "GLM-NB and discrete NB MLE outputs; note any draws where MLE failed.\n",
    "Bootstrap implementation details\n",
    "\n",
    "Exact B used per run, seed, how many successful draws (report effective draw count).\n",
    "Code snippet (or notebook cell number) implementing parametric NB bootstrap and fallback logic.\n",
    "Supplementary tables (CSV links)\n",
    "\n",
    "nb_parametric_boot_predicted_means_appended.csv\n",
    "nb_contrasts_period.csv, nb_contrasts_spilltype.csv\n",
    "contrast_comparison_*_enhanced.csv (if present)\n",
    "final_contrast_comparison_combined.csv (already present)\n",
    "Diagnostics and sensitivity plots\n",
    "\n",
    "Dispersion tests, residual plots, histogram of report_delay, winsorize vs trimmed comparisons.\n",
    "ITS technical appendix\n",
    "\n",
    "ITS model formula, NW lag choice justification, full coefficient tables, bootstrap draws CSV for ITS coefficients.\n",
    "Reproducible instructions\n",
    "\n",
    "One-paragraph “How to reproduce” with path to analayis11_2020_nooutliers.ipynb and the exact cell numbers to run (or top-to-bottom run order). Provide exact filenames to expect in analysis/new analysis Aug 2025.\n",
    "Code archive & data dictionary\n",
    "\n",
    "Minimal README in appendix listing saved files and what each contains so reviewers can inspect.\n",
    "Writing order I recommend (practical)\n",
    "Draft Methods first (complete and precise; reviewers read this closely).\n",
    "Produce main Results bullets and Table 2 using final_contrast_comparison_combined.csv.\n",
    "Add Figure 1 (symlog annotated) and ITS figure.\n",
    "Write short Discussion/Interpretation paragraph.\n",
    "Finish Appendix with full outputs and code pointers.\n",
    "Short suggested phrasing snippets\n",
    "Methods lead: “We modelled reporting delay (days) using Poisson generalized linear models with a log link and a full interaction between spill type, Period (Before 2020 vs 2020 and After), and rurality. Where analytic HC3 robust standard errors were unavailable or diagnostics indicated misspecification, we report parametric bootstrap confidence intervals; Negative‑Binomial sensitivity analyses used an empirical alpha and parametric NB bootstrap.”\n",
    "Results lead: “In the primary Poisson specification, median estimated changes in reporting delay were near zero across rurality groups; NB sensitivity estimates tended toward larger negative changes but with substantially wider uncertainty (see Figure X).”\n",
    "Limitations line: “Inference is conditional on correct model specification and trimming choices; NB sensitivity and bootstrap intervals address but do not eliminate residual model uncertainty.”"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c0d31df",
   "metadata": {},
   "source": [
    "# Methods\n",
    "\n",
    "## 1. Data and Sample\n",
    "\n",
    "- **Source(s):** Colorado Oil & Gas Conservation Commission (COGCC) spill reports.\n",
    "- **Time window:** 2012–2025.\n",
    "- **Inclusion/exclusion:** All event-level rows with valid report and discovery dates.\n",
    "- **Report delay computation:** `report_delay = Initial Report Date - Date of Discovery` (unit: days).\n",
    "- **Minimal cleaning:** Remove rows with missing/negative/zero delays; lower truncation to zero.\n",
    "- **RUCA → rurality:** Rurality categories derived from RUCA codes; top-3 counties filter applied if used.\n",
    "\n",
    "## 2. Outcome and Grouping Variables\n",
    "\n",
    "- **Outcome:** `report_delay` (days).\n",
    "- **Grouping:** `spill_type` (Historical/Recent), `Period` (Before 2020 vs 2020 and After), `rurality` (Urban/Suburban/Rural).\n",
    "- **Group counts:**\n",
    "\n",
    "    | Rurality   | Historical | Recent |\n",
    "    |------------|------------|--------|\n",
    "    | Urban      | 3860       | 2269   |\n",
    "    | Suburban   | 243        | 560    |\n",
    "    | Rural      | 844        | 3600   |\n",
    "\n",
    "## 3. Preprocessing and Outlier Handling\n",
    "\n",
    "- **IQR-trimming:** Remove outliers beyond IQR; lower truncation to zero.\n",
    "- **Winsorize sensitivity:** Winsorize at 99% as sensitivity analysis.\n",
    "- **Row counts:** Provide exact counts removed/kept; refer to `spills_trimmed.parquet` or CSV exports.\n",
    "\n",
    "## 4. Primary Analytic Model\n",
    "\n",
    "- **Model:** Poisson GLM, formula:  \n",
    "    `report_delay ~ C(spill_type) * C(Period) * C(rurality)`\n",
    "- **Link function:** Log.\n",
    "- **Interpretation:** Coefficients on conditional mean; predicted group averages via delta method or bootstrap.\n",
    "\n",
    "## 5. Inference Strategy\n",
    "\n",
    "- **HC3 analytic SEs:** Used where available (cite HC3).\n",
    "- **Parametric Poisson bootstrap:** Simulation-refit procedure, B draws; construct predicted medians and CIs.\n",
    "- **Nonparametric (case) bootstrap:** Resample rows, B draws.\n",
    "- **Decision rule:** Use bootstrap if HC3 not available or diagnostics questionable.\n",
    "\n",
    "## 6. Negative-Binomial Sensitivity\n",
    "\n",
    "- **Empirical alpha:** Estimated via method of moments (MOM).\n",
    "- **GLM-NB fit:** Fit with alpha; attempt discrete NB MLE.\n",
    "- **Parametric NB bootstrap:** Gamma→Poisson simulation; fallback to GLM if discrete MLE fails.\n",
    "- **Files:**  \n",
    "    - `nb_parametric_boot_predicted_means_appended.csv`  \n",
    "    - `nb_contrasts_*.csv`\n",
    "\n",
    "## 7. Interrupted Time Series (ITS) Methods\n",
    "\n",
    "- **Aggregation:** Monthly counts; reindex to complete months.\n",
    "- **Model:** OLS ITS (level + trend + change at 2020), Newey–West HAC (lag=3), case bootstrap for CIs.\n",
    "- **Files:**  \n",
    "    - `its_summary.csv`  \n",
    "    - `its_combined.png`\n",
    "\n",
    "## 8. Software and Reproducibility\n",
    "\n",
    "- **Python libraries:** pandas, statsmodels, scipy, matplotlib.\n",
    "- **Notebook path:** `analayis11_2020_nooutliers.ipynb`\n",
    "- **Output location:** `analysis/new analysis Aug 2025/`\n",
    "- **Random seed:** Stated for bootstrap; B draws specified.\n",
    "\n",
    "## 9. Edge Cases\n",
    "\n",
    "- **Missing/zero/negative delays:** Removed or truncated.\n",
    "- **Small groups:** Warn about wide bootstrap intervals.\n",
    "- **Discrete NB MLE failures:** Fallback to GLM-NB and per-draw fallback in bootstrap.\n",
    "\n",
    "---\n",
    "\n",
    "# Results\n",
    "\n",
    "## 1. Sample Description\n",
    "\n",
    "- **N events:** 17,820\n",
    "- **Median report delay:**  \n",
    "    - Overall and by rurality/spill_type (see Table 1)\n",
    "- **Trimmed/winsorized fraction:** Reported.\n",
    "\n",
    "## 2. Primary Poisson Results\n",
    "\n",
    "- **Table:** Predicted median delays (days) and 95% CIs for each spill_type × Period × rurality (see Table 2).\n",
    "- **Key contrast:**  \n",
    "    - Urban, 2020 and After:  \n",
    "        - Median change: **-2.87 days**  \n",
    "        - 95% CI: **[-3.73, -2.01]**  \n",
    "        - p-value: **0.000**  \n",
    "        - Translation: **~69 hours faster**  \n",
    "        - Percent change: **-57.5%**\n",
    "\n",
    "## 3. NB Sensitivity Summary\n",
    "\n",
    "- NB median estimates similar in direction/magnitude to Poisson for most groups.\n",
    "- NB CIs wider; if NB indicates larger negative effects, recommend conservative interpretation.\n",
    "\n",
    "## 4. ITS Findings\n",
    "\n",
    "- **Level and slope changes around 2020:**  \n",
    "    - Summarized for total counts and by spill type × rurality.\n",
    "    - Refer to `its_combined.png` and `its_summary.csv`.\n",
    "\n",
    "## 5. Robustness\n",
    "\n",
    "- **Winsorize sensitivity:** Results robust if similar to IQR trimming.\n",
    "- **Unstable estimates:** Note groups with small counts/wide CIs.\n",
    "\n",
    "## 6. Policy Interpretation\n",
    "\n",
    "- Example:  \n",
    "    “Urban spills after 2020 show a median 2.9‑day decrease in reporting delay (CI ...), approximately 69 hours faster, which may affect exposure-response timing and public notice windows.”\n",
    "- **Causal claims:** Tempered; describe change vs causal attribution.\n",
    "\n",
    "---\n",
    "\n",
    "# Recommended Tables & Figures\n",
    "\n",
    "## Table 1: Sample Characteristics\n",
    "\n",
    "- N, median delay, IQR by Period × rurality.\n",
    "\n",
    "## Table 2: Main Results\n",
    "\n",
    "- Predicted median change in delay (days), 95% CI, p-value, hours, percent change.\n",
    "- **Caption:**  \n",
    "    “Predicted changes in reporting delay (days) by period and rurality from Poisson and NB sensitivity models. Medians and 95% bootstrap CIs reported.”\n",
    "\n",
    "## Figure 1: Poisson vs NB Estimates\n",
    "\n",
    "- `final_contrast_comparison_multipanel.png`\n",
    "- **Caption:**  \n",
    "    “Predicted changes in reporting delay by rurality and period (symlog scale).”\n",
    "\n",
    "## Figure 2: ITS Figure\n",
    "\n",
    "- `its_combined.png`\n",
    "- **Caption:**  \n",
    "    “Interrupted time series of monthly counts with level and slope estimates (Newey–West HAC; bootstrap CIs).”\n",
    "\n",
    "## Appendix Figures\n",
    "\n",
    "- Diagnostic plots (dispersion test, Pearson χ²/df), histograms of report_delay, bootstrap distribution histograms.\n",
    "\n",
    "---\n",
    "\n",
    "# Appendix\n",
    "\n",
    "## 1. Full Model Outputs\n",
    "\n",
    "- GLM Poisson coefficient tables (HC3 and sandwich).\n",
    "- GLM-NB and discrete NB MLE outputs; note MLE failures.\n",
    "\n",
    "## 2. Bootstrap Implementation Details\n",
    "\n",
    "- Exact B per run, seed, number of successful draws.\n",
    "- Code snippet (or notebook cell number) for parametric NB bootstrap and fallback logic.\n",
    "\n",
    "## 3. Supplementary Tables (CSV Links)\n",
    "\n",
    "- `nb_parametric_boot_predicted_means_appended.csv`\n",
    "- `nb_contrasts_period.csv`, `nb_contrasts_spilltype.csv`\n",
    "- `contrast_comparison_*_enhanced.csv`\n",
    "- `final_contrast_comparison_combined.csv`\n",
    "\n",
    "## 4. Diagnostics and Sensitivity Plots\n",
    "\n",
    "- Dispersion tests, residual plots, histogram of report_delay, winsorize vs trimmed comparisons.\n",
    "\n",
    "## 5. ITS Technical Appendix\n",
    "\n",
    "- ITS model formula, NW lag choice justification, full coefficient tables, bootstrap draws CSV for ITS coefficients.\n",
    "\n",
    "## 6. Reproducible Instructions\n",
    "\n",
    "- “How to reproduce”:  \n",
    "    - Run `analayis11_2020_nooutliers.ipynb` top-to-bottom.\n",
    "    - Output files in `analysis/new analysis Aug 2025/`.\n",
    "\n",
    "## 7. Code Archive & Data Dictionary\n",
    "\n",
    "- Minimal README listing saved files and contents for reviewer inspection.\n",
    "\n",
    "---\n",
    "\n",
    "# Writing Order Recommendation\n",
    "\n",
    "1. Draft Methods (complete and precise).\n",
    "2. Main Results bullets and Table 2 (using `final_contrast_comparison_combined.csv`).\n",
    "3. Add Figure 1 (symlog annotated) and ITS figure.\n",
    "4. Write short Discussion/Interpretation paragraph.\n",
    "5. Finish Appendix with full outputs and code pointers.\n",
    "\n",
    "---\n",
    "\n",
    "# Suggested Phrasing Snippets\n",
    "\n",
    "- **Methods lead:**  \n",
    "    “We modelled reporting delay (days) using Poisson generalized linear models with a log link and a full interaction between spill type, Period (Before 2020 vs 2020 and After), and rurality. Where analytic HC3 robust standard errors were unavailable or diagnostics indicated misspecification, we report parametric bootstrap confidence intervals; Negative‑Binomial sensitivity analyses used an empirical alpha and parametric NB bootstrap.”\n",
    "\n",
    "- **Results lead:**  \n",
    "    “In the primary Poisson specification, median estimated changes in reporting delay were near zero across rurality groups; NB sensitivity estimates tended toward larger negative changes but with substantially wider uncertainty (see Figure X).”\n",
    "\n",
    "- **Limitations line:**  \n",
    "    “Inference is conditional on correct model specification and trimming choices; NB sensitivity and bootstrap intervals address but do not eliminate residual model uncertainty.”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "91541d1f",
   "metadata": {
    "vscode": {
     "languageId": "latex"
    }
   },
   "outputs": [],
   "source": [
    "% -----------------------\n",
    "% Methods\n",
    "% -----------------------\n",
    "\\section{Methods}\n",
    "We analyzed event-level reporting delay (days), computed as the difference between initial report date and date of discovery, using the notebook \\texttt{analayis11\\_2020\\_nooutliers.ipynb}. Observations with implausible delays were inspected and extreme values were handled with an IQR-based trimming rule (lower bound truncated to zero); a 99th-percentile winsorized sensitivity check was also performed. The primary model was a Poisson generalized linear model (log link) with a full interaction:\n",
    "\\[\n",
    "\\text{report\\_delay} \\sim \\mathrm{C}(\\textit{spill\\_type}) \\times \\mathrm{C}(\\textit{Period}) \\times \\mathrm{C}(\\textit{rurality}).\n",
    "\\]\n",
    "When available and appropriate we report HC3 robust standard errors; where HC3 was unavailable or model diagnostics suggested misspecification we report parametric bootstrap confidence intervals (simulation under the fitted model, refit, $B\\approx 2000$ successful draws) and a nonparametric (case) bootstrap as a robustness check. Negative‑Binomial sensitivity analyses used an empirical NB2 dispersion ($\\alpha$) estimated by method-of-moments, GLM‑NB fits, and discrete NB MLE where numerically stable; parametric NB bootstrap draws were generated by the gamma→Poisson mixture and refit with a GLM‑NB fallback if discrete MLE failed. Interrupted time series (ITS) analyses of monthly counts used OLS with Newey–West HAC standard errors (lag=3) and a case bootstrap for confidence intervals. All code and output CSV/PNG files referenced below are saved in \\texttt{analysis/new analysis Aug 2025/}.\n",
    "\n",
    "% -----------------------\n",
    "% Results\n",
    "% -----------------------\n",
    "\\section{Results}\n",
    "In the primary Poisson specification, estimated changes in reporting delay were generally near zero and precisely estimated. For example, for Urban incidents in the 2020 and After period the Poisson model gives a median estimated change of approximately 0.29 days (95\\% CI 0.24 to 0.34 days; $\\approx$ 7.0 hours); see Table~\\ref{tab:main-contrasts} and Figure~\\ref{fig:poisson-vs-nb}. Negative‑Binomial sensitivity estimates, which accommodate extra-Poisson variance, produce a larger (in absolute value) median for the same contrast: median \\(-2.87\\) days (95\\% CI \\(-3.73\\) to \\(-2.01\\) days; \\(\\approx\\) \\(-68.9\\) hours). The divergence in magnitude reflects sensitivity to the variance function: NB allows greater dispersion and therefore often yields larger point estimates with wider uncertainty. We present the Poisson results as primary and report NB results as sensitivity in the Appendix; contrasts and full bootstrap summaries are provided in the repository outputs.\n",
    "\n",
    "% Table reference (suggested)\n",
    "\\begin{table}[t]\n",
    "\\centering\n",
    "\\caption{Selected predicted changes in reporting delay (days). Medians and 95\\% bootstrap CIs are shown for Poisson (primary) and Negative‑Binomial (sensitivity). Full table: \\texttt{final\\_contrast\\_comparison\\_combined.csv}.}\n",
    "\\label{tab:main-contrasts}\n",
    "\\begin{tabular}{llrrr}\n",
    "\\toprule\n",
    "Period & Rurality & Model & Median (days) & 95\\% CI \\\\\n",
    "\\midrule\n",
    "2020 and After & Urban & Poisson & 0.29 & (0.24, 0.34) \\\\\n",
    "2020 and After & Urban & NegBin  & -2.87 & (-3.73, -2.01) \\\\\n",
    "\\bottomrule\n",
    "\\end{tabular}\n",
    "\\end{table}\n",
    "\n",
    "% Figure reference (suggested)\n",
    "\\begin{figure}[t]\n",
    "\\centering\n",
    "\\includegraphics[width=0.95\\textwidth]{analysis/new analysis Aug 2025/final_contrast_comparison_symlog_annotated.png}\n",
    "\\caption{Poisson vs Negative‑Binomial estimated change in reporting delay (days), by rurality and period. Points show median estimates and vertical lines show 95\\% CIs; blue circles = Poisson GLM, orange squares = Negative‑Binomial sensitivity. The signed-log (symlog) scale displays magnitudes of negative delays while preserving near-zero Poisson estimates.}\n",
    "\\label{fig:poisson-vs-nb}\n",
    "\\end{figure}\n",
    "\n",
    "% -----------------------\n",
    "% Appendix / Reproducibility\n",
    "% -----------------------\n",
    "\\appendix\n",
    "\\section{Appendix: reproducibility and full outputs}\n",
    "All code used to generate the analyses is in \\texttt{analayis11\\_2020\\_nooutliers.ipynb}. Key output files (in \\texttt{analysis/new analysis Aug 2025/}) include:\n",
    "\\begin{itemize}\n",
    "  \\item \\texttt{final\\_contrast\\_comparison\\_combined.csv} : combined Poisson and NB contrast table used for main text Table~\\ref{tab:main-contrasts}.\n",
    "  \\item \\texttt{final\\_contrast\\_comparison\\_symlog\\_annotated.png} and \\texttt{final\\_contrast\\_comparison\\_symlog\\_column.png} : annotated multipanel figures (Poisson vs NB).\n",
    "  \\item \\texttt{nb\\_parametric\\_boot\\_predicted\\_means\\_appended.csv}, \\texttt{nb\\_contrasts\\_period.csv}, \\texttt{nb\\_contrasts\\_spilltype.csv} : raw NB bootstrap predicted means and contrasts.\n",
    "  \\item \\texttt{its\\_combined.png}, \\texttt{its\\_summary.csv} : ITS figures and coefficient summaries.\n",
    "  \\item diagnostic and preprocessing exports: \\texttt{spills\\_trimmed.parquet}, \\texttt{spills\\_trimmed\\_removed.parquet}, etc.\n",
    "\\end{itemize}\n",
    "\n",
    "Reproducibility note: to reproduce main tables and figures, run the notebook from top to bottom in a Python environment with pandas, statsmodels, scipy, and matplotlib installed; the notebook cells produce the CSVs and PNGs listed above. In the Appendix include (i) full GLM coefficient tables (HC3 and bootstrap), (ii) NB MLE notes (report any per-draw failures and the GLM fallback), and (iii) bootstrap diagnostics (number of draws, number of successful draws). "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5333ff82",
   "metadata": {
    "vscode": {
     "languageId": "latex"
    }
   },
   "outputs": [],
   "source": [
    "@inproceedings{seabold2010statsmodels,\n",
    "  title = {Statsmodels: Econometric and Statistical Modeling with {P}ython},\n",
    "  author = {Seabold, Skipper and Perktold, Josef},\n",
    "  booktitle = {Proceedings of the 9th Python in Science Conference},\n",
    "  pages = {61--66},\n",
    "  year = {2010},\n",
    "  url = {https://www.statsmodels.org/}\n",
    "}\n",
    "\n",
    "@article{virtanen2020scipy,\n",
    "  title = {{SciPy} 1.0: Fundamental Algorithms for Scientific Computing in Python},\n",
    "  author = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and {et al.}},\n",
    "  journal = {Nature Methods},\n",
    "  volume = {17},\n",
    "  number = {3},\n",
    "  pages = {261--272},\n",
    "  year = {2020},\n",
    "  doi = {10.1038/s41592-019-0686-2}\n",
    "}"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "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.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
