\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage{listings}
\usepackage{xcolor} % For custom colors
\usepackage{sectsty} % For customizing section fonts
% \subsectionfont{\raggedright} % Allow line breaks and ragged right alignment             
\usepackage{geometry}
% \geometry{margin=1in}
\usepackage{graphicx}
                
\title{TexTOM - Manual}
\author{Moritz Frewein, Moritz Stammer, Marc Allain, Tilman Grünewald}
\begin{document}
\maketitle
\label{toc}
\tableofcontents

% Define a custom style for docstrings
\lstdefinelanguage{docstring}{
    basicstyle=\ttfamily\small, % Monospaced font
    backgroundcolor=\color[HTML]{F5F5F5}, % Light gray background
    frame=single, % Border around the docstring
    rulecolor=\color[HTML]{D6D6D6}, % Border color
    keywordstyle=\color{blue}, % Optional: color for keywords
    breaklines=true, % Wrap long lines
}
                
\subsectionfont{\large\ttfamily\raggedright}

\include{introduction}
\section{Functions}\label{sec:functions}
\subsection*{\texttt{set\_path(path)}}
\label{fun:setpath}
\addcontentsline{toc}{subsection}{set\_path}

\begin{lstlisting}[language=docstring]
Set the path where integrated data and analysis is stored

Parameters
----------
path : str
    full path to the directory, must contain a folder '/data_integrated'
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/set_path}

\vspace{5mm}

\hrule

\subsection*{\texttt{check\_state()}}
\label{fun:checkstate}
\addcontentsline{toc}{subsection}{check\_state}

\begin{lstlisting}[language=docstring]
Prints in terminal which parts of the reconstruction are ready
    
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/check_state}

\vspace{5mm}

\hrule

\subsection*{\texttt{integration\_test(dset\_no=0)}}
\label{fun:integrationtest}
\addcontentsline{toc}{subsection}{integration\_test}

\begin{lstlisting}[language=docstring]
Set up integration parameters, perform a 2D and 1D integration and plot them

Parameters
----------
dset_no : int, optional
    allows to choose a different file from the raw data folder
    (they will be assigned indices in alphabetic order), by default 0
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/integration_test}

\vspace{5mm}

\hrule

\subsection*{\texttt{generate\_sample()}}
\label{fun:generatesample}
\addcontentsline{toc}{subsection}{generate\_sample}

\begin{lstlisting}[language=docstring]
Allows the creation of custom samples for testing the pipeline.
Input of parameters occurs via a custom generation.py file, which opens automatically,
in addition to usual textom input files.
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/generate_sample}

\vspace{5mm}

\hrule

\subsection*{\texttt{integrate(parallel=True, wait=5.0, confirm=True, ignore=[], parallel\_gpu=False)}}
\label{fun:integrate}
\addcontentsline{toc}{subsection}{integrate}

\begin{lstlisting}[language=docstring]
Integrates raw 2D diffraction data via pyFAI

All necessary input will be handled via the file integration_parameters.py

Parameters
----------
mode : str
    'online' does one by one, updates filelist after each integration
    'parallel' loads filelist when started, can be parallelized over CPUs
wait : float
    waits this number of seconds after integrating the last file before
    stopping, by default 5.
confirm : bool
    if True, will open integration_parameters.py and ask for confirmation
    else, takes current file and starts
ignore : list
    here you can provide a list of datasets you want to skip (if they crash
    they will automatically be skipped)
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/integrate}

\vspace{5mm}

\hrule

\subsection*{\texttt{check\_geometry(testfile\_path, testfile\_h5path, dset\_no=0, vmin=1, vmax=10, logscale=False)}}
\label{fun:checkgeometry}
\addcontentsline{toc}{subsection}{check\_geometry}

\begin{lstlisting}[language=docstring]
No docstring available.
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/check_geometry}

\vspace{5mm}

\hrule

\subsection*{\texttt{align\_data(pattern='.h5', sub\_data='data\_integrated', align\_by\_transmission=False, q\_index\_range=(0, 5), q\_range=False, crop\_image=False, mode='optical\_flow', redo\_import=False, regroup\_max=16, align\_horizontal=True, align\_vertical=True, pre\_rec\_it=5, pre\_max\_it=5, last\_rec\_it=40, last\_max\_it=5, do\_align=True)}}
\label{fun:aligndata}
\addcontentsline{toc}{subsection}{align\_data}

