Update the docs a bit

This commit is contained in:
Abe Levitan
2021-07-06 14:55:29 -04:00
parent 53cd966c33
commit 3e72243a50
7 changed files with 24 additions and 39 deletions
+3 -3
View File
@@ -20,7 +20,7 @@ sys.path.insert(0, os.path.abspath('../..'))
# -- Project information -----------------------------------------------------
project = 'CDTools'
copyright = '2019, Abraham Levitan'
copyright = '2019-2021, Abraham Levitan'
author = 'Abraham Levitan'
# The short X.Y version
@@ -166,8 +166,8 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'ADCD', 'ADCD Documentation',
author, 'ADCD', 'One line description of project.',
(master_doc, 'CDTools', 'CDTools Documentation',
author, 'CDTools', 'One line description of project.',
'Miscellaneous'),
]
+4 -4
View File
@@ -8,7 +8,7 @@ The source code for CDTools is hosted on it's `MIT github page`_. Access to the
.. _`MIT github page`: https://github.mit.edu/Scattering/CDTools
It is recommended that you clone the repository, rather than just downloading the contents, as it remains under heavy development. Cloning the repository will allow you to get access to new updates.
It is recommended that you clone the repository, rather than just downloading the contents, as it remains under rapid development. Cloning the repository will allow you to get access to new updates.
Step 2: Install Dependencies
----------------------------
@@ -19,7 +19,7 @@ The dependencies for CDTools can be installed, if you are managing your environm
$ conda install --file conda_requirements.txt
There are two optional dependencies which are not installed via this procedure - the dependency sphinx-argparse for building the docs, and the pathlib2 module that provides python 2 compatibility. These can either be installed manually via conda-forge, or otherwise they will be installed automatically by pip during the final installation step if needed.
One optional dependencies is not installed via this procedure - the dependency sphinx-argparse for building the docs. Sphinx-argparse can either be installed manually via conda-forge, otherwise it will be installed automatically by pip during the final installation step if needed.
If you manage your environment with pip, all required packges should be installed automatically. The only thing to be aware of is that pytorch must be compiled with MKL support, and CUDA support if you would like to use the GPU. For this reason, using anaconda python is strongly recommended.
@@ -40,9 +40,9 @@ And has optional dependencies on
* `sphinx <https://www.sphinx-doc.org/>`_
* `sphinx-argparse <https://sphinx-argparse.readthedocs.io>`_
* `sphinx_rtd_theme <https://sphinx-rtd-theme.readthedocs.io/en/stable/>`_
* `pathlib2 <https://pypi.org/project/pathlib2/>`_
All of these can be installed via pip or conda. Finally, CDTools is written to be python 2.7+ compatible, but is only actively tested on python 3.
All of these can be installed via pip or conda. Finally, CDTools is NOT python 2 compatible.
**It is required that pytorch is built with MKL**, as that enables FFTs. Additionally, installing pytorch **with CUDA support** is recommended, if you intend to run any serious reconstructions with the package.
+2 -2
View File
@@ -22,8 +22,8 @@ CDTools is a python library for ptychography and CDI reconstructions, using an A
model = CDTools.models.SimplePtycho.from_dataset(dataset)
# Run a reconstruction
for i, loss in enumerate(model.Adam_optimize(20, dataset)):
print(i, loss)
for loss in model.Adam_optimize(20, dataset):
print(model.report())
# And look at the results!
model.inspect(dataset)
-5
View File
@@ -1,5 +0,0 @@
Cmath
=====
.. automodule:: CDTools.tools.cmath
:members:
-2
View File
@@ -4,7 +4,6 @@ Tools
.. toctree::
:maxdepth: 1
cmath
image_processing
data
initializers
@@ -14,4 +13,3 @@ Tools
losses
plotting
analysis
projectors
-5
View File
@@ -1,5 +0,0 @@
Projectors
==========
.. automodule:: CDTools.tools.projectors
:members:
+15 -18
View File
@@ -13,11 +13,9 @@ Our first step will be creating the file and filling out the boilerplate: All th
.. code-block:: python
from __future__ import division, print_function, absolute_import
import CDTools
from matplotlib import pyplot as plt
import pickle
from scipy import io
You can always import more libraries, like numpy, or pytorch, or pandas, or what have you, as needed. Next, we load the dataset and give it a look-over
@@ -46,9 +44,9 @@ We then try a basic Adam reconstruction with this model, with no changes to the
.. code-block:: python
for i, loss in enumerate(model.Adam_optimize(50, dataset)):
for loss in model.Adam_optimize(50, dataset):
model.inspect(dataset)
print(i,loss)
print(model.report())
model.compare(dataset)
plt.show()
@@ -58,7 +56,7 @@ It is worth noting here exactly how this code is working. The reconstruction met
In CDTools, every reconstruction method will return a generator. Whenever the generator is asked for the next item, it runs a single epoch of the reconstructionalgorithm, and then returns the average loss over that epoch as that next item. This allows the execution of the reconstruction algorithm to pause once every epoch, allowing some time for the user to run a small snippet of code to inspect how the reconstruction is coming along.
From the end user perspective, all this means is: follow the format above, or more generally put the :code:`model.Adam_optimize(n, dataset)` call anywhere that you would feel comfortable putting a call to :code:`range(n)` - list comprehensions, for loops, etc.
From the end user perspective, all this means is: follow the format above, or more generally put the :code:`model.Adam_optimize(n, dataset)` call anywhere that you would feel comfortable putting a call to :code:`range(n)` - list comprehensions, for loops, etc. In this case, we have called a function to plot out the current state of the reconstruction, and a function to print out the current loss and iteration time.
Once we run this, we can take a look at the result. What we see is pretty good, but we can see that there are some issues with the reconstruction near the edge, and the probe itself seems to be larger than the "stage" on which we're reconstructing it. So, we can make two tweaks to this code in response. First, we increase the oversampling ratio, which doubles the size of the stage (this often can cause other issues as well, but generally works well in situations like this where the probe is honestly too large.
@@ -94,8 +92,8 @@ Now we expect to get a nice reconstruction, so we can save the data. You can sav
.. code-block:: python
with open('example_reconstructions/lab_ptycho.pickle', 'wb') as f:
pickle.dump(model.save_results(dataset),f)
io.savemat('example_reconstructions/lab_ptycho.pickle',
model.save_results(dataset))
This is usually placed before the call to :code:`plt.show()`, to make sure that if the user manually exits the program once all the plot windows are opened, the data will still have been saved.
@@ -127,7 +125,7 @@ We can start with the basic skeleton for this file. In addition to our standard
.. code-block:: python
from __future__ import division, print_function, absolute_import
import numpy as np
import torch as t
from matplotlib import pyplot as plt
@@ -288,7 +286,6 @@ Once again, we start with the basic skeleton
.. code-block:: python
from __future__ import division, print_function, absolute_import
import numpy as np
import torch as t
from CDTools.models import CDIModel
@@ -323,10 +320,10 @@ It's important to note that there's not requirement for what the arguments to th
self.probe_basis = t.Tensor(probe_basis)
# We rescale the probe so it learns at the same rate as the object
self.probe_norm = t.max(tools.cmath.cabs(probe_guess.to(t.float32)))
self.probe = t.nn.Parameter(probe_guess.to(t.float32)
self.probe_norm = t.max(t.abs(probe_guess).to(t.float32))
self.probe = t.nn.Parameter(probe_guess.to(t.complex64)
/ self.probe_norm)
self.obj = t.nn.Parameter(obj_guess.to(t.float32))
self.obj = t.nn.Parameter(obj_guess.to(t.complex64))
Here, we chose to define the model based on a basis matrix describing the probe array, an initial guess at the probe, and an initial object. In addition, an optional offset for the translations is included.
@@ -375,7 +372,7 @@ To initialize the object from a dataset, we need to start by extracting the rele
probe_shape,
det_slice)
obj = t.ones(obj_size+(2,))
obj = t.ones(obj_size, dtype=t.complex64)
return cls(probe_basis, probe, obj, min_translation=min_translation)
@@ -472,9 +469,9 @@ At the moment, there is no consistent way to save out the results across the boa
.. code-block:: python
def save_results(self):
probe = tools.cmath.torch_to_complex(self.probe.detach().cpu())
probe = self.probe.detach().cpu().numpy()
probe = probe * self.probe_norm.detach().cpu().numpy()
obj = tools.cmath.torch_to_complex(self.obj.detach().cpu())
obj = self.obj.detach().cpu().numpy()
return {'probe':probe,'obj':obj}
@@ -499,9 +496,9 @@ We can test this model with a simple script, shown below. By filling in the back
model.to(device='cuda')
dataset.get_as(device='cuda')
for i, loss in enumerate(model.Adam_optimize(100, dataset)):
for loss in model.Adam_optimize(100, dataset):
model.inspect(dataset)
print(i,loss)
print(model.report())
model.compare(dataset)
plt.show()