From 52e515bd3a3369f34f43c0d727563023c74dcc0c Mon Sep 17 00:00:00 2001
From: Impact <pascal.mouquet@ird.fr>
Date: Fri, 28 Oct 2022 17:19:33 +0400
Subject: [PATCH] bugfix sen2cor version

---
 sen2chain/sen2cor.py | 208 +++++++++++++++++++++----------------------
 1 file changed, 104 insertions(+), 104 deletions(-)

diff --git a/sen2chain/sen2cor.py b/sen2chain/sen2cor.py
index 3157d55..b382c4a 100644
--- a/sen2chain/sen2cor.py
+++ b/sen2chain/sen2cor.py
@@ -46,119 +46,119 @@ def process_sen2cor(
     # TODO: Add 60m resolution.
 
 # <<<<<<< HEAD
-    # s2c_path = s2c_path or get_latest_s2c_version_path(pathlib.Path(l1c_product_path).stem)
-    # if s2c_path:
-        # s2c_v = get_Sen2Cor_version(s2c_path)
-        # l2a_product_path_tmp = l2a_product_path.parent / (l2a_product_path.stem + '.tmp')
-        # if s2c_v == '02.05.05':
-            # logger.info("sen2cor {} processing: {}".format(s2c_v, l1c_product_path))
-            # if resolution == 10:
-                # logger.info("sen2cor processing 20 m: {}".format(l1c_product_path))
-                # command1 = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --resolution {res} {l1c_folder}".format(
-                    # sen2cor_bashrc=str(s2c_path),
-                    # res=20,
-                    # l1c_folder=str(l1c_product_path)
-                    # )
-                # process1 = subprocess.run(command1.split(", "))
-                # logger.info("sen2cor processing 10 m: {}".format(l1c_product_path))
-                # command2 = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --resolution {res} {l1c_folder}".format(
-                    # sen2cor_bashrc=str(s2c_path),
-                    # res=10,
-                    # l1c_folder=str(l1c_product_path)
-                # )
-                # process2 = subprocess.run(command2.split(", "))
+    s2c_path = s2c_path or get_latest_s2c_version_path(pathlib.Path(l1c_product_path).stem)
+    if s2c_path:
+        s2c_v = get_Sen2Cor_version(s2c_path)
+        l2a_product_path_tmp = l2a_product_path.parent / (l2a_product_path.stem + '.tmp')
+        if s2c_v == '02.05.05':
+            logger.info("sen2cor {} processing: {}".format(s2c_v, l1c_product_path))
+            if resolution == 10:
+                logger.info("sen2cor processing 20 m: {}".format(l1c_product_path))
+                command1 = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --resolution {res} {l1c_folder}".format(
+                    sen2cor_bashrc=str(s2c_path),
+                    res=20,
+                    l1c_folder=str(l1c_product_path)
+                    )
+                process1 = subprocess.run(command1.split(", "))
+                logger.info("sen2cor processing 10 m: {}".format(l1c_product_path))
+                command2 = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --resolution {res} {l1c_folder}".format(
+                    sen2cor_bashrc=str(s2c_path),
+                    res=10,
+                    l1c_folder=str(l1c_product_path)
+                )
+                process2 = subprocess.run(command2.split(", "))
             
-            # else:
-                # logger.debug("sen2cor processing: {}".format(l1c_product_path))
-                # command = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --resolution {resolution} {l1c_folder}".format(
-                    # sen2cor_bashrc=str(s2c_path),
-                    # resolution=resolution,
-                    # l1c_folder=str(l1c_product_path)
-                # )
-                # process = subprocess.run(command.split(", "))
+            else:
+                logger.debug("sen2cor processing: {}".format(l1c_product_path))
+                command = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --resolution {resolution} {l1c_folder}".format(
+                    sen2cor_bashrc=str(s2c_path),
+                    resolution=resolution,
+                    l1c_folder=str(l1c_product_path)
+                )
+                process = subprocess.run(command.split(", "))
                 