\begin{lstlisting}[language=docstring]
Align data using the Mumott optical flow alignment

Requires that data has been integrated and that sample_dir contains
a subfolder with data

Parameters
----------
pattern : str, optional
    substring contained in all files you want to use, by default '.h5'
sub_data : str, optional
    subfolder containing the data, by default 'data_integrated'
q_index_range : tuple, optional
    determines which q-values are used for alignment (sums over them), by default (0,5)
q_range : tuple, optional
    give the q-range in nm instead of indices e.g. (15.8,18.1), by default False
mode : str, optional
    choose alignment mode, 'optical_flow' or 'phase_matching', by default 'optical_flow'
crop_image : bool or tuple of int, optional
    give the range you want to use in x and y, e.g. ((0,-1),(10,-10))
    only available with the 'phase_matching'-option, by default False
redo_import : bool, optional
    set True if you want to recalculate data_mumott.h5, by default False
regroup_max : int, optional
    maximum size of groups when downsampling for faster processing, by default 16
align_horizontal : bool, optional
    align your data horizontally, by default True
align_vertical : bool, optional
    align your data vertically, by default True
pre_rec_it : int, optional
    reconstruciton iterations for downsampled data, by default 5
pre_max_it : int, optional
    alignment iterations for downsampled data, by default 5
last_rec_it : int, optional
    reconstruciton iterations for full data, by default 40
last_max_it : int, optional
    alignment iterations for full data, by default 5
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/align_data}

\vspace{5mm}

\hrule

\subsection*{\texttt{check\_alignment\_consistency()}}
\label{fun:checkalignmentconsistency}
\addcontentsline{toc}{subsection}{check\_alignment\_consistency}

\begin{lstlisting}[language=docstring]
Plots the squared residuals between data and the projected tomograms,
with data shifted according to the alignment.
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/check_alignment_consistency}

\vspace{5mm}

\hrule

\subsection*{\texttt{check\_alignment\_projection(g=0)}}
\label{fun:checkalignmentprojection}
\addcontentsline{toc}{subsection}{check\_alignment\_projection}

\begin{lstlisting}[language=docstring]
Plots the data and the projected tomogram of projection g

Parameters
----------
g : int, optional
    projection running index, by default 0
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/check_alignment_projection}

\vspace{5mm}

\hrule

\subsection*{\texttt{reconstruct\_1d\_full(q\_index\_range=None, redo\_import=False, only\_mumottize=False, batch\_size=10)}}
\label{fun:reconstruct1dfull}
\addcontentsline{toc}{subsection}{reconstruct\_1d\_full}

\begin{lstlisting}[language=docstring]
Reconstructs scalar tomographic data such as azimutally averaged
diffraction data. Uses the same alignment as textom

Parameters
----------    
q_index_range : list or ndarray or None, optional
    [starting_q_index, end_q_index], takes the whole range if None, by default None
redo_import : bool, optional
    set true if you want to redo the preprocessing, by default False
only_mumottize : bool, optional
    only preprocesses a file analysis/rec1d/data_rec1d.h5, by default False
batch_size : int, optional
    number of q-values to load at the same time. Needs to be an integer fraction
    of the total number of q-values, else it will crash at the last batch. Higher
    numbers will decrease i/o time, but require more memory, by default 10
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/reconstruct_1d_full}

\vspace{5mm}

\hrule

\subsection*{\texttt{check\_powder\_pattern(projection=0, datafile\_pattern='.h5')}}
\label{fun:checkpowderpattern}
\addcontentsline{toc}{subsection}{check\_powder\_pattern}

\begin{lstlisting}[language=docstring]
Calculates the theoretical powder pattern according to the input in crystal.py
and plots it together with the average over a given projection.

Parameters
----------
projection : int, optional
    Index of the projection from the data_integrated directory,
    (sorted by rotation angles or alphabetical, as stated in the terminal) by default 0
