コード例 #1
0
ファイル: buneman_helper.py プロジェクト: benjum/JupyterPIC
    def something(rundir, file_no):

        my_path = os.getcwd()
        #print(my_path)
        working_dir = my_path + '/' + rundir
        #print(working_dir)
        efield_dir = working_dir + '/DIAG/Ex/'
        phase_space_dir = working_dir + '/DIAG/Vx_x/'
        ex_prefix = 'Ex-0_'
        phase_prefix = 'vx_x_'
        plt.figure(figsize=(10, 5))

        filename1 = phase_space_dir + phase_prefix + repr(file_no).zfill(
            6) + '.h5'
        filename2 = efield_dir + ex_prefix + repr(file_no).zfill(6) + '.h5'

        #print(filename1)
        #print(filename2)

        phase_space = np.abs(osh5io.read_h5(filename1))
        # print(repr(phase_space))
        ex = osh5io.read_h5(filename2)

        phase_plot = plt.subplot(121)
        #print(repr(phase_space.axes[0].min))
        #print(repr(phase_space.axes[1].min))
        title = phase_space.data_attrs['LONG_NAME']
        time = phase_space.run_attrs['TIME'][0]
        ext_stuff = [
            phase_space.axes[1].min, phase_space.axes[1].max,
            phase_space.axes[0].min, phase_space.axes[0].max
        ]
        phase_contour = plt.contourf(
            abs(phase_space) + 1e-11,
            levels=[0.1, 1, 2, 3, 5, 10, 100, 1000, 100000],
            extent=ext_stuff,
            cmap='Spectral',
            vmin=1e-1,
            vmax=100000,
            norm=matplotlib.colors.LogNorm(vmin=0.1, vmax=100000))
        phase_plot.set_title('Phase Space' + ' , t=' + repr(time) +
                             ' $\omega_{pe}^{-1}$')
        phase_plot.set_xlabel('Position [$\Delta x$]')
        phase_plot.set_ylabel('Velocity [$\omega_{pe} \Delta x$]')
        #plt.colorbar()
        #osh5vis.oscontour(phase_space,levels=[10**-5,10**-3,10**-1,1,10,100],colors='black',linestyles='dashed',vmin=1e-5,vmax=1000)
        plt.contour(phase_space,
                    levels=[0.1, 1, 2, 3, 5, 10, 100, 1000, 100000],
                    extent=ext_stuff,
                    colors='black',
                    linestyles='dashed')
        plt.colorbar(phase_contour)
        ex_plot = plt.subplot(122)

        plt.plot(ex[0, :])
        plt.ylim([-2, 2])
        ex_plot.set_xlabel('Position [$\Delta x$]')
        ex_plot.set_ylabel('Electric Field')
        plt.tight_layout()
        plt.show()
コード例 #2
0
ファイル: osh5utils.py プロジェクト: zcl-maker/pyVisOS
def combine(dir_or_filelist,
            prefix=None,
            file_slice=slice(None, ),
            preprocess=None,
            axesdata=None,
            save=None):
    """
    stack a directory of grid data and optionally save the result to a file
    :param dir_or_filelist: name of the directory
    :param prefix: string, match file names with specific prefix
    :param file_slice: a slice that applies to the file name list, useful for skipping every other files or start
                        in the middle of the list for example
    :param preprocess: a list of callable (and their args and kwargs if any) that will act on the data before stacking
                        happens. It has to accept one H5Data objects as argument and return one H5Data objects.
                        Note that it has to be a list, not tuple or any other type, aka if isinstance(preprocess, list)
                        returns False then this parameter will be ignored entirely.
    :param axesdata: user difined axes, see stack for more detail
    :param save: name of the save file. user can also set it to true value and the output will use write_h5 defaults
    :return: combined grid data, one dimension more than the preprocessed original data
    Usage of preprocess:
    The functino list should look like:
    [(func1, arg11, arg21, ..., argn1, {'kwarg11': val11, 'kwarg21': val21, ..., 'kwargn1', valn1}),
     (func2, arg12, arg22, ..., argn2, {'kwarg12': val12, 'kwarg22': val22, ..., 'kwargn2', valn2}),
     ...,
     (func2, arg1n, arg2n, ..., argnn, {'kwarg1n': val1n, 'kwarg2n': val2n, ..., 'kwargnn', valnn})] where
     any of the *args and/or **args can be omitted. see also __parse_func_param for limitations.
        if preprocess=[(numpy.power, 2), (numpy.average, {axis=0}), numpy.sqrt], then the data to be stacked is
        numpy.sqrt( numpy.average( numpy.power( read_h5(file_name), 2 ), axis=0 ) )
    """
    prfx = str(prefix).strip() if prefix else ''

    if isinstance(dir_or_filelist, str):
        flist = sorted(glob.glob(dir_or_filelist + '/' + prfx +
                                 '*.h5'))[file_slice]
    else:  # dir_or_filelist is a list of file names
        flist = dir_or_filelist[file_slice]
    if isinstance(preprocess, list) and preprocess:
        func_list = [__parse_func_param(item) for item in preprocess]
        tmp = [
            reduce(lambda x, y: y[0](x, *y[1], **y[2]), func_list,
                   osh5io.read_h5(fn)) for fn in flist
        ]
    else:
        tmp = [osh5io.read_h5(f) for f in flist]
    res = stack(tmp, axesdata=axesdata)
    if save:
        if not isinstance(save, str):
            save = dir_or_filelist if isinstance(
                dir_or_filelist, str) else './' + res.name + '.h5'
        osh5io.write_h5(res, save)
    return res
コード例 #3
0
    def __init__(self,
                 filefilter,
                 processing=Generic2DPlotCtrl._idle,
                 **extra_kwargs):
        fp = filefilter + '/*.h5' if os.path.isdir(filefilter) else filefilter
        self.filter, self.flist, self.processing = fp, sorted(
            glob.glob(fp)), processing
        try:
            self.data = processing(osh5io.read_h5(self.flist[0]))
        except IndexError:
            raise IOError('No file found matching ' + fp)

        items_layout = Layout(flex='1 1 auto', width='auto')
        self.file_slider = widgets.SelectionSlider(options=self.flist,
                                                   description='filename:',
                                                   value=self.flist[0],
                                                   continuous_update=False,
                                                   layout=items_layout)
        self.time_label = widgets.Label(value=osh5vis.time_format(
            self.data.run_attrs['TIME'][0], self.data.run_attrs['TIME UNITS']),
                                        layout=items_layout)
        self.file_slider.observe(self.update_slice, 'value')

        super(DirSlicer, self).__init__(self.data,
                                        time_in_title=False,
                                        **extra_kwargs)
コード例 #4
0
    def make_plot(rundir, file_no):

        my_path = os.getcwd()
        working_dir = my_path + '/' + rundir

        efield_dir = working_dir + '/MS/FLD/e1/'
        laser_dir = working_dir + '/MS/FLD/e2/'
        eden_dir = working_dir + '/MS/DENSITY/electrons/charge/'
        phase_space_dir = working_dir + '/MS/PHA/p1x1/electrons/'
        p2x1_dir = working_dir + '/MS/PHA/p2x1/electrons/'

        efield_prefix = 'e1-'
        laser_prefix = 'e2-'
        phase_prefix = 'p1x1-electrons-'
        p2x1_prefix = 'p2x1-electrons-'
        eden_prefix = 'charge-electrons-'

        filename1 = phase_space_dir + phase_prefix + repr(file_no).zfill(
            6) + '.h5'

        fig = plt.figure(figsize=(12, 5))
        phase_space = np.abs(osh5io.read_h5(filename1))
        time = phase_space.run_attrs['TIME'][0]
        fig.suptitle('Time = ' + repr(time) + '$\omega_p^{-1}$', fontsize=18)

        filename2 = eden_dir + eden_prefix + repr(file_no).zfill(6) + '.h5'
        filename3 = efield_dir + efield_prefix + repr(file_no).zfill(6) + '.h5'

        eden = osh5io.read_h5(filename2)
        ex = osh5io.read_h5(filename3)
        psi = osh5io.read_h5(filename3)

        den_plot = plt.subplot(121)
        osh5vis.osplot(eden, title='Electron Density')

        ex_plot = plt.subplot(122)

        for i in range(psi.shape[0] - 2, -1, -1):
            psi[i] = psi[i + 1] + psi.axes[0].increment * psi[i]

        osh5vis.osplot(psi, title='Wake $\psi$ ', ylabel='$\psi [m_e c^2/e]$')

        second_x = plt.twinx()
        second_x.plot(ex.axes[0], ex, 'g', linestyle='-.')
        second_x.set_ylabel('$E_{z}$', color='g')
        second_x.tick_params(axis='y', labelcolor='g')
コード例 #5
0
def plot_maxgamma_t(simdir):

    maxg, time = [], []
    for f in sorted(glob.glob(simdir + '/MS/PHA/p1x1/electrons/*.h5')):
        data = read_h5(f)
        ind = np.nonzero(data)
        if len(ind[0] == 0):
            maxg.append(np.sqrt(1 + (data.axes[0][max(ind[0])])**2))
            time.append(data.run_attrs['TIME'])
    print('max gamma = ', max(maxg))
コード例 #6
0
    def make_plot(rundir, file_no):

        my_path = os.getcwd()
        #print(my_path)
        working_dir = my_path + '/' + rundir
        #print(working_dir)
        efield_dir = working_dir + '/MS/FLD/e1/'
        laser_dir = working_dir + '/MS/FLD/e2/'
        eden_dir = working_dir + '/MS/DENSITY/electrons/charge/'
        phase_space_dir = working_dir + '/MS/PHA/p1x1/electrons/'
        p2x1_dir = working_dir + '/MS/PHA/p2x1/electrons/'

        efield_prefix = 'e1-'
        laser_prefix = 'e2-'
        phase_prefix = 'p1x1-electrons-'
        p2x1_prefix = 'p2x1-electrons-'
        eden_prefix = 'charge-electrons-'

        filename1 = phase_space_dir + phase_prefix + repr(file_no).zfill(
            6) + '.h5'

        fig = plt.figure(figsize=(12, 5))
        phase_space = np.abs(osh5io.read_h5(filename1))
        time = phase_space.run_attrs['TIME'][0]
        fig.suptitle('Time = ' + repr(time) + '$\omega_p^{-1}$', fontsize=18)

        filename4 = laser_dir + laser_prefix + repr(file_no).zfill(6) + '.h5'

        ey = osh5io.read_h5(filename4)

        ey_plot = plt.subplot(121)

        osh5vis.osplot(ey, title='Laser Electric Field')

        ey_plot_k = plt.subplot(122)

        osh5vis.osplot(np.abs(osh5utils.fft(ey)),
                       xlim=[0, 20],
                       linestyle='-',
                       title='k spectrum')
コード例 #7
0
    def make_plot(rundir, file_no):

        my_path = os.getcwd()
        working_dir = my_path + '/' + rundir

        efield_dir = working_dir + '/MS/FLD/e1/'
        laser_dir = working_dir + '/MS/FLD/e2/'
        eden_dir = working_dir + '/MS/DENSITY/electrons/charge/'
        phase_space_dir = working_dir + '/MS/PHA/p1x1/electrons/'
        p2x1_dir = working_dir + '/MS/PHA/p2x1/electrons/'

        efield_prefix = 'e1-'
        laser_prefix = 'e2-'
        phase_prefix = 'p1x1-electrons-'
        p2x1_prefix = 'p2x1-electrons-'
        eden_prefix = 'charge-electrons-'

        filename1 = phase_space_dir + phase_prefix + repr(file_no).zfill(
            6) + '.h5'

        fig = plt.figure(figsize=(12, 5))
        phase_space = np.abs(osh5io.read_h5(filename1))
        time = phase_space.run_attrs['TIME'][0]
        fig.suptitle('Time = ' + repr(time) + '$\omega_p^{-1}$', fontsize=18)

        filename2 = eden_dir + eden_prefix + repr(file_no).zfill(6) + '.h5'
        filename3 = efield_dir + efield_prefix + repr(file_no).zfill(6) + '.h5'

        eden = osh5io.read_h5(filename2)
        ex = osh5io.read_h5(filename3)

        den_plot = plt.subplot(121)
        osh5vis.osplot(eden, title='Electron Density')

        for i in range(ex.shape[0] - 2, -1, -1):
            ex[i] = ex[i + 1] + ex.axes[0].increment * ex[i]
        ex_plot = plt.subplot(122)

        osh5vis.osplot(ex, title='Wake $\psi$ ', ylabel='$\psi [m_e c^2/e]$')
コード例 #8
0
ファイル: para_poynt.py プロジェクト: zcl-maker/python-tsung
b2 = sorted(glob.glob(dirName + '/FLD/b2' + dir_ext + '/*.h5'))
b3 = sorted(glob.glob(dirName + '/FLD/b3' + dir_ext + '/*.h5'))
total_time = len(e2)
my_share = total_time // size
i_begin = rank * my_share
if rank < (size - 1):
    i_end = (rank + 1) * my_share
else:
    i_end = total_time
part = total_time / size

#
# read the second file to get the time-step
#
h5_filename = e2[1]  
h5_data = osh5io.read_h5(h5_filename)
array_dims = h5_data.shape
nx = array_dims[0]
# ny = array_dims[1]

time_step = h5_data.run_attrs['TIME'][0]
# h5_output = hdf_data()
# h5_output.shape = [total_time, nx]
print('nx=' + repr(nx))
# print('ny=' + repr(ny))
print('time_step=' + repr(time_step))
print('total_time=' + repr(total_time))
h5_output = np.zeros((total_time, nx))
total = np.zeros((total_time,nx))

#total = 0
コード例 #9
0
ファイル: osh5utils.py プロジェクト: zcl-maker/pyVisOS
            #             tmp = ndimage.filters.median_filter(r.values, size=3)
            tmp = scipy.signal.medfilt2d(r.values)
            mask = np.abs(r.values) > np.abs(tmp) * 2
            np.copyto(r.values, tmp, where=mask)
        else:
            r.values = ndimage.filters.median_filter(r.values, size=3)
    if kmax is not None:
        r.values[r.values > kmax] = kmax
        r.values[r.values < -kmax] = -kmax
    r.data_attrs['UNITS'] = monogenic_local_phase.axes[axis].units**-1
    return r


if __name__ == '__main__':
    fn = 'n0-123456.h5'
    d = osh5io.read_h5(fn)
    # d = subrange(d, ((0, 35.5), (0, 166)))
    # d = np.ones((7, 20))
    # d = rebin(d, fac=[3, 3])
    # d = d.subrange(bound=[None, (None, 23., -10.)])
    d.set_value(bound=(None, (None, 140., 10.)),
                val=2.,
                inverse_select=True,
                method=np.multiply)
    print(repr(d.view(np.ndarray)))
    c = hfft(d)
    print('c = ', repr(c))
    b = ihfft(c)
    print('b is d? ', b is d)
    diff = d - b
    print('b - d = ', diff.view(np.ndarray))
コード例 #10
0

total_time = len(e1)
my_share = total_time // size
i_begin = rank * my_share
if rank < (size - 1):
    i_end = (rank + 1) * my_share
else:
    i_end = total_time
part = total_time / size

#
# read the second file to get the time-step
#
h5_filename = e1[1]  
h5_data = osh5io.read_h5(h5_filename)
array_dims = h5_data.shape

# 
# the array is transposed due to Fortran array ordering
nx = array_dims[0]
ny = array_dims[1]
#
#


time_step = h5_data.run_attrs['TIME'][0]
# h5_output = hdf_data()
# h5_output.shape = [total_time, nx]
print('nx=' + repr(nx))
print('ny=' + repr(ny))
コード例 #11
0
ファイル: srs_helper.py プロジェクト: tsung1029/JupyterPIC
    def something(rundir, file_no):

        my_path = os.getcwd()
        #print(my_path)
        working_dir = my_path + '/' + rundir
        #print(working_dir)
        efield_dir = working_dir + '/MS/FLD/e1/'
        laser_dir = working_dir + '/MS/FLD/e2/'
        eden_dir = working_dir + '/MS/DENSITY/electrons/charge/'
        iden_dir = working_dir + '/MS/DENSITY/ions/charge/'
        phase_space_dir = working_dir + '/MS/PHA/p1x1/ions/'
        p1x1_dir = working_dir + '/MS/PHA/p1x1/electrons/'

        efield_prefix = 'e1-'
        laser_prefix = 'e2-'
        phase_prefix = 'p1x1-ions-'
        p1x1_prefix = 'p1x1-electrons-'
        eden_prefix = 'charge-electrons-'
        iden_prefix = 'charge-ions-'
        fig = plt.figure(figsize=(12, 16))

        # filename1=phase_space_dir+phase_prefix+repr(file_no).zfill(6)+'.h5'
        filename2 = eden_dir + eden_prefix + repr(file_no).zfill(6) + '.h5'
        filename3 = efield_dir + efield_prefix + repr(file_no).zfill(6) + '.h5'
        filename4 = laser_dir + laser_prefix + repr(file_no).zfill(6) + '.h5'
        filename5 = p1x1_dir + p1x1_prefix + repr(file_no).zfill(6) + '.h5'
        # filename6=iden_dir+iden_prefix+repr(file_no).zfill(6)+'.h5'

        #print(filename1)
        #print(filename2)

        phase_space = np.abs(osh5io.read_h5(filename5))
        # print(repr(phase_space))
        eden = osh5io.read_h5(filename2)
        ex = osh5io.read_h5(filename3)
        ey = osh5io.read_h5(filename4)
        # p1x1=np.abs(osh5io.read_h5(filename5))
        # iden = osh5io.read_h5(filename6)

        phase_plot = plt.subplot(224)
        #print(repr(phase_space.axes[0].min))
        #print(repr(phase_space.axes[1].min))
        title = phase_space.data_attrs['LONG_NAME']
        time = phase_space.run_attrs['TIME'][0]

        fig.suptitle('Time = ' + repr(time) + '$\omega_p^{-1}$', fontsize=24)
        ext_stuff = [
            phase_space.axes[1].min, phase_space.axes[1].max,
            phase_space.axes[0].min, phase_space.axes[0].max
        ]
        data_max = max(np.abs(np.amax(phase_space)), 100)
        #print(repr(data_max))
        phase_contour = plt.contourf(
            np.abs(phase_space + 0.000000001),
            levels=[
                0.000001 * data_max, 0.00001 * data_max, 0.0001 * data_max,
                0.001 * data_max, 0.005 * data_max, 0.01 * data_max,
                0.02 * data_max, 0.05 * data_max
            ],
            extent=ext_stuff,
            cmap='Spectral',
            vmin=1e-6 * data_max,
            vmax=1.5 * data_max,
            norm=colors.LogNorm(vmin=0.000001 * data_max, vmax=1.5 * data_max))
        phase_plot.set_title('Ion P1X1 Phase Space')
        phase_plot.set_xlabel('Position [$c / \omega_{p}$]')
        phase_plot.set_ylabel('Proper Velocity $\gamma v_1$ [ c ]')
        # second_x = plt.twinx()
        # second_x.plot(ex.axes[0],ex,'g',linestyle='-.')

        #plt.colorbar()
        #osh5vis.oscontour(phase_space,levels=[10**-5,10**-3,10**-1,1,10,100],colors='black',linestyles='dashed',vmin=1e-5,vmax=1000)
        # plt.contour(np.abs(phase_space+0.000001),levels=[0.0001,0.001,0.01,0.05,0.1,0.2,0.5,1],extent=ext_stuff,colors='black',linestyles='dashed')
        plt.colorbar(phase_contour)

        den_plot = plt.subplot(223)
        osh5vis.osplot(np.log(np.sum(np.abs(phase_space), axis=1) + 0.001),
                       title='f(v)')

        ex_plot = plt.subplot(222)

        osh5vis.osplot(ex, title='Wake E-field ', ylabel='$E_1 [m_e c^2/e]$')

        ey_plot = plt.subplot(221)

        osh5vis.osplot(ey, title='Laser Electric Field')
コード例 #12
0
 def update_slice(self, change):
     self.data = self.processing(osh5io.read_h5(change['new']))
     self.time_label.value = osh5vis.time_format(
         self.data.run_attrs['TIME'][0], self.data.run_attrs['TIME UNITS'])
     self.redraw(self.data)
コード例 #13
0
    def make_plot(rundir, file_no):

        my_path = os.getcwd()
        working_dir = my_path + '/' + rundir
        efield_dir = working_dir + '/MS/FLD/e1/'
        phase_space_dir = working_dir + '/MS/PHA/p1x1/electrons/'
        p2x1_dir = working_dir + '/MS/PHA/p2x1/electrons/'

        efield_prefix = 'e1-'
        phase_prefix = 'p1x1-electrons-'
        p2x1_prefix = 'p2x1-electrons-'
        fig = plt.figure(figsize=(12, 5))

        filename1 = phase_space_dir + phase_prefix + repr(file_no).zfill(
            6) + '.h5'
        filename3 = efield_dir + efield_prefix + repr(file_no).zfill(6) + '.h5'
        filename5 = p2x1_dir + p2x1_prefix + repr(file_no).zfill(6) + '.h5'

        phase_space = np.abs(osh5io.read_h5(filename1))
        ex = osh5io.read_h5(filename3)
        p2x1 = np.abs(osh5io.read_h5(filename5))

        phase_plot = plt.subplot(121)
        title = phase_space.data_attrs['LONG_NAME']
        time = phase_space.run_attrs['TIME'][0]

        fig.suptitle('Time = ' + repr(time) + '$\omega_p^{-1}$', fontsize=18)
        ext_stuff = [
            phase_space.axes[1].min, phase_space.axes[1].max,
            phase_space.axes[0].min, phase_space.axes[0].max
        ]
        data_max = max(np.abs(np.amax(phase_space)), 100)
        phase_contour = plt.contourf(
            np.abs(phase_space + 0.000000001),
            levels=[
                0.00001 * data_max, 0.0001 * data_max, 0.001 * data_max,
                0.01 * data_max, 0.05 * data_max, 0.1 * data_max,
                0.2 * data_max, 0.5 * data_max
            ],
            extent=ext_stuff,
            cmap='Spectral',
            vmin=1e-5 * data_max,
            vmax=1.5 * data_max,
            norm=colors.LogNorm(vmin=0.00001 * data_max, vmax=1.5 * data_max))
        phase_plot.set_title('P1X1 Phase Space')
        phase_plot.set_xlabel('Position [$c / \omega_{p}$]')
        phase_plot.set_ylabel('Proper Velocity $\gamma v_1$ [ c ]')
        second_x = plt.twinx()
        second_x.plot(ex.axes[0], ex, 'g', linestyle='-.')

        plt.colorbar(phase_contour)

        p2x1_plot = plt.subplot(122)
        title = p2x1.data_attrs['LONG_NAME']
        time = p2x1.run_attrs['TIME'][0]
        ext_stuff = [
            p2x1.axes[1].min, p2x1.axes[1].max, p2x1.axes[0].min,
            p2x1.axes[0].max
        ]
        p2x1_contour = plt.contourf(np.abs(p2x1 + 0.000000001),
                                    levels=[
                                        0.00001, 0.0001, 0.001, 0.01, 0.05,
                                        0.1, 0.2, 0.5, 1, 10, 100, 500
                                    ],
                                    extent=ext_stuff,
                                    cmap='Spectral',
                                    vmin=1e-5,
                                    vmax=3000,
                                    norm=colors.LogNorm(vmin=0.0001,
                                                        vmax=3000))
        p2x1_plot.set_title('P2X1 Phase Space')
        p2x1_plot.set_xlabel('Position [$c/ \omega_{p}$]')
        p2x1_plot.set_ylabel('Proper Velocity $\gamma v_2$ [$c$]')
        plt.colorbar(p2x1_contour)
コード例 #14
0
total_time = len(e2)
i_end=i_begin+total_time*file_interval
my_share = total_time // size
i_begin = rank * my_share
if rank < (size - 1):
    i_end = (rank + 1) * my_share
else:
    i_end = total_time
part = total_time / size
avg_array=np.ones(n_avg)/n_avg
#
# read the second file to get the time-step
#
# 
h5_filename = e2[1]  
h5_data = osh5io.read_h5(h5_filename)
array_dims = h5_data.shape
nx = array_dims[0]
dx=h5_data.axes[0]
ny = array_dims[1]

