ocelot.common package

Submodules

ocelot.common.conf module

ocelot.common.globals module

ocelot.common.globals.alpha = 0.007297352566206497
def lambda2eV(Lambda):

Eph = h_eV_s*speed_of_light/Lambda return Eph

def eV2lambda(Ephoton):

Lambda = h_eV_s*speed_of_light/Ephoton return Lambda

def Ephoton2K(Eph, lu = 0.04, Eeb = 14):

gamma = Eeb/m_e_GeV K = np.sqrt(4.*gamma*gamma/lu*h_eV_s*speed_of_light/Eph - 2) return K

def K2Ephoton(K, lu = 0.04, E=14):

gamma = E/m_e_GeV Eph = 4.*gamma*gamma*h_eV_s*speed_of_light/((K*K + 2)*lu) return Eph

def K2Lambda(K, lu = 0.04, E=14):

gamma = E/m_e_GeV Eph = 4.*gamma*gamma*h_eV_s*speed_of_light/((K*K + 2)*lu) Lambda = eV2lambda(Eph) return Lambda

def field2K(field, lu = 0.04):

K = field*lu*speed_of_light/(m_e_eV*2.*pi) return K

def K2field(K, lu = 0.04):

field = K*m_e_eV*2.*pi/(lu*speed_of_light) return field

def field2Ephoton(field, lu=0.04, E=14):

gamma = E/m_e_GeV K = field2K(field, lu) l = lu/(2.*gamma*gamma)*(1.+K*K/2.) Eph = h_eV_s*speed_of_light/l return Eph

def Ephoton2field(energy, lu = 0.04, Eeb = 14):

K = Ephoton2K(energy, lu, Eeb) field = K*2.*pi*m_e_eV/(lu*speed_of_light) return field

ocelot.common.math_op module

statistical analysis functions, fitting, optimization and the like

ocelot.common.math_op.bin_array(array, bin_size)
ocelot.common.math_op.bin_scale(scale, bin_size)
ocelot.common.math_op.complete_gamma(a, z)

return ‘complete’ gamma function

ocelot.common.math_op.conj_sym(x)

function to make “nearly conjugate symmetric” vector in order to compute matplab IFFT function with ‘symmetric’ option: MATLAB >> ifft(x, ‘symmetric’) PYTHON >> numpy.fft.ifft(conj_sym(x))

ocelot.common.math_op.convolve(f, g)

FFT based convolution

Parameters
  • f – array

  • g – array

Returns

array, (f * g)[n]

ocelot.common.math_op.corr_c_nb(corr, val, n_skip=1, norm=1, count=0)
ocelot.common.math_op.corr_c_np(corr, n_corr, val, norm)
ocelot.common.math_op.corr_c_py(corr, n_corr, val, norm)
ocelot.common.math_op.corr_f_nb(corr, val, n_skip=1, norm=1, count=0)
ocelot.common.math_op.corr_f_np(corr, val, n_skip=1, norm=1, count=0)
ocelot.common.math_op.corr_f_py(corr, val, n_skip=1, norm=1)
ocelot.common.math_op.correlation2d(val, norm=0, n_skip=1, use_numba=False)
ocelot.common.math_op.correlation2d_center(n_corr, val, norm=0, use_numba=1)
ocelot.common.math_op.deconvolve(f, g)

FFT based deconvolution

Parameters
  • f – array

  • g – array

Returns

array,

ocelot.common.math_op.find_nearest(array, value)
ocelot.common.math_op.find_nearest_idx(array, value)
ocelot.common.math_op.find_saturation(power, z, n_smooth=5)
ocelot.common.math_op.fit_gauss_1d(x, F)
ocelot.common.math_op.fit_gauss_2d(x, y, F)
ocelot.common.math_op.fwhm(x, F)
ocelot.common.math_op.fwhm3(valuelist, height=0.5, peakpos=- 1, total=1)

calculates the full width at half maximum (fwhm) of the array. the function will return the fwhm with sub-pixel interpolation. It will start at the maximum position and ‘walk’ left and right until it approaches the half values. if total==1, it will start at the edges and ‘walk’ towards peak until it approaches the half values. INPUT: - valuelist: e.g. the list containing the temporal shape of a pulse OPTIONAL INPUT: -peakpos: position of the peak to examine (list index) the global maximum will be used if omitted. if total = 1 - OUTPUT: - peakpos(index), interpolated_width(npoints), [index_l, index_r]

ocelot.common.math_op.gauss_fit(X, Y)

golden section search

ocelot.common.math_op.index_of(array, value)
ocelot.common.math_op.invert_cdf(y, x)

Invert cumulative distribution function of the probability distribution

# analytical formula for the beam distribution f = lambda x: A * np.exp(-(x - mu) ** 2 / (2. * sigma ** 2))

# we are interesting in range from -30 to 30 e.g. [um] x = np.linspace(-30, 30, num=100)

# Inverted cumulative distribution function i_cdf = invert_cdf(y=f(x), x=x)

# get beam distribution (200 000 coordinates) tau = i_cdf(np.random.rand(200000))

Parameters
  • y – array, [y0, y1, y2, … yn] yi = y(xi)

  • x – array, [x0, x1, x2, … xn] xi

Returns

function

ocelot.common.math_op.mut_coh_func(J, fld, norm=1)

Mutual Coherence function

ocelot.common.math_op.mut_coh_func_py(J, fld, norm=1)

Mutual Coherence function

ocelot.common.math_op.n_moment(x, counts, c, n)
ocelot.common.math_op.peaks(x, y, n=0)
ocelot.common.math_op.rolling_mean(x, window)

Fat method for rolling mean

X = np.random.rand(10000)

X_mean = rolling_mean(X, 500)

Parameters
  • x – np.array, len(a) must be larger than window

  • window – int, length of the window

Returns

np.array, len = len(x) + 1 - window

ocelot.common.math_op.rolling_window(x, window)

Function return x-array slices with length of the window, which can be used for rolling analysis.

X = np.random.rand(10000)

X_std = np.std(rolling_window(X, 500), 1) X_mean = np.mean(rolling_window(X, 500), 1)

Parameters
  • x – np.array, len(a) must be larger than window

  • window – int, length of the window

Returns

np.array, shape: (len(a) + 1 - window, window)

ocelot.common.math_op.stats(outputs)

return mean, std, median and extreme (farthest from mean) of a time series

ocelot.common.math_op.std_moment(x, counts)

ocelot.common.ocelog module

class ocelot.common.ocelog.OcelogFormatter(patern)

Bases: logging.Formatter

format(record)

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

ocelot.common.ocelog.ocelog_indentate()

ocelot.common.py_func module

ocelot.common.py_func.background(command)

start command as background process the argument shohuld preferably be a string in triple quotes ‘

class ocelot.common.py_func.bcolors

Bases: object

BOLD = '\x1b[1m'
ENDC = '\x1b[0m'
FAIL = '\x1b[91m'
HEADER = '\x1b[95m'
OKBLUE = '\x1b[94m'
OKGREEN = '\x1b[92m'
UNDERLINE = '\x1b[4m'
WARNING = '\x1b[93m'
ocelot.common.py_func.copy_this_script(file, folderPath)
ocelot.common.py_func.deep_sim_dir(path, **kwargs)
ocelot.common.py_func.directory_from_path(path_string)
ocelot.common.py_func.filename_from_path(path_string)
ocelot.common.py_func.list_attr(obj)

lists all attributes of an object

ocelot.common.py_func.loc_class(obj)

locates the file where class of the object is defined

ocelot.common.xio module

Module contents