Beispiel #1
0
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()
Beispiel #2
0
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')
Beispiel #3
0
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()
Beispiel #4
0
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()
Beispiel #5
0
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()
Beispiel #6
0
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})
Beispiel #7
0
def test_mdsplus_efit():

    plt.close('all')
    print("**** Reading all EFIT MDS signals.")
    flap.delete_data_object('*')
    try:
        d = flap_mdsplus.FlapEFITObject()
        d.get_data('NSTX_MDSPlus', exp_id=141399)
        print(d)
    except Exception as e:
        raise e

#    flap.plot('TEST_MDS',plot_type='animation',axes=['Device R','Device Z','Time'],options={'Z range':[0,512],'Wait':0.0,'Clear':False})
    flap.list_data_objects()
Beispiel #8
0
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()
Beispiel #9
0
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})
Beispiel #10
0
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)')
Beispiel #11
0
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')
Beispiel #12
0
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))
Beispiel #13
0
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 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()
Beispiel #15
0
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')
Beispiel #16
0
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')
Beispiel #17
0
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',
    )
Beispiel #18
0
def test_saveload():
    print()
    print("\n>>>>>>>>>>>>>>>>>>> Test save/load <<<<<<<<<<<<<<<<<<<<<<<<")
    flap.delete_data_object('*')
    print("**** Storage contents before save.")
    flap.list_data_objects()
    print("**** Saving all storage and deleting storage contents.")
    flap.save('*', 'flap_save_test.dat')
    flap.delete_data_object('*')
    print("**** Storage contents after erasing.")
    flap.list_data_objects()
    flap.load('flap_save_test.dat')
    print("**** Storage contents after loading.")
    flap.list_data_objects()
    flap.delete_data_object('*')
    print("**** Storage contents after erasing.")
    d = flap.load('flap_save_test.dat', options={'No': True})
    print(d)
    print("**** Storage contents after loading with 'No storage' option.")
    flap.list_data_objects()
    flap.delete_data_object('*')
    flap.save([d, 'test'], 'flap_save_test.dat')
    d1 = flap.load('flap_save_test.dat', options={'No': True})
    print(d1)
Beispiel #19
0
def test_arithmetic():
    print()
    print(
        "\n>>>>>>>>>>>>>>>>>>> Testing DataObject arithmetic <<<<<<<<<<<<<<<<<<<<<<<<"
    )
    d = flap.get_data('TESTDATA',
                      name='TEST-*',
                      options={'Scaling': 'Volt'},
                      object_name='TESTDATA',
                      coordinates={'Time': [0, 0.001]})

    print("\n***** Adding two DataObjects. One coordinate name is different.")
    d1 = copy.deepcopy(d)
    d1.coordinates[1].unit.name = 'ssd'
    d2 = d + d1
    flap.list_data_objects([d, d1, d2])
    print(d.data[0, 0, 0], d1.data[0, 0, 0], d2.data[0, 0, 0])
    print(d.data[1, 1, 1], d1.data[1, 1, 1], d2.data[1, 1, 1])

    print("\n***** Adding scalar to a DataObject.")
    d2 = d + 3
    flap.list_data_objects([d, d2])
    print(d.data[0, 0, 0], d2.data[0, 0, 0])
    print(d.data[1, 1, 1], d2.data[1, 1, 1])
    d2 = 3 + d
    print(d.data[0, 0, 0], d2.data[0, 0, 0])
    print(d.data[1, 1, 1], d2.data[1, 1, 1])

    print("\n***** Subtracting two DataObjects.")
    d1 = d + 3
    d2 = d - d1
    flap.list_data_objects([d, d1, d2])
    print(d.data[0, 0, 0], d1.data[0, 0, 0], d2.data[0, 0, 0])
    print(d.data[1, 1, 1], d1.data[1, 1, 1], d2.data[1, 1, 1])
    d2 = d1 - d
    flap.list_data_objects([d, d1, d2])
    print(d.data[0, 0, 0], d1.data[0, 0, 0], d2.data[0, 0, 0])
    print(d.data[1, 1, 1], d1.data[1, 1, 1], d2.data[1, 1, 1])

    print("\n***** Subtracting scalar from a DataObject.")
    d2 = d - 3
    flap.list_data_objects([d, d2])
    print(d.data[0, 0, 0], d2.data[0, 0, 0])
    print(d.data[1, 1, 1], d2.data[1, 1, 1])
    d2 = 3 - d
    print(d.data[0, 0, 0], d2.data[0, 0, 0])
    print(d.data[1, 1, 1], d2.data[1, 1, 1])

    print("\n***** Multiplying two DataObjects.")
    d1 = copy.deepcopy(d)
    d1 = d1 + 3
    d2 = d * d1
    flap.list_data_objects([d, d1, d2])
    print(d.data[0, 0, 0], d1.data[0, 0, 0], d2.data[0, 0, 0])
    print(d.data[1, 1, 1], d1.data[1, 1, 1], d2.data[1, 1, 1])

    print("\n***** Multiplying DataObject with constant.")
    d1 = d * 3
    flap.list_data_objects([d, d1, d2])
    print(d.data[0, 0, 0], d1.data[0, 0, 0])
    print(d.data[1, 1, 1], d1.data[1, 1, 1])
