# precompile_script.jl # This script exercises the core MSI processing kernels (imzML and mzML) # to ensure they are precompiled into the custom system image. using MSI_src using Mmap using Base64 using PlotlyBase # --- DYNAMIC WARM-UP WORKLOAD --- # function create_warmup_datasets(dir, T_mz::Type, T_int::Type) # 1. Create minimal imzML/ibd imzml_path = joinpath(dir, "warmup_$(T_mz)_$(T_int).imzML") ibd_path = joinpath(dir, "warmup_$(T_mz)_$(T_int).ibd") n_points = 10 n_pixels = 1 mz_bytes = n_points * sizeof(T_mz) int_bytes = n_points * sizeof(T_int) # Write some dummy binary data open(ibd_path, "w") do f write(f, rand(T_mz, n_points)) write(f, rand(T_int, n_points)) end # Minimal but VALID imzML structure that passes axes_config_img imzml_content = """ """ write(imzml_path, imzml_content) # 2. Create minimal mzML (Base64) mzml_path = joinpath(dir, "warmup_$(T_mz)_$(T_int).mzML") b64_mz = base64encode(rand(T_mz, n_points)) b64_int = base64encode(rand(T_int, n_points)) mzml_content = """ $b64_mz $b64_int PLACEHOLDER ID_OFFSET """ spec_start = findfirst(" string(spec_start)) mzml_content = replace(mzml_content, "ID_OFFSET" => string(index_start)) write(mzml_path, mzml_content) return imzml_path, mzml_path end println("Starting robust precompilation warmup (imzML + mzML)...") try mktempdir() do tmp_dir for (T_mz, T_int) in [(Float32, Float32), (Float64, Float32)] println("Exercising pathways for $T_mz and $T_int...") imzml_path, mzml_path = create_warmup_datasets(tmp_dir, T_mz, T_int) try # Exercise imzML pathway imzml_data = MSI_src.load_imzml_lazy(imzml_path; use_mmap=true) MSI_src.get_multiple_mz_slices(imzml_data, [10.0, 20.0], 0.1) # Exercise mzML pathway mzml_data = MSI_src.load_mzml_lazy(mzml_path) MSI_src.GetSpectrum(mzml_data, 1) catch e @warn "Warmup failed for $T_mz/$T_int: $e" end end # --- COMMON KERNELS --- println("Precompiling image processing kernels...") dummy_slice = rand(Float32, 4, 4) MSI_src.TrIQ(dummy_slice, 256, 1.0) MSI_src.save_bitmap(joinpath(tmp_dir, "d.bmp"), zeros(UInt8, 4, 4), MSI_src.ViridisPalette) # Plotly Warmup p = PlotlyBase.Plot(PlotlyBase.scatter(x=1:2, y=[1,2])) end catch e @warn "Global Warmup failed: $e" catch # Silent fail for interrupt end println("Precompilation workload completed.")