forked from allenai/sar_vessel_detect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
S1Processing.sh
85 lines (71 loc) · 2.73 KB
/
S1Processing.sh
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
#!/usr/bin/env bash
# source this script
s1scene_name=S1A_IW_GRDH_1SDV_20240814T171426_20240814T171451_055212_06BAD3_F4BF.SAFE.zip
s1scene_path=/home/ryan/sar_vessel_detect/s1_safe/$s1scene_name
model_input_folder=/home/ryan/sar_vessel_detect/model_input/1
process_grd=/home/ryan/sar_vessel_detect/xview/process_grd.py
reproject_grd=/home/ryan/sar_vessel_detect/xview/reproject_grd.py
processing_folder=/home/ryan/sar_vessel_detect/processing
bathy_raster_script_path=/home/ryan/sar_vessel_detect/get_bathy_raster.py
bathy_rasters_path=/home/ryan/sar_vessel_detect/bathymetry/rasters
# Clean up previous run
rm -r $processing_folder
rm -r $model_input_folder
mkdir $processing_folder
mkdir $model_input_folder
# Process the S1 image using the xView code
conda activate xview3
python3 $process_grd $s1scene_path
python3 $reproject_grd $processing_folder/${s1scene_name::-4}/${s1scene_name::-4}_Sigma0_VH_LOG.tif
python3 $reproject_grd $processing_folder/${s1scene_name::-4}/${s1scene_name::-4}_Sigma0_VV_LOG.tif
mv $processing_folder/${s1scene_name::-4}/${s1scene_name::-4}_Sigma0_VV_LOG_UTM_10m_16b.tif \
$model_input_folder/VV_dB.tif
mv $processing_folder/${s1scene_name::-4}/${s1scene_name::-4}_Sigma0_VH_LOG_UTM_10m_16b.tif \
$model_input_folder/VH_dB.tif
echo
echo "Finished S1 processing"
echo
# Get image footprint
conda activate ships
gdal_footprint $model_input_folder/VH_dB.tif $model_input_folder/footprint.geojson -overwrite
# Select bathy raster
conda activate gpd # geopandas does not like the repo env
bathy_raster=$(python3 $bathy_raster_script_path)
conda activate ships
# Get EPSG for bathy reproject to UTM
utm_epsg=$(gdalinfo ${model_input_folder}/VH_dB.tif -json | jq -r .stac | jq -r .'["proj:epsg"]')
# Clip bathy raster to S1 extent. Reproject to UTM and set resolution to 500m
gdalwarp -cutline \
$model_input_folder/footprint.geojson \
$bathy_rasters_path/$bathy_raster \
$model_input_folder/bathymetry.tif \
-t_srs EPSG:$utm_epsg \
-tr 500 500
echo
echo "Processed bathymetry raster"
echo
# Time for inference!! >8-)
cd ./src
python -m xview3.infer.inference --image_folder ../model_input/ \
--weights ../data/models/model.pth --output out.csv \
--config_path ../data/configs/final.txt --padding 400 \
--window_size 3072 --overlap 20
cd ..
echo
echo "*** Inference complete!!! ***"
echo
# Grab date/time of image
cd s1_safe
unzip $s1scene_path
datetime=$(gdalinfo ${s1scene_name::-4} -json | jq -r .metadata | jq -r .'[""]' | jq -r .ACQUISITION_STOP_TIME)
rm -r ${s1scene_name::-4}
cd ..
echo
echo "*** Inference complete!!! ***"
echo
# Convert predictions to spatial predictions
conda activate gpd
python3 /home/ryan/sar_vessel_detect/csv_to_gdf.py $datetime
echo
echo "*** Predictions projected to map ***"
echo