<jupyter_start><jupyter_text>Tutorial 3: Structure Reconstruction<jupyter_code>#Import required system libraries for file management
import sys,importlib,os

# Provide path to oct-cbort library
module_path=os.path.abspath('/Users/damondepaoli/Documents/GitHub/oct-cbort')
if module_path not in sys.path:
    sys.path.append(module_path)

# Import oct-cbort library
from oct import *

# Choose a directory with all meta/ofd/ofb data within it
d = os.path.join(module_path,'examples/data/3_BL_Catheter2_human_coronary_artery_ramp_struct_ps')
data = Load(directory = d)<jupyter_output><empty_output><jupyter_text>First we need to compute the tomogram, like we did in the previous tutorial<jupyter_code>tom = Tomogram(mode='heterodyne')
outtom = tom.reconstruct(data=data)<jupyter_output><empty_output><jupyter_text>There are several different ways to create the structure contrast using the reconstruct library (oct.reconstruct.structure). Technique 1: Direct variable assignment without class instanceThis technique is most like MATLAB, but does not take avantage of all the initialization that can be taken advantage of thanks to object oriented programming.<jupyter_code>out = Structure().reconstruct(tomch1=outtom['tomch1'],
                                 tomch2=outtom['tomch2'],
                                 settings=data.structureSettings)<jupyter_output><empty_output><jupyter_text>Technique 2: Create Structure instance -> direct variable assigmentUsing this technique, we can keep the class in memory and continue to process other frames without needing to reinitialize and variables or memory space, important for GPU processing<jupyter_code>struct = Structure(mode='log')
out = struct.reconstruct(tomch1=outtom['tomch1'],
                            tomch2=outtom['tomch2'],
                            settings=data.structureSettings)<jupyter_output><empty_output><jupyter_text>Technique 3 : Create Structure instance -> data object variable assigmentThis method automatically grabs all the required tomogramgs and settings from the `data` object and reconstructs the contrast using it.  To use this method, we now much place the outputted tomogram into the data.processedData dictionary. This is specfically useful for post processing efficiency and less so for scripting<jupyter_code>for key,val in outtom.items():
    data.processedData[key] = outtom[key]
struct = Structure(mode='log')
out = struct.reconstruct(data=data)<jupyter_output><empty_output><jupyter_text>What is in "out"?The processed structure image resides in an output dictionary at `out['struct']` . Why use dictionaries? Because they're scalable and more outputs can be added later.<jupyter_code>for key,val in out.items():
    if not (out[key] is None):
        print('Dictionary key ', key, ' : ', out[key].shape, out[key].dtype)
    else:
        print('Dictionary key ', key, ' : ', 'None' , 'None')<jupyter_output>Dictionary key  struct  :  (2048, 1024) uint8<jupyter_text>This is not required, but to keep everything in the same place, it is often convenient to store all outputs into the data object<jupyter_code>for key,val in out.items():
    data.processedData[key] = out[key]
plt.figure()
plt.imshow(data.processedData['struct'],cmap='gray', aspect='auto')<jupyter_output><empty_output><jupyter_text>As Before, we can also view what `Structure` requires<jupyter_code>struct.requires()<jupyter_output>Required:
tomch1=tomch1


Optional:
tomch2=tomch2


OR:
data=data


Settings:
data.structureSettings['contrastLowHigh'] ( [min, max])
data.structureSettings['invertGray'] ( [0 or 1])
data.structureSettings['imgWidth'] (for big-seg scans) 


For reference, all possible settings and defaults are:
self.settings[' contrastLowHigh '] :  [-40, 130]
self.settings[' invertGray '] :  0
self.settings[' imgDepth '] :  1<jupyter_text>We can also output the data in the linear format<jupyter_code>struct = Structure(mode='linear')
outlinear = struct.reconstruct(data=data)
plt.figure()
plt.plot(outlinear['struct'][512,:])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09801980198019802, 'fraction_numerical': 0.009653465346534653, 'mean_word_length': 5.444976076555024, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '192891', 'license': 'MIT', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1177, 'n_words': 352, 'path': 'tutorials/.ipynb_checkpoints/oct_cb_tutorial_03_structure-checkpoint.ipynb', 'repo_name': 'CBORT-NCBIB/oct-cbort', 'size': '4040'}