Skip to content
Snippets Groups Projects
it4s1_get_coord.sh 1.44 KiB
Newer Older
  • Learn to ignore specific revisions
  • Milan Lazecky's avatar
    Milan Lazecky committed
    #!/bin/bash
    #(c) 2017-2018 Milan Lazecky, IT4Innovations
    
    #This is to find radar coordinates of given WGS84 location, based on lat/lon
    
    if [ -z $6 ]; then
     echo "Usage: "`basename $0`" relorb iw burst LAT LON RADIUS(in km)"
     echo "  e.g. "`basename $0`" 73 3 8008 49.511058 18.415157 7"
     exit
    fi
    
    
    RESS=3
    RESL=13
    
    Milan Lazecky's avatar
    Milan Lazecky committed
    
    relorb=$1
    SWATH=$2
    BURST=$3
    LAT=$4
    LON=$5
    RADIUS=$6
    
    
    espiritocz's avatar
    espiritocz committed
    if [ ! -z $7 ]; then
     if [ ! -f metadata.txt ]; then
      echo 'seems you are not in INSAR_* folder?';
     else
      source metadata.txt
      lat='lat'
      lon='lon'
     fi
    else
     source $IT4S1STORAGE/$relorb/$SWATH/metadata.txt
     lat=$IT4S1STORAGE/$relorb/$SWATH/$BURST/geom/lat
     lon=$IT4S1STORAGE/$relorb/$SWATH/$BURST/geom/lon
    fi
    
    Milan Lazecky's avatar
    Milan Lazecky committed
    
    #find coordinates
    cat << EOF > find_coord.m
    mujlat=$LAT;
    mujlon=$LON;
    radius=$RADIUS;
    resS=$RESS;
    resL=$RESL;
    %first compute coordinate centers
    addpath('$MATLABDIR');
    len=$lines;
    sam=$samples;
    
    espiritocz's avatar
    espiritocz committed
    lat=freadbk('$lat',len,'float32');
    lon=freadbk('$lon',len,'float32');
    
    Milan Lazecky's avatar
    Milan Lazecky committed
    lat2=lat-mujlat;
    lon2=lon-mujlon;
    lonlat2=abs(lon2.*lat2);
    [L,S]=find(lonlat2 == min(min(lonlat2)))
    %now compute coordinates of min and max for the crop
    radiusS=round(radius*1000/resS);
    radiusL=round(radius*1000/resL);
    LMIN=max([1 L-radiusL])
    LMAX=min([len L+radiusL])
    SMIN=max([1 S-radiusS])
    SMAX=min([sam S+radiusS])
    samples=SMAX-SMIN+1
    lines=LMAX-LMIN+1
    EOF
    
    
    echo "Converting WGS84 crop to radar coordinates (see crop.txt for result)"
    
    Milan Lazecky's avatar
    Milan Lazecky committed
    octave --eval find_coord -q 2>/dev/null | grep = | sed 's/ //g' > crop.txt
    
    espiritocz's avatar
    espiritocz committed
    rm find_coord.m