def byteScale(fi, lower, upper): outfile = fi.replace('.tif', '%s_%s.tif' % (int(lower), int(upper))) gdal.Translate(outfile, fi, outputType=gdal.GDT_Byte, scaleParams=[[lower, upper]], noData=0) # Once again, I'm getting zeros in my files eventhough I have set # the output range to 1,255! The following will fix the issue. (x, y, trans, proj, data) = saa.read_gdal_file(saa.open_gdal_file(fi)) mask = np.isinf(data) data[mask == True] = 0 mask = (data < 0).astype(bool) (x, y, trans, proj, data) = saa.read_gdal_file(saa.open_gdal_file(outfile)) mask2 = (data > 0).astype(bool) saa.write_gdal_file_byte("mask2.tif", trans, proj, mask.astype(np.byte), nodata=0) mask3 = mask ^ mask2 data[mask3 == True] = 1 saa.write_gdal_file_byte(outfile, trans, proj, data, nodata=0) return (outfile)
def gdal_interferogram(folder_in=None, name=''): if folder_in is None: folder_in = os.getcwd() qfile = glob.glob(os.path.join(folder_in, 'q_*.img'))[0] ifile = qfile.replace('q_', 'i_') (x, y, trans, proj, idata) = saa.read_gdal_file(saa.open_gdal_file(ifile)) (x, y, trans, proj, qdata) = saa.read_gdal_file(saa.open_gdal_file(qfile)) #amp = np.sqrt(np.sqrt(np.power(idata,2) + np.power(qdata,2))) amp = np.log10( (np.sqrt(np.sqrt(np.power(idata, 2) + np.power(qdata, 2))) + 1) / 100000000) amp = (amp - np.min(amp)) ma = amp[amp != 0] amp = amp - np.min(ma) #amp = np.where(amp < 0, amp, 0) amp = amp / np.max(amp) * 255 phase = (np.arctan2(qdata, idata) + np.pi) / (2 * np.pi) * 255 saa.write_gdal_file_byte(os.path.join(folder_in, f'amplitude{name}.tif'), trans, proj, amp) saa.write_gdal_file_byte(os.path.join(folder_in, f'phase{name}.tif'), trans, proj, phase)
import saa_func_lib as saa i = sys.argv[1] q = sys.argv[2] (x,y,trans,proj,idata) = saa.read_gdal_file(saa.open_gdal_file(i)) (x,y,trans,proj,qdata) = saa.read_gdal_file(saa.open_gdal_file(q)) #amp = np.sqrt(np.sqrt(np.power(idata,2) + np.power(qdata,2))) amp = np.log10((np.sqrt(np.sqrt(np.power(idata,2) + np.power(qdata,2)))+1)/100000000) amp = (amp - np.min(amp)) ma = amp[amp != 0] amp = amp - np.min(ma) #amp = np.where(amp < 0, amp, 0) amp = amp/np.max(amp)*255 phase = (np.arctan2(qdata,idata)+np.pi)/(2*np.pi)*255 saa.write_gdal_file_byte('amplitude.tif',trans,proj,amp) saa.write_gdal_file_byte('phase.tif',trans,proj,phase)