{ "cells": [ { "cell_type": "markdown", "id": "5b497c5a", "metadata": {}, "source": [ "# Generate footprint climatology and export results" ] }, { "cell_type": "markdown", "id": "3b1af91e", "metadata": {}, "source": [ "## Import Supporting Libraries" ] }, { "cell_type": "code", "execution_count": null, "id": "90cc2bae", "metadata": {}, "outputs": [], "source": [ "import sys\n", "import os\n", "import warnings\n", "import pandas as pd\n", "import configparser" ] }, { "cell_type": "markdown", "id": "718d7599", "metadata": {}, "source": [ "## Import Fluxfootprints" ] }, { "cell_type": "code", "execution_count": 2, "id": "a4571e1a", "metadata": {}, "outputs": [], "source": [ "sys.path.insert(0, os.path.abspath(\"../../src\")) # adjust path as needed\n", "\n", "from fluxfootprints import (\n", " build_climatology,\n", " summarize_periods, export_contours_gpkg, export_rasters_geotiff\n", ")" ] }, { "cell_type": "markdown", "id": "42a1bfc5", "metadata": {}, "source": [ "## 1. Load site config and half-hourly data" ] }, { "cell_type": "code", "execution_count": null, "id": "17aa36d7", "metadata": {}, "outputs": [], "source": [ "config_path = \"G:/Shared drives/UGS_Flux/Data_Processing/config/US-UTV.ini\"\n", "cfg = configparser.ConfigParser(interpolation=None) \n", "cfg.read(config_path)\n", "lat = cfg.getfloat(\"METADATA\", \"station_latitude\")\n", "lon = cfg.getfloat(\"METADATA\", \"station_longitude\")\n", "\n", "\n", "df = pd.read_csv(\"G:/Shared drives/UGS_Flux/Data_Processing/config/station_data/US-UTV_HH_202309271630_202507221300.csv\")\n", "df['datetime_start'] = pd.to_datetime(df['datetime_start'], format=\"%Y-%m-%d %H:%M:%S\")\n", "df = df.set_index('datetime_start')\n", "df = df.sort_index()\n", "# Instrument & canopy heights (site-level constants if not in file)\n", "df[\"instr_height_m\"] = 3.66 # set your tower’s measurement height here (m)\n", "df[\"canopy_height_m\"] = 0.2 # set your vegetation height here (m)\n", "df[\"Z0_roughness\"] = 0.123 * df[\"canopy_height_m\"] # roughness length ≈ 0.123*h_c\n", "df['date_time'] = df.index\n", "df['LE'] = df['LE_1_1_1']\n", "df['H'] = df['H_1_1_1']\n", "df['Rn'] = df['NETRAD_1_1_1']\n", "df['G'] = df['G_1_1_A']" ] }, { "cell_type": "markdown", "id": "602efecc", "metadata": {}, "source": [ "## 2. Build the footprint climatology object (computes f_2d per timestep)" ] }, { "cell_type": "code", "execution_count": null, "id": "b314e918", "metadata": {}, "outputs": [], "source": [ "\n", "clim = build_climatology(\n", " df,\n", " dx=5.0, dy=5.0,\n", " domain=(-300, 300, -300, 300), # 500 m domain at 5 m resolution\n", " inst_height=3.66,\n", " crop_height=0.5,\n", " atm_bound_height=2000.0,\n", ")" ] }, { "cell_type": "markdown", "id": "e021b427", "metadata": {}, "source": [ "## 3. Summarize to daily & monthly" ] }, { "cell_type": "code", "execution_count": null, "id": "fc7917dc", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\Users\\paulinkenbrandt\\.conda\\envs\\py313\\Lib\\site-packages\\xarray\\core\\computation.py:824: RuntimeWarning: overflow encountered in exp\n", " result_data = func(*input_data)\n" ] } ], "source": [ "summ = summarize_periods(\n", " clim, df,\n", " et_source=\"LE\", # convert LE W/m² → ET mm/hr for weighting\n", " daily=True,\n", " monthly=True\n", ")" ] }, { "cell_type": "markdown", "id": "ba55dc59", "metadata": {}, "source": [ "## 4. Export 50% and 80% footprint contours to a GeoPackage + CSV stats" ] }, { "cell_type": "code", "execution_count": null, "id": "af4e95f7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "WindowsPath('ffp_geotiffs')" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "export_contours_gpkg(\n", " clim, summ, df,\n", " station_lat=lat,\n", " station_lon=lon,\n", " gpkg_path=\"US-CRT_footprints.gpkg\",\n", " crs_out=\"auto\", # auto-choose UTM zone for station\n", " levels=[0.9], # multiple contour levels\n", " stats_csv=\"US-CRT_footprints_stats.csv\",\n", " centroid_out=26912, # NAD83 / UTM zone 12N\n", " contour_method=\"skimage\", # or \"rasterio\" / \"auto\"\n", " rn_col=None, h_col=None, # optionally set explicit column names\n", " le_col=None, g_col=None # (auto-detects if left None)\n", ")" ] }, { "cell_type": "markdown", "id": "a080cdcf", "metadata": {}, "source": [ "## 5. Export footprint fields as GeoTIFF rasters" ] }, { "cell_type": "code", "execution_count": null, "id": "13bce00b", "metadata": {}, "outputs": [], "source": [ "\n", "export_rasters_geotiff(\n", " clim, summ,\n", " station_lat=lat,\n", " station_lon=lon,\n", " out_dir=\"ffp_geotiffs\",\n", " crs_out=\"auto\",\n", " which=(\"daily_mean\", \"monthly_mean\", \"daily_etw\", \"monthly_etw\"),\n", " prefix=\"US-UTV\"\n", ")" ] } ], "metadata": { "kernelspec": { "display_name": "py313", "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.1" } }, "nbformat": 4, "nbformat_minor": 5 }