datafile_pattern : str, optional
    allows use a certain file that contains the pattern, by default '.h5'
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/check_powder_pattern}

\vspace{5mm}

\hrule

\subsection*{\texttt{make\_model(light\_mode=False)}}
\label{fun:makemodel}
\addcontentsline{toc}{subsection}{make\_model}

\begin{lstlisting}[language=docstring]
Calculates the TexTOM model for reconstructions

Is automatically performed by the functions that require it
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/make_model}

\vspace{5mm}

\hrule

\subsection*{\texttt{list\_sample\_rotations()}}
\label{fun:listsamplerotations}
\addcontentsline{toc}{subsection}{list\_sample\_rotations}

\begin{lstlisting}[language=docstring]
Gives a list in the terminal of all projections present in the model, with rotation and tilt angle. 
Useful to choose a certain projection for other functions using index.
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/list_sample_rotations}

\vspace{5mm}

\hrule

\subsection*{\texttt{show\_sample\_outline()}}
\label{fun:showsampleoutline}
\addcontentsline{toc}{subsection}{show\_sample\_outline}

\begin{lstlisting}[language=docstring]
Plots the sample outline after masking.
    
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/show_sample_outline}

\vspace{5mm}

\hrule

\subsection*{\texttt{mask\_peak\_regions(projection=0, datafile\_pattern='.h5')}}
\label{fun:maskpeakregions}
\addcontentsline{toc}{subsection}{mask\_peak\_regions}

\begin{lstlisting}[language=docstring]
lets the user choose the regions that contain the peaks for fitting

Parameters
----------
projection : int, optional
    projection index, by default 0
datafile_pattern : str, optional
    allows use a certain file that contains the pattern, by default '.h5'
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/mask_peak_regions}

\vspace{5mm}

\hrule

\subsection*{\texttt{check\_baselines(projection=0, datafile\_pattern='.h5')}}
\label{fun:checkbaselines}
\addcontentsline{toc}{subsection}{check\_baselines}

\begin{lstlisting}[language=docstring]
Picks some data containing from the given projection and calculates baselines with all available methods,
using the input parameters from the background_subtraction.py file.
    
Parameters
----------
projection : int, optional
    projection index, by default 0
datafile_pattern : str, optional
    allows use a certain file that contains the pattern, by default '.h5'
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/check_baselines}

\vspace{5mm}

\hrule

\subsection*{\texttt{mask\_detector\_pixels(projection=0, datafile\_pattern='.h5')}}
\label{fun:maskdetectorpixels}
\addcontentsline{toc}{subsection}{mask\_detector\_pixels}

\begin{lstlisting}[language=docstring]
Opens a window that allows excluding detector pixels by mouse clicks

Parameters
----------
projection : int, optional
    projection index, by default 0
datafile_pattern : str, optional
    allows use a certain file that contains the pattern, by default '.h5'
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/mask_detector_pixels}

\vspace{5mm}

\hrule

\subsection*{\texttt{preprocess\_data(proj\_test=0, pattern='.h5', use\_ion=True)}}
\label{fun:preprocessdata}
\addcontentsline{toc}{subsection}{preprocess\_data}

\begin{lstlisting}[language=docstring]
Loads integrated data and pre-processes them for TexTOM

Parameters
----------
proj_test : int, optional
    projection index (only for displaying), by default 0
pattern : str, optional
    substring contained in all files you want to use, 
    (this actually filters the files you process), by default '.h5'
use_ion : bool, optional
    choose if you want to normalize data by the field 'ion' in the 
    data files, by default True
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/preprocess_data}

\vspace{5mm}

\hrule

\subsection*{\texttt{make\_fit(redo=True)}}
\label{fun:makefit}
\addcontentsline{toc}{subsection}{make\_fit}

\begin{lstlisting}[language=docstring]
Initializes a TexTOM fit object for reconstructions

Is automatically performed by the functions that require it

Parameters
----------
redo : bool, optional
    set True for recalculating, by default True
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/make_fit}

\vspace{5mm}

\hrule

\subsection*{\texttt{optimize(mode=4, proj='full', zero\_peak=None, redo\_fit=False, step\_size\_0=1.0, tol=0.001, minstep=1e-09, max\_iter=500, alg='simple', save\_h5=True)}}
\label{fun:optimize}
\addcontentsline{toc}{subsection}{optimize}

