Skip to content

Instantly share code, notes, and snippets.

@DPeterK
Created December 1, 2020 13:35
Show Gist options
  • Save DPeterK/dc084ef46bfb773086131626c833b16a to your computer and use it in GitHub Desktop.
Save DPeterK/dc084ef46bfb773086131626c833b16a to your computer and use it in GitHub Desktop.
Demonstrate a simple end-to-end usage example of tiledb-netcdf.
import os
import iris
import tiledb
import tiledb_netcdf
netcdf_path = "/path/to/my/nc-files"
base_nc_name = 'file1.nc'
append_nc_names = ['file2.nc', 'file3.nc', 'file4.nc']
append_files = [os.path.join(netcdf_path, name) for name in append_nc_names]
# 1a: create a custom data model.
data_model = tiledb_netcdf.NCDataModel(os.path.join(netcdf_path, base_nc_name))
# 1b: infer the types of variables.
data_model.populate()
# 2: create the TileDB array
writer = tiledb_netcdf.Writer(data_model,
array_filepath="/path/to/tiledb/array",
array_name="my_tiledb_array",
unlimited_dims="time")
writer.create_domains()
# 3: append the contents of extra NetCDF files
writer.append(append_files, unlimited_dims="time")
# 4: open the TileDB array as an Iris cube to interact with it further.
reader = tiledb_netcdf.Reader("my_tiledb_array", array_filepath="/path/to/tiledb/array")
cube = reader.to_iris()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment