---
# System prepended metadata

title: Study materials for the summer project

---

# Study materials

## Papers 

### X-ray multi-projection imaging
- X-ray multi-projection imaging: [Megahertz X-ray multi-projection imaging](https://arxiv.org/pdf/2305.11920)


### Deep learning
- Neural Radiance Fields: [NeRF](https://www.matthewtancik.com/nerf)
- 4D-ONIX for 4D reconstruction: [4D-ONIX](https://arxiv.org/pdf/2401.09508)
- HexPlane for 4D reconstruction: [HexPlane](https://caoang327.github.io/HexPlane/)

### Metallic foam
- First demonstration of 1000 tomograms per second: [Tomoscopy: Time-Resolved Tomography for Dynamic Processes in Materials](https://doi.org/10.1002/adma.202104659)
- Review of 3D/4D imaging of metals: [X-ray Tomography and Tomoscopy on Metals: A Review](https://doi.org/10.1002/adem.202201355)


# Instructions
## Access the computing cluster at MAX IV
1. Create an account at MAX IV: [instruction](https://www.maxiv.lu.se/user-access/duo-guides/duo-account-creation-login/)| [login page](https://duo.maxiv.lu.se/duo/)
2. Send username to Pablo
3. Pablo: add to one of the beamtime proposal
4. Yuhe: request GPU access

## Connect to the MAX IV computing server
1. Connect to MAX IV VPN: [VPN](https://www.maxiv.lu.se/beamlines-accelerators/controls-it/it-services/vpn/)
2. Setup One Time Password:  [OTP](https://www.maxiv.lu.se/beamlines-accelerators/controls-it/it-services/one-time-password-otp/)
3. Connect via Thinlinc: [Remote Desktop](https://www.maxiv.lu.se/beamlines-accelerators/controls-it/it-services/remote-desktop/)
4. Once connected, navigate to `/data/staff/tomograms/users/` and create a folder under your name, then you should be able to write code inside.

## Connect to the GPU server from front end
<!-- Useful code:


1. connect to gn0 (the visualization gpu node): ssh -X clu0-gn-0

2. apply for a gpu node (Nvidia V100) from gn0: interactive -p v100 -t 24:00:00 --exclusive


- Search for modules: module avail xxx

- Load modules: module load Anaconda3 -->
```plantuml
title Run code on MAX IV GPU cluster 

|Front end (fe)|
repeat
:From the terminal, log into gn0;
:`ssh -X clu0-gn-0`;
|gn0 (Visualization GPU)|
:Logged in;
:Connect to computing GPUs;


switch (How to connect?)
case (Interactive session)
: Occupy a GPU node;
: `interactive -p v100 -t 24:00:00 –exclusive`;
|sl0 / gn1-12 (Computing GPU)|
: Log in to terminal and play around\n This is usually for debugging purposes;
:Automatically disconnect after the applied time;
|gn0 (Visualization GPU)|
:end;
case (submit batch jobs)
: Use `sbatch` to submit batch script;
: `sbatch xxx.sh`, e.g., sbatch hex.sh;
|sl0 / gn1-12 (Computing GPU)|
: Run the code;
: Automatically disconnect when the job is finished \n or failed;
|gn0 (Visualization GPU)|
:end;
endswitch
|Front end (fe)|
stop
```


## Learn terminal commands
Bash cheatsheet: [Bash Cheat Sheet](https://github.com/RehanSaeed/Bash-Cheat-Sheet)
Slurm cheatsheet: [Slurm Cheat Sheet](https://www.carc.usc.edu/user-information/user-guides/hpc-basics/slurm-cheatsheet)

# Hexplane
## Environment Setup
    # create conda environment
    conda create --name hexplane python=3.8
    
    # activate env
    conda activate hexplane
    conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1  cudatoolkit=11.6 -c pytorch -c conda-forge

    # pip install 
    pip install -r requirements.txt
    python setup.py develop
## Config file
`config` file is in ./config folder. All hyperparameters for training, optimizing, and dataset location and structure are defined in this file. Meanwhile,`./XMPI.yaml` file calls the hyperparameter in `config` file and can redefine them.
## Dataset and Dataloader
We provide a customized npy Dataloader in `./hexplane/dataloader/XMPIDataset.py`. Please change the "datadir" in `config` based on the locations of datasets. For the training, the dataset should have a dimension of [dataset_size, num_projections, H, W], where H, W should be constistent with what is defined in `config`file

Parallel X-ray configuration is used in our approach. Please be sure to modify the `generate_poses` function in the dataset preparation files to match the projection angles.
## Train from Max IV cluster:
1. Connect to gn0: `ssh -X clu0-gn-0`
2. Run the commands below on gn0
```
module load Anaconda3
source activate /home/$YourUserName/.conda/envs/$EnvName
```
3. Cast training to the sl0 node with A100 gpu
```
cd $YourhexplanePath
sbatch hex.sh
```
In hex.sh, it uses `config=XMPI.yaml`
4. Monitor you training
    1. The log file: logs/jobid.out
    2. The plots and models: results/
## Evaluation
With render_test=True, results at test viewpoint are automatically evaluated after reconstruction.
# Notes

## Fourier Shell Correlation (FSC)
- Wikipedia: [FSC](https://en.wikipedia.org/wiki/Fourier_shell_correlation)
- Paper [Marin van Heel et al.](https://www.sciencedirect.com/science/article/pii/S1047847705001292)