# This file was extracted from the HV SDK Docusaurus examples. # It is intended as a downloadable, runnable companion to the documentation. # Set HSI_EXAMPLE_BASE_DIR and related env vars to use your own data. # Source page: /hsi/hv_sdk/examples/basics#read-lines-bands-and-regions # region: setup import os from pathlib import Path import numpy as np import qtec_hv_sdk as hs BASE_DIR = Path(os.environ.get("HSI_EXAMPLE_BASE_DIR", "/path/to/HSI_data/nuts")) if not BASE_DIR.exists(): raise SystemExit( "Run: 'export HSI_EXAMPLE_BASE_DIR=/path/to/HSI_data/' to setup the " "folder containing the example datacubes." ) CUBE = os.environ.get("HSI_EXAMPLE_CUBE", "mix1.pam") # end region # region: example cube = hs.open(str(BASE_DIR / CUBE)) line_index = 100 band_index = 164 x0, x1 = 300, 500 y0, y1 = 200, 350 line = cube.array_plane(line_index, hs.lines) band = cube.array_plane(band_index, hs.bands) band_from_slice = cube[:, :, band_index].to_numpy_with_interleave(hs.bip)[:, :, 0] assert np.array_equal(band, band_from_slice) region = cube[y0:y1, x0:x1, :].to_numpy_with_interleave(hs.bip) print(f"Line shape: {line.shape}") # bands x samples print(f"Band shape: {band.shape}") # lines x samples print(f"Region shape: {region.shape}") # lines x samples x bands # end region