示例#1
0
    print('Only {n} files found for {fl}'.format(fl=file_list, n=len(file_list)))
(ds_list, comment_list) = read_text_pyfusion(file_list, debug=debug, exception=exception, target=target)

if len(ds_list) == 0: raise LookupError('no valid files found in the {n} files in {f}'
                                        .format(f=file_list,n=len(file_list)))
if isinstance(file_list_in, str):
    comment_list = [file_list_in] + comment_list

if append_old_method:
    ds_list.append(dd)
    comment_list.extend(dd['info']['comment'])
if append:
    dd = merge_ds(ds_list, comment_list, old_dd=dd)
else:
    dd = merge_ds(ds_list, comment_list)

if save_filename != "None":
    from pyfusion.data.DA_datamining import DA
    DAtest=DA(dd)
    DAtest.info()
    DAtest.save(save_filename)









示例#2
0
DA766.extract(
    locals()
)  #  Extract all the data into local variables, such as freq, t_mid, phases[0]
wb = np.where((amp > 0.05) & (a12 > 0.7))[
    0]  #  find large amplitude, 'rotating' modes (see text).

mp = 1.67e-27
mu_0 = 4 * np.pi * 1e-7
V_A = b_0 / np.sqrt(
    mu_0 * n_e * 1e18 *
    mp)  # Calculate VA as a local variable , an array of the same size as the
#   extracted data
DA766.update(
    dict(V_A=V_A
         ))  #  Add it to the dictionary - no problem if you use the same name
#   for the dictionary key
DA766.save(
    'H1_766_new')  #  Save the data set (under a new name if you prefer).
#  When you load the dataset in the future, the variable V_A will be there.
plt.plot(
    k_h, freq * 1e3 / V_A, '.c'
)  # symbol '.', colour cyan - we see the values are in the range sqrt beta
plt.plot(
    k_h[wb], freq[wb] * 1e3 / V_A[wb], 'ob',
    ms=12)  # selecting large amplitude as above, we see beginnings of fig 5
plt.xlabel(r'$k_H$')
plt.ylabel(r'${\rm frequency/V_{Alfven}}$', fontdict={'fontsize': 'large'})
plt.show()
# Note - there will be a warning "invalid value encountered in sqrt" due to noise in n_e
# This could be eliminated by selecting using np.where(n_e >= 0)[0]
示例#3
0
        if verbose>0:
            msg += ' because\n {r}'
        print(msg.format(s=shot_number, r=reason))

# store the data in a DA (Dictionary of Arrays) object, which is like a DataFrame in R or python panda
#myDA = pf.data.DA_datamining.Masked_DA(
#    DAordict = dict(shot=shot, ne_profile=np.array(ne_profile), t_mid=t_mid), valid_keys=['ne_profile'], mask=0)
myDA = DA(dict(shot=shot, ne_profile=np.array(ne_profile), t_mid=t_mid))
myDA.masked = Masked_DA(valid_keys=['ne_profile'], baseDA=myDA)
myDA.da['mask'] = np.ones(shape=np.shape(myDA[myDA.masked.valid_keys[0]])).astype(np.uint8)
channels = [ch.name.split(':')[-1] for ch in seg.channels]
myDA.infodict.update(dict(channels = channels))
for (c, ch) in enumerate(channels):
    if np.any([ex in ch for ex in exclude]): # if any of exclude in that channel
        myDA.da['mask'][:,c] = 0
myDA.save('/tmp/density_scan')
# the next step - write to arff
# myDA.write_arff('ne_profile.arff',['ne_profile'])

import matplotlib.pyplot as plt
def pl(array, comment=None,**kwargs):
    plt.figure(num=comment)  # coment written to window title
    plt.plot(array, **kwargs)

# get the variables into local scope - so they can be accessed directly
myDA.extract(locals())        

# the ne profiles are in an Nx15 array, where N is the numer of channels
pl(ne_profile[40,:],'one profile')

# plot a sequence of profiles, showing every fifth 
示例#4
0
""" Example 5 - Figure 7
Adding the Alfven speed for each item into the data set. colour
"""
from pyfusion.data.DA_datamining import DA           
import numpy as np
import matplotlib.pyplot as plt

plt.figure('Example 5 - Figure 7')
DA766 = DA('H1_766.npz',load=1)    #  Load data from 30 shots into a dictionary of arrays (DA)
DA766.extract(locals())            #  Extract all the data into local variables, such as freq, t_mid, phases[0]
wb = np.where((amp>0.05) & (a12>0.7))[0]  #  find large amplitude, 'rotating' modes (see text).  

mp = 1.67e-27
mu_0 = 4 * np.pi * 1e-7
V_A = b_0/np.sqrt(mu_0 * n_e * 1e18* mp)  # Calculate VA as a local variable , an array of the same size as the   
                                          #   extracted data
