From 856df02e573be975b00d2b97e74a5df7281ef63d Mon Sep 17 00:00:00 2001 From: Tharles de Sousa Andrade Date: Sat, 12 Oct 2024 15:44:05 -0300 Subject: [PATCH] Fix sentinel imagens --- app/api/layers.py | 38 +++++++++++++++++--------------------- app/visParam.py | 6 ------ 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/app/api/layers.py b/app/api/layers.py index ed1562e..da24df3 100644 --- a/app/api/layers.py +++ b/app/api/layers.py @@ -47,7 +47,6 @@ async def get_s2_harmonized( month: int = int(datetime.now().month), ): - logger.info(f'period {period}, year {year}, month {month}') metadata = list(filter(lambda x: x['name'] == 's2_harmonized', CAPABILITIES['collections']))[0] if not year in metadata['year']: @@ -71,7 +70,7 @@ async def get_s2_harmonized( "dtStart": f"{year}-{month:02}-01", "dtEnd": f"{year}-{month:02}-{last_day:02}" } - + logger.info(f'month: {month}') if not (9 < z < 19): logger.debug('zoom ') return FileResponse('data/maxminzoom.png', media_type="image/png") @@ -92,8 +91,7 @@ async def get_s2_harmonized( logger.info(f'period {period}, year {year}, month {month}, period_select {period_select}') _geohash, bbox = tile2goehashBBOX(x, y, z) - path_cache = f's2_harmonized_{period_select["name"]}_{year}_{visparam}/{_geohash}' - + path_cache = f's2_harmonized_{period_select["name"]}_{year}_{month}_{visparam}/{_geohash}' file_cache = f"{path_cache}/{z}/{x}_{y}.png" binary_data = request.app.state.valkey.get(file_cache) @@ -110,17 +108,17 @@ async def get_s2_harmonized( ): try: - logger.debug(f"New url: {path_cache}") + # logger.debug(f"New url: {path_cache}") geom = ee.Geometry.BBox(bbox["w"], bbox["s"], bbox["e"], bbox["n"]) - s2 = ee.ImageCollection("COPERNICUS/S2_HARMONIZED") - s2 = s2.filterDate( - period_select["dtStart"], period_select["dtEnd"] - ).filterBounds(geom) - s2 = s2.sort("CLOUDY_PIXEL_PERCENTAGE", False) - s2 = s2.select(*_visparam["select"]) + logger.info(f'range date: {period_select["dtStart"]}, {period_select["dtEnd"]}') + s2 = (ee.ImageCollection("COPERNICUS/S2_HARMONIZED") + .filterDate(period_select["dtStart"], period_select["dtEnd"]) + .filterBounds(geom) + .sort("CLOUDY_PIXEL_PERCENTAGE", False) + .select(*_visparam["select"])) best_image = s2.mosaic() - - logger.debug(f'{_visparam["select"]} | {_visparam["visparam"]}') + + # logger.debug(f'{_visparam["select"]} | {_visparam["visparam"]}') map_id = ee.data.getMapId({"image": best_image, **_visparam["visparam"]}) layer_url = map_id["tile_fetcher"].url_format @@ -220,18 +218,16 @@ async def get_landsat( geom = ee.Geometry.BBox(bbox["w"], bbox["s"], bbox["e"], bbox["n"]) period_year = datetime.strptime(period_select["dtStart"], "%Y-%m-%d").year - if 1983 <= period_year <= 1993: - collection_name = 'LANDSAT/LT04/C02/T1_L2' - elif 1984 <= period_year <= 2012: - collection_name = 'LANDSAT/LT05/C02/T1_L2' + if 1984 <= period_year <= 2012: + collection_name = 'LANDSAT/LT05/C02/T1_L2' # Landsat 5 elif 1999 <= period_year <= 2022: - collection_name = 'LANDSAT/LE07/C02/T1_L2' + collection_name = 'LANDSAT/LE07/C02/T1_L2' # Landsat 7 elif 2013 <= period_year <= 2022: - collection_name = 'LANDSAT/LC08/C02/T1_L2' + collection_name = 'LANDSAT/LC08/C02/T1_L2' # Landsat 8 elif period_year >= 2022: - collection_name = 'LANDSAT/LC09/C02/T1_L2' + collection_name = 'LANDSAT/LC09/C02/T1_L2' # Landsat 9 else: - raise ValueError("No valid Landsat collection for the provided date range") + raise ValueError("No valid Landsat collection (Landsat 5 onwards) for the provided date range") vis_params = get_landsat_vis_params(visparam, collection_name) diff --git a/app/visParam.py b/app/visParam.py index 952a5d7..eb7da28 100644 --- a/app/visParam.py +++ b/app/visParam.py @@ -28,8 +28,6 @@ }, 'landsat-tvi-true': { "visparam": { - 'LANDSAT/LT04/C02/T1_L2': {'bands': ['SR_B3', 'SR_B2', 'SR_B1'], 'min': [0.03, 0.03, 0.0], - 'max': [0.25, 0.25, 0.25], 'gamma': [1.2]}, 'LANDSAT/LT05/C02/T1_L2': {'bands': ['SR_B3', 'SR_B2', 'SR_B1'], 'min': [0.03, 0.03, 0.0], 'max': [0.25, 0.25, 0.25], 'gamma': [1.2]}, 'LANDSAT/LE07/C02/T1_L2': {'bands': ['SR_B3', 'SR_B2', 'SR_B1'], 'min': [0.03, 0.03, 0.0], @@ -42,8 +40,6 @@ }, 'landsat-tvi-agri': { "visparam": { - 'LANDSAT/LT04/C02/T1_L2': {'bands': ['SR_B5', 'SR_B4', 'SR_B3'], 'min': [0.05, 0.05, 0.03], - 'max': [0.5, 0.55, 0.3], 'gamma': [0.9]}, 'LANDSAT/LT05/C02/T1_L2': {'bands': ['SR_B5', 'SR_B4', 'SR_B3'], 'min': [0.05, 0.05, 0.03], 'max': [0.5, 0.55, 0.3], 'gamma': [0.9]}, 'LANDSAT/LE07/C02/T1_L2': {'bands': ['SR_B5', 'SR_B4', 'SR_B3'], 'min': [0.05, 0.05, 0.03], @@ -56,8 +52,6 @@ }, 'landsat-tvi-false': { "visparam": { - 'LANDSAT/LT04/C02/T1_L2': {'bands': ['SR_B4', 'SR_B5', 'SR_B3'], 'min': [0.05, 0.05, 0.03], - 'max': [0.6, 0.55, 0.3], 'gamma': [1.2]}, 'LANDSAT/LT05/C02/T1_L2': {'bands': ['SR_B4', 'SR_B5', 'SR_B3'], 'min': [0.05, 0.05, 0.03], 'max': [0.6, 0.55, 0.3], 'gamma': [1.2]}, 'LANDSAT/LE07/C02/T1_L2': {'bands': ['SR_B5', 'SR_B4', 'SR_B3'], 'min': [0.05, 0.05, 0.03],