\begin{lstlisting}[language=docstring]
Performs a single TexTOM parameter optimization

Parameters
----------
mode : int, optional
    set 0 for only optimizing order 0, 1 for highest order, 2 for all,
    3 for all but the lowest order, 4 for all with enhanced stepsize calibration
    by default 4
proj : str, optional
    choose projections to be optimized: 'full', 'half', 'third', 'notilt', 
    by default 'full'
zero_peak : int or None
    index of the peak you want to use for 0-order fitting (should be as
    isotropic as possible), if None uses the whole dataset, default None
redo_fit : bool, optional
    recalculate the fit object, by default False
step_size_0 : float, optional
    starting value for automatic stepsize tuning, by default 1.
tol : float, optional
    tolerance for precision break criterion, by default 1e-3
minstep : float, optional
    minimum stepsize in line search (another break criterion), by default 1e-9
max_iter : int, optional
    maximum number of iterations, by default 500
alg : str, optional
    choose algorithm between 'backtracking', 'simple', 'quadratic', 
    by default 'simple'
save_h5 : bool, optional
    choose if you want to save the result to the directory analysis/fits, 
    by default True    
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/optimize}

\vspace{5mm}

\hrule

\subsection*{\texttt{list\_opt(info=True)}}
\label{fun:listopt}
\addcontentsline{toc}{subsection}{list\_opt}

\begin{lstlisting}[language=docstring]
Shows all stored optimizations in the terminal
    
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/list_opt}

\vspace{5mm}

\hrule

\subsection*{\texttt{load\_opt(h5path='last', redo\_fit=False, exclude\_ghosts=True)}}
\label{fun:loadopt}
\addcontentsline{toc}{subsection}{load\_opt}

\begin{lstlisting}[language=docstring]
Loads a previous Textom optimization into memory
seful: load_opt(results['optimization'])

Parameters
----------
h5path : str, optional
    filepath, just filename or full path
    if 'last', uses the youngest file is used in analysis/fits/, 
    by default 'last'
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/load_opt}

\vspace{5mm}

\hrule

\subsection*{\texttt{check\_lossfunction(opt\_file=None)}}
\label{fun:checklossfunction}
\addcontentsline{toc}{subsection}{check\_lossfunction}

\begin{lstlisting}[language=docstring]
Plots the lossfunction of an optimization

Parameters
----------
opt_file : str or None, optional
    name of the file in the fit directory, if None takes currently loaded one, by default None
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/check_lossfunction}

\vspace{5mm}

\hrule

\subsection*{\texttt{check\_fit\_average()}}
\label{fun:checkfitaverage}
\addcontentsline{toc}{subsection}{check\_fit\_average}

\begin{lstlisting}[language=docstring]
Plots the reconstructed average intensity for each projection with data

Parameters
----------
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/check_fit_average}

\vspace{5mm}

\hrule

\subsection*{\texttt{check\_fit\_random(N=10, mode='line')}}
\label{fun:checkfitrandom}
\addcontentsline{toc}{subsection}{check\_fit\_random}

\begin{lstlisting}[language=docstring]
Generates TexTOM reconstructions and plots them with data for random points

Parameters
----------
N : int, optional
    Number of images created, by default 10    
mode : str, optional
    plotting mode, 'line' or 'color', by default line
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/check_fit_random}

\vspace{5mm}

\hrule

\subsection*{\texttt{check\_residuals()}}
\label{fun:checkresiduals}
\addcontentsline{toc}{subsection}{check\_residuals}

\begin{lstlisting}[language=docstring]
Plots the squared residuals summed over each projection
    
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/check_residuals}

\vspace{5mm}

\hrule

\subsection*{\texttt{check\_projections\_average(G=None)}}
\label{fun:checkprojectionsaverage}
\addcontentsline{toc}{subsection}{check\_projections\_average}

\begin{lstlisting}[language=docstring]
Plots the reconstructed average intensity for chosen projections with data

