# External modules
import hvplot.pandas
import holoviews as hv
import json
import pandas as pd
= 'holoviews'
pd.options.plotting.backend import warnings
'ignore')
warnings.filterwarnings(
# Local modules
import sys; sys.path.append('..')
from cog_tile_test import CogTileTest
import helpers.dataframe as dataframe_helpers
import helpers.eodc_hub_role as eodc_hub_role
Tile Generation Benchmarks for COGs with GDAL Environment Variables
Explanation
In this notebook we demonstrate the importance of using GDAL environment variables when working with rasterio to read data from Cloud-Optimized GeoTIFFs. titiler-pgstac creates image tiles using rio-tiler which uses rasterio.
The GDAL variables set for optimizing titiler performance are documented in titiler documentation. The documentation is copied into cog_tile_test.py
where the GDAL variables are set and unset before tests for ease of reference.
We run mulitiple iterations of generating tiles for various zooms for tiling when GDAL environment variables are set and when they are unset and display the results.
Setup
= eodc_hub_role.fetch_and_set_credentials() credentials
# Run 3 iterations of each setting
= 5
iterations = range(6)
zooms = list(json.loads(open('../01-generate-datasets/cmip6-pgstac/cog-datasets.json').read()).items())[0] dataset_id, dataset
dataset
{'example_query': {'collections': ['CMIP6_daily_GISS-E2-1-G_tas'],
'filter': {'op': 't_intersects',
'args': [{'property': 'datetime'}, {'interval': ['1950-04-01T00:00:00Z']}]},
'filter-lang': 'cql2-json'}}
Run tests
= {
shared_args 'dataset_id': dataset_id,
'lat_extent': [-59, 89],
'lon_extent': [-179, 179],
'extra_args': {
'query': dataset['example_query'],
'credentials': credentials
} }
# Create a test with gdal vars unset
'extra_args']['set_gdal_vars'] = False
shared_args[= CogTileTest(**shared_args) cog_tile_test_unset
Caught exception: An error occurred (InvalidPermission.Duplicate) when calling the AuthorizeSecurityGroupIngress operation: the specified rule "peer: 35.93.112.139/32, TCP, from port: 5432, to port: 5432, ALLOW" already exists
Connected to database
for zoom in zooms:
'zoom': zoom}, batch_size=iterations) cog_tile_test_unset.run_batch({
= cog_tile_test_unset.store_results(credentials) unset_results
Wrote instance data to s3://nasa-eodc-data-store/test-results/20230907005511_CogTileTest_CMIP6_daily_GISS-E2-1-G_tas.json
# Create a test with gdal vars SET
'extra_args']['set_gdal_vars'] = True
shared_args[= CogTileTest(**shared_args) cog_tile_test_set
Caught exception: An error occurred (InvalidPermission.Duplicate) when calling the AuthorizeSecurityGroupIngress operation: the specified rule "peer: 35.93.112.139/32, TCP, from port: 5432, to port: 5432, ALLOW" already exists
Connected to database
for zoom in zooms:
'zoom': zoom}, batch_size=iterations)
cog_tile_test_set.run_batch({
= cog_tile_test_set.store_results(credentials) set_results
Wrote instance data to s3://nasa-eodc-data-store/test-results/20230907005649_CogTileTest_CMIP6_daily_GISS-E2-1-G_tas.json
Read + Plot results
= [unset_results, set_results]
results_urls = dataframe_helpers.load_all_into_dataframe(credentials, results_urls) results_df
= dataframe_helpers.expand_timings(results_df)
expanded_df 'set_gdal_vars'] = expanded_df['set_gdal_vars'].astype(str) expanded_df[
= ["#E1BE6A", "#40B0A6"]
cmap = {"width": 300, "height": 250}
plt_opts
= []
plts
for zoom_level in zooms:
= expanded_df[expanded_df["zoom"] == zoom_level]
df_level
plts.append(
expanded_df.hvplot.box(="time",
y=["set_gdal_vars"],
by="set_gdal_vars",
c=cmap,
cmap="Time to render (ms)",
ylabel="GDAL Environment Variables Set/Unset",
xlabel=False,
legend**plt_opts)
).opts(
)2) hv.Layout(plts).cols(
'results-csvs/01-cog-gdal-results.csv') expanded_df.to_csv(