Skip to content

Commit

Permalink
Fix tests that write files to same location.
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileSonneveld committed Oct 15, 2024
1 parent 46b092e commit bcf9cc6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import org.apache.spark.{SparkConf, SparkContext}
import org.junit.jupiter.api.Assertions.{assertEquals, assertFalse, assertTrue}
import org.junit.jupiter.api.{AfterAll, BeforeAll, Test}

import java.nio.file.{Files, Paths}
import java.time.format.DateTimeFormatter
import java.time.{LocalDate, LocalTime, ZoneOffset, ZonedDateTime}
import java.util
import scala.reflect.io.Directory

object ProbaVPyramidFactoryTest {
private var sc: SparkContext = _
Expand Down Expand Up @@ -108,6 +110,10 @@ class ProbaVPyramidFactoryTest extends RasterMatchers {

@Test
def writeS10NDVIGeoTiffs(): Unit = {
val outDir = Paths.get("tmp/writeS10NDVIGeoTiffs/")
new Directory(outDir.toFile).deepFiles.foreach(_.delete())
Files.createDirectories(outDir)

val boundingBox = ProjectedExtent(Extent(xmin = 2.5, ymin = 49.5, xmax = 2.55, ymax = 49.55), LatLng)
val from = ZonedDateTime.of(LocalDate.of(2019, 8, 1), LocalTime.MIDNIGHT, ZoneOffset.UTC)
val to = from plusDays 2
Expand All @@ -125,7 +131,7 @@ class ProbaVPyramidFactoryTest extends RasterMatchers {
assertTrue(baseLayer.partitioner.get.isInstanceOf[SpacePartitioner[SpaceTimeKey]])
println(s"got ${baseLayer.count()} tiles")
val cropBounds = boundingBox.reproject(baseLayer.metadata.crs)
val timestampedFiles = org.openeo.geotrellis.geotiff.saveRDDTemporal(baseLayer,"./",cropBounds = Some(cropBounds))
val timestampedFiles = org.openeo.geotrellis.geotiff.saveRDDTemporal(baseLayer,outDir.toString,cropBounds = Some(cropBounds))
assertEquals(1, timestampedFiles.size())
val (fileName, timestamp, bbox) = timestampedFiles.get(0)
assertEquals("2019-08-01T00:00:00Z", timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class GlobalNetCdfFileLayerProviderTest {

layer
.toSpatial(date)
.writeGeoTiff("/tmp/lai300_georgia2.tif")
.writeGeoTiff("/tmp/lai300_georgia2_readTileLayer.tif")
}

@Test
Expand All @@ -101,7 +101,7 @@ class GlobalNetCdfFileLayerProviderTest {

layer
.toSpatial(date)
.writeGeoTiff("/tmp/lai300_georgia2.tif")
.writeGeoTiff("/tmp/lai300_georgia2_readDataCube.tif")
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ class Sentinel2FileLayerProviderTest extends RasterMatchers {
builder.argumentEnd()
builder.constantArgument("y", 6)
builder.expressionEnd("gte", args)
mask.toSpatial(date).writeGeoTiff("tmp/Sentinel2FileLayerProvider_multiband_SCL.tif", bbox)
mask.toSpatial(date).writeGeoTiff(f"tmp/Sentinel2FileLayerProvider_multiband_SCL_${parameters.hashCode()}.tif", bbox)
val p = new OpenEOProcesses()
mask = p.mapBands(mask, builder)
mask.toSpatial(date).writeGeoTiff("tmp/Sentinel2FileLayerProvider_multiband_mask.tif", bbox)
mask.toSpatial(date).writeGeoTiff(f"tmp/Sentinel2FileLayerProvider_multiband_mask_${parameters.hashCode()}.tif", bbox)

var layer = tocLayerProvider.readMultibandTileLayer(from = date, to = date, bbox, Array(MultiPolygon(bbox.extent.toPolygon())),bbox.crs, sc = sc,zoom = 14,datacubeParams = Option.empty)

Expand All @@ -311,10 +311,10 @@ class Sentinel2FileLayerProviderTest extends RasterMatchers {
.toSpatial(date)
.cache()

spatialLayer.writeGeoTiff("tmp/Sentinel2FileLayerProvider_multiband.tif", bbox)
spatialLayer.writeGeoTiff(f"tmp/Sentinel2FileLayerProvider_multiband_${parameters.hashCode()}.tif", bbox)
assertNotEquals(originalCount,maskedCount)

val resultTiff = GeoTiff.readMultiband("tmp/Sentinel2FileLayerProvider_multiband.tif")
val resultTiff = GeoTiff.readMultiband(f"tmp/Sentinel2FileLayerProvider_multiband_${parameters.hashCode()}.tif")

val refFile = Thread.currentThread().getContextClassLoader.getResource("org/openeo/geotrellis/Sentinel2FileLayerProvider_multiband_reference.tif")
val refTiff = GeoTiff.readMultiband(refFile.getPath)
Expand Down

0 comments on commit bcf9cc6

Please sign in to comment.