-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow setting tiff scale + offset + custom metadata #317
allow setting tiff scale + offset + custom metadata #317
Comments
example of custom metadata: https://github.com/VITO-RS-Vegetation/lcfm-production/issues/18 |
For tiffset, we would need to add libtiff-tools to the container. |
The current metadata, visible through gdalinfo, is: Metadata: both can stay, but what we are looking for is: Metadata: So this would be something quite flexible. We are setting the metadata through rasterio (python) and passing a dictionary:
Additionally, there is a difference in how we set the band description and how OpenEO does it: We: The description in OpenEO is at metadata level, which makes that the band names are not displayed in the symbology in Qgis. Relatedly, as you see in the output, there's an offset and scale on every band. In principle, the offset and scale can be different per band. |
Just checking whether this issue is already planned? |
We set the scale and offset through gdal_translate: |
Regardless of how we put them in the GeoTiff, will the user also provide values for scale/offset in the format options? |
I could get this to work:
where:
|
The spec demands that TIFF tiles have a tile size that is a multiple of 16. We write GeoTIFFs with a tile size that is equal to the TileLayerRDD's tile size so a tile size of 4 will produce GeoTiffs that are not compliant. Some tools cope, like gdalinfo (with a warning), but some will simply fail, like tiffset. Open-EO/openeo-geotrellis-extensions#317
Runs locally but tests in Jenkins fail with a segmentation fault:
|
Possible method to get core dumps within the container: https://stackoverflow.com/a/72048923. |
The segfault can be reproduced in kubernetes, but it does seem to depend on the exact tag and value, as I was able to set for instance the description tag. dmesg entry for segfaults is not so helpfull:
|
Found a potential solution: you can also set tag values via a file, and that seems to avoid the segfault. |
Oh dear. That does seem to work. 👍 |
Remaining work:
|
KeyError: DESCRIPTION Open-EO/openeo-geotrellis-extensions#317
py4j.protocol.Py4JJavaError: An error occurred while calling z:org.openeo.geotrellis.geotiff.package.saveRDDAllowAssetPerBand. : java.io.IOException: tiffset -sf 42112 /tmp/GDALMetadata_14266360818144674820.xml.tmp /tmp/18350960666773006729.tif failed; output was: _TIFFVSetField: /tmp/18350960666773006729.tif: Bad value 5 for "TileWidth" tag. at org.openeo.geotrellis.geotiff.package$.embedGdalMetadata(package.scala:940) at org.openeo.geotrellis.geotiff.package$.$anonfun$writeGeoTiff$2(package.scala:839) at org.openeo.geotrellis.geotiff.package$.$anonfun$writeGeoTiff$2$adapted(package.scala:839) at scala.Option.foreach(Option.scala:407) at org.openeo.geotrellis.geotiff.package$.writeGeoTiff(package.scala:839) at org.openeo.geotrellis.geotiff.package$.writeTiff(package.scala:588) at org.openeo.geotrellis.geotiff.package$.saveRDDGeneric(package.scala:415) at org.openeo.geotrellis.geotiff.package$.saveRDDAllowAssetPerBand(package.scala:254) at org.openeo.geotrellis.geotiff.package.saveRDDAllowAssetPerBand(package.scala) at jdk.internal.reflect.GeneratedMethodAccessor439.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:374) at py4j.Gateway.invoke(Gateway.java:282) at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) at py4j.commands.CallCommand.execute(CallCommand.java:79) at py4j.ClientServerConnection.waitForCommands(ClientServerConnection.java:182) at py4j.ClientServerConnection.run(ClientServerConnection.java:106) at java.base/java.lang.Thread.run(Thread.java:829) Open-EO/openeo-geotrellis-extensions#317
Specify band-specific scale, offset and other metadata in the {
"bands_metadata": {
"Flat:1": {
"SCALE": 1.23
},
"Flat:2": {
"OFFSET": 4.56
},
"Flat:3": {
"SCALE": 7.89,
"OFFSET": 10.11,
"ARBITRARY": "value"
}
}
} |
* use tiffset to write GDAL metadata with "role" support Open-EO/openeo-geotrellis-extensions#317 * encapsulate tiffset Open-EO/openeo-geotrellis-extensions#317 * fix tests that rely on test layer with tile size 4 The spec demands that TIFF tiles have a tile size that is a multiple of 16. We write GeoTIFFs with a tile size that is equal to the TileLayerRDD's tile size so a tile size of 4 will produce GeoTiffs that are not compliant. Some tools cope, like gdalinfo (with a warning), but some will simply fail, like tiffset. Open-EO/openeo-geotrellis-extensions#317 * fix some tests Open-EO/openeo-geotrellis-extensions#317 * try workaround for tiffset segfault in container Open-EO/openeo-geotrellis-extensions#317 * fix tests Open-EO/openeo-geotrellis-extensions#317 * add TODOs Open-EO/openeo-geotrellis-extensions#317 * test tiffset Open-EO/openeo-geotrellis-extensions#317 * fix tests Open-EO/openeo-geotrellis-extensions#317 * fix interaction with asset-per-band Open-EO/openeo-geotrellis-extensions#317 * include details if tiffset fails Open-EO/openeo-geotrellis-extensions#317 * simplify asset-per-band mapping Open-EO/openeo-geotrellis-extensions#317 * tiffset is called from Scala instead + adapt/add tests Open-EO/openeo-geotrellis-extensions#317 * cleanup Open-EO/openeo-geotrellis-extensions#317 * fix tests KeyError: DESCRIPTION Open-EO/openeo-geotrellis-extensions#317 * quick fix test py4j.protocol.Py4JJavaError: An error occurred while calling z:org.openeo.geotrellis.geotiff.package.saveRDDAllowAssetPerBand. : java.io.IOException: tiffset -sf 42112 /tmp/GDALMetadata_14266360818144674820.xml.tmp /tmp/18350960666773006729.tif failed; output was: _TIFFVSetField: /tmp/18350960666773006729.tif: Bad value 5 for "TileWidth" tag. at org.openeo.geotrellis.geotiff.package$.embedGdalMetadata(package.scala:940) at org.openeo.geotrellis.geotiff.package$.$anonfun$writeGeoTiff$2(package.scala:839) at org.openeo.geotrellis.geotiff.package$.$anonfun$writeGeoTiff$2$adapted(package.scala:839) at scala.Option.foreach(Option.scala:407) at org.openeo.geotrellis.geotiff.package$.writeGeoTiff(package.scala:839) at org.openeo.geotrellis.geotiff.package$.writeTiff(package.scala:588) at org.openeo.geotrellis.geotiff.package$.saveRDDGeneric(package.scala:415) at org.openeo.geotrellis.geotiff.package$.saveRDDAllowAssetPerBand(package.scala:254) at org.openeo.geotrellis.geotiff.package.saveRDDAllowAssetPerBand(package.scala) at jdk.internal.reflect.GeneratedMethodAccessor439.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:374) at py4j.Gateway.invoke(Gateway.java:282) at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) at py4j.commands.CallCommand.execute(CallCommand.java:79) at py4j.ClientServerConnection.waitForCommands(ClientServerConnection.java:182) at py4j.ClientServerConnection.run(ClientServerConnection.java:106) at java.base/java.lang.Thread.run(Thread.java:829) Open-EO/openeo-geotrellis-extensions#317 * update version and CHANGELOG Open-EO/openeo-geotrellis-extensions#317
Available on CDSE-dev. Example process graph: {
"process_graph": {
"loadcollection1": {
"arguments": {
"bands": [
"B04",
"B03",
"B02"
],
"id": "SENTINEL2_L2A",
"spatial_extent": {
"east": 5.506705419643688,
"north": 50.35658998840864,
"south": 50.35253773281718,
"west": 5.50057681627676
},
"temporal_extent": [
"2024-04-04T00:00:00Z",
"2024-05-04T00:00:00Z"
]
},
"process_id": "load_collection"
},
"saveresult1": {
"arguments": {
"data": {
"from_node": "loadcollection1"
},
"format": "GTIFF",
"options": {
"bands_metadata": {
"B04": {"SCALE": 1.23},
"B03": {"OFFSET": 4.56},
"B02": {"SCALE": 7.89, "OFFSET": 10.11}
}
}
},
"process_id": "save_result",
"result": true
}
}
} From
|
Add a format option to set tiff metadata. Some of these are regular tiff tags, others will have to be encoded as gdal band metadata.
The options in geotrellis are limited, but there are very basic tifftools available in linux:
https://linux.die.net/man/1/tiffset
The idea is to be able to set metadata tags without touching the rest of the file, avoiding a full rewrite. Ideally this is done right after writing the tiff in geotrellis.
Format option will have to be passed through via save_result.
The text was updated successfully, but these errors were encountered: