Skip to content

Radarsat-2 stackStripMap.py #941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
S-Nari opened this issue Mar 27, 2025 · 1 comment
Open

Radarsat-2 stackStripMap.py #941

S-Nari opened this issue Mar 27, 2025 · 1 comment

Comments

@S-Nari
Copy link

S-Nari commented Mar 27, 2025

I used stackStripMap.py to make Radarsat-2's SLC stack for StaMPS. Before running it, I successfully ran 'run_unPackRSAT2' by following the README.md in /share/isce2/stripmapStack. For reading orbit information, I have made correction about reading Radarsat-2 orbit information, as mentioned by @fdelgadodelapuente, #654.

I ran stackStripMap.py as followed, and got the following error.

stackStripMap.py -s Slc -d DEM/merge_gsi10m.dehm.wgs84 -t 3650 -b 5000 -a 1 -r 1  -f 0 -W slc -x '36.68 37.10 137.68 138.43'  -m 20150926  --nofocus -z
dirs =  ['/home/ksvo/sar_proc/NiigataYakeyama/Radarsat2/stack/Dsc_gsi10m/Slc/20150926', '/home/ksvo/sar_proc/NiigataYakeyama/Radarsat2/stack/Dsc_gsi10m/Slc/20160803', '/home/ksvo/sar_proc/NiigataYakeyama/Radarsat2/stack/Dsc_gsi10m/Slc/20160710', '/home/ksvo/sar_proc/NiigataYakeyama/Radarsat2/stack/Dsc_gsi10m/Slc/20151113', '/home/ksvo/sar_proc/NiigataYakeyama/Radarsat2/stack/Dsc_gsi10m/Slc/20160920', '/home/ksvo/sar_proc/NiigataYakeyama/Radarsat2/stack/Dsc_gsi10m/Slc/20161107', '/home/ksvo/sar_proc/NiigataYakeyama/Radarsat2/stack/Dsc_gsi10m/Slc/20160827', '/home/ksvo/sar_proc/NiigataYakeyama/Radarsat2/stack/Dsc_gsi10m/Slc/20160523']
acquisitionDates =  ['20150926', '20151113', '20160523', '20160710', '20160803', '20160827', '20160920', '20161107']
Orbit.calculateHeight: self.position =  [-4698369.860842591, 3475353.832133946, 4148475.469110697]
Orbit.calculateHeight: ellipsoid.a, ellipsoid.e2 =  6378137.0 0.0066943799901
Orbit.calculateHeight: self.position =  [-4698369.860842591, 3475353.832133946, 4148475.469110697]
Orbit.calculateHeight: ellipsoid.a, ellipsoid.e2 =  6378137.0 0.0066943799901
Using entire span of image for estimating baselines
2025-03-27 21:59:18,644 - isce.mroipac.baseline - INFO - Sampling time 0
2025-03-27 21:59:18,650 - isce.mroipac.baseline - INFO - Sampling time 1
2025-03-27 21:59:18,655 - isce.mroipac.baseline - INFO - Sampling time 2
2025-03-27 21:59:18,655 - isce.Orbit - ERROR - Unable to select 2 state vectors before and after chosen time 2015-09-26 20:51:56.629446
Traceback (most recent call last):
  File "/home/ksvo/miniconda3/envs/isce2_env2/share/isce2/stripmapStack/stackStripMap.py", line 367, in <module>
    main(sys.argv[1:])
  File "/home/ksvo/miniconda3/envs/isce2_env2/share/isce2/stripmapStack/stackStripMap.py", line 340, in main
    pairs = selectPairs(inps,stackReferenceDate, secondaryDates, acquisitionDates,doBaselines=True)
  File "/home/ksvo/miniconda3/envs/isce2_env2/share/isce2/stripmapStack/Stack.py", line 745, in selectPairs
    baselineDict, timeDict = baselineStack(inps, stackReference, acuisitionDates,doBaselines)
  File "/home/ksvo/miniconda3/envs/isce2_env2/share/isce2/stripmapStack/Stack.py", line 734, in baselineStack
    baselineDict[slv]=baselinePair(baselineDir, reference, secondary, doBaselines)
  File "/home/ksvo/miniconda3/envs/isce2_env2/share/isce2/stripmapStack/Stack.py", line 707, in baselinePair
    bObj.baseline()    # calculate baseline from orbits
  File "/home/ksvo/miniconda3/envs/isce2_env2/lib/python3.8/site-packages/isce/components/mroipac/baseline/Baseline.py", line 193, in baseline
    referenceBasis = self.calculateBasis(self.referenceOrbit,referenceTime[i])
  File "/home/ksvo/miniconda3/envs/isce2_env2/lib/python3.8/site-packages/isce/components/mroipac/baseline/Baseline.py", line 127, in calculateBasis
    x1 = sv.getPosition()
AttributeError: 'NoneType' object has no attribute 'getPosition'

This looks like error about reading state vectors. In the **.slc.xml files, created by unpackFrame_RSAT2.py, there is no orbit information. Perhaps, my process of unpackFrame_RSAT2 was not successful? The following output is the result of run_unPackRSAT2 (picking up a result on one SLC). This looks like correct reading state vectors from 'product.xml'.

(isce2_env2) $ ./run_unPackRSAT2
effective PRF 2680.285889, original PRF 1340.142944
Successfully read state vectors from product XML
Warning 1: /home/ksvo/sar_proc/NiigataYakeyama/Radarsat2/stack/Dsc_gsi10m/Data/20150926/imagery_HH.tif: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.
Horizontally Flipping data