-        # elif s2c_v in ['02.08.00','02.09.00', '02.10.01']:
-            # logger.info("sen2cor {} processing: {}".format(s2c_v, l1c_product_path))
-            # command = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --processing_baseline {processing_baseline} --output_dir {out_dir} {l1c_folder}".format(
-                # sen2cor_bashrc = str(s2c_path),
-                # processing_baseline = pb,
-                # out_dir = l2a_product_path_tmp,
-                # l1c_folder = str(l1c_product_path)
-            # )
-            # process = subprocess.run(command.split(", "))
-            # sorted(l2a_product_path_tmp.glob("*.SAFE"))[0].rename(l2a_product_path.parent / (l2a_product_path.stem + '.SAFE'))
-            # l2a_product_path_tmp.rmdir()
-        # elif s2c_v is not None:
-            # logger.info('Provided Sen2Cor version {} is not compatible with Sen2Chain yet'.format(s2c_v))
+        elif s2c_v in ['02.08.00','02.09.00', '02.10.01']:
+            logger.info("sen2cor {} processing: {}".format(s2c_v, l1c_product_path))
+            command = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --processing_baseline {processing_baseline} --output_dir {out_dir} {l1c_folder}".format(
+                sen2cor_bashrc = str(s2c_path),
+                processing_baseline = pb,
+                out_dir = l2a_product_path_tmp,
+                l1c_folder = str(l1c_product_path)
+            )
+            process = subprocess.run(command.split(", "))
+            sorted(l2a_product_path_tmp.glob("*.SAFE"))[0].rename(l2a_product_path.parent / (l2a_product_path.stem + '.SAFE'))
+            l2a_product_path_tmp.rmdir()
+        elif s2c_v is not None:
+            logger.info('Provided Sen2Cor version {} is not compatible with Sen2Chain yet'.format(s2c_v))
         
-        # else:
-            # logger.info('Could not determine Sen2Cor version from provided path, please check pattern "Sen2Cor-**.**.**" is in path')
+        else:
+            logger.info('Could not determine Sen2Cor version from provided path, please check pattern "Sen2Cor-**.**.**" is in path')
 
-    # else:
-        # logger.info('Could not determine a compatible installed sen2cor version to process this product')
+    else:
+        logger.info('Could not determine a compatible installed sen2cor version to process this product')
 # =======
-    sen2cor_bashrc_path = Config().get("sen2cor_bashrc_path")
+    # sen2cor_bashrc_path = Config().get("sen2cor_bashrc_path")
     # ~ s2c_v = next(iter(re.findall('Sen2Cor-(\d{2}\.\d{2}\.\d{2})', str(sen2cor_bashrc_path))), None)
-    s2c_v = get_current_Sen2Cor_version()
-    l2a_product_path_tmp = l2a_product_path.parent / (
-        l2a_product_path.stem + ".tmp"
-    )
-
-    if s2c_v == "02.05.05":
-        logger.info(
-            "sen2cor {} processing: {}".format(s2c_v, l1c_product_path)
-        )
-        if resolution == 10:
-
-            logger.info("sen2cor processing 20 m: {}".format(l1c_product_path))
-            command1 = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --resolution {res} {l1c_folder}".format(
-                sen2cor_bashrc=str(sen2cor_bashrc_path),
-                res=20,
-                l1c_folder=str(l1c_product_path),
-            )
+    # s2c_v = get_current_Sen2Cor_version()
+    # l2a_product_path_tmp = l2a_product_path.parent / (
+        # l2a_product_path.stem + ".tmp"
+    # )
+
+    # if s2c_v == "02.05.05":
+        # logger.info(
+            # "sen2cor {} processing: {}".format(s2c_v, l1c_product_path)
+        # )
+        # if resolution == 10:
+
+            # logger.info("sen2cor processing 20 m: {}".format(l1c_product_path))
+            # command1 = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --resolution {res} {l1c_folder}".format(
+                # sen2cor_bashrc=str(sen2cor_bashrc_path),
+                # res=20,
+                # l1c_folder=str(l1c_product_path),
+            # )
 
