Skip to main content

Images

Upload hyperspectral imagery, fetch image metadata, attach workspace labels, and download processed image files.

Module methods​

sdk.image exposes:

  • get(image_id): return one ImageResource
  • get_by_ids(image_ids): return a list of resources
  • upload(file_paths, name, folder_id, geotiff_source=None, processing_level=REFLECTANCE): import one HSI file bundle and return its image resource

Pass every required file in file_paths. geotiff_source is optional and is used to identify a GeoTIFF provider such as EnMAP; omit it for non-GeoTIFF imports. The selected processing_level describes the uploaded source data. It labels the values but does not convert or calibrate them.

REFLECTANCE is the method default, not an inference about the file contents. Set processing_level explicitly when the source values represent another level, and verify units and correction provenance before downstream analysis.

A returned image resource does not by itself confirm that background import processing has finished. Confirm the image's import status and available layers in Files before attaching labels or downloading a processed layer.

An ImageResource includes id, name, width, height, and top_processing_level. download(folder_path, correction_level=None) uses the top available level unless you pass a level explicitly.

Image downloads first prepare an archive on the server, then transfer and unpack it locally. The cache can remain empty during server preparation. The SDK reports the task UUID and status while waiting, followed by downloaded byte counts.

In the next SDK release, image.download(..., timeout=1800) limits the server preparation wait in seconds (30 minutes by default). A timeout raises TimeoutError and does not cancel the server task. Check its status before submitting another export, since repeated calls can queue duplicate work. Network transfers also have connection and idle-read timeouts.

Read a scientific pixel window​

The Python SDK with cube-window support exposes the available layers on image.layers and the primary layer ID on image.primary_layer_id. For a published scientific layer, read_window returns raw values, validity, and metadata from the native pixel grid. The following example reads two bands from a reflectance layer of an image with at least four bands and a 32 by 32 pixel window.

import numpy as np
from fusion_sdk.models.hsi_processing_level_enum import HsiProcessingLevelEnum

image = sdk.image.get(image_id=21)
for layer in image.layers:
print(layer.id, layer.processing_level, layer.id == image.primary_layer_id)

layer = next(
layer for layer in image.layers
if layer.processing_level == HsiProcessingLevelEnum.REFLECTANCE
)
window = image.read_window(
image_layer_id=layer.id,
row=0,
column=0,
height=32,
width=32,
band_indexes=[4, 2],
)
physical = window.physical_values()
for i, band in enumerate(window.metadata["source_band_indexes_1based"]):
samples = physical[:, :, i][window.valid[:, :, i]]
print(band, samples.size, np.mean(samples) if samples.size else None)

Row and column offsets start at zero. Source band indexes start at one and retain their requested order. window.values preserves the raw dtype and window.valid gives per-value validity with the same shape. physical_values() applies each selected band's gain and offset and fills invalid samples with NaN. When combining windows, compare window.metadata["source_revision"] to verify that they came from the same source version.

Read attached references and native training regions​

In the upcoming SDK, use the workspace ID where the image is attached. Both reads require SDK access and permission to read the workspace and image.

image = sdk.image.get(image_id=21)
workspace_id = 8
after_id = 0
while True:
page = image.reference_spectra(workspace_id, after_id=after_id, limit=16)
for reference in page.references:
print(reference.name, reference.reference_link_id)
samples = list(zip(reference.wavelengths_nm, reference.values))
if page.next_after_id is None:
break
after_id = page.next_after_id

regions = image.native_regions(workspace_id, label_set_id=12, limit=8)
for region in regions.regions:
print(region.label_uuid, region.ml_class_id, region.version)
print(region.geometry.type, region.geometry.coordinates)

reference_spectra returns original library samples with wavelengths in nanometres. Each entry includes the workspace attachment ID, library ID, signature ID and reference-link ID. Use the reference-link IDs in the class order you want when configuring a spectral mapper. Hidden chart references remain attached and report is_visible=False. Library access and archive filters apply.

native_regions returns native image-pixel vector labels, including polygon interiors. Coordinates are [column, row] on the source grid. Each result identifies the feature, label UUID, label set, optional training class, status and feature version. Point and line labels also carry their stored size or width when available. Omit label_set_id to read all accessible native vector sets on the image. Map-coordinate labels and raster masks have separate representations.

Both methods return up to 32 records per call. Continue with the returned next_after_id and the same workspace, image and filters. A null cursor ends the sequence. Reference pages are ordered by reference-link ID and region pages by feature ID. These reads reflect current workspace data, so records can change between requests. A single spectrum array or encoded geometry above 256 KiB returns HTTP 413 with the affected ID.

Example​

from fusion_sdk.models.data_source_enum import DataSourceEnum
from fusion_sdk.models.hsi_processing_level_enum import HsiProcessingLevelEnum

image = sdk.image.upload(
file_paths=[
"/path/to/METADATA.XML",
"/path/to/SPECTRAL_IMAGE.TIF",
],
name="imported_enmap",
folder_id=19,
processing_level=HsiProcessingLevelEnum.RADIANCE,
geotiff_source=DataSourceEnum.ENMAP,
)

# Continue after import processing has finished and the input layer is ready.
image.upload_shapefiles(
workspace_id=8,
shapefile_paths=[
"/path/to/polygon.shp",
"/path/to/polygon.shx",
"/path/to/polygon.dbf",
"/path/to/polygon.prj",
],
)

image.download(
folder_path="/local/downloads",
correction_level=HsiProcessingLevelEnum.RADIANCE,
)

upload_shapefiles and upload_rasters import label sources into the specified workspace for this image; they do not add standalone files to the Files page.

upload_rasters submits each TIFF or ENVI bundle separately, keeping matching sidecar files together. With the current API, a call without target semantics stages the imported rasters for configuration in the workspace. A successful upload does not mean those targets have been finalized for training.

To configure targets during upload, pass target_type ("categorical" or "continuous"), class_data for categorical mappings, or ml_class_id and common_attribute_definition_id for a continuous target. Set should_finalize=True when the supplied configuration is ready for training. The same configuration applies to every raster in that call; call the method separately for rasters with different target meanings.