Commit abaf77c8 authored by Germain Salgues's avatar Germain Salgues

ENH:add support for L8 new format in snow_annual_map

parent 6b1ef554
......@@ -132,7 +132,17 @@ class snow_annual_map():
self.use_l8_for_densification = params.get("use_l8_for_densification", False)
if self.use_l8_for_densification:
self.l8_tile_id = params.get("l8_tile_id")
self.l8_input_dir = str(params.get("l8_input_dir"))
self.l8_input_dir = str(op.join(params.get("l8_input_dir"), self.l8_tile_id))
if not os.path.exists(self.l8_input_dir) or not self.l8_tile_id:
logging.error("Cannot use L8 densification with "
+ str(self.l8_tile_id)
+ ", "
+ self.l8_input_dir)
else:
logging.info("Using L8 densification with "
+ str(self.l8_tile_id)
+ ", "
+ self.l8_input_dir)
# Define label for output snow product
self.label_no_snow = "0"
......@@ -158,7 +168,7 @@ class snow_annual_map():
os.environ["ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS"] = str(self.nbThreads)
# search matching snow product
self.product_list = self.find_products(self.input_dir, self.tile_id)
self.product_list = self.find_products(self.input_dir, self.tile_id, "SENTINEL2")
logging.debug("Product list:")
logging.debug(self.product_list)
......@@ -169,7 +179,7 @@ class snow_annual_map():
# @TODO clean the loading of the L8 products to densify the timeserie
if self.use_l8_for_densification:
# search matching L8 snow product
l8_product_list = self.find_products(self.l8_input_dir, self.l8_tile_id)
l8_product_list = self.find_products(self.l8_input_dir, self.l8_tile_id, "LANDSAT8")
logging.info("L8 product list:")
logging.info(l8_product_list)
......@@ -315,7 +325,7 @@ class snow_annual_map():
shutil.copytree(self.path_tmp, dest_debug_dir)
def find_products(self, input_dir, tile_id):
def find_products(self, input_dir, tile_id, product_type=None):
logging.info("Retrieving products in " + input_dir)
product_files = os.listdir(input_dir)
product_list = []
......@@ -329,7 +339,9 @@ class snow_annual_map():
if tile_id in product.tile_id and \
search_start_date <= product.acquisition_date and \
search_stop_date >= product.acquisition_date:
product_list.append(product)
if (product_type is not None) and (product_type in product.platform):
product_list.append(product)
logging.info("Keeping: " + str(product))
except Exception:
logging.error("Unable to load product :" + product_path)
return product_list
......
......@@ -123,7 +123,7 @@ class snow_annual_map_evaluation(snow_annual_map):
snow_annual_map.__init__(self, params)
self.l8_tile_id = params.get("l8_tile_id")
self.l8_input_dir = str(params.get("l8_input_dir"))
self.l8_input_dir = str(op.join(params.get("l8_input_dir"), self.l8_tile_id))
# Build useful paths
self.l8_dates_filename = op.join(self.path_tmp, "l8_inputs_dates.txt")
......@@ -149,7 +149,7 @@ class snow_annual_map_evaluation(snow_annual_map):
os.environ["ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS"] = str(self.nbThreads)
# search matching L8 snow product
self.product_list = self.find_products(self.l8_input_dir, self.l8_tile_id)
self.product_list = self.find_products(self.l8_input_dir, self.l8_tile_id, "LANDSAT8")
logging.debug("Product list:")
logging.debug(self.product_list)
......
......@@ -614,6 +614,7 @@ class snow_detector:
mask = x**2 + y**2 <= radius**2
struct[mask] = 1
# compute individual snow area size
(labels, label_counts)= np.unique(snowlabels, return_counts=True)
labels_area = dict(zip(labels, label_counts))
logging.debug(labels_area)
......
......@@ -57,7 +57,13 @@ class snow_product:
self.tile_id = name_splitted[3]
self.flag = name_splitted[4]
self.product_version = name_splitted[5]
elif "LANDSAT8" in self.platform:
elif "LANDSAT8-OLITIRS-XS" == self.platform:
self.acquisition_date = str_to_datetime(name_splitted[1], MUSCATE_DATETIME_FORMAT)
self.product_level = name_splitted[2]
self.tile_id = name_splitted[3]
self.flag = name_splitted[4]
self.product_version = name_splitted[5]
elif "LANDSAT8" in self.platform and "N2A" in self.product_name:
self.acquisition_date = str_to_datetime(name_splitted[3], "%Y%m%d")
self.product_level = name_splitted[4]
self.tile_id = name_splitted[5]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment