def monogenic_local_phase(monogenic_signal, **kwargs): """ get the local phase of a 2D monogenic signal :param monogenic_signal: the output of the monogenic_signal function :param unwrap: if True then unwrap the output angle, default is False :param kwargs: keyword arguments that will be passthrough to the unwrap function :return: local phase in h5Data format """ theta = np.arctan2( np.abs(monogenic_signal[1])*np.sign(np.real(monogenic_signal[1])), monogenic_signal[0]) unwrap_output = kwargs.pop('unwrap', False) if unwrap_output: return unwrap(theta, **kwargs) theta.data_attrs['UNITS'] = osh5def.OSUnits('a.u.') return theta
def sl(*args, **kwargs): # save meta data into a list saved = args[0].meta2dict() if hasattr(args[0], 'meta2dict') else None # execute user function out = func(args[0].view(np.ndarray), *args[1:], **kwargs) # load saved meta data into specified positions try: if isinstance(out, osh5def.H5Data): out.__dict__.update(saved) else: out = osh5def.H5Data(out, **saved) except: raise TypeError('Output is not/cannot convert to H5Data') # Update unit if necessary if unit is not None: out.data_attrs['UNITS'] = osh5def.OSUnits(unit) if axes is not None: out.axes = axes return out
attrs={'NAME':'t', 'LONG_NAME':'time', 'UNITS':'1 / \omega_p'}) delta_k = 2*np.pi/(h5_data.axis[0].max-h5_data.axis[0].min) nk = int(kmax/delta_k) nz=nx_end-nx_begin+1 # here we allocate the history array total_es = np.zeros((total_time,nk,nz)) total_em =np.zeros((total_time,nk,nz)) total_es = 0 total_em = 0 kaxis=osh5def.DataAxis(0, nk* delta_k, nk, attrs{'NAME':'k_{\perp}', 'LONG_NAME':'k_{\perp}', 'UNITS':osh5def.OSUnits('\omega_{0}/c')}) data_attrs_hfhi_es_hist = { 'UNITS': osh5def.OSUnits('a.u.'), 'NAME': 'ES modes history', 'LONG_NAME': 'hfhi_es_hist' } data_attrs_hfhi_em_hist = { 'UNITS': osh5def.OSUnits('a.u.'), 'NAME': 'EM modes history', 'LONG_NAME': 'hfhi_em_hist' } run_attrs = {'XMAX' : np.array( [ time_step * (total_time-1),kmax,zmax] ) , 'XMIN' : np.array( [0, 0, zmin] ) } i_count = 0 file_number = 0 for file_number in range(i_begin, i_end): e1_filename = e1[file_number] e2_filename = e2[file_number]
# 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 total2 = 0 # if rank == 0: # total = np.zeros((total_time, nx)) xaxis=h5_data.axes[0] taxis=osh5def.DataAxis(0, time_step * (total_time -1), total_time, attrs={'NAME':'t', 'LONG_NAME':'time', 'UNITS':'1 / \omega_p'}) data_attrs = { 'UNITS': osh5def.OSUnits('m_e \omega_p^3'), 'NAME': 's1', 'LONG_NAME': 'S_1' } # print(repr(xaxis.min)) # print(repr(xaxis.max)) run_attrs = {'XMAX' : np.array( [ time_step * (total_time-1),xaxis.max] ) , 'XMIN' : np.array( [0, xaxis.min, 0] ) } # h5_output.run_attrs['TIME'] = 0.0 # h5_output.run_attrs['UNITS'] = 'm_e /T' i_count = 0 file_number = 0 for file_number in range(i_begin, i_end): e2_filename = e2[file_number] e3_filename = e3[file_number]
h5_output = np.zeros((total_time, ny)) total = np.zeros((total_time,ny)) #total = 0 total2 = 0 # if rank == 0: # total = np.zeros((total_time, nx)) raxis=h5_data.axes[0] dr=(raxis.max-raxis.min)/ny xaxis=h5_data.axes[1] taxis=osh5def.DataAxis(0, time_step * (total_time -1), total_time, attrs={'NAME':'t', 'LONG_NAME':'time', 'UNITS':'1 / \omega_p'}) data_attrs = { 'UNITS': osh5def.OSUnits('m_e \omega_p^3'), 'NAME': 'Power', 'LONG_NAME': 'Trans. Int. Power' } print(repr(xaxis.min)) print(repr(xaxis.max)) run_attrs = {'XMAX' : np.array( [time_step * (total_time-1), xaxis.max] ) , 'XMIN' : np.array( [0, xaxis.min ] ) } # h5_output.run_attrs['TIME'] = 0.0 # h5_output.run_attrs['UNITS'] = 'm_e /T' file_number = 0 skip = 1 temp=np.zeros(ny) for file_number in range(i_begin, i_end):
print('time_step=' + repr(time_step)) print('total_time=' + repr(total_time)) e2_plus_output = np.zeros((total_time, nx)) e2_minus_output = np.zeros((total_time, nx)) total = np.zeros((total_time,nx)) #total = 0 total2 = 0 # if rank == 0: # total = np.zeros((total_time, nx)) xaxis=h5_data.axes[1] taxis=osh5def.DataAxis(0, time_step * (total_time -1), total_time, attrs={'NAME':'t', 'LONG_NAME':'time', 'UNITS':'1 / \omega_p'}) data_attrs_eplus = { 'UNITS': osh5def.OSUnits('m_e^2 c \omega_p/e'), 'NAME': 'e+', 'LONG_NAME': 'e2_+' } data_attrs_eminus = { 'UNITS': osh5def.OSUnits('m_e^2 c \omega_p/e'), 'NAME': 'e-', 'LONG_NAME': 'e2_-' } run_attrs = {'XMAX' : np.array( [ time_step * (total_time-1),xaxis.max] ) , 'XMIN' : np.array( [0, xaxis.min, 0] ) } i_count = 0 file_number = 0 for file_number in range(i_begin, i_end): e2_filename = e2[file_number] e3_filename = e3[file_number] b2_filename = b2[file_number]
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)
#total = 0 total2 = 0 xaxis = h5_data.axes[1] taxis = osh5def.DataAxis(0, time_step * (total_time - 1), total_time, attrs={ 'NAME': 't', 'LONG_NAME': 'time', 'UNITS': '1 / \omega_p' }) data_attrs = { 'UNITS': osh5def.OSUnits('m_e \omega_p^3'), 'NAME': 's1', 'LONG_NAME': 'S_1' } print(repr(xaxis.min)) print(repr(xaxis.max)) run_attrs = { 'XMAX': np.array([time_step * (total_time - 1), xaxis.max]), 'XMIN': np.array([0, xaxis.min]) } # h5_output.run_attrs['TIME'] = 0.0 # h5_output.run_attrs['UNITS'] = 'm_e /T' file_number = 0
# ****************************************************************** from h5_utilities import * import matplotlib.pyplot as plt import sys # Han Wen's pyVisOS sys.path.append('/Volumes/Lacie-5TB/codes/pyVisOS/') def os_rwigner(real_array,xaxis): nx=real_array.shape nxh=(nx+1)/2 dx=(xaxis.max-xaxis.min)/nx kmax=(np.pi)/dx dk=(2.0*np.pi)/xaxis.max w_data= rwigner(real_array) kaxis=osh5def.DataAxis(0,kmax,nx_h, attrs={'NAME':'k','LONG_NAME':'wave number', 'UNITS': '\omega_0/c'} data_attrs = data_attrs = { 'UNITS': osh5def.OSUnits('[a.u.]'), 'NAME': 'W_{\phi}', 'LONG_NAME': 'Wigner Transform' } run_attrs = {'XMAX' : np.array( [kmax, xaxis.max] ) , 'XMIN' : np.array( [0, xaxis.min ] ) } os5data_wigner=osh5def.H5Data(w_data,timestamp='x', data_attrs=data_attrs, axes=[kaxis,xaxis])