Parameters
----------
G : int or ndarray or None, optional
    projection indices, if None takes 10 equidistant ones, by default None
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/check_projections_average}

\vspace{5mm}

\hrule

\subsection*{\texttt{check\_projections\_residuals(g=0)}}
\label{fun:checkprojectionsresiduals}
\addcontentsline{toc}{subsection}{check\_projections\_residuals}

\begin{lstlisting}[language=docstring]
Plots the residuals per pixel for chosen projections with data

Parameters
----------
g : int e, optional
    projection index, by default 0
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/check_projections_residuals}

\vspace{5mm}

\hrule

\subsection*{\texttt{check\_projections\_orientations(G=None)}}
\label{fun:checkprojectionsorientations}
\addcontentsline{toc}{subsection}{check\_projections\_orientations}

\begin{lstlisting}[language=docstring]
Plots the reconstructed average orientations for chosen projections with data

Parameters
----------
G : int or ndarray or None, optional
    projection indices, if None takes 10 equidistant ones, by default None
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/check_projections_orientations}

\vspace{5mm}

\hrule

\subsection*{\texttt{calculate\_orientation\_statistics()}}
\label{fun:calculateorientationstatistics}
\addcontentsline{toc}{subsection}{calculate\_orientation\_statistics}

\begin{lstlisting}[language=docstring]
Calculates prefered orientations and stds and saves them to results dict

    
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/calculate_orientation_statistics}

\vspace{5mm}

\hrule

\subsection*{\texttt{calculate\_order\_parameters(axis=(0, 0, 1))}}
\label{fun:calculateorderparameters}
\addcontentsline{toc}{subsection}{calculate\_order\_parameters}

\begin{lstlisting}[language=docstring]
Calculates nematic order parameters and directors per voxel and adds them to results

Parameters
----------
axis : tuple, optional
    choose the axis direction along which particles are aligned, by default (0,0,1)
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/calculate_order_parameters}

\vspace{5mm}

\hrule

\subsection*{\texttt{calculate\_segments(thresh=10, min\_segment\_size=30, max\_segments\_number=31)}}
\label{fun:calculatesegments}
\addcontentsline{toc}{subsection}{calculate\_segments}

\begin{lstlisting}[language=docstring]
Segments the sample based on misorientation borders

Parameters
----------
thresh : float, optional
    misorientation angle threshold inside segment in degree, by default 10
min_segment_size : int, optional
    minimum number of voxels in segment, by default 30
max_segments_number : int, optional
    maximum number of segments (ordered by size), by default 32
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/calculate_segments}

\vspace{5mm}

\hrule

\subsection*{\texttt{show\_volume(data='scaling', plane='z', colormap='inferno', cut=1, save=False, show=True)}}
\label{fun:showvolume}
\addcontentsline{toc}{subsection}{show\_volume}

\begin{lstlisting}[language=docstring]
Visualizes the whole sample by slices, colored by a value of your choice

Parameters
----------
data : str or list, optional
    name of one entry in the results dict or list of entries, 
    by default 'scaling'
plane : str, optional
    sliceplane 'x'/'y'/'z', by default 'z'
colormap : str, optional
    identifier of matplotlib colormap, default 'inferno'
    https://matplotlib.org/stable/users/explain/colors/colormaps.html
cut : int, optional
    cut colorscale at upper and lower percentile, by default 0.1
save : bool, optional
    saves tomogram as .gif to results/images/, by default False
show : bool, optional
    open the figure upon calling the function, by default True
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/show_volume}

\vspace{5mm}

\hrule

\subsection*{\texttt{show\_slice\_ipf(h, plane='z')}}
\label{fun:showsliceipf}
\addcontentsline{toc}{subsection}{show\_slice\_ipf}

\begin{lstlisting}[language=docstring]
Plots an inverse pole figure of a sample slice

Parameters
----------
h : int
    height of the slice
plane : str, optional
    slice direction: x/y/z, by default 'z'
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/show_slice_ipf}

\vspace{5mm}

\hrule

\subsection*{\texttt{show\_slice\_directions(h, plane='z', direction='c')}}
\label{fun:showslicedirections}
\addcontentsline{toc}{subsection}{show\_slice\_directions}

