|
| 1 | +export ExperimentalData |
| 2 | +export initializeExperimentalData |
| 3 | + |
| 4 | +""" |
| 5 | + ExperimentalData{T} |
| 6 | +
|
| 7 | +`mutable struct` stores all parameters. |
| 8 | +
|
| 9 | +# Parameters |
| 10 | + |
| 11 | +## Physical Properties |
| 12 | +* `wavelength` of the laser |
| 13 | +
|
| 14 | +## General Properties |
| 15 | +
|
| 16 | +* `dtype`: datatype used for reconstructions. `Float32` is usually faster, especially on GPUs. |
| 17 | +* `propagator`: |
| 18 | +
|
| 19 | +## Probe |
| 20 | +* `dxp`: pixel size |
| 21 | +* `Np`: number of pixels |
| 22 | +* `xp`: 1D coordinates |
| 23 | +* `Lp`: field of view probe (field size) |
| 24 | +* `zp`: distance to next plane |
| 25 | +
|
| 26 | +## Object |
| 27 | +* `dxo`: pixel size |
| 28 | +* `No`: number of pixels |
| 29 | +* `xo`: 1D coordinates |
| 30 | +* `Lo`: field of view probe (field size) |
| 31 | +* `zo`: distance to next plane |
| 32 | +
|
| 33 | +## Detector |
| 34 | +* `dxd`: pixel size |
| 35 | +* `Nd`: number of pixels |
| 36 | +* `xd`: 1D coordinates |
| 37 | +* `Ld`: field of view probe (field size) |
| 38 | +
|
| 39 | +
|
| 40 | +""" |
| 41 | +@kwdef mutable struct ExperimentalData{T} |
| 42 | + wavelength::T |
| 43 | + # probe sampling |
| 44 | + dxp::T |
| 45 | + Np::Int |
| 46 | + xp::Vector{T} |
| 47 | + Lp::T |
| 48 | + zp::Union{T, Nothing} |
| 49 | + entrancePupilDiameter::Union{T, Nothing} |
| 50 | + # object sampling |
| 51 | + dxo::T |
| 52 | + No::Int |
| 53 | + xo::Vector{T} |
| 54 | + Lo::T |
| 55 | + zo::T |
| 56 | + # detector sampling |
| 57 | + dxd::T |
| 58 | + Nd::Int |
| 59 | + xd::Vector{T} |
| 60 | + Ld::T |
| 61 | + # the general data type which is enforced |
| 62 | + dtype::Type{T} |
| 63 | + ptychogram::Union{Nothing, Array{T, N}} where N |
| 64 | + encoder::Union{Nothing, Array{T, 2}} |
| 65 | +end |
| 66 | + |
| 67 | +""" |
| 68 | + ExperimentalData(fileName::String) |
| 69 | +
|
| 70 | +Fill the `ExperimentalData` struct with data from a `*.hdf5` file. |
| 71 | +""" |
| 72 | +function ExperimentalData(fileName::String, mode=CPM::CPM) |
| 73 | + # open h5 file |
| 74 | + fid = HDF5.h5open(fileName) |
| 75 | + |
| 76 | + # function to extract number from a vector wrap |
| 77 | + r_number(x) = read(fid, x)[begin] |
| 78 | + # read arrays, take full |
| 79 | + r_array(x) = read(fid, x) |
| 80 | + # call a simple constructor and fill with data |
| 81 | + expData = initializeExperimentalData( |
| 82 | + # those numbers are stored as arrays, take first element |
| 83 | + wavelength=r_number("wavelength"), |
| 84 | + No=r_number("No"), |
| 85 | + Nd=r_number("Nd"), |
| 86 | + dxd=r_number("dxd"), |
| 87 | + zo=r_number("zo"), |
| 88 | + entrancePupilDiameter=r_number("encoder"), |
| 89 | + # those are arrays, keep them |
| 90 | + ptychogram=r_array("ptychogram"), |
| 91 | + encoder=r_array("encoder"), |
| 92 | + ) |
| 93 | + |
| 94 | + return expData |
| 95 | +end |
| 96 | + |
| 97 | +""" |
| 98 | + initializeExperimentalData(<kwargs>) |
| 99 | +
|
| 100 | +Function to return parameter object `mutable struct` storing |
| 101 | +all meta information needed for reconstruction. |
| 102 | +Note that you can access all those parameters but many |
| 103 | +of them are connected hence to fill the struct we only need a few of |
| 104 | +them. |
| 105 | +""" |
| 106 | +function initializeExperimentalData(; |
| 107 | + wavelength=DEFAULT_WAVELENGTH, |
| 108 | + No=2^7, |
| 109 | + Nd=2^9, |
| 110 | + dxd=4.5e-6, |
| 111 | + zo=50e-3, |
| 112 | + dtype=Float32, |
| 113 | + zp=nothing, |
| 114 | + entrancePupilDiameter=nothing, |
| 115 | + ptychogram=nothing, |
| 116 | + encoder=nothing, |
| 117 | + ) |
| 118 | + |
| 119 | + # detector |
| 120 | + Ld = Nd * dxd |
| 121 | + xd = FourierTools.fftpos(Ld, Nd) |
| 122 | + # probe |
| 123 | + dxp = wavelength * zo / Ld |
| 124 | + Np = Nd |
| 125 | + Lp = dxp*Np |
| 126 | + xp = FourierTools.fftpos(Lp, Np) |
| 127 | + # object |
| 128 | + dxo = dxp |
| 129 | + Lo = dxo * No |
| 130 | + xo = FourierTools.fftpos(Lo, No) |
| 131 | + |
| 132 | + # anonymous function to convert to the dtype |
| 133 | + _dtype(x) = isnothing(x) ? x : dtype(x) |
| 134 | + |
| 135 | + |
| 136 | + # fill struct |
| 137 | + ExperimentalData( |
| 138 | + wavelength=_dtype(wavelength), |
| 139 | + # probe sampling |
| 140 | + dxp=_dtype(dxp), |
| 141 | + Np=Np, |
| 142 | + xp=_dtype.(xp), |
| 143 | + Lp=_dtype(Lp), |
| 144 | + zp=_dtype(zp), |
| 145 | + # object sampling, |
| 146 | + dxo=_dtype(dxo), |
| 147 | + No=No, |
| 148 | + xo=_dtype.(xo), |
| 149 | + Lo=_dtype(Lo), |
| 150 | + zo=_dtype(zo), |
| 151 | + # detector sampling, |
| 152 | + dxd=_dtype(dxd), |
| 153 | + Nd=Nd, |
| 154 | + entrancePupilDiameter=dtype(entrancePupilDiameter), |
| 155 | + xd=_dtype.(xd), |
| 156 | + Ld=_dtype(Ld), |
| 157 | + # the general data type which is enforced, |
| 158 | + dtype=dtype, |
| 159 | + ptychogram=dtype.(ptychogram)), |
| 160 | + encoder=dtype.(encoder) |
| 161 | +end |
0 commit comments