Repository navigation
Expand file tree
/
Copy pathfetch_gee.py
More file actions
105 lines (77 loc) · 2.85 KB
/
Copy pathfetch_gee.py
File metadata and controls
105 lines (77 loc) · 2.85 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 5 11:02:38 2025
@author: advit
"""
import ee
import os
import subprocess
from datetime import datetime, timedelta
ee.Initialize(project='satellite-472011')
states = ee.FeatureCollection("FAO/GAUL/2015/level1")
hp = states.filter(ee.Filter.eq('ADM1_NAME', 'Himachal Pradesh'))
himachal = hp.geometry()
def getS1VVVH(start, end):
vv = ee.ImageCollection('COPERNICUS/S1_GRD') \
.filterBounds(himachal) \
.filterDate(start, end) \
.filter(ee.Filter.eq('instrumentMode','IW')) \
.filter(ee.Filter.listContains('transmitterReceiverPolarisation','VV')) \
.select('VV')
vh = ee.ImageCollection('COPERNICUS/S1_GRD') \
.filterBounds(himachal) \
.filterDate(start, end) \
.filter(ee.Filter.eq('instrumentMode','IW')) \
.filter(ee.Filter.listContains('transmitterReceiverPolarisation','VH')) \
.select('VH')
vvImg = ee.Image(ee.Algorithms.If(vv.size().gt(0), vv.median().clip(himachal), ee.Image(0).rename('VV')))
vhImg = ee.Image(ee.Algorithms.If(vh.size().gt(0), vh.median().clip(himachal), ee.Image(0).rename('VH')))
return ee.Image.cat([
vvImg.multiply(1000).toInt16(),
vhImg.multiply(1000).toInt16()
]).resample('bilinear')
def getChirps(start, end):
return ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY') \
.filterBounds(himachal) \
.filterDate(start, end) \
.sum() \
.clip(himachal) \
.multiply(10).toInt16() \
.resample('bilinear') \
.rename('rainfall')
def getSlope():
dem = ee.Image('USGS/SRTMGL1_003').clip(himachal)
return ee.Terrain.slope(dem).multiply(100).toInt16().resample('bilinear').rename('slope')
slope = getSlope()
def stackWeek(start, end):
return ee.Image.cat([
getS1VVVH(start, end),
getChirps(start, end),
slope
]).rename(['VV','VH','rainfall','slope'])
# -------------------------
# 4) Generate weekly dates (example: monsoon season 14 weeks)
# -------------------------
start_dates = [
'2016-06-01','2016-06-08','2016-06-15','2016-06-22',
'2016-06-29','2016-07-06','2016-07-13','2016-07-20',
'2016-07-27','2016-08-03','2016-08-10','2016-08-17',
'2016-08-24','2016-08-31'
]
# Download weekly GeoTIFFs and save to drive
for i, s in enumerate(start_dates):
start = ee.Date(s)
end = start.advance(7, 'day')
img = stackWeek(start, end)
print(f"[🚀] Exporting Week-{i+1} to Google Drive...")
task = ee.batch.Export.image.toDrive(
image=img.reproject('EPSG:4326', None, 20),
description=f"HP_week_{i+1}",
folder="HP_SAT_EXPORTS", # <-- this folder will appear in your Google Drive
fileNamePrefix=f"HP_week_{i+1}",
scale=20,
region=himachal,
maxPixels=1e13
)
task.start()
print("✅ All exports started.")