def main(iargs=None): from isceobj.Sensor.TOPS.Sentinel1 import Sentinel1 inps = cmdLineParse(iargs) if inps.swaths is None: inps.swaths = [1,2,3] else: inps.swaths = [int(i) for i in inps.swaths.split()] for swath in inps.swaths: obj = Sentinel1() obj.configure() obj.safe = inps.dirname.split() obj.swathNumber = swath obj.output = os.path.join(inps.outdir, 'IW{0}'.format(swath)) obj.orbitFile = inps.orbit obj.auxFile = inps.auxprod obj.orbitDir = inps.orbitdir obj.auxDir = inps.auxdir obj.polarization = inps.polid if inps.bbox is not None: obj.regionOfInterest = [float(x) for x in inps.bbox.split()] try: obj.parse() obj.extractImage(virtual=True) except Exception as e: print (e)
def get_lat_lon_v3(self, inps): from isceobj.Sensor.TOPS.Sentinel1 import Sentinel1 lats = [] lons = [] for swathnum in inps.swath_num.split(): obj = Sentinel1() obj.configure() obj.safe = self.safe_file.split() obj.swathNumber = int(swathnum) print(obj.polarization) # add by Minyan obj.polarization = 'vv' #obj.output = '{0}-SW{1}'.format(safe,swathnum) obj.parse() s, n, w, e = obj.product.bursts[0].getBbox() lats.append(s) lats.append(n) lons.append(w) lons.append(e) s, n, w, e = obj.product.bursts[-1].getBbox() lats.append(s) lats.append(n) lons.append(w) lons.append(e) self.SNWE = [min(lats), max(lats), min(lons), max(lons)]
def get_number_of_bursts(inps_dict): """ calculates the number of bursts based on boundingBox and returns an adjusting factor for walltimes """ system_path = os.getenv('PATH') sys.path.append(os.path.join(os.getenv('ISCE_STACK'), 'topsStack')) from stackSentinel import cmdLineParse as stack_cmd, get_dates try: #inpd = create_default_template(inps_dict) topsStack_template = pathObj.correct_for_isce_naming_convention( inps_dict) command_options = [] for item in topsStack_template: if item in ['useGPU', 'rmFilter']: if topsStack_template[item] == 'True': command_options = command_options + ['--' + item] elif not topsStack_template[item] is None: command_options = command_options + ['--' + item] + [ topsStack_template[item] ] inps = stack_cmd(command_options) dateList, reference_date, secondaryList, safe_dict = get_dates(inps) dirname = safe_dict[reference_date].safe_file if inps.swath_num is None: swaths = [1, 2, 3] else: swaths = [int(i) for i in inps.swath_num.split()] number_of_bursts = 0 for swath in swaths: obj = Sentinel1() obj.configure() obj.safe = dirname.split() obj.swathNumber = swath obj.output = os.path.join(inps.work_dir, 'reference', 'IW{0}'.format(swath)) obj.orbitFile = None obj.auxFile = None obj.orbitDir = inps.orbit_dirname obj.auxDir = inps.aux_dirname obj.polarization = inps.polarization if inps.bbox is not None: obj.regionOfInterest = [float(x) for x in inps.bbox.split()] os.environ['PATH'] = system_path try: obj.parse() number_of_bursts = number_of_bursts + obj.product.numberOfBursts except Exception as e: print(e) except: number_of_bursts = 1 print('number of bursts: {}'.format(number_of_bursts)) return number_of_bursts
def load(eof: dict) -> Sentinel: '''load the file if not already available and return an ISCE object''' filename = os.path.join(eof['id'], eof['id'].split('-')[0] + '.EOF') if eof['id'] not in _CACHE: print('-> download remote information') url = eof['urls'][[s[:4] for s in eof['urls']].index('s3:/')] hysds.utils.download_file(url, eof['id']) print('-> local file:', filename) if not os.path.isfile(filename): raise NoOrbitsAvailable(eof['id']) sentinel = Sentinel() # see import statements as this an ISCE object sentinel.configure() sentinel.orbitFile = filename _CACHE[eof['id']] = sentinel pass return _CACHE[eof['id']]
def extract(begin: str, end: str, orbit: Sentinel) -> BurstSLC: '''Function that will extract the sentinel-1 state vector information from the orbit files and populate a ISCE sentinel-1 product with the state vector information. ''' # ISCE internals read the required time-period to be extracted from the # orbit using the sentinel-1 product start and end-times. # Below we will add a dummy burst with the user-defined start and end-time # and include it in the sentinel-1 product object. # # Create empty burst SLC burst = BurstSLC() # see import statements as this an ISCE object burst.configure() burst.burstNumber = 1 burst.sensingStart = datetime.datetime.fromisoformat(begin[:-1]) burst.sensingStop = datetime.datetime.fromisoformat(end[:-1]) orbit.product.bursts = [burst] orb = orbit.extractPreciseOrbit() for state_vector in orb: burst.orbit.addStateVector(state_vector) return burst
def fetchSLCImagery(self): """ Create VRTs for TIFF files. """ import isce from isceobj.Sensor.TOPS.Sentinel1 import Sentinel1 dirname = os.path.join(self.srcsafe, 'measurement') res = gdal.ReadDir(dirname) # If more were known about the tiff, this can be improved vrt_template = """<VRTDataset rasterXSize="{samples}" rasterYSize="{lines}"> <VRTRasterBand dataType="CInt16" band="1"> <NoDataValue>0.0</NoDataValue> <SimpleSource> <SourceFilename relativeToVRT="0">{tiffname}</SourceFilename> <SourceBand>1</SourceBand> <SourceProperties RasterXSize="{samples}" RasterYSize="{lines}" DataType="CInt16" BlockXSize="{samples}" BlockYSize="1"/> <SrcRect xOff="0" yOff="0" xSize="{samples}" ySize="{lines}"/> <DstRect xOff="0" yOff="0" xSize="{samples}" ySize="{lines}"/> </SimpleSource> </VRTRasterBand> </VRTDataset>""" # Parse annotation files to have it ready with information for ii in res: parts = ii.split('-') swath = int(parts[1][-1]) pol = parts[3] # Read and parse metadata for swath xmlname = ii.replace('.tiff', '.xml') try: reader = Sentinel1() reader.configure() reader.xml = [ os.path.join("/vsizip", self.dest, self.zip2safe, 'annotation', xmlname) ] reader.manifest = [ os.path.join("/vsizip", self.dest, self.zip2safe, 'manifest.safe') ] reader.swathNumber = swath reader.polarization = pol reader.parse() vrtstr = vrt_template.format( samples=reader.product.bursts[0].numberOfSamples, lines=(reader.product.bursts[0].numberOfLines * len(reader.product.bursts)), tiffname=os.path.join(self.srcsafe, 'measurement', ii)) #Write the VRT to zip file with zipfile.ZipFile(self.dest, mode='a') as myzip: destname = os.path.join(self.zip2safe, 'measurement', ii) with myzip.open(destname, 'w') as myfile: myfile.write(vrtstr.encode('utf-8')) except: raise Exception("Could not create vrt for {0} at {1} in " "{2}".format(ii, self.url, self.dest))
''' Main driver. ''' #Parse command line inputs inps = cmdLineParse() ###Number of safe files nSafe = len(inps.safe) ####Parse individual swaths swaths = [] for safe in inps.safe: for swathnum in inps.swaths: obj = Sentinel1() obj.configure() obj.safe = [safe] obj.swathNumber = swathnum obj.output = '{0}-SW{1}'.format(safe, swathnum) ###Only parse and no extract obj.parse() swt = Swath(obj) swaths.append(swt) ###Identify the 4 corners and dimensions topSwath = min(swaths, key=lambda x: x.sensingStart)