Skip to content

Commit

Permalink
Use uuid (unique identifier) for vrt files
Browse files Browse the repository at this point in the history
  • Loading branch information
ghislainv committed Jun 17, 2024
1 parent 5ec7a54 commit 87359ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
7 changes: 5 additions & 2 deletions forestatrisk/data/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from glob import glob # To explore files in a folder
import os # Operating system interfaces
import sys # To read and write files
import uuid

# Third party imports
import numpy as np # For arrays
Expand Down Expand Up @@ -263,8 +264,10 @@ def sample(
yRes=-gt[5],
separate=True,
)
gdal.BuildVRT("/vsimem/var.vrt", raster_list, options=param)
stack = gdal.Open("/vsimem/var.vrt")
rand_uuid = uuid.uuid4()
vrt_file = f"/vsimem/var_{rand_uuid}.vrt"
gdal.BuildVRT(vrt_file, raster_list, options=param)
stack = gdal.Open(vrt_file)

# List of nodata values
nband = stack.RasterCount
Expand Down
10 changes: 3 additions & 7 deletions forestatrisk/predict/predict_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from glob import glob
import os
import sys
import random
import uuid

# Third party imports
import numpy as np
Expand Down Expand Up @@ -91,8 +91,8 @@ def predict_raster(
yRes=-gt[5],
separate=True,
)
rand_int = random.randint(1, 999999)
vrt_file = f"/vsimem/var_{rand_int:06}.vrt"
rand_uuid = uuid.uuid4()
vrt_file = f"/vsimem/var_{rand_uuid}.vrt"
cback = gdal.TermProgress if verbose else 0
gdal.BuildVRT(vrt_file, raster_list,
options=param, callback=cback)
Expand Down Expand Up @@ -213,10 +213,6 @@ def predict_raster(
Pband.FlushCache() # Write cache data to disk
Pband.ComputeStatistics(False)

# # Build overviews
# print("Build overviews")
# Pdrv.BuildOverviews("nearest", [4, 8, 16, 32])

# Dereference driver
Pband = None
del Pdrv
Expand Down
6 changes: 3 additions & 3 deletions forestatrisk/predict/predict_raster_binomial_iCAR.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from glob import glob
import os
import sys
import random
import uuid

# Third party imports
import numpy as np
Expand Down Expand Up @@ -109,8 +109,8 @@ def predict_raster_binomial_iCAR(
yRes=-gt[5],
separate=True,
)
rand_int = random.randint(1, 999999)
vrt_file = f"/vsimem/var_{rand_int:06}.vrt"
rand_uuid = uuid.uuid4()
vrt_file = f"/vsimem/var_{rand_uuid}.vrt"
cback = gdal.TermProgress if verbose else 0
gdal.BuildVRT(vrt_file, raster_list,
options=param, callback=cback)
Expand Down

0 comments on commit 87359ee

Please sign in to comment.