# Path: atlas_report.py
# def do_strip_prefix(label_name):
#     # if desired, remove prefixes from label names 
#     idx = label_name.rfind('_') + 1
#     stripped_label_name = label_name[idx:]
#     # print("Stripping atlas label name, from %s to %s" % (label_name, stripped_label_name))
#     return stripped_label_name


import os
import sys
import argparse
import nibabel as nib
import numpy as np
import matplotlib.pyplot as plt
from atlas_report import do_strip_prefix
    Create a cumulative histogram for each label in a probabilistic atlas

    Parameters
    ----------
    p: numpy array
    keys
    nrows
    ncols
    fontsize
    img_fname

    Returns
    -------

    """

    fig, axs = plt.subplots(nrows, ncols, figsize=(12,9))
    axs = np.array(axs).reshape(-1)

    im = []

    # Determine lower left axis index
    lower_left = (nrows - 1) * ncols

    for aa, ax in enumerate(axs):

        if aa < len(keys):
            v = p[:,:,:,aa].ravel()
            v = v[v > 0]
            im = ax.hist(v, bins=50, cumulative=True, density=True, range=(0,1))

# Path: atlas_report.py
# def do_strip_prefix(label_name):
#     # if desired, remove prefixes from label names 
#     idx = label_name.rfind('_') + 1
#     stripped_label_name = label_name[idx:]
#     # print("Stripping atlas label name, from %s to %s" % (label_name, stripped_label_name))
#     return stripped_label_name


# Path: prob_label_vol_info.py
import os
import sys
import argparse
import nibabel as nib
import numpy as np
import matplotlib.pyplot as plt
from atlas_report import do_strip_prefix

    Create a cumulative histogram for each label in a probabilistic atlas

    Parameters
    ----------
    p: numpy array
    keys
    nrows
    ncols
    fontsize
    img_fname

    Returns
    -------

    """

    fig, axs = plt.subplots(nrows, ncols, figsize=(12,9))
    axs = np.array(axs).reshape(-1)

    im = []

    # Determine lower left axis index
    lower_left = (nrows - 1) * ncols

    for aa, ax in enumerate(axs):

        if aa < len(keys):
            v = p[:,:,:,aa].ravel()
            v = v[v > 0]
            im = ax.hist(v, bins=50, cumulative=True, density=True, range=(0,1))

            key = do_strip_prefix(keys[aa])