macsdata¶
This is a python object that is the main wrapper for all of the methods of pyMACS. It requires only a few details to initialize - a .cif file to specify the sample being simulated, and a few instrumental settings.
- class pyMACS.macsdata.Data(sample, exptName=None, kidney_result_dir=None, compile_mode='all', beta_1=1.0, beta_2=1.0, PTAI_det=3, datamode='single_crystal')¶
Bases:
object
Class to handle the results of McStas simulations and compare to experimental data. Also used to convert to ng0 format for Mslice.
- Parameters:
exptName (str) – Name assosciated with the experiment.
data_matrix (pd.Dataframe) – Huge pandas matrix containing all of the previous results. Store all results in memory to be quickly referenced. Gone into in more detail elsewhere in individual functions, but can technically also be accessed directly by users.
projected_matrix (pd.Dataframe) – Results after being projected into Q/E space the viewing axis specified by the sample alignment. Also a pandas dataframe.
expt_data_matrix (pd.Dataframe) – Pandas Dataframe containing all imported experimental results. Convenient to compare to the normal data_matrix directly.
projected_expt_matrix (pd.Dataframe) – Experimental data projected into Q/E space using the specified sample orientation.
PTAI_det (int) – If PTAI is being used, specifies the detector.
datamode (str, optional) – String specifying if the scattering is from a single crystalline or powder sample.
csv_name (str) – Specifies the name of the .csv file where the cumulative data matrix is stored.
- append_data_matrix_from_csv(csv_file=False)¶
Loads a csv_file containing a data matrix and appends it to the data matrix.
- Parameters:
csv_file (str) – Filename of data matrix stored in .csv file.
- bin_constE_slice(num_ubins, num_vbins, urange, vrange, omega_range, which_data='mcstas')¶
If the data matrix has already been projection into Q-space, returns a constant energy slice based on the specified bins. The directions are specified by the crystal orientation, i.e. the u-v vectors.
- Parameters:
num_ubins (int) – Number of bins along the u-direction.
num_vbins (int) – number of bins along the v-direction.
urange (list) – List of min and max values along u-axis in format of [umin, umax]
vrange (list) – list of min and max values along v-axis in format of [vmin, vmax]
omega_range ([float, float]) – List of min and max values in energy transfer to average over in format of [Emin, Emax]
which_data (str) – Determines if experimental or simulated data should be used, ‘mcstas’ to use calculated scattering and ‘macs’ for experimental. Allowed value ‘mcstas’ and ‘macs’
- Return X,Y,Z:
Matrices of U-coordinates, V-coordinates, and intensities. Suitable to plot in plt.pcolormesh.
- Return type:
np.ndarray,np.ndarray,np.ndarray
- combine_all_csv(fname='_total.csv')¶
- Combines all of the .csv files in the result directory and saves into a composite large one. This can be slow.
Preserves old files.
- Parameters:
fname – Suffix to append output csv filename with. Total filename is (result_dir + exptName + fname).
- combine_csv_scans(preserve_old=False, flagstr=False)¶
Takes individual csvs which are the output of each scan and combines them into a master csv. Also updates the data matrix to reflect this.
- fake_A3_scan(A3_angles)¶
- Function that fakes the rotation of the sample and simply copies the intensity at one angle over many.
Will throw an error if multiple A3 angles exist in the data matrix already.
- Parameters:
A3_angles (list) – List of A3_angles to imitate
- get_QE_FWHM(hkl_pt, omega, Q_dir)¶
Gets FWHM values in Q and energy in Ang^-1 for a specified (h,k,l,omega) position. Requires a cut direction (longitudinal). The transverse direction is defined by the cross product of the +z vector and the cut direction. Returns a FWHM for the longitudinal, transverse, and energy axes. A Q-resolution can also be specfied, but energy transfer is never binned.
- import_ng0_to_matrix(fname)¶
Given a real MACS ng0 file, imports the result to the experimental data matrix.
- Parameters:
fname (str) – Filename of the ng0 file.
- load_data_matrix_from_csv(csv_file=False)¶
Provided a csv_file produced by a previous data matrix, loads it and appends it to the current data_matrix. Duplicates are automatically removed.
- project_data_QE(which_data='mcstas', PTAI=False, viewing_axes=False)¶
Project the results stored in the data matrix into QE space- requires information from the sample object
- Parameters:
which_data (str) – Determines if experimental or simulated data should be used, ‘mcstas’ to use calculated scattering and ‘macs’ for experimental. Allowed value ‘mcstas’ and ‘macs’
- take_cut(ubins, vbins, omegabins, which_data='mcstas', statistic='mean')¶
- Takes a cut of the data in the same style as MANTID.
Syntax for bins are [min,max] - averaged (or integrated) within this limit [min,max,numBins] - cut axis, cut will be from min to max with that number of steps. Two of the three bins must be integrated over.
Integration not supported now- only mean in the region.
- Parameters:
ubins (list) – Binning along u-direction in format of [min,max,numBins] or [min,max]
vbins (list) – Binning along v-direction in format of [min,max,numBins] or [min,max]
omegabins (list) – Binning along energy-axis in format of [min,max,numBins] or [min,max]
which_data (str) – Determines if experimental or simulated data should be used, ‘mcstas’ to use calculated scattering and ‘macs’ for experimental. Allowed value ‘mcstas’ and ‘macs’
statistic (str) – Only mean is supported right now. Integration in the future.
- Return x,i,err:
Returns three np arrays of the cut axis dimension coordinates, the intensities, and errors at this points.
- Return type:
np.ndarray, np.ndarray, np.ndarray
- take_slice(ubins, vbins, omegabins, which_data='mcstas', statistic='mean', smooth=False)¶
Takes a slice integrating over one dimension in Q-space. Two of the bins must be in MANTID/HORACE style format [min,max,number of bins], and one must be integrated over and specified as [min,max]
- Parameters:
ubins (list) – Bin specification in mantid format along u-direction (min,max,number of bins)
vbins (list) – Bin specification in mantid format along v-direction (min,max,number of bins)
omeagabins – Bin specification in mantid format along energy axis (min,max,number of bins)
which_data (str) – Determines if experimental or simulated data should be used, ‘mcstas’ to use calculated scattering and ‘macs’ for experimental. Allowed value ‘mcstas’ and ‘macs’
statistic (str) – Todo - not currently supported, always ‘mean’
smooth – Output slice gaussian smoothing, either false or std dev in pixels.
- Return X,Y,Z:
Matrices of U-coordinates, V-coordinates, and intensities. Suitable to plot in plt.pcolormesh. The X and Y matrices are bin edges, not centers.
- Return type:
np.ndarray,np.ndarray,np.ndarray
- take_volume(ubins, vbins, omegabins, which_data='mcstas', statistic='mean', smooth=False)¶
Returns a volume integrating over no dimensions. All bins must be in MANTID/HORACE style format [min,max,number of bins]
- Parameters:
ubins (list) – Bin specification in mantid format along u-direction (min,max,number of bins)
vbins (list) – Bin specification in mantid format along v-direction (min,max,number of bins)
omeagabins – Bin specification in mantid format along energy axis (min,max,number of bins)
which_data (str) – Determines if experimental or simulated data should be used, ‘mcstas’ to use calculated scattering and ‘macs’ for experimental. Allowed value ‘mcstas’ and ‘macs’
statistic (str) – Todo - not currently supported, always ‘mean’
smooth – Output slice gaussian smoothing, either false or std dev in pixels.
- Return X,Y,Z:
Matrices of U-coordinates, V-coordinates, and intensities. Suitable to plot in plt.pcolormesh. The X and Y matrices are bin edges, not centers.
- Return type:
np.ndarray,np.ndarray,np.ndarray
- write_data_to_ng0(filename='McStas_output_', beta_1=1.0, beta_2=1.0)¶
Writes the current data matrix to an ng0 file directly readable by MSlice. :param filename: Output filename beginning. :type filename: str
Create a list of object parameters, like n_mono.