-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfetchLST.py
More file actions
44 lines (34 loc) · 1.42 KB
/
Copy pathfetchLST.py
File metadata and controls
44 lines (34 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import ee
import numpy as np
from datetime import datetime, timedelta
def fetch_lst(lat: float, lon: float):
credentials = ee.ServiceAccountCredentials(
"imsukudu24@gmail.com", "key.json"
)
ee.Initialize(credentials, project="careful-drummer-462304-u9")
point = ee.Geometry.Point(lon, lat)
region = point.buffer(10_000).bounds() # radius 10 km → 20 km square
today = datetime.utcnow().date()
start = today - timedelta(days=30)
coll = (
ee.ImageCollection("LANDSAT/LC09/C02/T1_L2")
.filterDate(str(start), str(today))
.filterBounds(region)
.filter(ee.Filter.lt("CLOUD_COVER", 10))
.select("ST_B10") # LST band in Kelvin × 0.00341802 + 149
.map(lambda img: (
img.multiply(0.00341802)
.add(149) # DN → Kelvin
.subtract(273.15) # Kelvin → °C
.copyProperties(img, img.propertyNames()) # keep metadata
))
)
if coll.size().getInfo() == 0:
raise RuntimeError("No cloud‑free scenes in the last 30 days.")
lst_celsius = coll.median()
url = lst_celsius.getDownloadURL({
"scale": 100, # ≈ 100 m/pixel → manageable array
"region": region,
"format": "NPY"
})
return url