DA766.update(dict(V_A=V_A))        #  Add it to the dictionary - no problem if you use the same name
                                   #   for the dictionary key
DA766.save('H1_766_new')           #  Save the data set (under a new name if you prefer).
                                   #  When you load the dataset in the future, the variable V_A will be there.
plt.plot(k_h, freq*1e3/V_A,'.c')   # symbol '.', colour cyan - we see the values are in the range sqrt beta
plt.plot(k_h[wb], freq[wb]*1e3/V_A[wb],'ob',ms=12) # selecting large amplitude as above, we see beginnings of fig 5
plt.xlabel(r'$k_H$'); plt.ylabel(r'${\rm frequency/V_{Alfven}}$',fontdict={'fontsize':'large'})
plt.show()
# Note - there will be a warning "invalid value encountered in sqrt" due to noise in n_e
# This could be eliminated by selecting using np.where(n_e >= 0)[0]
示例#5
0
    def write_DA(self, filename):
        from pyfusion.data.DA_datamining import DA,  Masked_DA
        dd = {}
        res = np.array(self.fitdata, dtype=np.float32)
        nt = len(res)
        nc = len(res[0])
        for key in ['date', 'progId', 'shot']:
            dd[key] = np.zeros(nt, dtype=np.int64)
            
        dd['date'][:] = self.shot[0]
        dd['progId'][:] = self.shot[1]
        dd['shot'][:] = self.shot[1] + 1000*self.shot[0]

        for key in ['nits','maxits']:
            dd[key] = np.zeros([nt,nc], dtype=np.uint16)

        # make all the f32 arrays - note - ne is just I0 for now - fixed below
        lookup = [(0, 't_mid'), (1, 'Te'), (2, 'Vf'), (3, 'I0'), 
                  (4, 'resid'), (5, 'nits'), (6, 'maxits'), (7, 'Ie_Ii'),
                  (3, 'ne18')]

        if self.fitter.fit_params.get('esterr',False):
            lookup.extend([(8, 'eTe'), (9, 'eVf'), (10, 'eI0') ])

        for (ind, key) in lookup:
            if key not in dd:
                dd[key] = np.zeros([nt, nc], dtype=np.float32)
            dd[key][:] = res[:, :, ind]

        # fudge t_mid is not a vector...should fix properly
        dd['t_mid'] = dd['t_mid'][:, 0]
        dd['info'] = dict(params=self.actual_params,
                          coords=[self.coords[ic] for ic in self.select],
                          #area=[self.area[ic] for ic in self.select], # needs to be in npz file etc first
                          shotdata=dict(shot=[self.shot], utc_ns=[self.imeas.utc[0]]),
                          channels=[chn.replace(self.dev.name+'_', '')
                                    .replace('_I', '')
                                    for chn in
                                    [self.i_chans[ic] for ic in self.select]],
                          orig_name = os.path.split(filename)[-1],
                          username = os.getlogin())
        
        da = DA(dd)
        da.masked = Masked_DA(['Te', 'I0', 'Vf', 'ne18', 'Ie_Ii'], baseDA=da)
        #  da.da['mask']=(da['resid']/abs(da['I0']) < .7) & (da['nits']<100)
        #  da.da['mask'] = ((da['resid']/abs(da['I0']) < .7) & (da['nits'] < da['maxits'])
        # from version 0.7.0 onwards, resid is already normed to I0
        lpf = self.fitter.actual_fparams['lpf']
        # Note: these multilines ('down to here') can be applied to a DA by 
        #       pasting to reset mask AFTER uncommenting the following # line
        # lpf = da['info']['params']['actual_fit_params']['lpf']
        rthr = 0.7  # LP20160309_29_L53__amoebaNone1.2N_2k.npz is < .12  others 
                    # None 0310_9 up to 0.7-0.8
        if lpf is not None:
            rthr = rthr * np.sqrt(lpf/100.0)
        da.da['mask'] = ((da['resid'] < rthr) & (da['nits'] < da['maxits'])
                         & (np.abs(da['Vf']) < 200) & (np.abs(da['Te']) < 200) 
                         & (da['I0']>0.0004))
        # additional restriction applied if the error estimate is available
        if 'eTe' in da.da:  # want error not too big and smaller than temp
            da.da['mask'] &= ((np.abs(da['eTe']) < 100)
                              & (np.abs(da['eTe']) < np.abs(da['Te'])))
        #   down to here
        qe = 1.602e-19
        mp = 1.67e-27
        fact = 1/(0.6*qe)*np.sqrt(self.amu*mp/(qe))/1e18         # units of 1e18
        # check if each channel has an area

        for (c, chn) in enumerate([self.i_chans[ic] for ic in self.select]):
            cd = get_config_as_dict('Diagnostic', chn)
            A = cd.get('area', None)
            if A is None:
                A = 1.0e-6
                pyfusion.logging.warn('Defaulting area for {chn} to {A}'.format(chn=chn, A=A))
            A = float(A)
            da.da['ne18'][:, c] = fact/A * da['I0'][:, c]/np.sqrt(da['Te'][:, c])
        da.save(filename)
