Saving output in a task type¶
Primitive parameters¶
Primitive outputs (of type Int
, Float
, String
or Bool
; see Parameter Types) can be stored directly via the Python module xfworkerutil
.
For example Lucid.CLIP.StatMinMax
stores minimum and maximum output parameters:
import xfworkerutil
import clip_runtop
worker = xfworkerutil.XFWorkerJob()
inputs = worker.job['inputs']
calibration_name = inputs['calibration']
# Download input files
image = worker.get_omni_image(inputs['image'])
# CLIP
min, max = clip_runtop.runtop_min_max(image, worker.working_dir.path / "temp")
if calibration_name is not None:
calibrations = image.pixel_calibrations_of_unit_type(calibration_name)
if len(calibrations) == 0:
worker.error(f"Image is missing calibration metadata of type {calibration_name}")
calibration = calibrations[0]
min = calibration.raw_to_calibrated(min)
max = calibration.raw_to_calibrated(max)
# Save outputs
outputs = {
"min": min,
"max": max,
}
worker.finish(outputs)
Bulk data¶
Composite parameters like Image
refer to bulk data that should be stored separately on FSS.
OMNI image data can be stored using the xfworkerutil.XFWorkerJob.upload_omni_output()
.
The returned value should be passed to xfworkerutil.XFWorkerJob.finish()
for the respective output key.
For example Lucid.CLIP.Threshold
does this as follows:
import xfworkerutil
import clip_thres
worker = xfworkerutil.XFWorkerJob()
inputs = worker.job['inputs']
threshold_lower = inputs['threshold_lower0']
threshold_upper = inputs['threshold_upper0']
# Download input files
image = worker.get_omni_image(inputs['image'])
seg_image_omni_path = worker.create_related_path(image.metadata_path, '_seg.omni')
seg_image_pixels_path = worker.create_related_path(image.metadata_path, '_seg.raw')
thres_temp_dir_path = worker.working_dir.path / "thres"
# CLIP
seg_image = clip_thres.thres_image(
image,
threshold_lower,
threshold_upper,
seg_image_omni_path,
seg_image_pixels_path,
thres_temp_dir_path)
# Upload output files
seg_image_output = worker.upload_omni_output(seg_image)
# Save outputs
outputs = {
"segments": seg_image_output,
}
worker.finish(outputs)
See also Saving an OMNI Image.
For other data files xfworkerutil.XFWorkerJob.upload_output_file()
can be used instead.
The value to be passed to xfworkerutil.XFWorkerJob.finish()
for the respective output key can be created using e.g. xfworkerutil.XFWorkerJob.create_output_image()
or similar methods.
See Using IPL in a task type for an example.