58 hips_base_path: ResourcePath,
62 """Write a processed image to disk in the HealPix tile format.
64 This function takes processed image data, converts it to the specified output
65 type, and saves it into the appropriate directory structure based on the HealPix
66 pixel ID and order level.
70 image_data : `NDArray`
71 The RGB image data array to be written as a HealPix tile.
73 The unique HealPix ID corresponding to the output tile.
75 The HealPix order level of the output tile.
76 hips_base_path : `ResourcePath`
77 Base directory path where the HealPix tiles will be stored.
78 file_extension : `str`
79 File extension (format) for saving the image ('png' or 'webp').
81 Data type of the output array, which can be:
82 - "uint8": 8-bit unsigned integers (0-255)
83 - "uint16": 16-bit unsigned integers (0-65535)
84 - "half": 16-bit floating-point numbers
85 - "float": 32-bit floating-point numbers
89 image_data = np.clip(image_data, 0, 1)
93 image_data = (image_data * 255.0).astype(np.uint8)
95 image_data = (image_data * 65535.0).astype(np.uint16)
97 image_data = image_data.astype(np.float16)
103 hips_dir = hips_base_path.join(f
"Norder{hpx_level}", forceDirectory=
True).join(
104 f
"Dir{dir_number}", forceDirectory=
True
108 uri = hips_dir.join(f
"Npix{pixel_id}.{file_extension}")
111 im = Image.fromarray(image_data, mode=
"RGB")
114 if file_extension ==
"webp":
116 extra_args[
"lossless"] =
True
117 extra_args[
"quality"] = 80
120 with ResourcePath.temporary_uri(suffix=uri.getExtension())
as temporary_uri:
121 im.save(temporary_uri.ospath, **extra_args)
122 uri.transfer_from(temporary_uri, transfer=
"copy", overwrite=
True)