Beispiel #20
0
def test_ccf():
    plt.close('all')
    print()
    print(
        '>>>>>>>>>>>>>>>>>>> Test ccf (Cross Correlation Function) <<<<<<<<<<<<<<<<<<<<<<<<'
    )
    flap.delete_data_object('*')
    print(
        "**** Generating 10x15 random test signals, 5000 points each, 1 MHz sampling."
    )
    flap.get_data('TESTDATA',
                  name='TEST-*-*',
                  options={
                      'Length': 0.005,
                      'Signal': 'Random'
                  },
                  object_name='TESTDATA')
    print("**** Filtering with 10 microsec integrating filter.")
    flap.filter_data('TESTDATA',
                     coordinate='Time',
                     options={
                         'Type': 'Int',
                         'Tau': 1e-5
                     },
                     output_name='TESTDATA_filt')
    flap.list_data_objects()
    plt.figure()
    print("**** Plotting an original and a filtered signal.")
    flap.plot('TESTDATA', slicing={'Row': 1, 'Column': 1}, axes='Time')
    flap.plot('TESTDATA_filt', slicing={'Row': 1, 'Column': 1})
    print('**** Calculating the 10x15x10x15 CCFs, each 5000 samples.')
    print('**** CCF START')
    start = time.time()
    flap.ccf('TESTDATA_filt',
             coordinate='Time',
             options={
                 'Trend': 'Mean',
                 'Range': [-1e-4, 1e-4],
                 'Res': 1e-5,
                 'Norm': True
             },
             output_name='CCF')
    stop = time.time()
    print('**** CCF STOP')
    print("**** Calculation time: {:6.3f} ms/signal".format(
        1000 * (stop - start) / (10 * 15 * 10 * 15)))
    flap.list_data_objects()
    print(
        "**** Plotting spatiotemporal correlation function at ref row, column 3,3, column 3"
    )
    plt.figure()
    flap.plot('CCF',
              slicing={
                  'Row (Ref)': 3,
                  'Column (Ref)': 3,
                  'Column': 3
              },
              axes=['Time lag'],
              plot_type='multi xy')

    print("**** Slicing TESTDATA_filt for row: 1-3, column:1-4")
    flap.slice_data('TESTDATA_filt',
                    slicing={
                        'Row': [1, 2, 3],
                        'Column': [1, 2, 3, 4]
                    },
                    output_name='TESTDATA_filt_3x4')
    print('**** Calculating CCFs, between original and sliced TESTDATAfilt')
    print('**** CCF START')
    flap.ccf('TESTDATA_filt',
             ref='TESTDATA_filt_3x4',
             coordinate='Time',
             options={
                 'Trend': 'Mean',
                 'Range': [-1e-4, 1e-4],
                 'Res': 1e-5,
                 'Norm': True
             },
             output_name='CCF_ref')
    print('**** CCF STOP')
    flap.list_data_objects()
    print(
        "**** Plotting spatiotemporal correlation function at ref row, column 3,3, column 3"
    )
    plt.figure()
    flap.plot('CCF_ref',
              slicing={
                  'Row (Ref)': 3,
                  'Column (Ref)': 3,
                  'Column': 3
              },
              axes=['Time lag'],
              plot_type='multi xy')
