# Path: perses/analysis/utils.py
# def open_netcdf(filename):
# def get_offline_free_energies(filename,offline_frequency=10):
# def get_t0(filename):
# def plot_replica_mixing(ncfile_name, title='',filename='replicas.png'):


import matplotlib.pyplot as plt
import os
import sys
from glob import glob
from perses.analysis import utils

if __name__ == '__main__':
    directory = sys.argv[1]
    files = sorted(glob(os.path.join(os.getcwd(), directory, '*.nc')))
    files = [x for x in files if 'checkpoint' not in x]
    f, axarr = plt.subplots(2, 3, sharex=False, sharey=False, figsize=(16, 8))
    for i, filename in enumerate(files):
        phase = filename.split('-')[1].rstrip('.nc')
        ncfile = utils.open_netcdf(filename)
        t0 = ncfile.groups['online_analysis'].variables['t0']
        logZ = ncfile.groups['online_analysis'].variables['logZ_history']
        n_iterations, n_states = logZ.shape
        axarr[i, 0].plot(logZ, '.')

# Path: perses/analysis/utils.py
# def open_netcdf(filename):
# def get_offline_free_energies(filename,offline_frequency=10):
# def get_t0(filename):
# def plot_replica_mixing(ncfile_name, title='',filename='replicas.png'):


# Path: perses/analysis/analyse_sams_convergence.py
import matplotlib.pyplot as plt
import os
import sys
from glob import glob
from perses.analysis import utils


if __name__ == '__main__':
    directory = sys.argv[1]
    files = sorted(glob(os.path.join(os.getcwd(), directory, '*.nc')))
    files = [x for x in files if 'checkpoint' not in x]
    f, axarr = plt.subplots(2, 3, sharex=False, sharey=False, figsize=(16, 8))
    for i, filename in enumerate(files):
        phase = filename.split('-')[1].rstrip('.nc')
        ncfile = utils.open_netcdf(filename)
        t0 = ncfile.groups['online_analysis'].variables['t0']
        logZ = ncfile.groups['online_analysis'].variables['logZ_history']
        n_iterations, n_states = logZ.shape
        axarr[i, 0].plot(logZ, '.')

        axarr[i, 0].set_xlabel('iteration')