From c2244d1dc486cd70322efe56cc88e1145f2f09ae Mon Sep 17 00:00:00 2001
From: "julie.mlls" <julie.mollies.pro@gmail.com>
Date: Tue, 3 Dec 2024 15:49:01 +0400
Subject: [PATCH] Integration de jpylyzer dans clean_lib pour detection des jp2
 non valides

---
 sen2chain/tiles.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/sen2chain/tiles.py b/sen2chain/tiles.py
index 998d888..07bb370 100644
--- a/sen2chain/tiles.py
+++ b/sen2chain/tiles.py
@@ -21,6 +21,7 @@ from pprint import pformat
 import multiprocessing
 from queue import Queue
 from threading import Thread
+from jpylyzer import jpylyzer
 
 # type annotations
 from typing import List, Dict, Iterable
@@ -1858,6 +1859,27 @@ class Tile:
                         )
                         f.unlink()
                         nb_rm += 1
+            
+            # check jp2 validity 
+            for key, sub_path in self._paths["indices"].items():
+                sub_path = Path(sub_path)  # Convertit le chemin en objet Path
+                print(f"Exploration du dossier {key}: {sub_path}")
+                for jp2_file in sub_path.rglob("*.jp2"):
+                    #print(f"  - Fichier : {jp2_file}")
+                    test_validity = jpylyzer.checkOneFile(jp2_file).findtext('isValid')
+                    if test_validity == 'False':
+                        txt = "Invalid jp2 {} (jpylyzer)".format(jp2_file.name)
+                        prob_id.append(txt)
+                        logger.info(txt)
+                        nb_id += 1
+                        if remove:
+                            logger.info(
+                                "Removing invalid jp2 {} from L2A folder".format(
+                                    jp2_file.name
+                                )
+                            )
+                            jp2_file.unlink()
+                            nb_rm += 1
                         
         # identify 0B or absent indice QL
         """
-- 
GitLab