Beispiel #21
0
def test_apsd():
    plt.close('all')
    print()
    print(
        '>>>>>>>>>>>>>>>>>>> Test apsd (Auto Power Spectral Density) <<<<<<<<<<<<<<<<<<<<<<<<'
    )
    flap.delete_data_object('*')
    #plt.close('all')
    print(
        '**** Generating test signals with frequency changing from channel to channel.'
    )
    d = flap.get_data('TESTDATA',
                      name='TEST*',
                      object_name='TEST-1_S',
                      options={
                          'Signal': 'Sin',
                          'F': [1e3, 1e4],
                          'Length': 1.
                      })
    print('**** Calculating 150 APSDs, each 1 million sample.')
    print('**** APSD START')
    start = time.time()
    flap.apsd('TEST-1_S',
              output_name='TEST-1_APSD_Sin1',
              options={
                  'Res': 12,
                  'Int': 10
              })
    stop = time.time()
    print('**** APSD STOP')
    print("**** Calculation time: {:5.2f} second/signal".format(
        (stop - start) / 150.))
    plt.figure()
    flap.plot('TEST-1_APSD_Sin1',
              slicing={'Row': 1},
              axes='Frequency',
              options={
                  'All': True,
                  'X range': [0, 5e3]
              })
    plt.title('TEST-1-1_APSD_Sin1')

    print("**** Testing with a complex signal.")
    flap.delete_data_object('*')
    d = flap.get_data('TESTDATA',
                      name='TEST-1-1',
                      object_name='TEST-1-1_CS',
                      options={'Signal': 'Complex-Sin'})
    flap.apsd('TEST-1-1_CS',
              coordinate='Time',
              output_name='TEST-1-1_APSD_Complex-Sin',
              options={
                  'Res': 10,
                  'Range': [-1e5, 1e5]
              })
    flap.slice_data('TEST-1-1_APSD_Complex-Sin',
                    slicing={'Frequency': flap.Intervals(-5e3, 5e3)},
                    output_name='TEST-1-1_APSD_Complex-Sin_sliced')
    flap.list_data_objects()
    plt.figure()
    flap.plot('TEST-1-1_APSD_Complex-Sin_sliced',
              axes='Frequency',
              options={'All': True})
    plt.title('TEST-1-1_APSD_Complex-Sin_sliced')

    print(
        "**** Testing interval selection in apsd. APSD from 8 intervals, each 80 ms long."
    )
    d = flap.get_data('TESTDATA',
                      name='TEST-1-1',
                      object_name='TEST-1-1',
                      options={
                          'Signal': 'Sin',
                          'Length': 1
                      })
    intervals = flap.Intervals(0, 0.08, step=0.1, number=8)
    flap.apsd('TEST-1-1',
              output_name='TEST-1-1_APSD',
              intervals=intervals,
              options={
                  'Res': 12,
                  'Int': 10
              })
    plt.figure()
    flap.plot('TEST-1-1_APSD', options={'X range': [0, 5e3]})
Beispiel #22
0
def test_NSTX_GPI_data_animation(exp_id=141918):
    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('Gathering MDSPlus data')

    flap.get_data('NSTX_MDSPlus',
                  name='\EFIT01::\RBDRY',
                  exp_id=exp_id,
                  object_name='SEP X OBJ'
                  )

    flap.get_data('NSTX_MDSPlus',
                  name='\EFIT01::\ZBDRY',
                  exp_id=exp_id,
                  object_name='SEP Y OBJ'
                  )
    
