<commit_before>module Imagine

using Images
using Units

import Images.imread

function imread{S<:IO}(s::S, ::Type{Images.ImagineFile})
    h = parse_header(s, Images.ImagineFile)
    filename = s.name[7:end-1]
    basename, ext = splitext(filename)
    camfilename = basename*".cam"
    # Check that the file size is consistent with the expected size
    fsz = filesize(camfilename)
    T = h["pixel data type"]
    sz = [h["image width"], h["image height"], h["frames per stack"], h["nStacks"]]
    if fsz != sizeof(T)*prod(sz)
        warn("Size of image file is different from expected value")
        n_stacks = ifloor(fsz / sizeof(T) / prod(sz[1:3]))
        if n_stacks < sz[4]
            println("Truncating to ", n_stacks, " stacks")
        end
        sz[4] = n_stacks
    end
    sc = open(camfilename, "r")
    data = mmap_array(T, ntuple(4, i->sz[i]), sc)
    um_per_pixel = h["um per pixel"]
    if !(um_per_pixel > 0)
        if h["camera"] == "DV8285_BV"<commit_msg>Imagine: return an empty image if .cam file is missing<commit_after>module Imagine

using Images
using Units

import Images.imread

function imread{S<:IO}(s::S, ::Type{Images.ImagineFile})
    h = parse_header(s, Images.ImagineFile)
    filename = s.name[7:end-1]
    basename, ext = splitext(filename)
    camfilename = basename*".cam"
    T = h["pixel data type"]
    sz = [h["image width"], h["image height"], h["frames per stack"], h["nStacks"]]
    # Check that the file size is consistent with the expected size
    if !isfile(camfilename)
        warn("Cannot open ", camfilename)
        data = Array(T, sz[1], sz[2], sz[3], 0)
    else
        fsz = filesize(camfilename)
        if fsz != sizeof(T)*prod(sz)
            warn("Size of image file is different from expected value")
            n_stacks = ifloor(fsz / sizeof(T) / prod(sz[1:3]))
            if n_stacks < sz[4]
                println("Truncating to ", n_stacks, " stacks")
            end
            sz[4] = n_stacks
        end
        sc = open(camfilename, "r")
        data = mmap_array(T, ntuple(4, i->sz[i]), sc)
    end
    um_per_pixel = h["um per pixel"]
    if !(um_per_pixel > 0)
        if h["camera"] == "DV8285_BV"
{'fraction_non_alphanumeric': 0.13939670932358317, 'fraction_numerical': 0.012797074954296161, 'mean_word_length': 2.78719723183391, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6685381', 'n_tokens_mistral': 763, 'n_tokens_neox': 743, 'n_words': 205}