def _defaultData(self): x_min = self._defaultSimulationParameters()['x_min'] x_max = self._defaultSimulationParameters()['x_max'] x_step = self._defaultSimulationParameters()['x_step'] num_points = int((x_max - x_min) / x_step + 1) x_data = np.linspace(x_min, x_max, num_points) data = DataStore() data.append( DataSet1D(name='PND', x=x_data, y=np.zeros_like(x_data), x_label='2theta (deg)', y_label='Intensity', data_type='experiment')) data.append( DataSet1D(name='{:s} engine'.format(self._interface_name), x=x_data, y=np.zeros_like(x_data), x_label='2theta (deg)', y_label='Intensity', data_type='simulation')) data.append( DataSet1D(name='Difference', x=x_data, y=np.zeros_like(x_data), x_label='2theta (deg)', y_label='Difference', data_type='simulation')) return data
def _updateCalculatedData(self): if not self._experiment_loaded and not self._experiment_skipped: return self._sample.output_index = self._current_phase_index # THIS IS WHERE WE WOULD LOOK UP CURRENT EXP INDEX sim = self._data.simulations[0] if self._experiment_loaded: exp = self._data.experiments[0] sim.x = exp.x elif self._experiment_skipped: x_min = float(self._simulation_parameters_as_obj['x_min']) x_max = float(self._simulation_parameters_as_obj['x_max']) x_step = float(self._simulation_parameters_as_obj['x_step']) num_points = int((x_max - x_min) / x_step + 1) sim.x = np.linspace(x_min, x_max, num_points) sim.y = self._interface.fit_func(sim.x) hkl = self._interface.get_hkl() self.parent.chartsLogic._plotting_1d_proxy.setCalculatedData( sim.x, sim.y) # noqa: E501 self.parent.chartsLogic._plotting_1d_proxy.setBraggData( hkl['ttheta'], hkl['h'], hkl['k'], hkl['l']) # noqa: E501
b = BaseObj('line', m=Parameter('m', 1), c=Parameter('c', 1)) def fit_fun(x, *args, **kwargs): # In the real case we would gust call the evaluation fn without reference to the BaseObj return b.c.raw_value + b.m.raw_value * x f = Fitter() f.initialize(b, fit_fun) nx = 1E3 x_min = 0 x_max = 100 x = np.linspace(x_min, x_max, num=int(nx)) y1 = 2 * x - 1 + 5 * (np.random.random(size=x.shape) - 0.5) x2 = x + 20 y2 = 2 * x2 - 1 + 5 * (np.random.random(size=x2.shape) - 0.5) d.easyCore.add_coordinate('x1', x) d.easyCore.add_variable('y1', ['x1'], y1, auto_sigma=True) d.easyCore.add_coordinate('x2', x2) d.easyCore.add_variable('y2', ['x2'], y2, auto_sigma=True) res = d.easyCore.fit(f, ['y1', 'y2']) fig, axs = plt.subplots(1, len(res), sharey=True) for idx, r in enumerate(res): r.y_obs.plot(ax=axs[idx]) r.y_calc.plot(ax=axs[idx])
from easyDiffractionLib.sample import Sample from easyDiffractionLib import Phase, Phases from easyDiffractionLib.interface import InterfaceFactory from easyDiffractionLib.Profiles.P1D import Instrument1DCWParameters import matplotlib.pyplot as plt i = InterfaceFactory() c = Phases.from_cif_file('tests/SrTiO3.cif') S = Sample(phases=c, parameters=Instrument1DCWParameters.default(), interface=i) x_data = np.linspace(5, 150, 10000) y_data = i.fit_func(x_data) i.switch('CrysPy') S._updateInterface() y_data2 = np.array(i.fit_func(x_data)) fig = plt.figure() axprops = dict() ax1 = fig.add_axes([0.1, 0.5, 0.8, 0.4], **axprops) ax1.plot(x_data, y_data, label="CrysFML") ax1.legend() axprops['sharex'] = ax1 # axprops['sharey'] = ax1 # force x axes to remain in register, even with toolbar navigation
parameters.resolution_u = 0.1447 parameters.resolution_v = -0.4252 parameters.resolution_w = 0.3864 parameters.resolution_x = 0.0 parameters.resolution_y = 0.0 pattern = Powder1DParameters.default() pattern.zero_shift = 0.0 pattern.scale = 100.0 S = Sample(phases=phases, parameters=parameters, pattern=pattern, calculator=calculator) x_data = np.linspace(1, 120, 500) y_data = calculator.fit_func(x_data) plt.plot(x_data, y_data, label="CW") plt.show() phases = S.phases[0] pattern = S.pattern parameters = TOFParams.default() parameters.length_a = 8.56 parameters.length_c = 6.12 parameters.length_b = 8.56 parameters.dtt1 = 6167.24700 parameters.dtt2 = -2.28000 parameters.ttheta_bank = 145.00
# rST and your code. This separates your example # into distinct text and code blocks. You can continue writing code below the # embedded rST text block: p1 = Pendulum.from_pars() # Another pendulum with Amplitude = 5 p2 = Pendulum.from_pars(A=5) # Another pendulum with Frequency = 4 p3 = Pendulum.from_pars(A=5, f=4) # Another pendulum with Phase = pi/2 p4 = Pendulum.from_pars(A=5, f=4, p=np.pi/2) #%% # Plotting t = np.linspace(0, 3, 601) fig = plt.figure() gs = fig.add_gridspec(2, 2) (ax1, ax2), (ax3, ax4) = gs.subplots(sharex='col', sharey='row') p1.plot(t, axis=ax1) p2.plot(t, axis=ax2) p3.plot(t, axis=ax3) p4.plot(t, axis=ax4) fig.show() #%% # Multiple Examples # ***************** # To include embedded rST, use a line of >= 20 ``#``'s or ``#%%`` between your # rST and your code. This separates your example # into distinct text and code blocks. You can continue writing code below the