timeseries plot helper...in progress

def res_obs_v_sim(pst,logger=None, filename=None,  **kwargs):
    """
    timeseries plot helper...in progress

    """
    if logger is None:
        logger=Logger('Default_Loggger.log',echo=False)
    logger.log("plot res_obs_v_sim")

    if "ensemble" in kwargs:
        try:
            res=pst_utils.res_from_en(pst,kwargs['ensemble'])
        except:
            logger.statement("res_1to1: could not find ensemble file {0}".format(kwargs['ensemble']))
    else:
        try:
            res = pst.res
        except:
            logger.lraise("res_phi_pie: pst.res is None, couldn't find residuals file")

    obs = pst.observation_data

    if "grouper" in kwargs:
        raise NotImplementedError()
    else:
        grouper = obs.groupby(obs.obgnme).groups

    fig = plt.figure(figsize=figsize)
    if "fig_title" in kwargs:
        plt.figtext(0.5,0.5,kwargs["fig_title"])
    else:
        plt.figtext(0.5, 0.5, "pyemu.Pst.plot(kind='obs_v_sim')\nfrom pest control file '{0}'\n at {1}"
                    .format(pst.filename, str(datetime.now())), ha="center")
    figs = []
    ax_count = 0
    axes = None
    for g, names in grouper.items():
        logger.log("plotting obs_v_sim for {0}".format(g))

        obs_g = obs.loc[names, :]
        obs_g.loc[:, "sim"] = res.loc[names, "modelled"]
        if "include_zero" not in kwargs or kwargs["include_zero"] is False:
            obs_g = obs_g.loc[obs_g.weight > 0, :]

        if obs_g.shape[0] == 0:
            logger.statement("no non-zero obs for group '{0}'".format(g))
            logger.log("plotting obs_v_sim for {0}".format(g))
            continue

        # parse datetimes
        # suffix in decreasing magnitude (yearmonthday)
        try:
            obs_g.loc[:, "datetime_str"] = obs_g.obsnme.apply(lambda x: x.split('_')[-1])
        except:
            logger.statement("res_obs_v_sim error forming datetime_str")
            continue
        # Default datetime
        try:
            obs_g.loc[:, "datetime"] = pd.to_datetime(obs_g.datetime_str,format="%Y%m%d")
        except:
            logger.statement("res_obs_v_sim error casting datetime using default {0}".format(g))

        # abbreviated date format ALWAY 2 digit year, mabye followed by 2 digit month, maybe followed by 2 digit day
        obs_g['datetime']=0
        try:
            obs_g.loc[obs_g['datetime_str'].str.len()==2,'datetime']=pd.to_datetime(obs_g['datetime_str']+'1231',format='%y%m%d')
        except:
            logger.statement("res_obs_v_sim error casting datetime using %y {0}".format(g))
        try:
            obs_g.loc[obs_g['datetime_str'].str.len()==4,'datetime']=pd.to_datetime(obs_g['datetime_str'].astype(str)+'01',format='%y%m%d')+datetime.timedelta(months=1)-datetime.timedelta(days=1)
        except:
            logger.statement("res_obs_v_sim error casting datetime using %y%m {0}".format(g))
        try:
            obs_g.loc[obs_g['datetime_str'].str.len()==6,'datetime']=pd.to_datetime(obs_g['datetime_str'].astype(str),format='%y%m%d')
        except:
            logger.statement("res_obs_v_sim error casting datetime using %y%m%d {0}".format(g))


        if ax_count % (nr * nc) == 0:
            plt.tight_layout()
            #pdf.savefig()
            #plt.close(fig)
            figs.append(fig)
            fig = plt.figure(figsize=figsize)
            axes = get_page_axes()
            ax_count = 0

        ax = axes[ax_count]
        obs_g.loc[:,"site"] = obs_g.obsnme.apply(lambda x: x.split('_')[0])
        for site in obs_g.site.unique():
            obs_s = obs_g.loc[obs_g.site==site,:]
            obs_s.sort_values(by="datetime")
            ax.plot(obs_s.datetime, obs_s.obsval, ls='-', marker='.', ms=10, color='b')
            ax.plot(obs_s.datetime, obs_s.sim, ls='-', marker='.', ms=10, color='0.5')
        ax.set_xlim(obs_g.datetime.min(),obs_g.datetime.max())
        ax.grid()
        ax.set_xlabel("datetime",labelpad=0.1)
        ax.set_title("{0}) group:{1}, {2} observations".
                     format(abet[ax_count], g, names.shape[0]), loc="left")
        ax_count += 1
        logger.log("plotting obs_v_sim for {0}".format(g))

    if axes is None:
        return

    for a in range(ax_count,nr*nc):
        axes[a].set_axis_off()
        axes[a].set_yticks([])
        axes[a].set_xticks([])



    plt.tight_layout()
    #pdf.savefig()
    #plt.close(fig)
    figs.append(fig)
    if filename is not None:
        with PdfPages(pst.filename.replace(".pst", ".obs_v_sim.pdf")) as pdf:
            for fig in figs:
                pdf.savefig(fig)
                plt.close(fig)
                logger.log("plot res_obs_v_sim")
    else:
        logger.log("plot res_obs_v_sim")
        return figs