#    flap.get_data('NSTX_MDSPlus',
#                  name='\EFIT01::\RLIM',
#                  exp_id=exp_id,
#                  object_name='LIM X OBJ'
#                  )
#
#    flap.get_data('NSTX_MDSPlus',
#                  name='\EFIT01::\ZLIM',
#                  exp_id=exp_id,
#                  object_name='LIM Y OBJ'
#                  )
    
    d=flap.get_data('NSTX_MDSPlus',
                  name='\EFIT01::\PSIRZ',
                  exp_id=exp_id,
                  object_name='PSI RZ OBJ'
                  )
    
    d=flap.get_data('NSTX_MDSPlus',
                  name='\EFIT01::\GAPIN',
                  exp_id=exp_id,
                  object_name='GAPIN'
                  )
    d=flap.get_data('NSTX_MDSPlus',
                  name='\EFIT01::\SSIMAG',
                  exp_id=exp_id,
                  object_name='SSIMAG'
                  )
    d=flap.get_data('NSTX_MDSPlus',
                  name='\EFIT01::\SSIBRY',
                  exp_id=exp_id,
                  object_name='SSIBRY'
                  )
    
    efit_options={'Plot separatrix': True,
                  'Separatrix X': 'SEP X OBJ',
                  'Separatrix Y': 'SEP Y OBJ',
                  'Separatrix color': 'red',
#                  'Plot limiter': True,
#                  'Limiter X': 'LIM X OBJ',
#                  'Limiter Y': 'LIM Y OBJ',
#                  'Limiter color': 'white',
                  'Plot flux': True,
                  'Flux XY': 'PSI RZ OBJ',}
    
    print("**** Plotting filtered GPI")
    flap.plot('GPI',plot_type='animation',
              slicing={'Time':flap.Intervals(250.,260.)},
              axes=['Device R','Device z','Time'],
              options={'Z range':[0,512],'Wait':0.0,'Clear':False,
                       'EFIT options':efit_options})
    
    flap.list_data_objects()
Beispiel #23
0
def test_image():
    plt.close('all')
    print()
    print('>>>>>>>>>>>>>>>>>>> Test image <<<<<<<<<<<<<<<<<<<<<<<<')
    flap.delete_data_object('*')
    print("**** Generating a sequence of test images")
    flap.get_data('TESTDATA',
                  name='VIDEO',
                  object_name='TEST_VIDEO',
                  options={
                      'Length': 0.1,
                      'Samplerate': 1e3,
                      'Frequency': 10,
                      'Spotsize': 100
                  })
    flap.list_data_objects()
    print("***** Showing one image")
    plt.figure()
    flap.plot('TEST_VIDEO',
              slicing={'Time': 30e-3 / 4},
              plot_type='image',
              axes=['Image x', 'Image y'],
              options={'Clear': True})
    plt.figure()
    print("**** Showing a sequence of images and saving to test_video.avi")
    flap.plot('TEST_VIDEO',
              plot_type='anim-image',
              axes=['Image x', 'Image y', 'Time'],
              options={
                  'Z range': [0, 4095],
                  'Wait': 0.01,
                  'Clear': True,
                  'Video file': 'test_video.avi',
                  'Colorbar': True,
                  'Aspect ratio': 'equal'
              })
    plt.figure()
    print(
        "*** Showing the same images as contour plots and saving to test_video_contour.avi"
    )
    flap.plot('TEST_VIDEO',
              plot_type='anim-contour',
              axes=['Image x', 'Image y', 'Time'],
              options={
                  'Z range': [0, 4095],
                  'Wait': 0.01,
                  'Clear': True,
                  'Video file': 'test_video_contour.avi',
                  'Colorbar': False
              })
    print("*** Converting data object x, y coordinates to non-equidistant.")
    d = flap.get_data_object('TEST_VIDEO')
    coord_x = d.get_coordinate_object('Image x')
    index = [0] * 3
    index[coord_x.dimension_list[0]] = ...
    x = np.squeeze(d.coordinate('Image x', index=index)[0])
    coord_x.mode.equidistant = False
    coord_x.values = x
    coord_x.shape = x.shape
    coord_y = d.get_coordinate_object('Image y')
    index = [0] * 3
    index[coord_y.dimension_list[0]] = ...
    y = np.squeeze(d.coordinate('Image y', index=index)[0])
    coord_y.mode.equidistant = False
    coord_y.values = y
    coord_y.shape = y.shape
    flap.add_data_object(d, "TEST_VIDEO_noneq")
    flap.list_data_objects()
    plt.figure()
    print("**** Showing this video and saving to  test_video_noneq.avi")
    flap.plot('TEST_VIDEO_noneq',
              plot_type='anim-image',
              axes=['Image x', 'Image y', 'Time'],
              options={
                  'Z range': [0, 4095],
                  'Wait': 0.01,
                  'Clear': True,
                  'Video file': 'test_video_noneq.avi',
                  'Colorbar': True,
                  'Aspect ratio': 'equal'
              })