示例#6
0
exec(pf.utils.process_cmd_line_args())

# prepare an empty lists for data - lists are easy to append to
ne_profile = []
shot = [] 
t_mid = []

dev = pf.getDevice(device_name) # open the device (choose the experiment)

for shot_number in shot_range:
    try:
        d = dev.acq.getdata(shot_number, ne_set)
        if time_range != None:
            d.reduce_time(time_range)
        sections = d.segment(n_samples, overlap)
        print(d.history, len(sections))

        for ss,t_seg in enumerate(sections):
            ne_profile.append(np.average(t_seg.signal,axis=1))
            t_mid.append(np.average(t_seg.timebase))

            shot.append(shot_number)
    except exception as reason:
        print 'Error {e} on shot {s}'.format(e=reason, s=shot)
# make the dictionary of arrays and put it in a DA object
myDA = DA(dict(shot=shot, ne_profile=ne_profile, t_mid=t_mid))
myDA.save('ne_profile')



示例#7
0
if len(file_list)<10:
    print('Only {n} files found for {fl}'.format(fl=file_list, n=len(file_list)))
(ds_list, comment_list) = read_text_pyfusion(file_list, debug=debug, exception=exception, target=target)

if len(ds_list) == 0: raise LookupError('no valid files found in the {n} files in {f}'
                                        .format(f=file_list,n=len(file_list)))

if append_old_method:
    ds_list.append(dd)
    comment_list.extend(dd['info']['comment'])
if append:
    dd = merge_ds(ds_list, comment_list, old_dd=dd)
else:
    dd = merge_ds(ds_list, comment_list)

if save_filename != "None":
    from pyfusion.data.DA_datamining import DA
    DAtest=DA(dd)
    DAtest.info()
    DAtest.save(save_filename)









                       
               else:
                   dd[key][ws] = basic_data[key].astype(pyfusion.prec_med)
               if debug: print('{key}: avg={a:.3g}'.
                               format(key=key,a=np.average(dd[key][ws]))),

try:
    filename
except:
    filename='ddfile'
    print('filename defaulting to ', filename)

save_name = 'saved_'+os.path.splitext(os.path.split(filename)[1])[0]
print('Saving as {0}'.format(save_name))
newDA=DA(dd)
newDA.save(save_name)

print("{0} missing shots out of {1}".format(len(missing_shots),(len(missing_shots)+len(good_shots))))

if verbose>0: print('missing shots are {0}'.format(missing_shots))

for key in diags:
        print('{0:10s}: {1:.1f}%'.format(key, 100.0*np.sum(dd[key]*0==0)/sz))

"""
source /home/LHD/blackwell/pyfusion/pyfusion_mar_2015/pyfusion/run_pyfusion NV13 $x
exit
set_window_title $x
python pyfusion/examples/merge_basic_diagnostics.py diags=diags+diag_extra "filename='/home/LHD/blackwell/datamining/DA/PF2_150311_VSL6_$x'"

"""
示例#9
0
                    dd[key][ws] = basic_data[key].astype(pyfusion.prec_med)
                if debug:
                    print('{key}: avg={a:.3g}'.format(key=key,
                                                      a=np.average(
                                                          dd[key][ws]))),

try:
    filename
except:
    filename = 'ddfile'
    print('filename defaulting to ', filename)

save_name = 'saved_' + os.path.splitext(os.path.split(filename)[1])[0]
print('Saving as {0}'.format(save_name))
newDA = DA(dd)
newDA.save(save_name)

print("{0} missing shots out of {1}".format(
    len(missing_shots), (len(missing_shots) + len(good_shots))))

if verbose > 0: print('missing shots are {0}'.format(missing_shots))

for key in diags:
    print('{0:10s}: {1:.1f}%'.format(key,
                                     100.0 * np.sum(dd[key] * 0 == 0) / sz))
"""
source /home/LHD/blackwell/pyfusion/pyfusion_mar_2015/pyfusion/run_pyfusion NV13 $x
exit
set_window_title $x
python pyfusion/examples/merge_basic_diagnostics.py diags=diags+diag_extra "filename='/home/LHD/blackwell/datamining/DA/PF2_150311_VSL6_$x'"