Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titleExample script of fetching data from JET
linenumberstrue
collapsetrue
#example of saving experimental data to ids

import os
import json	

def read_ppf(conn, shot, ppf, seq=0, uid='jetppf',debug=False):
    ierr = conn.get('_sig=ppfuid("' + uid +'")')
    c = '_sig=jet("ppf/%s/%d",%d)'% (ppf, seq, shot)
    if debug: print('\nDEBUG: %s\n' % c)
    try:
        s = conn.get(c)
        raw = s.data()
        dim0 = conn.get('dim_of(_sig,0)').data()
        try:
          dim1 = conn.get('dim_of(_sig,1)').data()
          return {'raw': raw, 'x':dim0, 't':dim1}
        except:
          return {'raw': raw, 't':dim0}
    except:
      return None


def readExperimental(data_exp, host, server='ssh://'):
    '''
    reads experimental data after connecting to the host via ssh server
    data_exp: data details in dictionary format	
    '''
    import sys
    try:	
        import MDSplus
        haveMDS = True
    except:
        print(' No MDSplus support found.\n')
        print('\n\n\n Exiting...\n')
        exit(1)

    try:
      conn = MDSplus.Connection(server+host)
      print('Connection OK')
      connected = True
    except:
      print('in readExperimental, MDSplus failed: ',sys.exc_info()[1])
      connected = False

    if connected:
        try:
            EXP={}
            for sig in data_exp['dtype']:
                print('reading dtype: ',sig)
                signal= data_exp['dda']+'/'+sig
                aux = read_ppf(conn, discharge, signal, seq=data_exp['seq'], uid=data_exp['uid']) 
                #conv# = read_ppf(conn,args.Shot, 'WSXP/RHOT', seq=args.seq, uid=args.uid)
	        #print("rhot:dx ", conv['x']-aux['x'])Z coordinate is one dimensional, aux['raw'] is 2D by default
                #print('rhot[raw]:', conv['raw'])
if sig=='Z':
                 print('len(x): ',len(aux['x']))
                print('time: ',aux['t'][0],aux['t'][-1],len(aux['t']))
                print('shape(value):',aux['raw'].shape)
                print('len(aux)', len(aux))
                print('')
	        #EXP=None   aux['raw'] = aux['raw'].flatten()

                EXP[sig] =  {
                    'time': aux['t'].tolist(),
                    'x':aux['x'].tolist(),
                    'data': aux['raw'].tolist(),
                    'signal': signal
                #'rhot'  : np.sqrt(conv['raw']) 
                    }
        except:
            print('in readExperimental, read_ppf failed: ',sys.exc_info()[1])
            return None
        del(conn)
    else:
        EXP=None
    
    return EXP

###########


host='jet'

discharge=99357

# data to download
data={}
data['dda']='hrts'
data['uid'] = 'jetppf'
data['seq']=0
data['dtype']=['TE','DTE','NE','DNE','Z']

EXP=readExperimental(data,host)

if FalseEXP:
     a a_file = open("'data_jet_ssh_fetched.json"_fetched_'+str(discharge)+'_'+data['dda']+'_'+str(data['seq'])+'.json', "w")
    json.dump(EXP, a_file)
    a_file.close()

...