def params_dict(plotitem, base_params, level_params, level):
    """
    Create a dictionary containing the plot parameters.

    For each level_param check if there is an amr_ list for this
    parameter and if so select the value corresponding to the level of
    this patch.  Otherwise, use plotitem attribute of this name.
    """
    pp = {}
    for plot_param in base_params:
        pp[plot_param] = getattr(plotitem, plot_param, None)


    for plot_param in level_params:
        amr_plot_param = "amr_%s" % plot_param
        amr_list = getattr(plotitem, amr_plot_param, [])
        if len(amr_list) > 0:
            index = min(level, len(amr_list)) - 1
            pp[plot_param] = amr_list[index]
        else:
            pp[plot_param] = getattr(plotitem, plot_param, None)

    return pp