Skip to content

Commit

Permalink
Fix sentinel imagens
Browse files Browse the repository at this point in the history
  • Loading branch information
tharlestsa committed Oct 12, 2024
1 parent 383eddf commit 856df02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
38 changes: 17 additions & 21 deletions app/api/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 0 additions & 6 deletions app/visParam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
Expand All @@ -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],
Expand Down

0 comments on commit 856df02

Please sign in to comment.