def __init__(self, config):
        self.config = config
        self.q = config['image_generation']['q'] 
        self.ppm = config['image_generation']['ppm'] #parts per million -  a measure of how accurate the mass spectrometer is
        self.nlevels = config['image_generation']['nlevels']  # parameter for measure of chaos
        self.data_file = config['file_inputs']['data_file']

        self.measure_value_score = {}
        self.iso_correlation_score = {}
        self.iso_ratio_score = {}
        self.monotone_pattern_score = {}
        self.intensity = {} # total image intensity

        self.chunk_size = max(1, 600 / len(config['isotope_generation']['adducts']))

        from colourmaps import viridis_colormap
        self.cmap = viridis_colormap()

        self.measure_tol = config['results_thresholds']['measure_tol']
        self.iso_corr_tol = config['results_thresholds']['iso_corr_tol']
        self.iso_ratio_tol = config['results_thresholds']['iso_ratio_tol']
            return get_datacube(self.paths[dataset], mzs, tol)

app = ImageWebserver()

@app.route('/', method='GET')
def show_form():
    return bottle.template('show_images', hs_removal=True, selected_dataset=app.paths.iterkeys().next(),
                           isotope_patterns={}, formula="", selected_adduct='H', pretty_formula="", tol=5,
                           resolution=100000, npeaks=4, datasets=app.paths.keys())

import io
import os
import numpy as np
from matplotlib.colors import Normalize

cmap = viridis_colormap()

@app.route("/show_image/<dataset>/<mz>/<tol>")
def generate_image(dataset, mz, tol):
    mz, tol = float(mz), float(tol)
    img = app.get_ion_image(dataset, mz, tol)
    if img.shape[0] > img.shape[1]:
        img = img.T
    buf = io.BytesIO()
    mask = img >= 0
    if bottle.request.query.remove_hotspots:
        pc = np.percentile(img[mask], 99)
        img[img > pc] = pc
    values = img[mask]
    norm = Normalize(vmin=np.min(values), vmax=np.max(values))
    colorized_img = np.zeros((img.shape[0], img.shape[1], 4))
import matplotlib
matplotlib.use('Agg')
import h5py
import numpy as np
import logging

import matplotlib.pyplot as plt
from matplotlib import gridspec
from colourmaps import viridis_colormap
viridis = viridis_colormap()

import os

from pyMS.pyisocalc import pyisocalc
from pyIMS.inMemoryIMS import inMemoryIMS
from pyIMS.image_measures.isotope_image_correlation import *
from pyimzml.ImzMLParser import ImzMLParser

def read_mean_spectrum(raw_data):
    if isinstance(raw_data, h5py.File):
        return read_mean_spectrum_h5(raw_data)
    elif isinstance(raw_data, str) and raw_data.endswith(".RAW"):
        return read_mean_spectrum_raw(raw_data)
    else:
        return NotImplemented

def read_mean_spectrum_h5(raw_h5):
    for k in raw_h5['Regions'].keys():
        try:
            mzs = raw_h5['Regions'][k]['SamplePositions/SamplePositions'][:]
            total_intensities = raw_h5['Regions'][k]['Intensities'][:]