-            process1 = subprocess.run(command1.split(", "))
+            # process1 = subprocess.run(command1.split(", "))
 
-            logger.info("sen2cor processing 10 m: {}".format(l1c_product_path))
-            command2 = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --resolution {res} {l1c_folder}".format(
-                sen2cor_bashrc=str(sen2cor_bashrc_path),
-                res=10,
-                l1c_folder=str(l1c_product_path),
-            )
-            process2 = subprocess.run(command2.split(", "))
+            # logger.info("sen2cor processing 10 m: {}".format(l1c_product_path))
+            # command2 = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --resolution {res} {l1c_folder}".format(
+                # sen2cor_bashrc=str(sen2cor_bashrc_path),
+                # res=10,
+                # l1c_folder=str(l1c_product_path),
+            # )
+            # process2 = subprocess.run(command2.split(", "))
 
-        else:
-            logger.debug("sen2cor processing: {}".format(l1c_product_path))
-            command = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --resolution {resolution} {l1c_folder}".format(
-                sen2cor_bashrc=str(sen2cor_bashrc_path),
-                resolution=resolution,
-                l1c_folder=str(l1c_product_path),
-            )
-            process = subprocess.run(command.split(", "))
+        # else:
+            # logger.debug("sen2cor processing: {}".format(l1c_product_path))
+            # command = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --resolution {resolution} {l1c_folder}".format(
+                # sen2cor_bashrc=str(sen2cor_bashrc_path),
+                # resolution=resolution,
+                # l1c_folder=str(l1c_product_path),
+            # )
+            # process = subprocess.run(command.split(", "))
 
-    elif s2c_v in ["02.08.00", "02.09.00", "02.10.01"]:
-        logger.info(
-            "sen2cor {} processing: {}".format(s2c_v, l1c_product_path)
-        )
-        command = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --processing_baseline {processing_baseline} --output_dir {out_dir} {l1c_folder}".format(
-            sen2cor_bashrc=str(sen2cor_bashrc_path),
-            processing_baseline=pb,
-            out_dir=l2a_product_path_tmp,
-            l1c_folder=str(l1c_product_path),
-        )
-        process = subprocess.run(command.split(", "))
-        sorted(l2a_product_path_tmp.glob("*.SAFE"))[0].rename(
-            l2a_product_path.parent / (l2a_product_path.stem + ".SAFE")
-        )
-        l2a_product_path_tmp.rmdir()
-
-    elif s2c_v is not None:
-        logger.info(
-            "Sen2Cor version {} is not compatible with Sen2Chain".format(s2c_v)
-        )
+    # elif s2c_v in ["02.08.00", "02.09.00", "02.10.01"]:
+        # logger.info(
+            # "sen2cor {} processing: {}".format(s2c_v, l1c_product_path)
+        # )
+        # command = "/bin/bash, -c, source {sen2cor_bashrc} && L2A_Process --processing_baseline {processing_baseline} --output_dir {out_dir} {l1c_folder}".format(
+            # sen2cor_bashrc=str(sen2cor_bashrc_path),
+            # processing_baseline=pb,
+            # out_dir=l2a_product_path_tmp,
+            # l1c_folder=str(l1c_product_path),
+        # )
+        # process = subprocess.run(command.split(", "))
+        # sorted(l2a_product_path_tmp.glob("*.SAFE"))[0].rename(
+            # l2a_product_path.parent / (l2a_product_path.stem + ".SAFE")
+        # )
+        # l2a_product_path_tmp.rmdir()
+
+    # elif s2c_v is not None:
+        # logger.info(
+            # "Sen2Cor version {} is not compatible with Sen2Chain".format(s2c_v)
+        # )
 
-    else:
-        logger.info(
-            'Could not determine sen2cor version from path, please check pattern "Sen2Cor-**.**.**" is in path'
-        )
+    # else:
+        # logger.info(
+            # 'Could not determine sen2cor version from path, please check pattern "Sen2Cor-**.**.**" is in path'
+        # )
 # >>>>>>> 571a1f934055bd9bc242e2f3dde14e38a7f4b5ca
-- 
GitLab