import os
import sys


def get_script_path():
    #return os.path.dirname(os.path.realpath(sys.argv[0]))
    return os.getcwd()


def norm(dataframe, ref_dataframe=None, ref_mean=None, ref_std=None):
    if ref_dataframe is not None:
        df_norm = (dataframe - ref_dataframe.mean())/ref_dataframe.std()
    elif ref_mean is not None and ref_std is not None:
        df_norm = (dataframe - ref_mean)/ref_std
    else:
        raise RuntimeError("Either a reference dataset or a reference mean + std must be supplied.")
    return df_norm


def norm_inputs(dataframe, ref_dataframe=None, ref_mean=None, ref_std=None):
    if ref_dataframe is not None:
        df_norm = (dataframe - ref_dataframe.mean(axis=0)) / ref_dataframe.std(axis=0)
    elif ref_mean is not None and ref_std is not None:
        df_norm = (dataframe - ref_mean) / ref_std
    else:
        raise RuntimeError("Either a reference dataset or a reference mean + std must be supplied.")
    return df_norm


def unnorm(dataframe_norm, ref_dataframe=None, ref_mean=None, ref_std=None):
    if ref_dataframe is not None:
        dataframe = (dataframe_norm * ref_dataframe.std()) + ref_dataframe.mean()
    elif ref_mean is not None and ref_std is not None:
        dataframe = (dataframe_norm * ref_std) + ref_mean
    else:
        raise RuntimeError("Either a reference dataset or a reference mean + std must be supplied.")
    return dataframe


def unnorm_inputs(dataframe_norm, ref_dataframe,ref_mean=None, ref_std=None):
    if ref_dataframe is not None:
        dataframe = (dataframe_norm * ref_dataframe.std(axis=0)) + ref_dataframe.mean(axis=0)
    elif ref_mean is not None and ref_std is not None:
        dataframe = (dataframe_norm * ref_std) + ref_mean
    else:
        raise RuntimeError("Either a reference dataset or a reference mean + std must be supplied.")
    return dataframe
