Exemplo n.º 1
0
def multi_svd(shot_selection,array_name, other_arrays = None, other_array_labels = None, meta_data = None,
    n_cpus=8, NFFT = 2048, power_cutoff=0.05, min_svs=2, overlap = 4,): 
    '''Runs through all the shots in shot_selection other_arrays is a
    list of the other arrays you want to get information from '''

    #Get the scan details 
    shot_list, start_times, end_times = H1_scan_list.return_scan_details(shot_selection) 
    rep = itertools.repeat
    if other_arrays is None: other_arrays = ['ElectronDensity','H1ToroidalNakedCoil']
    if other_array_labels is None: other_array_labels = [['ne_static','ne_mode'],[None,'naked_coil']]
    if meta_data is None : meta_data = ['kh','heating_freq','main_current','sec_current', 'shot']

    input_data_iter = itertools.izip(shot_list, rep(array_name),
                                     rep(other_arrays),
                                     rep(other_array_labels),
                                     start_times, end_times,
                                     rep(NFFT), rep(power_cutoff),
                                     rep(min_svs), rep(overlap),rep(meta_data))
    #generate the shot list for each worker
    if n_cpus>1:
        pool_size = n_cpus
        pool = Pool(processes=pool_size, maxtasksperchild=3)
        print('creating pool map')

        results = pool.map(single_shot_svd_wrapper, input_data_iter)
        print('waiting for pool to close ')
        pool.close()
        print('joining pool')
        pool.join()
        print('pool finished')
    else:
        results = map(single_shot_svd_wrapper, input_data_iter)
    start=1
    for i,tmp in enumerate(results):
        print(i)
        if tmp[0]!=None:
            if start==1:
                instance_array = copy.deepcopy(tmp[0])
                misc_data_dict = copy.deepcopy(tmp[1])
                start = 0
            else:
                instance_array = np.append(instance_array, tmp[0],axis=0)
                for i in misc_data_dict.keys():
                    misc_data_dict[i] = np.append(misc_data_dict[i], tmp[1][i],axis=0)
        else:
            print('One shot may have failed....')
    return clust.feature_object(instance_array = instance_array, misc_data_dict = misc_data_dict)
Exemplo n.º 2
0
def multi_stft(shot_selection, array_names, n_cpus=1, NFFT=2048, perform_datamining = 1, overlap=4, n_pts=20, lower_freq = 1500, filter_cutoff = 20, cutoff_by = 'sigma_eq'):
    #Get the scan details
    shot_list, start_times, end_times = H1_scan_list.return_scan_details(shot_selection)
    rep = itertools.repeat
    hop = NFFT/overlap
    input_data = itertools.izip(shot_list, rep(array_names), rep(NFFT), 
                                rep(hop), rep(n_pts), rep(lower_freq), rep(None),
                                start_times, end_times, rep(perform_datamining), 
                                rep(filter_cutoff), rep(cutoff_by))
    if n_cpus>1:
        pool_size = n_cpus
        pool = Pool(processes=pool_size, maxtasksperchild=3)
        print('creating pool map')
        results = pool.map(single_shot_wrapper, input_data)
        print('waiting for pool to close ')
        pool.close();pool.join()
        print('pool finished')
    else:
        results = map(single_shot_wrapper, input_data)
    start=1
    #Put everything back together
    kappa_list = []
    for i,tmp in enumerate(results):
        print(i)
        kappa_list.append(copy.deepcopy(tmp[2]))
        if tmp[0]!=None:
            if start==1:
                instance_array = copy.deepcopy(tmp[0])
                misc_data_dict = copy.deepcopy(tmp[1])
                start = 0
            else:
                instance_array = np.append(instance_array, tmp[0],axis=0)
                for i in misc_data_dict.keys():
                    misc_data_dict[i] = np.append(misc_data_dict[i], tmp[1][i],axis=0)
        else:
            print('something has failed....')
    return clust.feature_object(instance_array = instance_array, misc_data_dict = misc_data_dict), kappa_list
Exemplo n.º 3
0
""" plot a single diagnostic for a range of shots.  Could be made a subset of plot_multi?
"""
import pyfusion
import pylab as pl
import numpy as np
from pyfusion.devices.H1 import H1_scan_list

all_shots = H1_scan_list.get_all_shots()


_var_defaults = """
dev_name = "H1Local"
diag_name = "H1PoloidalMirnov1_6"
shot_list = all_shots[1:1000:10]
rows=3
cols=4
exception=Exception
ylims=None
"""
exec(_var_defaults)

from  pyfusion.utils import process_cmd_line_args
exec(process_cmd_line_args())

bad = []

sharey=None
if ylims is not None:
    sharey='all'

dev = pyfusion.getDevice(dev_name)