File: do_reramp_SLC.py

package info (click to toggle)
doris 5.0.3~beta%2Bdfsg-14
  • links: PTS, VCS
  • area: contrib
  • in suites: bullseye
  • size: 6,668 kB
  • sloc: cpp: 43,593; python: 8,213; csh: 3,636; sh: 2,527; ansic: 649; makefile: 346; xml: 208
file content (99 lines) | stat: -rwxr-xr-x 3,646 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python
import numpy as np
from numpy import *
from doris.doris_stack.functions.get_ramp import get_ramp
from doris.doris_stack.functions.ESD_functions import freadbk
from doris.doris_stack.main_code.resdata import ResData
import sys

def usage():
    print('\nUsage: python  do_reramp_SLC.py dataFilename resFilename resampled')
    print('  where dataFilename        is the name of burst you want to deramp')
    print('        resFilename         is the .res file of burst              ')
    print(' This python applies the inverse phase ramp to the burst pointed by DATAFILENAME (slc)')
    print(' and RESFILENAME (res) that was deramped by deramp_SLC.m. The phase screen')
    print(' must account for the new resampled grids PIXRGGRID and PIXAZGRID    ')
    print(' [Nlines_mst x Nsamples_mst] that contain the time coordinates of the')
    print(' resampled image into the master grid:                               ')
    print('  for example                                                        ')
    print(' python   do_reramp_SLC.py slave_rsmp.raw slave.res False            ')
    print(' created by Gert Mulder')
    print(' Part of code adapted from Lorenzo Iannini and Wu Wenhao')
try:
    dataFilename = sys.argv[1]
    resFilename = sys.argv[2]
     
except:
    print('Unrecognized input')
    usage()
    sys.exit(1)
if len(sys.argv) == 3:
    resampled = True
elif len(sys.argv) == 4:
    resampled = sys.argv[3]
else:
    print('Unrecognized input')
    usage()
    sys.exit(1)

# Read information
################################################################################

res = ResData(resFilename)

# Image size properties
if res.process_control['resample'] == '1': #oversampled data
    l0 = int(res.processes['resample']['First_line (w.r.t. original_master)'])
    lN = int(res.processes['resample']['Last_line (w.r.t. original_master)'])
    p0 = int(res.processes['resample']['First_pixel (w.r.t. original_master)'])
    pN = int(res.processes['resample']['Last_pixel (w.r.t. original_master)'])
    dataFormat = 'complex64'
    resampled = True
else: # original data
    l0 = int(res.processes['crop']['First_line (w.r.t. original_image)'])
    lN = int(res.processes['crop']['Last_line (w.r.t. original_image)'])
    p0 = int(res.processes['crop']['First_pixel (w.r.t. original_image)'])
    pN = int(res.processes['crop']['Last_pixel (w.r.t. original_image)'])
    dataFormat = 'cpxint16'
    resampled = False

# Get resampled Slv size
Naz_res = lN-l0+1
Nrg_res = pN-p0+1

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#% Obtain chirp %
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if not resampled:
    ChirpFilt = get_ramp(resFilename, resampled=0, type='chirp')
elif resampled:
    ChirpFilt = get_ramp(resFilename, resampled=1, type='chirp')
else:
    print('Resampled should be True or False')

################################################################################
# Read data

slc = freadbk(dataFilename, 1, 1, int(Naz_res), int(Nrg_res), dataFormat, int(Naz_res), int(Nrg_res))

#######################################################################################

newFilename = dataFilename[:-4] + '_reramped.raw'
fid = open(newFilename, 'wb')
slc_reramped = slc * ChirpFilt
del ChirpFilt
del slc

#%% Apply reramping
if dataFormat == 'complex64':
    slc_dat = slc_reramped.astype(np.complex64)
else:  # cpxint16
    slc_dat = np.zeros(shape=(int(Naz_res), int(Nrg_res) * 2)).astype('int16')
    slc_dat[:, 0::2] = np.real(slc_reramped)
    slc_dat[:, 1::2] = np.imag(slc_reramped)

fid.write(slc_dat)
fid.close()

print("\nReramp operation completed\n")