From e1997c102e6ee7c5f5b4985ab7fb121ea6f341c9 Mon Sep 17 00:00:00 2001 From: xhong Date: Tue, 5 Aug 2025 17:21:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(DEM=5FSuPER):=20=E4=BF=AE=E5=A4=8DDEM?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=B8=8B=E8=BD=BD=E6=8B=BC=E6=8E=A5=E9=80=BB?= =?UTF-8?q?=E8=BE=91bug.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DATA_SuPER/DEM_SuPER.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/DATA_SuPER/DEM_SuPER.py b/DATA_SuPER/DEM_SuPER.py index 737ba0a..ad54b95 100644 --- a/DATA_SuPER/DEM_SuPER.py +++ b/DATA_SuPER/DEM_SuPER.py @@ -22,7 +22,7 @@ Step2: Process DEM data ------------------------------------------------------------------------------- Authors: Hong Xie -Last Updated: 2025-07-03 +Last Updated: 2025-08-05 =============================================================================== """ @@ -183,14 +183,14 @@ def process_granule( dem.rio.write_crs("EPSG:4326", inplace=True) dem.attrs["scale_factor"] = 1 dem_raster_list.append(dem) - if len(dem_raster_list) > 1: + if len(dem_raster_list) >= 1: if name == "slope" or name == "aspect": dem_mosaiced = mosaic_images(dem_raster_list, nodata=-9999) else: dem_mosaiced = mosaic_images(dem_raster_list, nodata=-32768) - if roi is not None and clip: - dem_mosaiced = clip_image(dem_mosaiced, roi) - dem_mosaiced.rio.to_raster(output_file, driver="COG", compress="DEFLATE") + if roi is not None and clip: + dem_mosaiced = clip_image(dem_mosaiced, roi, clip_by_box=True) + dem_mosaiced.rio.to_raster(output_file, driver="COG", compress="DEFLATE") except Exception as e: logging.error(f"Error processing files in {name}: {e}") return False @@ -211,6 +211,7 @@ def main(region: list, asset_name: list, tile_id: str): unzip_dir = os.path.join(download_dir, "UNZIP") output_dir = os.path.join(output_root_dir, "TIF", tile_id) os.makedirs(unzip_dir, exist_ok=True) + os.makedirs(output_dir, exist_ok=True) results_urls_file = f"{output_root_dir}\\NASADEM_{tile_id}_results_urls.json" if not os.path.isfile(results_urls_file): results_urls = earthdata_search(asset_name, roi=bbox)