time_step = h5_data.run_attrs['TIME'][0]
# h5_output = hdf_data()
# h5_output.shape = [total_time, nx]
print('nx=' + repr(nx))
print('ny=' + repr(ny))
print('time_step=' + repr(time_step))
print('total_time=' + repr(total_time))
print('i_begin =' + repr(i_begin))
print('i_end =' + repr(i_end))
print('file_interval =' + repr(file_interval))
コード例 #15
0
def srs_quick_look(path,fileno):
	path_e1=path_main+'/MS/FLD/e1/'
	file_prefix_e1='e1-'

	path_e2=path_main+'/MS/FLD/e2/'
	file_prefix_e2='e2-'

	path_e3=path_main+'/MS/FLD/e3/'
	file_prefix_e3='e3-'

	path_b1=path_main+'/MS/FLD/b1/'
	file_prefix_b1='b1-'

	path_b2=path_main+'/MS/FLD/b2/'
	file_prefix_b2='b2-'

	path_b3=path_main+'/MS/FLD/b3/'
	file_prefix_b3='b3-'


	path_p1x1_e = path_main+'/MS/PHA/p1x1/species_1/'
	file_prefix_p1x1_e = 'p1x1-species_1-'
	# fileno = 22500
	interval = 30
	nfiles=10

	path_p1p2_e = path_main+'/MS/PHA/p1p2/species_1/'
	file_prefix_p1p2_e = 'p1p2-species_1-'


	from scipy import signal




	filename_e1=path_e1+file_prefix_e1+repr(fileno).zfill(6)+'.h5'
	filename_e2=path_e2+file_prefix_e2+repr(fileno).zfill(6)+'.h5'
	filename_e3=path_e3+file_prefix_e3+repr(fileno).zfill(6)+'.h5'
	filename_b1=path_b1+file_prefix_b1+repr(fileno).zfill(6)+'.h5'
	filename_b2=path_b2+file_prefix_b2+repr(fileno).zfill(6)+'.h5'
	filename_b3=path_b3+file_prefix_b3+repr(fileno).zfill(6)+'.h5'

	filename_p1x1_e = path_p1x1_e+file_prefix_p1x1_e+repr(fileno).zfill(6)+'.h5'
	filename_p1p2_e = path_p1p2_e+file_prefix_p1p2_e+repr(fileno).zfill(6)+'.h5'


	# print(filename)
	e1 = osh5io.read_h5(filename_e1)
	e2 = osh5io.read_h5(filename_e2)
	e3 = osh5io.read_h5(filename_e3)

	b1 = osh5io.read_h5(filename_b1)
	b2 = osh5io.read_h5(filename_b2)
	b3 = osh5io.read_h5(filename_b3)


	# print(e1.axes[0].attrs)
	# Method 1:  Just read files
	# p1x1_e = osh5io.read_h5(filename_p1x1_e)
	# p1p2_e = osh5io.read_h5(filename_p1p2_e)

	# Method 2:  Average over N steps
	interval=30
	nfiles = 20
	p1x1_e = phase_space_average_new(path_p1x1_e,file_prefix_p1x1_e,fileno,interval,nfiles)
	p1p2_e = phase_space_average_new(path_p1p2_e,file_prefix_p1p2_e,fileno,interval,nfiles)


	SMALL_SIZE = 12
	MEDIUM_SIZE = 14
	BIGGER_SIZE = 18

	plt.rc('font', size=SMALL_SIZE)          # controls default text sizes
	plt.rc('axes', titlesize=SMALL_SIZE)     # fontsize of the axes title
	plt.rc('axes', labelsize=MEDIUM_SIZE)    # fontsize of the x and y labels
	plt.rc('xtick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
	plt.rc('ytick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
	plt.rc('legend', fontsize=SMALL_SIZE)    # legend fontsize
	plt.rc('figure', titlesize=BIGGER_SIZE)  # fontsize of the figure title


	s1 = e2*b3 - e3 * b2
	s1.data_attrs['NAME']='S1'
	s1.data_attrs['LONG_NAME']='S_1'

	n_smooth=200
	smoothing=np.ones((1,n_smooth))/n_smooth

	n_avg = 200
	smooth_array=np.ones((1,n_avg))/n_avg
	temp=signal.convolve2d(s1,smooth_array,mode='same',boundary='wrap')
	s1[:,:]=temp[:,:]
	s1 = np.average(s1,axis=0)

	plt.figure(figsize=(10,7.0))


	plt.subplot(222)
	temp=signal.convolve2d(e1,smoothing,mode='same',boundary='wrap')
	osh5vis.osplot(np.average(e1,axis=0))
	plt.ylim(-0.02,0.02)

	# plt.subplot(222)
	# osh5vis.osplot(e2,cmap='seismic',vmin=-0.02,vmax=0.02)

	# plt.subplot(223)
	# osh5vis.osplot(s1,cmap='PuBu',vmin=0,vmax=0.000025)

	plt.subplot(221)
	p1x1_e = numpy.abs(p1x1_e)
	data_max= numpy.amax(p1x1_e)
	p1x1_e=p1x1_e/data_max
	osh5vis.oscontourf(p1x1_e,levels=[10**-5,3.0*10**-3,5*10**-3,1*10**-2,10**-1,3*10**-1,5*10**1],norm=LogNorm(),cmap='terrain',vmin=1e-3,vmax=100)
	osh5vis.oscontour(p1x1_e,levels=[10**-5,3.0*10**-3,5*10**-3,1*10**-2,10**-1,3*10**-1,5*10**1],norm=LogNorm(),colors='black',linestyles='dashed',vmin=1e-5,vmax=500,colorbar=False)

	plt.subplot(223)
	# osh5vis.osplot(np.log(np.abs(p1p2_e)+1e-5),cmap='hsv')

	p1p2_e = numpy.abs(p1p2_e)
	data_max= numpy.amax(p1p2_e)
	p1p2_e=p1p2_e/data_max
	osh5vis.oscontourf(p1p2_e,levels=[10**-6,3.0*10**-3,5*10**-3,1*10**-2,10**-1,3*10**-1,5*10**1],norm=LogNorm(),cmap='terrain',vmin=1e-3,vmax=100)
	osh5vis.oscontour(p1p2_e,levels=[10**-6,3.0*10**-3,5*10**-3,1*10**-2,10**-1,3*10**-1,5*10**1],norm=LogNorm(),colors='black',linestyles='dashed',vmin=1e-5,vmax=500,colorbar=False)
	# plt.xlim(-0.8,0.8)
	plt.xlim(-0.35,0.35)
	plt.subplot(224)
	osh5vis.osplot(s1, title='Axial <Poynting Flux>')
	plt.ylim(0,0.00009)
	plt.tight_layout()
	plt.show()
コード例 #16
0
argc = len(sys.argv)
if (argc < 3):
    print('Usage: python combine_2d.py DIRNAME OUTNAME')
    sys.exit()

dirname = sys.argv[1]
outfilename = sys.argv[2]

filelist = sorted(glob.glob(dirname + '/*.h5'))
total_time = len(filelist)
my_share = total_time
i_begin = 0
i_end = total_time

h5_filename = filelist[1]
h5_data = osh5io.read_h5(h5_filename)
array_dims = h5_data.shape
nx = array_dims[0]
ny = array_dims[1]
time_step = h5_data.run_attrs['TIME'][0]
# h5_output=hdf_data()
# h5_output.shape=[total_time,ny]
print('nx=' + repr(nx))
print('time_step=' + repr(time_step))
print('total_time=' + repr(total_time))
#
xaxis = h5_data.axes[1]
taxis = osh5def.DataAxis(0,
                         time_step * (total_time - 1),
                         total_time,
                         attrs={
コード例 #17
0
def q3d_to_3d(rundir, plasma_field, fileno, mode_max, x1_min, x1_max, nx1,
              x2_min, x2_max, nx2, x3_min, x3_max, nx3):
    from scipy import interpolate
    dx1 = (x1_max - x1_min) / (nx1 - 1)
    dx2 = (x2_max - x2_min) / (nx2 - 1)
    dx3 = (x3_max - x3_min) / (nx3 - 1)

    x1_axis = np.arange(x1_min, x1_max + dx1, dx1)
    x2_axis = np.arange(x2_min, x2_max + dx2, dx2)
    x3_axis = np.arange(x3_min, x3_max + dx3, dx3)

    a = np.zeros((nx1, nx2, nx3), dtype=float)

    filename_out = filename_3d(rundir, plasma_field, fileno)

    x1 = osh5def.DataAxis(x1_min,
                          x1_max,
                          nx1,
                          attrs={
                              'NAME': 'x1',
                              'LONG_NAME': 'x_1',
                              'UNITS': 'c / \omega_0'
                          })
    x2 = osh5def.DataAxis(x2_min,
                          x2_max,
                          nx2,
                          attrs={
                              'NAME': 'x2',
                              'LONG_NAME': 'x_2',
                              'UNITS': 'c / \omega_0'
                          })
    x3 = osh5def.DataAxis(x3_min,
                          x3_max,
                          nx3,
                          attrs={
                              'NAME': 'x3',
                              'LONG_NAME': 'x_3',
                              'UNITS': 'c / \omega_0'
                          })

    # More attributes associated with the data/simulation. Again no need to worry about the details.
    data_attrs = {
        'UNITS': osh5def.OSUnits('m_e c \omega_0 / e'),
        'NAME': plasma_field,
        'LONG_NAME': plasma_field
    }
    run_attrs = {
        'NOTE': 'parameters about this simulation are stored here',
        'TIME UNITS': '1/\omega_0',
        'XMAX': np.array([1., 15.]),
        'XMIN': np.array([0., 10.])
    }

    # Now "wrap" the numpy array into osh5def.H5Data. Note that the data and the axes are consistent and are in fortran ordering
    b = osh5def.H5Data(a,
                       timestamp='123456',
                       data_attrs=data_attrs,
                       run_attrs=run_attrs,
                       axes=[x1, x2, x3])

    # I am doing mode 0 outside of the loop

    fname_re = filename_re(rundir, plasma_field, 0, fileno)
    # DEBUG
    print(fname_re)
    # DEBUG
    data_re = osh5io.read_h5(fname_re)
    print(data_re.shape)
    print(data_re.axes[1].ax.shape)
    print(data_re.axes[0].ax.shape)

    func_re = interpolate.interp2d(data_re.axes[1].ax,
                                   data_re.axes[0].ax,
                                   data_re,
                                   kind='cubic')

    for i1 in range(0, nx1):
        for i2 in range(0, nx2):
            for i3 in range(0, nx3):
                z = x1_axis[i1]
                x = x3_axis[i3]
                y = x2_axis[i2]

                r = np.sqrt(x * x + y * y)
                # if r != 0:
                #     cos_th = x/r
                #     sin_th = y/r
                # else:
                #     cos_th = 1
                #     sin_th = 0
                a[i1, i2, i3] = a[i1, i2, i3] + func_re(z, r)

    for i_mode in range(1, mode_max + 1):
        fname_re = filename_re(rundir, plasma_field, i_mode, fileno)
        fname_im = filename_im(rundir, plasma_field, i_mode, fileno)

        # DEBUG
        print(fname_re)
        # DEBUG
        if (plasma_field == 'e2' or plasma_field == 'e3'):
            if (plasma_field == 'e2'):
                field_comp = 'e3'
            else:
                field_comp = 'e2'

            data_re_self = osh5io.read_h5(
                filename_re(rundir, plasma_field, i_mode, fileno))
            data_im_self = osh5io.read_h5(
                filename_im(rundir, plasma_field, i_mode, fileno))

            data_re_comp = osh5io.read_h5(
                filename_re(rundir, field_comp, i_mode, fileno))
            data_im_comp = osh5io.read_h5(
                filename_im(rundir, field_comp, i_mode, fileno))

        else:
            data_re = osh5io.read_h5(
                filename_re(rundir, plasma_field, i_mode, fileno))
            data_im = osh5io.read_h5(
                filename_im(rundir, plasma_field, i_mode, fileno))
            func_re = interpolate.interp2d(data_re.axes[1].ax,
                                           data_re.axes[0].ax,
                                           data_re,
                                           kind='cubic')
            func_im = interpolate.interp2d(data_im.axes[1].ax,
                                           data_im.axes[0].ax,
                                           data_im,
                                           kind='cubic')

        for i1 in range(0, nx1):
            for i2 in range(0, nx2):
                for i3 in range(0, nx3):
                    z = x1_axis[i1]
                    x = x3_axis[i3]
                    y = x2_axis[i2]

                    r = np.sqrt(x * x + y * y)

                    if r > 0.000001:
                        cos_th = x / r
                        sin_th = y / r
                    else:
                        cos_th = 1
                        sin_th = 0
                    # start the recursion relation to evaluate cos(n*theta) and sin(n_theta)
                    sin_n = sin_th
                    cos_n = cos_th
                    for int_mode in range(2, i_mode + 1):
                        temp_s = sin_n
                        temp_c = cos_n
                        cos_n = temp_c * cos_th - temp_s * sin_th
                        sin_n = temp_s * cos_th + temp_c * sin_th
                    #
                    # here we perform the addition of the N-th mode
                    # to the data in 3D
                    #
                    a[i1, i2,
                      i3] = a[i1, i2, i3] + func_re(z, r) * cos_n - func_im(
                          z, r) * sin_n

    osh5io.write_h5(b, filename=filename_out)
コード例 #18
0
def something_2(rundir, file_no):

    my_path = os.getcwd()
    #print(my_path)
    working_dir = my_path + '/' + rundir
    #print(working_dir)

    dir_0 = rundir + '/Vx_x/'
    dir_1 = rundir + '/Ex/'

    output_dir = rundir + '/movies/'
    try:
        os.mkdir(output_dir)
    except OSError as exc:
        if exc.errno != errno.EEXIST:
            raise
        pass

    quan_0_prefix = 'vx_x_'
    quan_1_prefix = 'Ex-0_'

    output_prefix = 'frame_'

    fig = plt.figure(figsize=(10, 8))

    phase_space_filename = dir_0 + quan_0_prefix + repr(file_no).zfill(
        6) + '.h5'
    e1_filename = dir_1 + quan_1_prefix + repr(file_no).zfill(6) + '.h5'

    output_filename = output_dir + '/' + output_prefix + repr(file_no).zfill(
        6) + '.png'

    phase_space_data = osh5io.read_h5(phase_space_filename)
    e1_data = np.average(osh5io.read_h5(e1_filename), axis=0)

    p1_x1_plot = plt.subplot(221)
    osh5vis.osplot(np.log(np.abs(phase_space_data) + 1e-10),
                   title='Phase Space',
                   vmax=10,
                   vmin=-2,
                   cmap='Blues')

    e1_plot = plt.subplot(222)
    osh5vis.osplot(e1_data, title='Electric Field')
    e1_plot.set_ylim([-0.1, 0.1])
    plt.tight_layout()
    fv_plot = plt.subplot(223)

    # print(hdf5_data)
    xmin = phase_space_data.axes[0].min
    xmax = phase_space_data.axes[0].max

    ymin = phase_space_data.axes[1].min
    ymax = phase_space_data.axes[1].max

    # dx=(xmax-xmin)/float(nx[0]-1)
    # dy=(ymax-ymin)/float(nx[1]-1)
    # print(dx)
    # print(dy)
    # xmax=xmax-dx
    # ymax=ymax-dy
    # xmin=xmin+10.0*dx
    # ymin=ymin-10.0*dy
    # print(repr(xmin)+' '+repr(xmax)+' '+repr(ymin)+' '+repr(ymax))
    nx = phase_space_data.shape
    xaxis = np.linspace(xmin, xmax, num=nx[0])
    yaxis = np.linspace(ymin, ymax, num=nx[1])
    plt.plot(xaxis, np.average(phase_space_data, axis=1))
    plt.xlabel('$v/v_{th}$')
    plt.ylabel('f(v) [a.u]')
    fv_plot.set_ylim([0, 1500])

    fv_slices = plt.subplot(224)

    # print(hdf5_data)
    xmin = phase_space_data.axes[0].min
    xmax = phase_space_data.axes[0].max

    ymin = phase_space_data.axes[1].min
    ymax = phase_space_data.axes[1].max

    # dx=(xmax-xmin)/float(nx[0]-1)
    # dy=(ymax-ymin)/float(nx[1]-1)
    # print(dx)
    # print(dy)
    # xmax=xmax-dx
    # ymax=ymax-dy
    # xmin=xmin+10.0*dx
    # ymin=ymin-10.0*dy
    # print(repr(xmin)+' '+repr(xmax)+' '+repr(ymin)+' '+repr(ymax))
    nx = phase_space_data.shape
    xaxis = np.linspace(xmin, xmax, num=nx[0])
    yaxis = np.linspace(ymin, ymax, num=nx[1])
    plt.plot(xaxis, np.average(phase_space_data[:, 492:532], axis=1))
    plt.plot(xaxis, np.average(phase_space_data[:, 352:372], axis=1), 'r')
    plt.plot(xaxis, np.average(phase_space_data[:, 652:672], axis=1), 'g')
    plt.xlabel('$v/v_{th}$')
    plt.ylabel('f(v) [a.u]')
    fv_slices.set_ylim([0, 1500])

    plt.savefig(output_filename)
コード例 #19
0
def phase_space_average_new(path,prefix,fileno,interval,nfiles):
    file_begin=fileno
    file_end=fileno+((nfiles)*interval)
    filename=path+prefix+repr(file_begin).zfill(6)+'.h5'
    # print(filename)
    hdf5_data=osh5io.read_h5(filename)
    # print(hdf5_data)
    xmin=hdf5_data.axes[0].min
    xmax=hdf5_data.axes[0].max

    ymin=hdf5_data.axes[1].min
    ymax=hdf5_data.axes[1].max

# dx=(xmax-xmin)/float(nx[0]-1)
# dy=(ymax-ymin)/float(nx[1]-1)
# print(dx)
# print(dy)
# xmax=xmax-dx
# ymax=ymax-dy
# xmin=xmin+10.0*dx
# ymin=ymin-10.0*dy
# print(repr(xmin)+' '+repr(xmax)+' '+repr(ymin)+' '+repr(ymax))
    nx=hdf5_data.shape
    xaxis=numpy.linspace(xmin,xmax,num=nx[0])
    yaxis=numpy.linspace(ymin,ymax,num=nx[1])
    
    total_files=1
    # print(repr(file_begin)+' '+repr(file_end)+' '+repr(nfiles))
    for i_file in range(file_begin+interval,file_end,interval):
        # print(repr(i_file))
        filename=path+prefix+repr(i_file).zfill(6)+'.h5'
        # print(filename)
        try:
            hdf5_data_temp=osh5io.read_h5(filename)
            total_files=total_files+1    
            xmin_temp=hdf5_data_temp.axes[0].min
            xmax_temp=hdf5_data_temp.axes[0].max
            ymin_temp=hdf5_data_temp.axes[1].min
            ymax_temp=hdf5_data_temp.axes[1].max
            nx_temp=hdf5_data_temp.shape
            if((xmin==xmin_temp) and (xmax==xmax_temp) and (ymin==ymin_temp) and (ymax==ymax_temp)):
                # print('passed')
                hdf5_data=numpy.abs(hdf5_data)+numpy.abs(hdf5_data_temp)
            else:
                # print('no pass')
                xaxis_temp=numpy.linspace(xmin_temp,xmax_temp,nx_temp[0])
                yaxis_temp=numpy.linspace(ymin_temp,ymax_temp,nx_temp[1])
                interp_func=interpolate.interp2d(xaxis_temp,yaxis_temp,hdf5_data_temp,kind='cubic')
                temp_data=numpy.zeros((nx[0],nx[1]))
                for ix in range(0,nx[0]):
                    for iy in range(0,nx[1]):
                        temp_data[iy,ix]=interp_func(xaxis[ix],yaxis[iy])
        
                hdf5_data=numpy.abs(hdf5_data)+numpy.abs(temp_data)
        except:
            print('error')
            continue
        

    # print(repr(total_files))   
    hdf5_data=hdf5_data/float(total_files)
    return hdf5_data
コード例 #20
0
    def something_2(rundir,file_no):
        v_phase = 1/.3
        v_group = 3/v_phase
        my_path=os.getcwd()
        #print(my_path)
        working_dir=my_path+'/'+rundir
        #print(working_dir)
        
        
        dir_0=rundir+'/Vx_x/'
        dir_1=rundir+'/Ex/'
        
        
        

        quan_0_prefix='vx_x_'
        quan_1_prefix='Ex-0_'
        
        
        fig = plt.figure(figsize=(10,8) )

        
        phase_space_filename=dir_0+quan_0_prefix+repr(file_no).zfill(6)+'.h5'
        e1_filename=dir_1+quan_1_prefix+repr(file_no).zfill(6)+'.h5'
        
        
        phase_space_data = osh5io.read_h5(phase_space_filename)
        e1_data = np.average(osh5io.read_h5(e1_filename),axis=0)
        fig.suptitle('Landau Boundary Problem, time = '+repr(phase_space_data.run_attrs['TIME'][0])+' $\omega_p^{-1}$ \n \n')

        p1_x1_plot = plt.subplot(221)
        osh5vis.osplot(np.log(np.abs(phase_space_data)+1e-10),title='Phase Space',vmax=10,vmin=-2,cmap='Blues')
        # =====================================================================
        # =====================================================================
        # the following lines draw vertical axis indicating the group velocity
        # p1_x1_plot.axvline(x=512-v_group*phase_space_data.run_attrs['TIME'][0])
        # p1_x1_plot.axvline(x=512+v_group*phase_space_data.run_attrs['TIME'][0])
        # =====================================================================
        # =====================================================================
        e1_plot = plt.subplot(222)
        osh5vis.osplot(e1_data,title='Electric Field')
        # plt.tight_layout()
        fig.subplots_adjust(top=0.82)
        fv_plot = plt.subplot(223)
        
        
        # print(hdf5_data)
        xmin=phase_space_data.axes[0].min
        xmax=phase_space_data.axes[0].max

        ymin=phase_space_data.axes[1].min
        ymax=phase_space_data.axes[1].max

# dx=(xmax-xmin)/float(nx[0]-1)
# dy=(ymax-ymin)/float(nx[1]-1)
# print(dx)
# print(dy)
# xmax=xmax-dx
# ymax=ymax-dy
# xmin=xmin+10.0*dx
# ymin=ymin-10.0*dy
# print(repr(xmin)+' '+repr(xmax)+' '+repr(ymin)+' '+repr(ymax))
        nx=phase_space_data.shape
        xaxis=np.linspace(xmin,xmax,num=nx[0])
        yaxis=np.linspace(ymin,ymax,num=nx[1])
        plt.plot(xaxis,np.average(phase_space_data,axis=1))
        plt.xlabel('$v/v_{th}$')
        plt.ylabel('f(v) [a.u]')
        fv_plot.set_ylim([0, 1500])
        
        fig.subplots_adjust(top=0.82)
        
        fv_slices = plt.subplot(224)
        
        
        # print(hdf5_data)
        xmin=phase_space_data.axes[0].min
        xmax=phase_space_data.axes[0].max

        ymin=phase_space_data.axes[1].min
        ymax=phase_space_data.axes[1].max

# dx=(xmax-xmin)/float(nx[0]-1)
# dy=(ymax-ymin)/float(nx[1]-1)
# print(dx)
# print(dy)
# xmax=xmax-dx
# ymax=ymax-dy
# xmin=xmin+10.0*dx
# ymin=ymin-10.0*dy
# print(repr(xmin)+' '+repr(xmax)+' '+repr(ymin)+' '+repr(ymax))
        nx=phase_space_data.shape
        xaxis=np.linspace(xmin,xmax,num=nx[0])
        yaxis=np.linspace(ymin,ymax,num=nx[1])
        plt.plot(xaxis,np.average(phase_space_data[:,492:532],axis=1))
        plt.plot(xaxis,np.average(phase_space_data[:,352:372],axis=1),'r')
        plt.plot(xaxis,np.average(phase_space_data[:,652:672],axis=1),'g')
        plt.xlabel('$v/v_{th}$')
        plt.ylabel('f(v) [a.u]')
        fv_slices.set_ylim([0, 1500])
        
        
        plt.tight_layout()
        plt.show()