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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157 | def run(cfg, burst=None, save_in_scratch=False):
'''run rdr2geo with provided runconfig
Parameters
----------
cfg: dict
Runconfig dictionary with user-defined options
burst: Sentinel1BurstSlc
Burst to run rdr2geo. If `None`, it will process all bursts in `cfg`
save_in_scratch: bool
Flag to save output in scratch dir instead of product dir
'''
module_name = get_module_name(__file__)
info_channel = journal.info(f"{module_name}.run")
info_channel.log(f"Starting {module_name} burst")
# Tracking time elapsed for processing
t_start = time.perf_counter()
# Extract rdr2geo cfg
rdr2geo_cfg = cfg.rdr2geo_params
# common rdr2geo inits
dem_raster = isce3.io.Raster(cfg.dem)
epsg = dem_raster.get_epsg()
proj = isce3.core.make_projection(epsg)
ellipsoid = proj.ellipsoid
# check if gpu ok to use and init CPU or CUDA object accordingly
use_gpu = isce3.core.gpu_check.use_gpu(cfg.gpu_enabled, cfg.gpu_id)
if use_gpu:
# Set the current CUDA device.
device = isce3.cuda.core.Device(cfg.gpu_id)
isce3.cuda.core.set_device(device)
Rdr2Geo = isce3.cuda.geometry.Rdr2Geo
else:
Rdr2Geo = isce3.geometry.Rdr2Geo
# list to keep track of ids processed
id_processed = []
# run rdr2geo for only once per burst_id
# save SLC for all bursts
if burst is None:
bursts = cfg.bursts
else:
bursts = [burst]
for burst in bursts:
# extract date string and create directory
date_str = burst.sensing_start.strftime("%Y%m%d")
burst_id = str(burst.burst_id)
# init output directory in product_path
burst_id_date_key = (burst_id, date_str)
out_paths = cfg.output_paths[burst_id_date_key]
output_path = out_paths.output_directory
if save_in_scratch:
output_path = out_paths.scratch_directory
# save SLC to Geotiff for all bursts
# run rdr2geo for only 1 burst avoid redundancy
burst.slc_to_file(f'{output_path}/{out_paths.file_name_pol}.slc.tif', 'GTiff')
# skip burst if id already rdr2geo processed
# save id if not processed to avoid rdr2geo reprocessing
if burst_id in id_processed:
continue
id_processed.append(burst_id)
# get radar grid of last SLC written and save for resample flattening
rdr_grid = burst.as_isce3_radargrid()
ref_grid_path = f'{output_path}/radar_grid.txt'
rdr_grid_to_file(ref_grid_path, rdr_grid)
# get isce3 objs from burst
isce3_orbit = burst.orbit
# init grid doppler
grid_doppler = isce3.core.LUT2d()
# init rdr2geo obj
rdr2geo_obj = Rdr2Geo(rdr_grid, isce3_orbit, ellipsoid, grid_doppler,
threshold=rdr2geo_cfg.threshold,
numiter=rdr2geo_cfg.numiter,
extraiter=rdr2geo_cfg.extraiter,
lines_per_block=rdr2geo_cfg.lines_per_block)
# Dict containing the rdr2geo layers to generate and their filenames
# key: rdr2geo layer name
# value: (boolean flag; True if layers needs to be generated, layer name)
topo_output = {file_name_x: (rdr2geo_cfg.compute_longitude, gdal.GDT_Float64),
file_name_y: (rdr2geo_cfg.compute_latitude, gdal.GDT_Float64),
file_name_z: (rdr2geo_cfg.compute_height, gdal.GDT_Float64),
file_name_layover: (
cfg.rdr2geo_params.compute_layover_shadow_mask,
gdal.GDT_Byte),
file_name_local_incidence: (
rdr2geo_cfg.compute_local_incidence_angle,
gdal.GDT_Float32),
file_name_los_east: (
rdr2geo_cfg.compute_ground_to_sat_east, gdal.GDT_Float32),
file_name_los_north: (
rdr2geo_cfg.compute_ground_to_sat_north, gdal.GDT_Float32),
}
raster_list = [
isce3.io.Raster(f'{output_path}/{fname}.tif', rdr_grid.width,
rdr_grid.length, 1, dtype, 'GTiff')
if enabled else None
for fname, (enabled, dtype) in topo_output.items()]
(x_raster, y_raster, z_raster, layover_shadow_raster,
local_incident_angle_raster, los_east_raster,
los_north_raster) = raster_list
# run rdr2geo
rdr2geo_obj.topo(dem_raster, x_raster=x_raster, y_raster=y_raster,
height_raster=z_raster,
local_incidence_angle_raster=local_incident_angle_raster,
layover_shadow_raster=layover_shadow_raster,
ground_to_sat_east_raster=los_east_raster,
ground_to_sat_north_raster=los_north_raster)
# remove undesired/None rasters from raster list
raster_list = [raster for raster in raster_list if raster is not None]
# save non-None rasters to vrt
output_vrt = isce3.io.Raster(f'{output_path}/topo.vrt', raster_list)
output_vrt.set_epsg(rdr2geo_obj.epsg_out)
dt = get_time_delta_str(t_start)
info_channel.log(
f"{module_name} burst successfully ran in {dt} (hr:min:sec)")
|