def get_nstx_efit_energy_data(exp_id=None, efit_tree='EFIT02'): """ \WB \EFIT01::TOP.RESULTS.AEQDSK:WB Poloidal magnetic field stored energy \WBDOT \EFIT01::TOP.RESULTS.AEQDSK:WBDOT time derivative of poloidal magnetic energy \WDIA \EFIT01::TOP.RESULTS.AEQDSK:WDIA diamagnetic energy \WMHD \EFIT01::TOP.RESULTS.AEQDSK:WMHD total plasma energy \WPDOT \EFIT01::TOP.RESULTS.AEQDSK:WPDOT time derivative of plasma stored energy """ if exp_id is None: raise ValueError('exp_id (shotnumber) needs to be set for gathering the efit energy data! Returning...') data={} d=flap.get_data('NSTX_MDSPlus',exp_id=exp_id,name='\\'+efit_tree+'::\WB',object_name='WB') data['Time']=d.coordinate('Time')[0] data['Poloidal']=d.data d=flap.get_data('NSTX_MDSPlus',exp_id=exp_id,name='\\'+efit_tree+'::\WDIA',object_name='WDIA') data['Diamagnetic']=d.data d=flap.get_data('NSTX_MDSPlus',exp_id=exp_id,name='\\'+efit_tree+'::\WMHD',object_name='WMHD') data['Total']=d.data return data
def test_storage(signals='TEST-*', timerange=[0, 0.001]): print() print( "\n>>>>>>>>>>>>>>>>>>> Test storage operations on test data <<<<<<<<<<<<<<<<<<<<<<<<" ) flap.delete_data_object('*', exp_id='*') if (type(signals) is list): s = "[" for sig in signals: s += sig + " " s += "]" else: s = signals print("**** Reading signal " + s + " for time range [" + str(timerange[0]) + '-' + str(timerange[1]) + '] with no_data=True') d = flap.get_data('TESTDATA', name=signals, options={'Scaling': 'Volt'}, object_name='TESTDATA', coordinates={'Time': timerange}, no_data=True) print("**** Storage contents") flap.list_data_objects() print() print("**** Reading the same with data") d = flap.get_data('TESTDATA', name=signals, options={'Scaling': 'Volt'}, object_name='TESTDATA', coordinates={'Time': timerange}) print("**** Storage contents") flap.list_data_objects()
def test_resample(): plt.close('all') print() print(">>>>>>>>>>>>> Test signal resampling (interpolation) <<<<<<<<<<<") flap.delete_data_object('*') print( "**** Generating two test signals with different sampling frequency.") flap.get_data('TESTDATA', name='TEST-1-1', options={ 'Scaling': 'Volt', 'Frequency': 1e3, 'Samplerate': 1e6 }, object_name='TEST-1MHz', coordinates={'Time': [0, 0.001]}) flap.get_data('TESTDATA', name='TEST-1-1', options={ 'Scaling': 'Volt', 'Frequency': 1.5e3, 'Samplerate': 3e6 }, object_name='TEST-3MHz', coordinates={'Time': [0, 0.001]}) print("\n***** Resampling from lower to higher frequency.") plt.figure() flap.plot('TEST-1MHz', axes='Time', plot_options={'marker': 'o'}) flap.plot('TEST-3MHz', plot_options={'marker': 'o'}) flap.slice_data('TEST-1MHz', slicing={'Time': flap.get_data_object('TEST-3MHz')}, options={'Interpol': 'Linear'}, output_name='TEST-1MHz_resample') flap.plot('TEST-1MHz_resample', plot_options={'marker': 'x'}) print("\n***** Resampling from higher to lower frequency.") plt.figure() flap.plot('TEST-1MHz', axes='Time', plot_options={'marker': 'o'}) flap.plot('TEST-3MHz', plot_options={'marker': 'o'}) flap.slice_data('TEST-3MHz', slicing={'Time': flap.get_data_object('TEST-1MHz')}, options={'Interpol': 'Linear'}, output_name='TEST-3MHz_resample') flap.plot('TEST-3MHz_resample', plot_options={'marker': 'x'}) print("\n***** Cutting parts.") plt.figure() flap.slice_data( 'TEST-1MHz', slicing={'Time': flap.Intervals([1e-4, 5e-4], [2e-4, 7e-4])}, options={'Slice': 'Simple'}, output_name='TEST-1MHz_parts') flap.plot('TEST-1MHz_parts', axes='Time', plot_options={'marker': 'o'}) flap.list_data_objects()
def test_get_data(): try: flap.get_data('CAMERA_APSD') apsd_available = True except: apsd_available = False if (not apsd_available): try: # flap.get_data('W7X_CAMERA',exp_id="20181018.032", name="AEQ20_EDICAM_ROIP1", coordinates={'Time':[3,4]}, object_name="EDI_ROIP1") flap.get_data('W7X_CAMERA', exp_id="20181018.012", name="AEQ21_PHOTRON_ROIP1", coordinates={'Time':[6.05,6.25]}, no_data=False, object_name="CAMERA") except Exception as e: raise e flap.list_data_objects() # flap.plot("CAMERA",plot_type='anim-image',axes=['Image y','Image x','Time'],options={'Wait':0.01,'Clear':True}) print("Slicing start") flap.slice_data('CAMERA', slicing={'Image x':flap.Intervals(0,4,step=5),'Image y':flap.Intervals(0,4,step=5)}, summing={'Interval(Image x) sample index':'Mean','Interval(Image y) sample index':'Mean'}, output_name='CAMERA_sliced') print("Slicing stop") # flap.plot("CAMERA_sliced", # plot_type='anim-image', # axes=['Start Image y in int(Image y)','Start Image x in int(Image x)','Time'], # options={'Wait':0.01,'Clear':True, 'Z range':[0,3000]}) print("*** APSD start") start = time.time() flap.apsd("CAMERA_sliced",coordinate='Time',options={'Res':200,'Range':[0,1e4]},output_name='CAMERA_APSD') stop = time.time() print('**** APSD STOP') print("**** Calculation time: {:5.2f} second".format(stop-start)) plt.close('all') # flap.plot('CAMERA_APSD', # slicing={'Start Image y in int(Image y)':50}, # plot_type='image', # axes=['Frequency','Start Image x in int(Image x)'], # options={'Z range':[0,5],'Aspect':'auto'}) # plt.figure() return flap.plot('CAMERA_APSD', plot_type='anim-image', axes=['Frequency','Start Image x in int(Image x)','Start Image y in int(Image y)'], options={'Z range':[0,5],'Aspect':'auto','Wait':0.1}) flap.list_data_objects()
def test_binning(): print() print() print('>>>>>>> Test image binning through multi-slice<<<<<<<<<<<') print("**** Generating a sequence of test images") flap.get_data('TESTDATA', name='VIDEO', object_name='TEST_VIDEO', options={ 'Length': 0.05, 'Samplerate': 1e3, 'Width': 500, 'Height': 800, 'Image': 'Gauss', 'Spotsize': 10 }) print("***** Showing one image") plt.figure() flap.plot('TEST_VIDEO', slicing={'Time': 30e-3 / 3}, plot_type='image', axes=['Image x', 'Image y'], options={ 'Clear': True, 'Interpolation': None, 'Aspect': 'equal' }) flap.slice_data('TEST_VIDEO', slicing={ 'Image x': flap.Intervals(0, 4, step=5), 'Image y': flap.Intervals(0, 9, step=10) }, summing={ 'Interval(Image x) sample index': 'Mean', 'Interval(Image y) sample index': 'Mean' }, output_name='TEST_VIDEO_binned') print("***** Showing one image of the (5,10) binned video ") plt.figure() flap.plot('TEST_VIDEO_binned', slicing={'Time': 30e-3 / 3}, plot_type='image', axes=['Image x', 'Image y'], options={ 'Clear': True, 'Interpolation': None, 'Aspect': 'equal' }) flap.list_data_objects()
def test_testdata(): print() print( "\n>>>>>>>>>>>>>>>>>>> Test TESTDATA data source <<<<<<<<<<<<<<<<<<<<<<<<" ) flap.delete_data_object('*', exp_id='*') print( "**** Generating 0.01 s long test data signals on [4,5] matrix with fixed frequency changing from channel to channel" ) d = flap.get_data('TESTDATA', name='TEST-*-*', options={ 'Scaling': 'Volt', 'Frequency': [1e3, 1e4], 'Length': 1e-2, 'Row number': 4, 'Column number': 5 }, object_name='TESTDATA') plt.figure() print("**** Plotting row 2") d.plot(slicing={'Row': 2}, axes=['Time']) print( "**** Generating 0.01 s long test data signal with linearly changing frequency: 10-100kHz" ) f = np.linspace(1e4, 1e5, num=11) coord = flap.Coordinate(name='Time', start=0.0, step=0.001, mode=flap.CoordinateMode(equidistant=True), dimension_list=[0]) f_obj = flap.DataObject(data_array=f, coordinates=[coord], data_unit=flap.Unit(name='Frequency', unit='Hz')) flap.list_data_objects(f_obj) d = flap.get_data('TESTDATA', name='TEST-1-1', options={ 'Scaling': 'Volt', 'Frequency': f_obj, 'Length': 0.01, 'Row number': 1, 'Column number': 1 }, object_name='TESTDATA') plt.figure() d.plot(axes='Time', options={'All': True})
def test_coordinates(): print() print( "\n>>>>>>>>>>>>>>>>>>> Testing adding coordinates <<<<<<<<<<<<<<<<<<<<<<<<" ) flap.delete_data_object('*', exp_id='*') print("**** Reading signal TEST-2-5 for time range [0,0.1]") d = flap.get_data('TESTDATA', name='TEST-2-5', options={'Scaling': 'Volt'}, object_name='TEST-1-1', coordinates={'Time': [0, 0.1]}) print("**** Storage contents") flap.list_data_objects() print() print("**** Adding Device x coordinate") flap.add_coordinate('TEST-1-1', exp_id='*', coordinates=['Device x', 'Device z', 'Device y']) print("**** Storage contents") flap.list_data_objects() print() print("**** Reading all test signals for time range [0,0.001]") d = flap.get_data('TESTDATA', name='TEST-*', options={'Scaling': 'Volt'}, object_name='TESTDATA', coordinates={'Time': [0, 0.001]}) print("**** Storage contents") flap.list_data_objects() print() print("**** Adding Device x coordinate") flap.add_coordinate('TESTDATA', exp_id='*', coordinates=['Device x', 'Device z', 'Device y']) print("**** Storage contents") flap.list_data_objects() print( "**** Getting the time coordinate. The result will be a 3D object with 1 element in all dimensions except along the time." ) t = flap.get_data_object_ref('TESTDATA').coordinate( 'Time', options={'Chang': True})[0].flatten() plt.figure() plt.plot(t) plt.xlabel('Index') plt.ylabel('Time')
def test_detrend(): plt.close('all') print() print('>>>>>>>>>>>>>>>>>>> Test detrend <<<<<<<<<<<<<<<<<<<<<<<<') flap.delete_data_object('*') print("**** Generating 8 sine signals with variable frequency.") d = flap.get_data('TESTDATA', name='TEST-1-*', object_name='TEST-1', options={ 'Signal': 'Sin', 'Freq': [1e3, 5E3], 'Length': 0.005 }) print("**** Detrending in 2 intervals with second order poly fit.") plt.figure() flap.plot('TEST-1', axes='Time') flap.detrend('TEST-1', intervals={ 'Time': flap.Intervals(0.001, 0.0015, step=0.003, number=2) }, options={'Trend': ['Poly', 2]}, output_name='TEST-1_detrend') flap.plot('TEST-1_detrend', axes='Time')
def test_cpsd(): plt.close('all') print() print( '>>>>>>>>>>>>>>>>>>> Test cpsd (Cross Spectral Power Density) <<<<<<<<<<<<<<<<<<<<<<<<' ) flap.delete_data_object('*') print("**** Generating 8 random data, 1 million points each.") d = flap.get_data('TESTDATA', name='TEST-1-[1-8]', options={ 'Signal': 'Random', 'Length': 1 }, object_name='TESTDATA') print("**** Calculating all cpsd") flap.cpsd('TESTDATA', options={ 'Norm': True, 'Interval': 50, 'Log': True, 'Res': 10, 'Range': [100, 1e5] }, output_name='TESTDATA_cpsd') flap.abs_value('TESTDATA_cpsd', output_name='TESTDATA_cpsd_abs') print( "**** Plotting coherency between channels 1-2 and its significance level." ) plt.figure() flap.plot('TESTDATA_cpsd_abs', axes='Frequency', slicing={ 'Row (Ref)': 1, 'Row': 2 }, options={ 'Log y': True, 'Log x': True, 'Error': False }) flap.error_value('TESTDATA_cpsd_abs').plot(slicing={ 'Row (Ref)': 1, 'Row': 2 }) plt.figure() print( "**** Plotting mean coherence in 1e4-1e5 frequency range as a function of row index." ) flap.slice_data('TESTDATA_cpsd_abs', slicing={ 'Frequency': flap.Intervals(1e4, 1e5) }, summing={ 'Frequency': 'Mean' }).plot(axes='Row (Ref)', options={'Y sep': 1.5})
def test_cache(): cached_file = os.sep.join(webapi.__file__.split(os.sep)[:-1] +\ ['cached','archivedb_codac_w7x_cbg_ecrh_totalpower_datastream'+ '_v1_0_ptot_ecrh_scaled_-20181016.037.hdf5']) existed = os.path.exists(cached_file) if existed is True: print("Can't properly test data caching, file already exists") flap.register_data_source('W7X_WEBAPI', get_data_func=webapi.get_data, add_coord_func=webapi.add_coordinate) d = flap.get_data( 'W7X_WEBAPI', name= 'ArchiveDB/codac/W7X/CBG_ECRH/TotalPower_DATASTREAM/V1/0/Ptot_ECRH/scaled/', exp_id='20181016.037', options={ 'Scale Time': True, 'Cache Data': True }, object_name='ECRH_data', coordinates={'Time': [2, 3]}) exists = os.path.exists(cached_file) if not existed: os.remove(cached_file) return exists
def test_mdsplus(): plt.close('all') print("**** Reading an explicit MDS signal.") flap.delete_data_object('*') try: # Explicit MDSPlus reference #d=flap.get_data('NSTX_MDSPlus', # name='IP', # exp_id=141398, # object_name='TEST_MDS' # ) d = flap.get_data('NSTX_MDSPlus', name='\EFIT01::\PSIRZ', exp_id=141399, object_name='TEST_MDS') #print(d.coordinate('Time')[0].shape) #print(d.coordinate('Device R')[0].shape) #print(d.coordinate('Device Z')[0].shape) #print(d.coordinate('Dimension 1')[0]) print(d.data) #print(d.data.shape) except Exception as e: raise e flap.plot('TEST_MDS', plot_type='animation', axes=['Device R', 'Device z', 'Time'], options={ 'Z range': [0, 0.05], 'Wait': 0.0, 'Clear': False }) #flap.plot('TEST_MDS',plot_type='contour',axes=['Time','Dimension 1'],options={}) #flap.plot('TEST_MDS') flap.list_data_objects()
def test_stft(): print( '>>>>>>>>>>>>>>>>>>> Test Short Time Fourier Transform (STFT) <<<<<<<<<<<<<<<<<<<<<<<<' ) print( "**** Generating 0.1 s long test data signal with linearly changing frequency: 10-100kHz" ) f = np.linspace(1e4, 1e5, num=11) coord = flap.Coordinate(name='Time', start=0.0, step=0.01, mode=flap.CoordinateMode(equidistant=True), dimension_list=[0]) f_obj = flap.DataObject(data_array=f, coordinates=[coord], data_unit=flap.Unit(name='Frequency', unit='Hz')) d = flap.get_data('TESTDATA', name='TEST-1-1', options={ 'Scaling': 'Volt', 'Frequency': f_obj, 'Length': 0.1, 'Row number': 1, 'Column number': 1 }, object_name='TESTDATA') flap.stft('TESTDATA', output_name='TEST_STFT') flap.abs_value('TEST_STFT', output_name='TEST_STFT') flap.list_data_objects() plt.figure() flap.plot('TEST_STFT', axes=['Time', 'Frequency'], plot_type='image')
def test_reading(): flap.register_data_source('JET_API', get_data_func=jetapi.get_data, add_coord_func=jetapi.add_coordinate) ky6 = flap.get_data('JET_API', name='JPF/DH/Y6-EMITER<VLT', exp_id=95531, object_name='JPF Voltage', options={}) return int(np.mean(ky6.data))
def test_mdsplus(): plt.close('all') print("**** Reading an explicit MDS signal.") flap.delete_data_object('*') try: # Explicit MDSPlus reference d=flap.get_data('W7X_MDSPlus', name='\QMC::TOP.HARDWARE:ACQ132_168:CHANNELS:INPUT_03', exp_id='20181018.003', object_name='TEST_MDS' ) except Exception as e: raise e print("**** Reading a virtual signal") try: # Explicit MDSPlus reference d1=flap.get_data('W7X_MDSPlus', name='PCI-1-16', exp_id='20180904.027', object_name="PCI-1-16" ) except Exception as e: raise e d1.plot(axes='Time') print("**** Reading multiple complex virtual signals in part of the time.") try: # Explicit MDSPlus reference d2=flap.get_data('W7X_MDSPlus', name=['CR-B','CR-C','CR-D','CR-E'], exp_id='20181018.003', coordinates={'Time':[4,4.1]}, object_name="CR" ) except Exception as e: raise e plt.figure() d2.abs_value().plot(axes='Time',options={'All':True}) flap.list_data_objects()
def test_plot_multi_xy(): print() print("\n>>>>>>>>>>>>>>>>>>> Test plot multi x-y --------") plt.close('all') plt.figure() flap.delete_data_object('*') d = flap.get_data('TESTDATA', name='TEST-1-*', options={'Scaling': 'Volt'}, object_name='TEST') print("**** Storage contents") flap.list_data_objects() flap.plot('TEST', axes='Time', options={'All points': False, 'Y sep': 4})
def test_pdf(): print( '>>>>>>>>>>>>>>>>>>> Test Probability Distribution Function (PDF) <<<<<<<<<<<<<<<<<<<<<<<<' ) print( "**** Generating 10x15 random test signals, 5000 points each, 1 MHz sampling." ) flap.get_data('TESTDATA', name='TEST-*-*', options={ 'Length': 0.005, 'Signal': 'Sin' }, object_name='TESTDATA') flap.pdf('TESTDATA', coordinate='Time', options={'Number': 30}, output_name='PDF') flap.list_data_objects() plt.figure() flap.plot('PDF', slicing={'Column': 3}, axes=['Signal']) plt.title('PDF of sine waves')
def test_plot_xy(): print() print("\n>>>>>>>>>>>>>>>>>>> Test plot x-y <<<<<<<<<<<<<<<<<<<<<<<<") plt.close('all') flap.delete_data_object('*') print("**** Reading signal TEST-2-5 for time range [0,0.1]") d = flap.get_data('TESTDATA', name='TEST-2-5', options={'Scaling': 'Volt'}, object_name='TEST-1-1', coordinates={'Time': [0, 0.1]}) print("**** Default plot") plt.figure() d.plot() print("**** Plotting time vs data") plt.figure() d.plot(axes=['__Data__', 'Time']) print("**** Reading all test signals for time range [0,0.001]") d = flap.get_data('TESTDATA', name='TEST-*', options={'Scaling': 'Volt'}, object_name='TESTDATA', coordinates={'Time': [0, 0.001]}) print("**** Adding Device coordinates") flap.add_coordinate('TESTDATA', exp_id='*', coordinates=['Device x', 'Device z', 'Device y']) flap.list_data_objects() print("**** Plotting measurement points in device corodinates.") plt.figure() flap.plot('TESTDATA', axes=['Device x', 'Device z'], plot_type='scatter') print("**** Plotting Device x as a function of Row.") plt.figure() flap.plot( 'TESTDATA', axes=['Row', 'Device x'], plot_type='scatter', )
def test_imagedata(): flap.register_data_source('W7X_WEBAPI', get_data_func=webapi.get_data, add_coord_func=webapi.add_coordinate) d = flap.get_data('W7X_WEBAPI', name='AUG-2', exp_id='20181016.037', options={ 'Scale Time': True, 'Cache Data': False }, object_name='AUG2_data', coordinates={'Time': [2, 3]}) return np.mean(d.data)
def test_reading(): flap.register_data_source('W7X_WEBAPI', get_data_func=webapi.get_data, add_coord_func=webapi.add_coordinate) d = flap.get_data('W7X_WEBAPI', name='ECRH', exp_id='20180912.012', options={ 'Scale Time': True, 'Check Time Equidistant': True, 'Cache Data': False }, object_name='ECRH_data') return [d.coordinates[0].mode.equidistant, d.coordinates[0].start]
def test_downsampling(): flap.register_data_source('W7X_WEBAPI', get_data_func=webapi.get_data, add_coord_func=webapi.add_coordinate) d = flap.get_data('W7X_WEBAPI', name='NBI-7', exp_id='20181016.037', options={ 'Scale Time': True, 'Downsample': 1024, 'Cache Data': False }, object_name='ECRH_data') return d.coordinates[0].shape
def export_gpi_data_to_paraview(exp_id=None, time_range=None, filename=None): if filename is None: filename='GPI_FOR_PARAVIEW_'+str(exp_id)+'_'+str(time_range[0])+'_'+str(time_range[1])+'.csv' d=flap.get_data('NSTX_GPI', exp_id=exp_id, name='', object_name='GPI') time=d.coordinate('Time')[0] ind=np.where(np.logical_and(time[:,0,0]>=time_range[0], time[:,0,0]<=time_range[1])) x=d.coordinate('Device R')[0][ind,:,:].flatten() y=d.coordinate('Device z')[0][ind,:,:].flatten() t=time[ind,:,:].flatten() data=d.data[ind,:,:].flatten() np.savetxt(filename, np.asarray([[x],[y],[10000*t],[data]])[:,0,:].T, delimiter=",", header='x [m], y [m], t [ms], data [a.u.]')
def test_vectordata(): flap.register_data_source('W7X_WEBAPI', get_data_func=webapi.get_data, add_coord_func=webapi.add_coordinate) # d = flap.get_data('W7X_WEBAPI', name='TS-v8-ne_map', d = flap.get_data('W7X_WEBAPI', name='ABES-v2-density', exp_id='20181016.037', options={ 'Scale Time': True, 'Cache Data': False }, object_name='ECRH_data', coordinates={'Time': [0, 3]}) return np.mean(d.data)
def test_timerange(): flap.register_data_source('W7X_WEBAPI', get_data_func=webapi.get_data, add_coord_func=webapi.add_coordinate) d = flap.get_data( 'W7X_WEBAPI', name= 'ArchiveDB/codac/W7X/CBG_ECRH/TotalPower_DATASTREAM/V1/0/Ptot_ECRH/scaled/', exp_id='20181016.037', options={ 'Scale Time': True, 'Cache Data': False }, object_name='ECRH_data', coordinates={'Time': [2, 3]}) return [d.coordinates[0].values[0], d.coordinates[0].values[-1]]
def test_select_multislice(): plt.close('all') print() print( '>>>>>>>>>>>>>>>>>>> Test select on maxima and multi slice <<<<<<<<<<<<<<<<<<<<<<<<' ) flap.delete_data_object('*') d = flap.get_data('TESTDATA', name='TEST-1-1', object_name='TEST-1-1', options={'Length': 0.050}) print( "**** Selecting 100 microsec long intervals around the maxima of the signal." ) d_int = flap.select_intervals('TEST-1-1', coordinate='Time', options={ 'Select': None, 'Length': 0.0001, 'Event': { 'Type': 'Max-weight', 'Threshold': 1, 'Thr-type': 'Sigma' } }, plot_options={'All points': True}, output_name='SELECT') flap.list_data_objects() d_int.plot(axes=['__Data__', 0], plot_type='scatter', options={'Force': True}) if (d_int is not None): print("**** Overplotting the signals in the selected intervals.") flap.slice_data('TEST-1-1', slicing={'Time': d_int}, output_name='TEST-1-1_sliced') flap.list_data_objects() plt.figure() n_int = d_int.shape[0] for i in range(n_int): flap.plot('TEST-1-1_sliced', slicing={'Interval(Time)': i}, axes='Rel. Time in int(Time)')
def get_data(self, data_source, exp_id=None, options=None): default_options = {'Verbose': False} _options = flap.config.merge_options(default_options,options,data_source='NSTX_GPI') try: efit_dictionary=flap.config.get_all_section('EFIT') except: raise ValueError("Couldn't read the EFIT section of the configuration file.") for index in efit_dictionary: if not (index == None): try: self[index]=flap.get_data(data_source, name=efit_dictionary[index], exp_id=exp_id, object_name=index) except: self[index]=None if (_options['Verbose']): print("Couldn't read "+efit_dictionary[index]+ " for shot "+str(exp_id))
def test_NSTX_GPI_norm_flux_coord(exp_id=141918): flap.delete_data_object('*') print("\n------- test data read with NSTX GPI data and plotting it as a function of normalized flux coordinates --------") d=flap.get_data('NSTX_GPI',exp_id=exp_id,name='',object_name='GPI') print("**** Storage contents") flap.list_data_objects() plt.close('all') print("**** Adding normalized flux coordinates.") print("--- %s seconds ---" % (time.time() - start_time)) #d.add_coordinate(coordinates='Flux r',exp_id=exp_id) print("--- %s seconds ---" % (time.time() - start_time)) d.add_coordinate(coordinates='Flux theta',exp_id=exp_id) flap.list_data_objects() print('Coordinate was read.') print("--- %s seconds ---" % (time.time() - start_time)) flap.plot('GPI',plot_type='animation',\ slicing={'Time':flap.Intervals(250.,260.)},\ axes=['Flux R','Flux theta','Time'],\ options={'Z range':[0,512],'Wait':0.0,'Clear':False}) print("--- %s seconds ---" % (time.time() - start_time))
def test_simple_slice(): print() print("\n>>>>>>>>>>>>>>>>>>> Test simple slice <<<<<<<<<<<<<<<<<<<<<<<<") flap.delete_data_object('*') print("**** Reading all test signals for time range [0,0.001]") d = flap.get_data('TESTDATA', name='TEST-*', options={'Scaling': 'Volt'}, object_name='TESTDATA', coordinates={'Time': [0, 0.001]}) print("**** Adding Device coordinates") flap.add_coordinate('TESTDATA', coordinates=['Device x', 'Device z', 'Device y']) print("**** Storage contents before slice") flap.list_data_objects() print("**** Slicing with {'Signal name': 'TEST-1-*'}") flap.slice_data('TESTDATA', slicing={'Signal name': 'TEST-1-*'}, output_name='TESTDATA_slice') print("**** Sliced object") flap.list_data_objects(name='TESTDATA_slice')
def test_gpi_trace(exp_id=140620): flap.delete_data_object('*') print("\n------- test data read with NSTX GPI data --------") d=flap.get_data('NSTX_GPI',exp_id=exp_id,name='',object_name='GPI') print("**** Storage contents") flap.list_data_objects() plt.close('all') #print("**** Filtering GPI") #d_filter=flap.filter_data('GPI',output_name='GPI_filt',coordinate='Time', # options={'Type':'Highpass','f_low':1e2/1e3,'Design':'Chebyshev II'}) #Data is in milliseconds print("**** Plotting filtered GPI") #flap.plot('GPI',plot_type='animation', # slicing={'Time':flap.Intervals(550.,580.)}, # axes=['Device R','Device z','Time'], # options={'Z range':[0,512],'Wait':0.0,'Clear':False}) # print(d.time) flap.list_data_objects()
def getdata(self): """ Callback function for get data. Returns ------- None. """ if (len(self.var_shotID.get()) == 0): self.add_message("No Measurement ID (directory name) is set.") return try: t_start = float(self.var_start_time.get()) except ValueError: t_start = None try: t_end = float(self.var_end_time.get()) except ValueError: t_end = None if ((t_start is not None) and (t_end is not None)): coord = {"Time": [t_start, t_end]} else: coord = None try: self.data = flap.get_data('APDCAM', name=self.var_signals.get(), coordinates=coord, options={ 'Datapath': self.var_shotID.get(), 'Camera type': self.camera_type, 'Camera version': self.camera_version }) self.add_message("Data '{:s}' read from '{:s}'.".format( self.var_signals.get(), self.var_shotID.get())) except Exception as e: self.add_message("Error reading data: {:s}".format(str(e)))
def export_gpi_data_to_paraview(exp_id=None, time_range=None, filename=None, filter_data=True, flux_coordinates=False): if filename is None: filename = 'GPI_FOR_PARAVIEW_' + str(exp_id) + '_' + str( time_range[0]) + '_' + str(time_range[1]) # d=flap.get_data('NSTX_GPI', exp_id=exp_id, name='', object_name='GPI') # d=flap.slice_data('GPI', slicing={'Time':flap.Intervals(time_range[0],time_range[1])}) # if filter_data: # d=flap.filter_data('GPI',exp_id=exp_id, # coordinate='Time', # options={'Type':'Highpass', # 'f_low':1e2, # 'Design':'Chebyshev II'}) # filename=filename+'_FILTERED' # time=d.coordinate('Time')[0] # x=d.coordinate('Device R')[0].flatten() # y=d.coordinate('Device z')[0].flatten() # t=time.flatten() # data=d.data.flatten() # np.savetxt(filename, np.asarray([[x],[y],[1000*t],[data]])[:,0,:].T, delimiter=",", header='x [m], y [m], t [ms], data [a.u.]') d = flap.get_data('NSTX_GPI', exp_id=exp_id, name='', object_name='GPI') if filter_data: d = flap.filter_data('GPI', exp_id=exp_id, coordinate='Time', options={ 'Type': 'Highpass', 'f_low': 1e2, 'Design': 'Chebyshev II' }) filename += '_FILTERED' if flux_coordinates: flap.add_coordinate('GPI', 'Flux r') filename += '_FLUX' d = flap.slice_data( 'GPI', slicing={'Time': flap.Intervals(time_range[0], time_range[1])}) # time=d.coordinate('Time')[0] # ind=np.where(np.logical_and(time[:,0,0]>=time_range[0], time[:,0,0]<=time_range[1])) # x1=d.coordinate('Device R')[0][ind,:,:].flatten() # y=d.coordinate('Device z')[0][ind,:,:].flatten() # t=time[ind,:,:].flatten() # data=d.data[ind,:,:].flatten() t = d.coordinate('Time')[0].flatten() x1 = d.coordinate('Device R')[0].flatten() y = d.coordinate('Device z')[0].flatten() data = d.data.flatten() filename = filename + '.csv' if flux_coordinates: #x2=d.coordinate('Flux r')[0][ind,:,:].flatten() x2 = d.coordinate('Flux r')[0].flatten() x2 = (x2 - np.min(x2)) / (np.max(x2) - np.min(x2)) * ( np.max(x1) - np.min(x1)) + np.min(x1) np.savetxt( filename, np.asarray([[x1], [x2], [y], [10000 * t], [data]])[:, 0, :].T, delimiter=",", header='R [m], PSI_rescaled [m], z [m], t [0.1ms], data [a.u.]') else: np.savetxt(filename, np.asarray([[x1], [y], [10000 * t], [data]])[:, 0, :].T, delimiter=",", header='R [m], z [m], t [0.1ms], data [a.u.]')