No, I don’t think so: what I learned is to generate the image, and your help was instrumental for that. The current issue is that I don’t seem to be able to save it in a file…
To recap, in post #10 above, the Julia code does not complain about creating img
, but issues the message ArgumentError: unable to check bounds for indices of type ColorTypes.
I don’t know how to interpret that error message because I’m just starting to learn about graphics in this language.
Coming back to the current situation: what exactly is Julia complaining about indices of type ColorTypes
? Should I assign a color to all intermediary values of colormap
between 5
and 0xfc
(inclusive), even though they never occur in the data array? Should I specify the dimensions of the individual digital maps contained in the array rccm[9, 512, 128]
?
For reference, here is the entire mapping function, which is supposed to image and save 9 maps, each of 512 by 128 pixels, where every pixel can only take one of 8 possible UInt8
values:
function map_rccm(
misr_path::Integer,
misr_orbit::Integer,
misr_block::Integer,
rccm::Array{UInt8, 3},
step::Integer;
user::Union{AbstractString, Nothing} = nothing,
project::Union{AbstractString, Nothing} = nothing,
misr_version::Union{AbstractString, Nothing} = nothing,
map_folder::Union{AbstractString, Nothing} = nothing
)::Vector{AbstractString}
# Retrieve the technical specifications of the MISR instrument:
misr_specs = set_misr_specs()
# Retrieve the acquisition date of the specified MISR Orbit and extract the year-month-date string needed to set the filename:
orbit_date, orbit_date_string = orbit2date(misr_orbit)
map_fspecs = Vector{AbstractString}(undef, misr_specs.ncameras)
for cam = 1:misr_specs.ncameras
# Set the specification of the save file:
qualifier = "Step" * string(step)
map_fspecs[cam] = mk_post_fspec("Map", "L1RCCMMR", "cldm", qualifier;
user = user, project = project,
misr_path1 = misr_path,
misr_orbit1 = misr_orbit,
misr_block1 = misr_block,
misr_camera1 = misr_specs.camera_names[cam],
misr_resolution = 1100,
from_date = orbit_date,
misr_version = misr_version,
ext = ".png", call_f = "fix_rccm", out_folder = map_folder)
# Generate a map of the cloud mask for the current camera:
colormap = zeros(RGB{N0f8}, 0:255)
colormap[[0, 1, 2, 3, 4, 0xfd, 0xfe, 0xff]] = [
colorant"red", colorant"white",
colorant"light gray", colorant"aqua",
colorant"blue", colorant"gold",
colorant"black", colorant"red"]
img = IndirectArray(rccm[cam, :, :], colormap)
FileIO.save(File(format"PNG", map_fspecs[cam]), colormap[img])
end
return map_fspecs
end
It’s pretty simple, really: the array rccm
is an input argument, and the purpose of function mk_post_fspec
is only to generate a path and name for the output file. The statement that causes problems is FileIO.save(File(format"PNG", map_fspecs[cam]), colormap[img])
.
Perhaps a first ‘next step’ could be to visualize those maps, just to make sure they look reasonable, and then to find a way to save them.
I really appreciate your patience in this matter.
UPDATE: I think I found one issue: the colormap
statement should probably be written colormap[[0x00, 0x01, 0x02, 0x03, 0x04, 0xfd, 0xfe, 0xff]]
, not colormap[[0, 1, 2, 3, 4, 0xfd, 0xfe, 0xff]]
. I assumed integer representations as decimals or hexadecimal constants could be mixed… In any case, I now don’t get any error messages, but no PNG file is saved either, so the writing of the file is still a problem…
UPDATE to the UPDATE: no cigar yet… After recompiling and executing, I still get the same error message as before:
julia> rccm, n_miss = fix_rccm(168, 1412, 108;
stats_it = true, save_it = true, map_it = true);
map_fspecs[cam] = /Users/michel/Projects/MISR/Scrap/Dev/Test/P168+O001412+B108/fix_rccm/L1RCCMMR/Map/Map_L1RCCMMR_cldm_Step1_P168+O001412+B108+DF_R1100_2000-03-24+2023-05-24_F04_0025.png
ERROR: ArgumentError: unable to check bounds for indices of type ColorTypes.RGB{FixedPointNumbers.N0f8}
Stacktrace:
[1] checkindex(#unused#::Type{Bool}, inds::OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}}, i::ColorTypes.RGB{FixedPointNumbers.N0f8})
@ Base ./abstractarray.jl:725
[2] checkindex
@ ./abstractarray.jl:740 [inlined]
[3] checkbounds
@ ./abstractarray.jl:653 [inlined]
[4] checkbounds
@ ./abstractarray.jl:668 [inlined]
[5] _getindex
@ ./multidimensional.jl:874 [inlined]
[6] getindex
@ ./abstractarray.jl:1241 [inlined]
[7] map_rccm(misr_path::Int64, misr_orbit::Int64, misr_block::Int64, rccm::Array{UInt8, 3}, step::Int64; user::Nothing, project::Nothing, misr_version::String, map_folder::Nothing)
@ JMRCCM ~/Projects/MISR/MISR_RCCM/JMRCCM/src/map_rccm.jl:99
[8] fix_rccm(misr_path::Int64, misr_orbit::Int64, misr_block::Int64; misr_version::Nothing, edge::Nothing, user::Nothing, project::Nothing, stats_it::Bool, stats_folder::Nothing, save_it::Bool, save_folder::Nothing, map_it::Bool, map_folder::Nothing)
@ JMRCCM ~/Projects/MISR/MISR_RCCM/JMRCCM/src/fix_rccm.jl:150
[9] top-level scope
@ REPL[12]:1