Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions generate_kings_canyon_timeseries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"""
Generate EMIT L2A Reflectance time series for Kings Canyon area.

This script downloads and processes EMIT L2A reflectance data for the Upper Kings
area of interest over a specified date range and generates a time series of
reflectance data.
"""

import logging
from os.path import join

import earthaccess
import geopandas as gpd
import matplotlib.pyplot as plt
import rasters as rt

from EMITL2ARFL import *


def main():
"""Main function to generate Kings Canyon EMIT time series."""

# Configure logging to see info messages
logging.basicConfig(level=logging.INFO, format='%(name)s - %(levelname)s - %(message)s')

# Configuration parameters
start_date_UTC = "2022-08-01"
end_date_UTC = "2025-11-20"
download_directory = "~/data/EMIT_download"
output_directory = "~/data/Kings Canyon EMIT"

# Load Upper Kings area of interest
print("Loading Upper Kings area of interest...")
gdf = gpd.read_file("upper_kings.kml")
print(f"Loaded geometry: {gdf.geometry[0]}")

# Create UTM bounding box and raster grid
print("Creating UTM bounding box and raster grid...")
bbox_UTM = rt.Polygon(gdf.unary_union).UTM.bbox
print(f"UTM bounding box: {bbox_UTM}")

grid = rt.RasterGrid.from_bbox(bbox_UTM, cell_size=60, crs=bbox_UTM.crs)
print(f"Raster grid: {grid}")

# Log into earthaccess using netrc credentials
print("Logging into earthaccess...")
earthaccess.login(strategy="netrc", persist=True)

# Generate EMIT L2A reflectance time series
print("Generating EMIT L2A reflectance time series...")
filenames = generate_EMIT_L2A_RFL_timeseries(
start_date_UTC=start_date_UTC,
end_date_UTC=end_date_UTC,
geometry=grid,
output_directory=output_directory
)

print(f"Generated {len(filenames)} files:")
for filename in filenames:
print(f" {filename}")

# Process and display each file
print("\nProcessing generated files...")
for filename in filenames:
print(f"\nProcessing: {filename}")
try:
raster = MultiRaster.open(filename)
print(f"Successfully opened raster: {raster}")
# Note: display() function removed as it's typically for Jupyter notebooks
# You can add specific processing or visualization code here if needed
except Exception as e:
print(f"Error processing {filename}: {e}")


if __name__ == "__main__":
main()



92 changes: 92 additions & 0 deletions upper_kings.kml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd http://www.google.com/kml/ext/2.2 http://code.google.com/apis/kml/schema/kml22gx.xsd">
<Document id="Kings20150403_fixed">
<name>Kings20150403_fixed</name>
<Snippet></Snippet>
<Style id="PolyStyle00">
<LabelStyle>
<color>00000000</color>
<scale>0.000000</scale>
</LabelStyle>
<LineStyle>
<color>ff000000</color>
<width>3.000000</width>
</LineStyle>
<PolyStyle>
<color>00f0f0f0</color>
<outline>1</outline>
</PolyStyle>
</Style>
<Folder id="FeatureLayer0">
<name>Kings20150403_fixed</name>
<Snippet></Snippet>
<Placemark id="ID_00000">
<name>0</name>
<Snippet></Snippet>
<description><![CDATA[<html xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:msxsl="urn:schemas-microsoft-com:xslt">

<head>

<META http-equiv="Content-Type" content="text/html">

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

</head>

<body style="margin:0px 0px 0px 0px;overflow:auto;background:#FFFFFF;">

<table style="font-family:Arial,Verdana,Times;font-size:12px;text-align:left;width:100%;border-collapse:collapse;padding:3px 3px 3px 3px">

<tr style="text-align:center;font-weight:bold;background:#9CBCE2">

<td>0</td>

</tr>

<tr>

<td>

<table style="font-family:Arial,Verdana,Times;font-size:12px;text-align:left;width:100%;border-spacing:0px; padding:3px 3px 3px 3px">

<tr>

<td>FID</td>

<td>0</td>

</tr>

<tr bgcolor="#D4E4F3">

<td>FID_1</td>

<td>0</td>

</tr>

</table>

</td>

</tr>

</table>

</body>

</html>

]]></description>
<styleUrl>#PolyStyle00</styleUrl>
<MultiGeometry>
<Polygon>
<extrude>0</extrude><altitudeMode>clampToGround</altitudeMode>
<outerBoundaryIs><LinearRing><coordinates> -118.75179336538,36.8560054055524,0 -118.75179336538,36.8560054055524,0 -118.743018955865,36.8464809995079,0 -118.718385467173,36.841233321285,0 -118.698729084739,36.8413356201814,0 -118.669965058155,36.8372454743763,0 -118.65096000978,36.8222238656854,0 -118.638768182765,36.804121860702,0 -118.612291487905,36.7981922604537,0 -118.612906142798,36.7569370160943,0 -118.605574450662,36.7297964802785,0 -118.563889322764,36.7013719685922,0 -118.542341087436,36.677865300318,0 -118.532451820717,36.6611097808275,0 -118.535847796164,36.6293005899985,0 -118.538842395183,36.6049780503338,0 -118.536558554096,36.5935506131577,0 -118.522756550821,36.5914562284022,0 -118.502327797986,36.6044074305123,0 -118.48768747109,36.6151827379332,0 -118.477562117532,36.6441629461739,0 -118.46873616642,36.6624084780356,0 -118.438078181179,36.6767815822392,0 -118.405608789618,36.6875806486806,0 -118.354841959651,36.6876914660071,0 -118.33529282043,36.7002257159523,0 -118.331319677407,36.7184427859625,0 -118.338943790322,36.7312835345775,0 -118.355924714641,36.7480377685847,0 -118.365759990699,36.7594452570892,0 -118.370258358109,36.7730047406643,0 -118.364541221074,36.7962365140716,0 -118.371730041928,36.814073621358,0 -118.376678607793,36.826221333032,0 -118.349502632642,36.8423704758143,0 -118.359339469176,36.8677768295363,0 -118.348291951553,36.8819824237906,0 -118.360932455294,36.9044360974935,0 -118.372071698168,36.9203796268144,0 -118.378825777923,36.9475681490007,0 -118.39290292684,36.9540379724336,0 -118.394450119182,36.9723627712262,0 -118.410787235715,36.9871234625091,0 -118.406388263987,36.9971898728096,0 -118.413832759893,37.0089994525078,0 -118.41165769123,37.0208332252118,0 -118.425762086294,37.0290832971361,0 -118.428857173621,37.0592596042781,0 -118.471181533243,37.0745518549307,0 -118.480871070126,37.0845984544677,0 -118.497963746718,37.0910537030511,0 -118.524038956875,37.1087572159892,0 -118.555881968322,37.1167349806868,0 -118.57055012219,37.1174158302619,0 -118.598170030074,37.1356049856822,0 -118.630270196234,37.1347531428026,0 -118.646816058709,37.1398151261614,0 -118.642106828584,37.1229987220022,0 -118.629207485116,37.1135415721163,0 -118.603518478564,37.1121793465625,0 -118.594176662526,37.0836880550974,0 -118.582079142131,37.0537363961676,0 -118.575573090131,37.0376709581218,0 -118.580911284085,37.0120648604171,0 -118.593496631153,36.976924255878,0 -118.605165733769,36.9425247288916,0 -118.675466290747,36.9268796358257,0 -118.727593041996,36.9259073994129,0 -118.753625032771,36.9091305106524,0 -118.75179336538,36.8560054055524,0</coordinates></LinearRing></outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
</Folder>
</Document>
</kml>