From 52ef34668adca509cc2c1931a1e73860901667f5 Mon Sep 17 00:00:00 2001 From: Cameron Bodine Date: Thu, 8 Feb 2024 04:15:11 -0700 Subject: [PATCH] Update substrate mosaic with warning --- utils/main_substrate_mosaic_transects.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/utils/main_substrate_mosaic_transects.py b/utils/main_substrate_mosaic_transects.py index 08b4a7d..678b35f 100644 --- a/utils/main_substrate_mosaic_transects.py +++ b/utils/main_substrate_mosaic_transects.py @@ -27,6 +27,9 @@ # SOFTWARE. ''' +WARNING: This is terribly inefficient on large areas. +Ubuntu: gdal_calc doesn't run + This script will mosaic substrate prediction maps from overlapping transects: 1) Create a VRT for a rivers substrate predictions maps (logits) 2) Apply a pixel function (average, min, max, etc.) to handle overlapping pixels @@ -72,11 +75,12 @@ ################# # Directory and Project Name -transectDir = r'./procData/' +transectDir = r'/mnt/md0/SynologyDrive/GulfSturgeonProject/SSS_Data_Processed/EGN_Test_Substrate_Mosaic' projName = 'Test_Transect_Mosaic' pix_fn = 'average' -scriptFile = r"C:\Users\csb67\AppData\Local\miniconda3\envs\ping\Scripts\gdal_calc.py" +# scriptFile = r"C:\Users\csb67\AppData\Local\miniconda3\envs\ping\Scripts\gdal_calc.py" +scriptFile = "/home/cbodine/miniconda3/envs/ping/bin/gdal_calc.py" @@ -370,6 +374,7 @@ def build_gtiff(vrt, outTIF): bandCount, bandDtype = getTiffAttributes(files[0]) # Build vrt + print('Building VRT') vrtName = '_'.join([name, 'substrate', 'logit', 'rast', 'transect', 'mosaic']) + '.vrt' outVRT_mosaic = os.path.join(projDir, vrtName) build_vrt(outVRT_mosaic, files) @@ -379,9 +384,12 @@ def build_gtiff(vrt, outTIF): add_pixel_fn(outVRT_mosaic, pix_fn, b, bandCount, bandDtype) # Create gtiff mosaic from vrt + print('Mosaic Logits') outTIF_mosaic = outVRT_mosaic.replace('.vrt', '.tif') build_gtiff(outVRT_mosaic, outTIF_mosaic) + # Do classification + print('Classifying Substrate') # https://courses.spatialthoughts.com/gdal-tools.html#calculate-pixel-wise-statistics-over-multiple-rasters # https://github.com/Doodleverse/dash_doodler/blob/41ce96b8c341c591bfa1c0d467dc6290b2e31963/website/blog/2020-08-01-blog-post.md # https://gis.stackexchange.com/questions/417936/gdal-calc-in-python-without-gdal-path @@ -410,7 +418,6 @@ def build_gtiff(vrt, outTIF): expr = '"numpy.argmax((numpy.dstack((B,C,D,E,F,G,H))/100), axis=2)"' f = '"Int8"' outTIF_class = outTIF_mosaic.replace('.tif', '_class.tif') - scriptFile = r"C:\Users\csb67\AppData\Local\miniconda3\envs\ping\Scripts\gdal_calc.py" calc_process = gdal_calc_str.format(outTIF_mosaic, outTIF_class, expr, f, scriptFile)