# Path: Utilities/jtools.py
# class OutOfOrderException(Exception):
# class AnalysisError(Exception):
# class CycledList(list):
#     def __getitem__(self, key):
# def slurm_id_from_output(sbatch_output):
# def check_slurm_for_job(squeue_output):
# def get_slurm_exit_state(sjobexitmod_output):
# def write_finished_file(f):
# def midpoint(x1, x2):
# def distance(x1, x2):
# def ANobj_times_to_time_window(t):
# def break_path(p, line_length):
# def text_location(xrange, yrange):
# def valid_int_from_str(s):
# def valid_float_from_str(s):
# def complex_mag(z):
# def complex_mag_list(zz):
# def type_verify(var, typ):
# def time_window_to_filelike_str(w):
# def scan_config(f):
# def in_tkStringVar_array(s, tksvarr):
# def valid_probe_array(s, f = DEFAULT_CONFIG_FILE):
# def return_methods():
# def valid_method(s):
# def probe_positions(probe_array):
# def valid_window(s):
# def remove_key(d, k):
# def time_window_parser(s):
# def t_in_window(t, win):
# def window_subset(w1, w2):
# def valid_num_or_range(s):
# def valid_shot_str(s):
# def shot_str_parser(s):
# def reverse_shot_str_parser(shot_list):
# def squareish_grid(n, swapxy=False):
# def find_closest(arr, x):


import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from Utilities import jtools as jt
        if dosave is not None:
            plt.savefig(dosave)
    else:
        ax.specgram(A.results[0][2][0, :], NFFT=1024, Fs=1. / np.mean(np.diff(A.results[0][3])),
                    noverlap=128, xextent=[A.results[0][3][0], A.results[0][3][-1]])
        if clust_arr is not None:
            for cl in clust_arr:
                mask = (A.z.cluster_assignments == cl)
                ax.plot(A.z.feature_obj.misc_data_dict["time"][mask],
                        A.z.feature_obj.misc_data_dict["freq"][mask],
                        color=plot_colors[cl], marker="o", linestyle="None",
                        markersize=A.markersize)
    return


def point_analysis(A, shot, time_window, t0, f0, probe_array, doplot=True, dosave=None, clustarr=None):
    fft = A.DM.raw_ffts[str(shot)]
    raw_mirnov = fft.signal
    raw_times = fft.timebase
    raw_freqs = fft.frequency_base

    nt, t_actual = jt.find_closest(raw_times, t0)
    nf, f_actual = jt.find_closest(raw_freqs, f0)
    print("Requested t={}ms. Got t={}ms. dt={}ms".format(t0, t_actual, abs(t0-t_actual)))
    print("Requested f={}kHz. Got f={}kHz. df={}kHz".format(f0, f_actual, abs(f0-f_actual)))

    complex_amps = []
    tmp = raw_mirnov[nt]
    for prb in tmp:
        complex_amps.append(prb[nf])

# Path: Utilities/jtools.py
# class OutOfOrderException(Exception):
# class AnalysisError(Exception):
# class CycledList(list):
#     def __getitem__(self, key):
# def slurm_id_from_output(sbatch_output):
# def check_slurm_for_job(squeue_output):
# def get_slurm_exit_state(sjobexitmod_output):
# def write_finished_file(f):
# def midpoint(x1, x2):
# def distance(x1, x2):
# def ANobj_times_to_time_window(t):
# def break_path(p, line_length):
# def text_location(xrange, yrange):
# def valid_int_from_str(s):
# def valid_float_from_str(s):
# def complex_mag(z):
# def complex_mag_list(zz):
# def type_verify(var, typ):
# def time_window_to_filelike_str(w):
# def scan_config(f):
# def in_tkStringVar_array(s, tksvarr):
# def valid_probe_array(s, f = DEFAULT_CONFIG_FILE):
# def return_methods():
# def valid_method(s):
# def probe_positions(probe_array):
# def valid_window(s):
# def remove_key(d, k):
# def time_window_parser(s):
# def t_in_window(t, win):
# def window_subset(w1, w2):
# def valid_num_or_range(s):
# def valid_shot_str(s):
# def shot_str_parser(s):
# def reverse_shot_str_parser(shot_list):
# def squareish_grid(n, swapxy=False):
# def find_closest(arr, x):


# Path: Analysis/point_analysis.py
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from Utilities import jtools as jt

        if dosave is not None:
            plt.savefig(dosave)
    else:
        ax.specgram(A.results[0][2][0, :], NFFT=1024, Fs=1. / np.mean(np.diff(A.results[0][3])),
                    noverlap=128, xextent=[A.results[0][3][0], A.results[0][3][-1]])
        if clust_arr is not None:
            for cl in clust_arr:
                mask = (A.z.cluster_assignments == cl)
                ax.plot(A.z.feature_obj.misc_data_dict["time"][mask],
                        A.z.feature_obj.misc_data_dict["freq"][mask],
                        color=plot_colors[cl], marker="o", linestyle="None",
                        markersize=A.markersize)
    return


def point_analysis(A, shot, time_window, t0, f0, probe_array, doplot=True, dosave=None, clustarr=None):
    fft = A.DM.raw_ffts[str(shot)]
    raw_mirnov = fft.signal
    raw_times = fft.timebase
    raw_freqs = fft.frequency_base

    nt, t_actual = jt.find_closest(raw_times, t0)
    nf, f_actual = jt.find_closest(raw_freqs, f0)
    print("Requested t={}ms. Got t={}ms. dt={}ms".format(t0, t_actual, abs(t0-t_actual)))
    print("Requested f={}kHz. Got f={}kHz. df={}kHz".format(f0, f_actual, abs(f0-f_actual)))

    complex_amps = []
    tmp = raw_mirnov[nt]
    for prb in tmp:
        complex_amps.append(prb[nf])

    amps = jt.complex_mag_list(complex_amps)