def create_ard(self, infile, out_dir, out_prefix, temp_dir, subset=None, polar='VV,VH,HH,HV'): self.proc_file = opj(out_dir, 'processing.json') self.update_ard_parameters() # check for correctness of ARD paramters # self.center_lat = self._get_center_lat(infile) # if float(self.center_lat) > 59 or float(self.center_lat) < -59: # print(' INFO: Scene is outside SRTM coverage. Will use 30m ASTER' # ' DEM instead.') # self.ard_parameters['dem'] = 'ASTER 1sec GDEM' #self.ard_parameters['resolution'] = h.resolution_in_degree( # self.center_lat, self.ard_parameters['resolution']) if self.product_type == 'GRD': # run the processing grd_to_ard([infile], out_dir, out_prefix, temp_dir, self.proc_file, subset=subset) # write to class attribute self.ard_dimap = glob.glob(opj(out_dir, '{}*bs.dim' .format(out_prefix)))[0] elif self.product_type != 'GRD': print(' ERROR: create_ard method for single products is currently' ' only available for GRD products')
def create_ard(self, infile, out_dir, out_prefix, temp_dir, subset=None, polar='VV,VH,HH,HV'): self.center_lat = self._get_center_lat(infile) if float(self.center_lat) > 59 or float(self.center_lat) < -59: print(' INFO: Scene is outside SRTM coverage. Will use 30m ASTER' ' DEM instead.') self.ard_parameters['dem'] = 'ASTER 1sec GDEM' self.ard_parameters['resolution'] = h.resolution_in_degree( self.center_lat, self.ard_parameters['resolution']) if self.product_type == 'GRD': if not self.ard_parameters: print(' INFO: No ARD definition given.' ' Using the OST standard ARD defintion' ' Use object.set_ard_defintion() first if you want to' ' change the ARD defintion.') self.set_ard_definition('OST') # we need to convert the infile t a list for the grd_to_ard routine infile = [infile] # run the processing grd_to_ard(infile, out_dir, out_prefix, temp_dir, self.ard_parameters, subset, polar) # write to class attribute self.ard_dimap = glob.glob(opj(out_dir, '{}*TC.dim' .format(out_prefix)))[0] elif self.product_type != 'GRD': print(' ERROR: create_ard method for single products is currently' ' only available for GRD products')
def grd_to_ard_batch(inventory_df, download_dir, processing_dir, temp_dir, proc_file, subset=None, data_mount='/eodata', exec_file=None): # where all frames are grouped into acquisitions processing_dict = _create_processing_dict(inventory_df) for track, allScenes in processing_dict.items(): for list_of_scenes in processing_dict[track]: # get acquisition date acquisition_date = Sentinel1_Scene(list_of_scenes[0]).start_date # create a subdirectory baed on acq. date out_dir = opj(processing_dir, track, acquisition_date) os.makedirs(out_dir, exist_ok=True) # check if already processed if os.path.isfile(opj(out_dir, '.processed')): print(' INFO: Acquisition from {} of track {}' ' already processed'.format(acquisition_date, track)) else: # get the paths to the file scene_paths = ([ Sentinel1_Scene(i).get_path(download_dir) for i in list_of_scenes ]) file_id = '{}_{}'.format(acquisition_date, track) # apply the grd_to_ard function grd_to_ard.grd_to_ard(scene_paths, out_dir, file_id, temp_dir, proc_file, subset=subset)
def create_ard(self, infile, out_dir, subset=None, overwrite=False): """ :param infile: :param out_dir: :param subset: :param overwrite: :return: """ if self.product_type != 'GRD': raise ValueError( 'The create_ard method for single products is currently ' 'only available for GRD products') if isinstance(infile, str): infile = Path(infile) if isinstance(out_dir, str): out_dir = Path(out_dir) # set config param necessary for processing self.config_dict['processing_dir'] = str(out_dir) self.config_dict['temp_dir'] = str(out_dir.joinpath('temp')) self.config_dict['snap_cpu_parallelism'] = os.cpu_count() self.config_dict['subset'] = False if subset: self.config_dict['subset'] = True self.config_dict['aoi'] = subset # create directories out_dir.mkdir(parents=True, exist_ok=True) out_dir.joinpath('temp').mkdir(parents=True, exist_ok=True) if overwrite: file_dir = out_dir.joinpath(f'{self.rel_orbit}/{self.start_date}') if file_dir.joinpath('.processed').exists(): file_dir.joinpath('.processed').unlink() # -------------------------------------------- # 2 Check if within SRTM coverage # set ellipsoid correction and force GTC production # when outside SRTM center_lat = self._get_center_lat(infile) if float(center_lat) > 59 or float(center_lat) < -59: logger.info( 'Scene is outside SRTM coverage. Snap will therefore use ' 'the GETASSE30 DEM. Also consider to use a stereographic ' 'projection.') epsg = input( 'Please type the EPSG you want to project the output data or ' 'just press enter for keeping Lat/Lon coordinate system ' '(e.g. 3413 for NSIDC Sea Ice Polar Stereographic North ' 'projection, or 3976 for NSIDC Sea Ice Polar Stereographic ' 'South projection') if not epsg: epsg = 4326 self.ard_parameters['single_ARD']['dem']['dem_name'] = 'GETASSE30' self.ard_parameters['single_ARD']['dem']['out_projection'] = int( epsg) # -------------------------------------------- # 3 Check ard parameters in case they have been updated, # and write them to json file # set config file to output directory self.config_file = out_dir.joinpath('processing.json') # write ard parameters, and check if they are correct self.update_ard_parameters() # -------------------------------------------- # 4 set resolution to degree # self.ard_parameters['resolution'] = h.resolution_in_degree( # self.center_lat, self.ard_parameters['resolution']) # -------------------------------------------- # 5 run the burst to ard batch routine filelist, out_bs, out_ls, error = grd_to_ard( [infile], self.config_file, ) # print error if any if error: logger.info(error) else: # remove temp folder h.remove_folder_content(out_dir.joinpath('temp')) out_dir.joinpath('temp').rmdir() self.ard_dimap = out_bs