\begin{lstlisting}[language=docstring]
Plots an inverse pole figure of a sample slice

Parameters
----------
h : int
    height of the slice
plane : str, optional
    slice direction: x/y/z, by default 'z'
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/show_slice_directions}

\vspace{5mm}

\hrule

\subsection*{\texttt{show\_volume\_ipf(plane='z', save=False, show=True)}}
\label{fun:showvolumeipf}
\addcontentsline{toc}{subsection}{show\_volume\_ipf}

\begin{lstlisting}[language=docstring]
Plots inverse pole figures as a tomogram with a slider to scroll through the sample

Parameters
----------
plane : str, optional
    slice direction: x/y/z, by default 'z'
save : bool, optional
    saves tomogram as .gif to results/images/, by default False
show : bool, optional
    open the figure upon calling the function, by default True
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/show_volume_ipf}

\vspace{5mm}

\hrule

\subsection*{\texttt{show\_histogram(x, nbins=50, cut=0.1, segments=None, save=False)}}
\label{fun:showhistogram}
\addcontentsline{toc}{subsection}{show\_histogram}

\begin{lstlisting}[language=docstring]
plots a histogram of a result parameter

Parameters
----------
x : str,
    name of a scalar from results
bins : int, optional
    number of bins, by default 50
cut : int, optional
    cut upper and lower percentile, by default 0.1
segments : list of int, optional
    list of segments or None for all data, by default None
save : bool/str, optional
    saves image with specified file extension, e.g. 'png', 'pdf'
    if True uses png, by default False
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/show_histogram}

\vspace{5mm}

\hrule

\subsection*{\texttt{show\_correlations(x, y, nbins=50, cut=(0.1, 0.1), segments=None, save=False)}}
\label{fun:showcorrelations}
\addcontentsline{toc}{subsection}{show\_correlations}

\begin{lstlisting}[language=docstring]
Plots a 2D histogram between 2 result parameters

Parameters
----------
x : str,
    name of a scalar from results
y : str,
    name of a scalar from results
bins : int, optional
    number of bins, by default 50
cut : tuple, optional
    cut upper and lower percentile of both parameters, by default (0.1,0.1)
segments : list, optional
    list of segments or None for all data, by default None
save : bool/str, optional
    saves image with specified file extension, e.g. 'png', 'pdf'
    if True uses png, by default False
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/show_correlations}

\vspace{5mm}

\hrule

\subsection*{\texttt{show\_voxel\_odf(x, y, z, num\_samples=1000, representation='quaternion', info=True)}}
\label{fun:showvoxelodf}
\addcontentsline{toc}{subsection}{show\_voxel\_odf}

\begin{lstlisting}[language=docstring]
Show a 3D plot of the ODF in the chosen voxel

Parameters
----------
x : int
    voxel x-coordinate
y : int
    voxel y-coordinate
z : int
    voxel z-coordinate
representation : 'quaternion'|'euler'|'rodrigues'
  different styles ('euler' and 'rodrigues' still experimental)
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/show_voxel_odf}

\vspace{5mm}

\hrule

\subsection*{\texttt{show\_voxel\_polefigure(x, y, z, hkl=(1, 0, 0), mode='density', alpha=0.1, num\_samples=10000.0, recenter=True)}}
\label{fun:showvoxelpolefigure}
\addcontentsline{toc}{subsection}{show\_voxel\_polefigure}

\begin{lstlisting}[language=docstring]
Show a polefigure plot for the chosen voxel and hkl

Parameters
----------
x : int
    voxel x-coordinate
y : int
    voxel y-coordinate
z : int
    voxel z-coordinate
hkl : tuple, optional
    Miller indices, by default (1,0,0)
mode : str, optional
    plotting style 'scatter' or 'density', by default 'density'
alpha : float, optional
    opacity of points, only for scatter, by default 0.1
num_samples : int/float, optional
    number of samples for plot generation, by default 1e4
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/show_voxel_polefigure}

\vspace{5mm}

\hrule

