From 89d322203ab681a11e68bff78f073935120d4ec8 Mon Sep 17 00:00:00 2001 From: Arka Dey Date: Sun, 17 Oct 2021 01:07:03 +0530 Subject: [PATCH] Update main.py Included print statement for info/warning/error messages in English; Added new feature to write computed CCI % values into a DataFrame. --- main.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/main.py b/main.py index 13ea545..3440810 100755 --- a/main.py +++ b/main.py @@ -19,6 +19,7 @@ __version__ = "0.1.0" __license__ = "MIT" +import pandas as pd import argparse from proyecto2.cloud_coverage import CloudCoverage from proyecto2.io import IO @@ -26,19 +27,30 @@ def main(image_path, export): """ Main entry point of the app """ + # Newly added Feature(s) + """ + Included print statement for info/warning/error messages in English + Added new feature to write computed CCI % values into a DataFrame + """ # Read the image located in image_path. try: image = IO.read(image_path) IO.write(image, "test.jpg") print("Se recibió la imagen {}".format(image_path)) + print(" ") + print("Translation: Picture was received {}".format(image_path)) except IOError: print("No se pudo leer la imagen {}".format(image_path)) + print(" ") + print("Translation: Image could not be read {}".format(image_path)) exit(1) # Get and print the cloud coverage index. index, new_image = CloudCoverage.compute(image) print("El índice de cobertura nubosa es: {}".format(index)) + print(" ") + print("Translation: The cloud cover index is: {}".format(index)) # Save image if the export flag was received. if export: @@ -46,8 +58,33 @@ def main(image_path, export): try: IO.write(new_image, out_path) print("Se guardó exitosamente la imagen {}".format(out_path)) + print(" ") + print("Translation: Image was successfully saved {}".format(out_path)) except: print("Ocurrió un error al guardar la imagen {}".format(out_path)) + print(" ") + print("Translation: An error occurred while saving the image {}".format(out_path)) + + # Capture the computed CCI % Value into an output DataFrame + opt_df_path = image_path.replace(image_path.split("/",)[-1],"",) + 'Image-CCI.csv' + try: + df = pd.read_csv(opt_df_path) + except: + df_new = pd.DataFrame({'Image':[image_path], 'CCI':[index]}) + df_new['Image'] = pd.Series(df_new['Image']).astype('str') + df_new['CCI'] = pd.Series(df_new['CCI']).astype('float') + df = df_new.copy() + else: + if df.loc[df['Image'] == image_path,].shape[0] > 0: + df.loc[df['Image'] == image_path, 'CCI'] = index + df['Image'] = pd.Series(df['Image']).astype('str') + df['CCI'] = pd.Series(df['CCI']).astype('float') + else: + df_new = pd.DataFrame({'Image':[image_path], 'CCI':[index]}) + df_new['Image'] = pd.Series(df_new['Image']).astype('str') + df_new['CCI'] = pd.Series(df_new['CCI']).astype('float') + df = pd.concat([df, df_new], axis=0) + df.to_csv(opt_df_path, index=False) if __name__ == "__main__": @@ -64,3 +101,4 @@ def main(image_path, export): args = parser.parse_args() main(args.image_path, bool(args.S)) +