def landsat(date, p, r, outdir='./', updateScenes=False, maxClouds=100): if outdir[-1] != '/': outdir = outdir + '/' if updateScenes == True: # get the latest scene metadata subprocess.run(['landsat', '--update-scenes'], shell=True) sDate = (date - datetime.timedelta(1)).strftime('%Y-%m-%d') eDate = (date + datetime.timedelta(1)).strftime('%Y-%m-%d') downloader = GoogleDownload(sDate, eDate, 8, path=p, row=r, max_cloud_percent=maxClouds, output_path=outdir) search = list(downloader.scenes_low_cloud.SCENE_ID) if len(search) == 1: fileList = search[0] downloader.download() else: fileList = None return None
def download_image(start_date, end_date, sat, img_path, img_row, max_cloud, folder): """Baixar a imagem do repo do google.""" g = GoogleDownload(start=start_date, end=end_date, satellite=sat, path=img_path, row=img_row, output_path=folder, max_cloud_percent=float(max_cloud)) g.download()
def get_landsat(self, fmask=False): """Download from internet and select scenes from n_landsat g.download() then saves the selected scenes into the root directory. """ if self.lat is None: g = GoogleDownload(self.start, self.end, self.sat, path=self.path, row=self.row, output_path=self.root, max_cloud_percent=self.max_cloud) else: g = GoogleDownload(self.start, self.end, self.sat, latitude=self.lat, longitude=self.lon, output_path=self.root, max_cloud_percent=self.max_cloud) g.select_scenes(self.n) self.scenes = g.selected_scenes # g.download(list_type='selected') g.download(list_type='all') self.image_dirs = [ x[0] for x in os.walk(self.root) if os.path.basename(x[0])[:3] in self.landsat_mapping.keys() ] self._get_geography() if fmask: [self._make_fmask(d) for d in self.image_dirs]
def test_all_scenes(self): g = GoogleDownload(self.start, self.end, self.sat, path=self.path, row=self.row, output_path=self.root, max_cloud_percent=self.max_cloud) _all = g.candidate_scenes(return_list=True, list_type='all') self.assertEqual(_all, [ 'LC80390272013167LGN01', 'LC80390272013183LGN01', 'LC80390272013199LGN01', 'LC80390272013231LGN01', 'LC80390272013279LGN01' ])
def main(args): return_scene_list = False if args: cfg = {} for arg in vars(args): var = getattr(args, arg) if var is not None: cfg[arg] = var if cfg['update_scenes']: update_metadata_lists() if cfg['return_list']: return_scene_list = True if args.configuration: if os.path.isdir(args.configuration): print('Creating template configuration file at {}.'.format(args.configuration)) check_config(args.configuration) with open(args.configuration, 'r') as rfile: ycfg = yaml.load(rfile) cfg.update(ycfg) del cfg['return_list'] del cfg['configuration'] del cfg['update_scenes'] if cfg['pymetric_root']: download(cfg['clear_scenes'], cfg['pymetric_root']) else: del cfg['clear_scenes'] del cfg['pymetric_root'] g = GoogleDownload(**cfg) if return_scene_list: return g.candidate_scenes(return_list=True) g.download() else: del cfg['return_list'] del cfg['update_scenes'] g = GoogleDownload(**cfg) if return_scene_list: return g.candidate_scenes(return_list=True) else: g.download()
def download(clear_scenes, pymetric_root): dates = [] years = [] paths = [] rows = [] sats = [] lst = read_csv(clear_scenes, header=None).iloc[:, 0].tolist() for item in lst: sat = int(item[3]) if sat not in sats: sats.append(sat) dt = datetime.strptime(item[-8:], fmt_1) if dt.year not in years: years.append(dt.year) dates.append(dt) path, row = item[5:8], item[8:11] if path not in paths: paths.append(path) if row not in rows: rows.append(row) start = datetime.strftime(min(dates) - timedelta(days=1), fmt_2) end = datetime.strftime(max(dates) + timedelta(days=1), fmt_2) objects = list(product(sats, paths, rows, years)) organize_directory(pymetric_root, objects) for item in objects: sat, p, r, y = item out = os.path.join(pymetric_root, 'landsat', str(p), str(r), str(y)) g = GoogleDownload(start, end, sat, path=p, row=r, output_path=out, alt_name=True) included_scenes = deepcopy(g.pymetric_ids) for scene in included_scenes: if scene not in lst: print('remove {}'.format(scene)) g.scenes_df = g.scenes_df[g.scenes_df.PYMETRIC_ID != scene] g.download() return None
def test_select_n(self): self.start = '2013-04-15' self.end = '2013-10-15' g = GoogleDownload(self.start, self.end, self.sat, path=self.path, row=self.row, output_path=self.root, max_cloud_percent=100) g.select_scenes(n=3) self.assertEqual(g.selected_scenes['SCENE_ID'].values.tolist(), [ 'LC80390272013119LGN02', 'LC80390272013183LGN01', 'LC80390272013231LGN01' ])
def get_image_list(self, max_cloud_pct=20): super_list = [] s = datetime.strftime(self.start_date, '%Y-%m-%d') e = datetime.strftime(self.end_date, '%Y-%m-%d') sat_key = int(self.satellite[-1]) self.g = GoogleDownload(start=s, end=e, satellite=sat_key, output_path=self.year_dir, path=self.path, row=self.row, max_cloud_percent=max_cloud_pct) images = self.g.scene_ids_low_cloud if images: super_list.append(images) try: flat_list = [ item for sublist in super_list for item in sublist ] flat_list.reverse() return flat_list except TypeError: super_list.reverse() return super_list else: raise AttributeError( 'No images for this time-frame and satellite....')
def test_low_cloud(self): g = GoogleDownload(self.start, self.end, self.sat, path=self.path, row=self.row, output_path=self.root, max_cloud_percent=self.max_cloud) low = g.candidate_scenes(return_list=True) self.assertEqual(low, [ 'LC80390272013151LGN02', 'LC80390272013167LGN01', 'LC80390272013183LGN01', 'LC80390272013199LGN01', 'LC80390272013215LGN01', 'LC80390272013231LGN01', 'LC80390272013247LGN01', 'LC80390272013279LGN01' ])
def get_landsat(self, fmask=False): g = GoogleDownload(self.start, self.end, self.sat, path=self.path, row=self.row, output_path=self.root, max_cloud_percent=self.max_cloud) g.select_scenes(self.n) self.scenes = g.selected_scenes g.download(list_type='selected') self.image_dirs = [ x[0] for x in os.walk(self.root) if os.path.basename(x[0])[:3] in self.landsat_mapping.keys() ] self._get_geography() if fmask: [self._make_fmask(d) for d in self.image_dirs]