def build_raw_csvs(self): """ Parse the input arguments and return a path containing the output intermediary files. :return: l1_output_path Posixpath """ self.log.info(f'Searching for WFR files inside: {self.INPUT_DIR}') self.log.info('Sorting input files by date.') self.sorted_file_list = self.build_list_from_subset( input_directory_path=self.INPUT_DIR) self.log.info(f'Input files found: {len(self.sorted_file_list)}') self.log.info('------') self.log.info(f'Generating ancillary data folder: {self.CSV_N1}') Path(self.CSV_N1).mkdir(parents=True, exist_ok=True) self.log.info(f'Attempting to extract geometries from: {self.ROI}') self.vertices = Utils.roi2vertex(roi=self.ROI, aux_folder_out=self.CSV_N1) total = len(self.sorted_file_list) t1 = time.perf_counter() done_csvs = [] for n, img in enumerate(self.sorted_file_list): percent = int((n * 100) / total) figdate = os.path.basename(img).split('____')[1].split('_')[0] self.log.info(f'({percent}%) {n + 1} of {total} - {figdate}') try: band_data, img_data = self.get_s3_data(wfr_img_folder=img, vertices=self.vertices, roi_file=self.ROI) f_b_name = os.path.basename(img).split('.')[0] out_dir = os.path.join(self.CSV_N1, f_b_name + '.csv') self.log.info(f'Saving DF at : {out_dir}') band_data.to_csv(out_dir, index=False) done_csvs.append(out_dir) except FileNotFoundError as e404: # If some Band.nc file was missing inside the image, move to the next one. self.log.info(f'{e404}') self.log.info(f'Skipping: {figdate}') continue t2 = time.perf_counter() outputstr = f'>>> Finished in {round(t2 - t1, 2)} second(s). <<<' self.log.info(outputstr) return done_csvs
def build_single_csv(self, multiFileBridge=False): """ Parse the input arguments and return a path containing the output intermediary file. :return: l1_output_path Posixpath """ if not multiFileBridge: # TODO: build_single_csv should be called by build_raw_csvs for code recycling. self.log.info(f'Searching for WFR file inside: {self.INPUT_DIR}') self.log.info(f'Generating ancillary data folder: {self.CSV_N1}') Path(self.CSV_N1).mkdir(parents=True, exist_ok=True) self.log.info(f'Attempting to extract geometries from: {self.ROI}') self.vertices = Utils.roi2vertex(roi=self.ROI, aux_folder_out=self.CSV_N1) # TODO: https://xarray-spatial.org/reference/_autosummary/xrspatial.multispectral.true_color.html band_data, img_data = self.get_s3_data(wfr_img_folder=self.INPUT_DIR, vertices=self.vertices) # if df is not None: f_b_name = os.path.basename(self.INPUT_DIR).split('.')[0] out_dir = os.path.join(self.CSV_N1, f_b_name + '.csv') self.log.info(f'Saving DF at : {out_dir}') band_data.to_csv(out_dir, index=False) return band_data, img_data, [out_dir]