\subsection*{\texttt{show\_subvolume\_average\_polefigure(x\_range=None, y\_range=None, z\_range=None, custom\_mask=None, hkl=(1, 0, 0), mode='density', alpha=0.1, num\_samples=10000.0)}}
\label{fun:showsubvolumeaveragepolefigure}
\addcontentsline{toc}{subsection}{show\_subvolume\_average\_polefigure}

\begin{lstlisting}[language=docstring]
Lets you visualize the texture of a chosen part of the sample, specified by ranges or a custom mask.

Parameters
----------
x_range : tuple or None, optional
    range of voxel coordinates, e.g. (0,10), by default None
y_range : tuple or None, optional
    range of voxel coordinates, e.g. (0,10), by default None
z_range : tuple or None, optional
    range of voxel coordinates, e.g. (0,10), by default None
custom_mask : 3darray(int), optional
    Input a custom voxel-mask via e.g. 
    custom_mask = np.where(results['order_parameters'].flatten() > 0.5)[0], by default None
hkl : tuple, optional
    Miller indices, by default (1,0,0)
mode : str, optional
    plotting style 'scatter' or 'density', by default 'density'
alpha : float, optional
    opacity of points, only for scatter, by default 0.1
num_samples : _type_, optional
    number of samples for plot generation, by default 1e4
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/show_subvolume_average_polefigure}

\vspace{5mm}

\hrule

\subsection*{\texttt{save\_results()}}
\label{fun:saveresults}
\addcontentsline{toc}{subsection}{save\_results}

\begin{lstlisting}[language=docstring]
Saves the results dictionary to a h5 file in the results/ directory

    
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/save_results}

\vspace{5mm}

\hrule

\subsection*{\texttt{export\_paraview()}}
\label{fun:exportparaview}
\addcontentsline{toc}{subsection}{export\_paraview}

\begin{lstlisting}[language=docstring]
Saves the results dictionary to a h5 file in the results/ directory
Here, the coordinate system is converted to fortran order (z,y,x)
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/export_paraview}

\vspace{5mm}

\hrule

\subsection*{\texttt{list\_results()}}
\label{fun:listresults}
\addcontentsline{toc}{subsection}{list\_results}

\begin{lstlisting}[language=docstring]
Shows all results .h5 files in results directory
    
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/list_results}

\vspace{5mm}

\hrule

\subsection*{\texttt{load\_results(h5path='last', make\_bg\_nan=False)}}
\label{fun:loadresults}
\addcontentsline{toc}{subsection}{load\_results}

\begin{lstlisting}[language=docstring]
Loads the results from a h5 file do the results dictionary

Parameters
----------
h5path : str, optional
    filepath, just filename or full path
    if 'last', uses the youngest file is used in results/, 
    by default 'last'
make_bg_nan : bool, optional
    if true, replaces all excluded voxels by NaN
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/load_results}

\vspace{5mm}

\hrule

\subsection*{\texttt{list\_results\_loaded()}}
\label{fun:listresultsloaded}
\addcontentsline{toc}{subsection}{list\_results\_loaded}

\begin{lstlisting}[language=docstring]
Shows all results currently in memory
    
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/list_results_loaded}

\vspace{5mm}

\hrule

\subsection*{\texttt{save\_images(x, ext='raw')}}
\label{fun:saveimages}
\addcontentsline{toc}{subsection}{save\_images}

\begin{lstlisting}[language=docstring]
Export results as .raw or .tiff files for dragonfly

Parameters
----------
x : str,
    name of a scalar from results, e.g. 'scaling'
ext : str,
    desired file type by extension, can do 'raw' or 'tiff', default: 'raw'
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/save_images}

\vspace{5mm}

\hrule

\subsection*{\texttt{help(method=None, module=None, filter='')}}
\label{fun:help}
\addcontentsline{toc}{subsection}{help}

\begin{lstlisting}[language=docstring]
Prints information about functions in this library

Parameters
----------
method : str or None, optional
    get more information about a function or None for overview over all functions, by default None
module : str or None, optional
    choose python module or None for the base TexTOM library, by default None
filter : str, optional
    filter the displayed functions by a substring, by default ''
\end{lstlisting}

\begin{flushright}

\hyperref[toc]{ToC}

\end{flushright}

\input{functions/help}

\vspace{5mm}

\hrule

\end{document}\end{document}