Can anyone give me any advice?

@S-Nari
Copy link
Author

S-Nari commented Mar 31, 2025

This error could not be solved in the end as long as I used only 5 state vectors provided in 'product.xml'. But after modifying the unpackFrame_RSAT2.py to read 15 state vectors from the POD file (*****_DEF.ORB), the problem with reading state vectors no longer occurs.

Using the original 'unpackFrame_RSAT2.py' caused an additional error in 'run_01_crop', which said that the value of obj.frame._dopplerVsPixel was none. So I added a part that assigns the value of obj.frame._dopplerVsPixel by referring to the corresponding part of 'Radarsat2.py'. I remember that almost the same error occurred when I used the 'alosstack' script #344.

The modified unpackFrame_RSAT2.py is as follows;

#!/usr/bin/env python3

import isce
from isceobj.Sensor import createSensor
import shelve
import argparse
import glob
from isceobj.Util import Poly1D
from isceobj.Planet.AstronomicalHandbook import Const
from isceobj.Util.decorators import use_api
import os
import numpy


def cmdLineParse():
    '''
    Command line parser.
    '''

    parser = argparse.ArgumentParser(description='Unpack RADARSAT2 SLC data and store metadata in pickle file.')
    parser.add_argument('-i','--input', dest='RSATdir', type=str,
            required=True, help='Input RADARSAT2 SLC directory')
    parser.add_argument('-o', '--output', dest='slcdir', type=str,
            required=True, help='Output unpacked SLC directory')
    return parser.parse_args()


def find_orbit_file(RSATdir): # 2025/03/28 added.
    '''
    Search for *****_DEF.ORB file in RSATdir and RSATdir/schemas.
    Returns the found file path or raises an error if not found.
    '''

    search_dirs = [RSATdir, os.path.join(RSATdir, 'schemas')]

    for directory in search_dirs:
        orbit_files = glob.glob(os.path.join(directory, '*_def.orb'))
        if orbit_files:
            return orbit_files[0]  # return what is found firstly

    raise FileNotFoundError("Error: No orbit file (*****_def.orb) found in RSATdir or RSATdir/schemas.")


@use_api
def unpack(RSATdir, slcname):
    '''
    Unpack RADARSAT2 data to binary SLC file. assume HH only for now
    
    # 2025/03/28: added 'orbname' into the arguments of 'unpack'

    '''

    ###Search for imagery and XML files in input directory
    imgname = glob.glob(os.path.join(RSATdir,'imagery*.tif'))[0]
    xmlname = glob.glob(os.path.join(RSATdir, 'product.xml'))[0]

    ### name of POD file
    orbname = find_orbit_file(RSATdir)
    
    ### Directory name of POD file (*****_def.orb) # 2025/03/28 added
    orbdirname = os.path.dirname(orbname)
    
    ####Create output SLC directory if needed
    if not os.path.isdir(slcname):
        os.mkdir(slcname)

    date = os.path.basename(slcname)

    #####Create an Radarsat2 object and wire it
    obj = createSensor('Radarsat2')
    obj.configure()
    obj.xml = xmlname
    obj.tiff = imgname
    obj.output = os.path.join(slcname, date+'.slc')

    obj.orbitDirectory = orbdirname # 2025/03/28 added
    obj.orbitFile = orbname             # 2025/03/28 added

    print(obj.xml)
    print(obj.tiff)
    print(obj.output)
    print(obj.orbitDirectory)
    print(obj.orbitFile)

    ####Extract the image and write the XML file for the SLC
    obj.extractImage()
    obj.frame.getImage().renderHdr()


    ####Save the doppler polynomial
    ####CEOS already provides doppler polynomial
    ####as a function of range pixel
    coeffs = obj.doppler_coeff
    print('coeffs:',coeffs)
    poly = Poly1D.Poly1D()
    poly.initPoly(order=len(coeffs)-1)
    poly.setCoeffs(coeffs)

    ## the following 5 lines are copied from line 419-423 in 'Radarsat2.py'
    pix = np.linspace(0, obj.frame.getNumberOfSamples(), num=len(coeffs)+1)
    evals = poly(pix)
    fit = np.polyfit(pix,evals, len(coeffs)-1)
    obj.frame._dopplerVsPixel = list(fit[::-1])
    print('Doppler Fit: ', fit[::-1])    
   

    ####Save the FMrate polynomial
    ####CEOS already provides FMrate polynomial
    ####as a function of range pixel
    fcoeffs = obj.azfmrate_coeff
#    fcoeffs = [0.0, 0.0, 0.0]  # zero-Doppler geometry, so this is not used
    fpoly = Poly1D.Poly1D()
    fpoly.initPoly(order=len(fcoeffs)-1)
    fpoly.setCoeffs(fcoeffs)


    ####Save required metadata for further use
    ####All data is output to a shelve file
    pickName = os.path.join(slcname, 'data')
    with shelve.open(pickName) as db:
        db['frame'] = obj.frame
        db['doppler'] = poly
        db['fmrate'] = fpoly


if __name__ == '__main__':
    '''
    Main driver.
    '''

    inps = cmdLineParse()
    if inps.slcdir.endswith('/'):
        inps.slcdir = inps.slcdir[:-1]

    if inps.RSATdir.endswith('/'):
        inps.RSATdir = inps.RSATdir[:-1]

    unpack(inps.RSATdir, inps.slcdir)

If there is something wrong in the modified script, please tell me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant