-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_IW_values_slc_data.py
121 lines (85 loc) · 3.13 KB
/
get_IW_values_slc_data.py
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import os
import stsa #pip install git+https://github.com/pbrotoisworo/s1-tops-split-analyzer.git
from sentinelsat import SentinelAPI
import geopandas as gpd
import pandas as pd
from shapely.geometry import box
#start_date = '20230201'
#end_date = '20230315'
#aoi_filepath = 'C:/Users/shubh/Downloads/split_poly/trial_shp.shp'
def save_burst_number(aoi_filepath, start_date, end_date):
# copernicus open access hub credentials
#username = 'arunbalaji'
#password = 'rsgisaji'
username = 'shubham6147'
password = 'Shubham@4475'
destination_location = os.path.basepath(aoi_filepath)
api = SentinelAPI(username, password, 'https://scihub.copernicus.eu/dhus')
aoi = gpd.read_file(aoi_filepath)
geom =box(*aoi.total_bounds)
#%% Query S1 SLC data
s1_products = api.query(geom,
date=(start_date, end_date),
platformname = 'Sentinel-1',
producttype='SLC')
s1_products.keys()
#%% Extracting only specific information from the products
title = []
ingestion_date = []
footprint = []
quick_look = []
product = []
for i in s1_products.keys():
title.append(s1_products[i]['title'])
ingestion_date.append(s1_products[i]['ingestiondate'])
footprint.append(s1_products[i]['footprint'])
quick_look.append(s1_products[i]['link_icon'])
product.append(s1_products[i]['link'])
# Converting s1 slc data lists to df
s1_df = pd.DataFrame(
{'title': title,
'ingestion_date': ingestion_date,
'quicklook_link': quick_look,
'product_link': product,
'footprint': footprint
})
#%% Using stsa package to extract only bursts and saving
iw1 = []
iw2 = []
iw3 = []
s1 = stsa.TopsSplitAnalyzer()
for i in s1_df['title']:
s1.load_api(username,
i,
password,
destination_location)
all_bursts = s1.df
overlaid = gpd.overlay(aoi,all_bursts,how='intersection')
x = overlaid[(overlaid['subswath'] == 'IW1')]['burst'].values
if len(x)==0: # no intersection
iw1.append((0,0))
elif len(x)==1: # intersection with only 1 burst
iw1.append((int(x[0]),int(x[0])))
else: # intersection with more than 1 burst
iw1.append((int(min(x)),int(max(x))))
y = overlaid[(overlaid['subswath'] == 'IW2')]['burst'].values
if len(y)==0:
iw2.append((0,0))
elif len(y)==1:
iw2.append((int(y[0]),int(y[0])))
else:
iw2.append((int(min(y)),int(max(y))))
z = overlaid[(overlaid['subswath'] == 'IW3')]['burst'].values
if len(z)==0:
iw3.append((0,0))
elif len(z)==1:
iw3.append((int(z[0]),int(z[0])))
else:
iw3.append((int(min(z)),int(max(z))))
#%% Converting the df to csv and saving it
s1_df['IW1'] = iw1
s1_df['IW2'] = iw2
s1_df['IW3'] = iw3
output_csv_path = aoi_filepath[:-4] + '.csv'
s1_df.to_csv(output_csv_path)
#save_burst_number(aoi_filepath, start_date, end_date)