API references

adorym.array_ops module

class adorym.array_ops.Gradient(obj, forward_model=None)

Bases: adorym.array_ops.ObjectFunction

create_file_object()
initialize_gradient_file(dtype='float32')
class adorym.array_ops.LargeArray(full_size, distribution_mode=None, monochannel=False, output_folder=None, device=None)

Bases: object

create_file_object(fname, use_checkpoint=False)
read_chunks_from_distributed_object(probe_pos, this_ind_batch_allranks, minibatch_size, probe_size, device=None, unknown_type='delta_beta', apply_to_arr_rot=False, dtype='float32', n_split='auto', create_variable=True)
read_chunks_from_file(this_pos_batch, probe_size, dset_2=None, device=None, unknown_type='delta_beta')
reverse_rotate_data_in_file(coords, interpolation='bilinear', precalculate_rotation_coords=True)
rotate_array(coords, interpolation='bilinear', precalculate_rotation_coords=True, apply_to_arr_rot=False, overwrite_arr=False, override_backend=None, dtype=None, override_device=None)
rotate_data_in_file(coords, interpolation='bilinear', dset_2=None, precalculate_rotation_coords=True)
sync_chunks_to_distributed_object(obj, probe_pos, this_ind_batch_allranks, minibatch_size, probe_size, dtype='float32', n_split='auto')
write_chunks_to_file(this_pos_batch, arr_channel_0, arr_channel_1, probe_size, write_difference=True, dset_2=None, dtype='float32')
class adorym.array_ops.Mask(full_size, finite_support_mask_path, distribution_mode=None, output_folder=None, ds_level=1)

Bases: adorym.array_ops.LargeArray

create_file_object(use_checkpoint=False)
initialize_array_with_values(mask, device=None, dtype=None)
initialize_distributed_array(mask, dtype='float32')
initialize_file_object(dtype='float32')
update_mask_array(obj, threshold=1e-09)
update_mask_file(obj, threshold=1e-09)
class adorym.array_ops.ObjectFunction(full_size, distribution_mode=None, output_folder=None, ds_level=1, object_type='normal', device=None)

Bases: adorym.array_ops.LargeArray

apply_finite_support_mask_to_array(mask, unknown_type='delta_beta', device=None)
apply_finite_support_mask_to_file(mask, unknown_type='delta_beta', device=None)
create_file_object(use_checkpoint=False)
create_temporary_file_object()

This file is used to save rotated object.

initialize_array(save_stdout=None, timestr=None, not_first_level=False, initial_guess=None, device=None, random_guess_means_sigmas=(8.7e-07, 5.1e-08, 1e-07, 1e-08), unknown_type='delta_beta', non_negativity=False)
initialize_array_with_values(obj_delta, obj_beta, device=None)
initialize_distributed_array(save_stdout=None, timestr=None, not_first_level=False, initial_guess=None, random_guess_means_sigmas=(8.7e-07, 5.1e-08, 1e-07, 1e-08), unknown_type='delta_beta', dtype='float32', non_negativity=False)
initialize_distributed_array_with_values(obj_delta, obj_beta, dtype='float32')
initialize_distributed_array_with_zeros(dtype='float32')
initialize_file_object(save_stdout=None, timestr=None, not_first_level=False, initial_guess=None, random_guess_means_sigmas=(8.7e-07, 5.1e-08, 1e-07, 1e-08), unknown_type='delta_beta', dtype='float32', non_negativity=False)
update_object(obj)
update_using_external_algorithm(algorithm, kwargs, device=None)

adorym.constants module

Constants in cgs units.

Attributes

AVOGADRO_NUMBER : float
Avagadro constant [1/mol]
BOLTZMANN_CONSTANT : float
Boltzmann constant [erg/k]
CLASSICAL_ELECTRON_RADIUS : float
Classical electron radius [cm]
ELECTRONIC_CHARGE : float
Electronic charge [esu]
ELECTRON_VOLT : float
Electron volt (keV) [erg]
ELECTRON_MASS : float
Electron mass [g]
FINE_STRUCTURE_CONSTANT : float
Fine structure constant
PLANCK_CONSTANT : float
Reduced planck’s constant [keV*s]
PROTON_MASS : float
Proton mass [g]
SPEED_OF_LIGHT : float
Speed of light in vacuum [cm/s]
THOMPSON_CROSS_SECTION : float
Thomson cross section [cm^2]
PI : float
Ratio of a circle’s circumference to its diameter
adorym.constants.wavelength(energy)

Return wavelength [cm] of light given energy [keV].

adorym.conventional module

adorym.conventional.alt_reconstruction_epie(obj_real, obj_imag, probe_real, probe_imag, probe_pos, probe_pos_correction, prj, device_obj=None, minibatch_size=1, alpha=1.0, n_epochs=100, **kwargs)

Reconstruct a 2D object and probe function using ePIE.

adorym.conventional.multidistance_ctf_wrapped(this_prj_batch, free_prop_cm, energy_ev, psize_cm, kappa=50, safe_zone_width=0, prj_affine_ls=None, device=None)

adorym.differentiator module

class adorym.differentiator.Differentiator

Bases: object

create_loss_node(loss, opt_args_ls=None)
Parameters:
  • loss – The loss object (loss node in PyTorch, or loss function handle in Autograd).
  • opt_args_ls – List of Int. A list of indices of arguments in forward_model.get_loss_function/predict to which the gradient should be calculated.
get_gradients(**kwargs)
Parameters:kwargs – Unwrapped dictionary or key word arguments that contain all optimizable variables.
get_l_h_hessian_and_h_x_jacobian_mvps(forward_model, ind_opt_arg, **kwargs)

Create functions to compute the matrix-vector product of loss-predict-Hessian and predict-object-Jacobian with any arbitrary vector in its argument. The predict function of forward_model must return detected magnitudes. :param forward_model: adorym.ForwardModel object. :param ind_opt_arg: List of Int. A list of indices of arguments in forward_model.get_loss_function to

which the gradient should be calculated.
Parameters:kwargs – Unwrapped dictionary or key word arguments that contain ALL arguments of forward_model.get_loss_function/predict.

adorym.forward_model module

class adorym.forward_model.ForwardModel(loss_function_type='lsq', distribution_mode=None, device=None, common_vars_dict=None, raw_data_type='magnitude', simulation_mode=False)

Bases: object

The parent forward model class.

Parameters:
  • loss_function_type – String. Can be 'lsq' or 'poisson'. Type of loss function.
  • distribution_modeNone, 'distributed_object', or 'shared_file'. Mode of parallelization.
  • deviceNone or device object. Use None for computations on CPU only.
  • common_vars_dict – Dict. A dictionary of variables that are static (i.e., won’t be optimized and won’t change with different minibatches). When the ForwardModel class is declared in reconstruct_ptycho, it can simply be the local namespace of the main module, i.e., locals().
  • raw_data_type – String. Can be 'magnitude' or 'intensity'. Type of raw data in HDF5. For line-projection tomography reconstruction where raw data have already been minus-logged, always use 'magnitude'.
add_regularizers(reg_list)
get_argument_index(arg)
get_data(this_i_theta, this_ind_batch, theta_downsample=None, ds_level=1)
get_loss_function()

Overwrite this function for each sub-class, but make sure it contains the explicitly listed arguments. Do not keep differentiable arguments as **kwargs since it will not be recognized by Autograd.

get_mismatch_loss(this_pred_batch, this_prj_batch)
get_regularization_value(obj, device=None)
loss(this_pred_batch, this_prj_batch, obj)

The last-layer loss function that computes (regularized) loss from predicted magnitude. This function is combined with predict to give the full loss function, as done in get_loss_function. Argument this_pred_batch is assumed to be detected magnitude (square root of intensity). If this is not the case for your specific ForwardModel class, override this method.

predict(*args, **kwargs)

Override and expand this method for each specific class. Generally the method should return the detected magnitude. If this is not the case, you should also override method loss (the last-layer loss) or get_loss_function (the full loss function constructor).

update_loss_args(kwargs)
class adorym.forward_model.MultiDistModel(loss_function_type='lsq', distribution_mode=None, device=None, common_vars_dict=None, raw_data_type='magnitude', simulation_mode=False)

Bases: adorym.forward_model.ForwardModel

get_loss_function()

Overwrite this function for each sub-class, but make sure it contains the explicitly listed arguments. Do not keep differentiable arguments as **kwargs since it will not be recognized by Autograd.

predict(obj, probe_real, probe_imag, probe_defocus_mm, probe_pos_offset, this_i_theta, this_pos_batch, prj, probe_pos_correction, this_ind_batch, free_prop_cm, safe_zone_width, prj_affine_ls, ctf_lg_kappa, prj_pos_offset)

Calculated predicted measurment. The signature of this function exactly matches the function returned by the get_loss_function method.

Parameters:
  • obj – Array with shape [obj_size_y, obj_size_x, obj_size_z, 2]. Object function.
  • probe_real – Array with shape [n_probe_modes, len_probe_y, len_probe_x]. Preal part of the probe.
  • probe_imag – Array with shape [n_probe_modes, len_probe_y, len_probe_x]. Imaginary part of the probe.
  • probe_defocus_mm – Probe defocus in mm.
  • probe_pos_offset – Array with shape [n_theta, 2]. Probe position offset for each angle, in pixels.
  • this_i_theta – Int. Current angle index.
  • this_pos_batch – Array with shape [minibatch_size, 2]. Current batch of probe positions.
  • prj – HDF5 measurement dataset handler.
  • probe_pos_correction – Array with shape [n_probes, 2]. Additive correction values of probe positions.
  • this_ind_batch – List of Int. Current batch of tile indices.
  • free_prop_cm – Array of Float. Propagation distances for all holograms.
  • safe_zone_width – Int. Width of safe zone to be padded to probes before propagation to prevent fringe wrapping.
  • prj_affine_ls – Array with shape [n_dists, 2, 3]. Affine transform matrices for each hologram.
  • ctf_lg_kappa – Log10 of kappa, the relation coefficient between delta and beta. If homogeneous assumption is not used, set as None.
  • prj_pos_offset – Array with shape [n_theta, 2]. Projection position offset for each angle, in pixels. Note that this is different from probe_pos_offset - shifting is applied after passing through the object.
Returns:

Array with shape [minibatch_size, len_probe_y, len_probe_x]. Magnitude of detected wavefields.

class adorym.forward_model.PtychographyModel(loss_function_type='lsq', distribution_mode=None, device=None, common_vars_dict=None, raw_data_type='magnitude', simulation_mode=False)

Bases: adorym.forward_model.ForwardModel

get_loss_function()

Overwrite this function for each sub-class, but make sure it contains the explicitly listed arguments. Do not keep differentiable arguments as **kwargs since it will not be recognized by Autograd.

predict(obj, probe_real, probe_imag, probe_defocus_mm, probe_pos_offset, this_i_theta, this_pos_batch, prj, probe_pos_correction, this_ind_batch, tilt_ls, prj_pos_offset)

Calculated predicted measurment. The signature of this function exactly matches the function returned by the get_loss_function method.

Parameters:
  • obj – Array with shape [obj_size_y, obj_size_x, obj_size_z, 2]. Object function.
  • probe_real – Array with shape [n_probe_modes, len_probe_y, len_probe_x]. Preal part of the probe.
  • probe_imag – Array with shape [n_probe_modes, len_probe_y, len_probe_x]. Imaginary part of the probe.
  • probe_defocus_mm – Probe defocus in mm.
  • probe_pos_offset – Array with shape [n_theta, 2]. Probe position offset for each angle, in pixels.
  • this_i_theta – Int. Current angle index.
  • this_pos_batch – Array with shape [minibatch_size, 2]. Current batch of probe positions.
  • prj – HDF5 measurement dataset handler.
  • probe_pos_correction – Array with shape [n_probes, 2]. Additive correction values of probe positions.
  • this_ind_batch – List of Int. Current batch of tile indices.
  • tilt_ls – Array with shape [3, n_theta]. 3-axis tilt to be applied before propagation.
  • prj_pos_offset – Array with shape [n_theta, 2]. Projection position offset for each angle, in pixels. Note that this is different from probe_pos_offset - shifting is applied after passing through the object.
Returns:

Array with shape [minibatch_size, len_probe_y, len_probe_x]. Magnitude of detected wavefields.

class adorym.forward_model.SingleBatchFullfieldModel(loss_function_type='lsq', distribution_mode=None, device=None, common_vars_dict=None, raw_data_type='magnitude', simulation_mode=False)

Bases: adorym.forward_model.PtychographyModel

predict(obj, probe_real, probe_imag, probe_defocus_mm, probe_pos_offset, this_i_theta, this_pos_batch, prj, probe_pos_correction, this_ind_batch, tilt_ls, prj_pos_offset)

Calculated predicted measurment. The signature of this function exactly matches the function returned by the get_loss_function method.

Parameters:
  • obj – Array with shape [obj_size_y, obj_size_x, obj_size_z, 2]. Object function.
  • probe_real – Array with shape [n_probe_modes, len_probe_y, len_probe_x]. Preal part of the probe.
  • probe_imag – Array with shape [n_probe_modes, len_probe_y, len_probe_x]. Imaginary part of the probe.
  • probe_defocus_mm – Probe defocus in mm.
  • probe_pos_offset – Array with shape [n_theta, 2]. Probe position offset for each angle, in pixels.
  • this_i_theta – Int. Current angle index.
  • this_pos_batch – Array with shape [minibatch_size, 2]. Current batch of probe positions.
  • prj – HDF5 measurement dataset handler.
  • probe_pos_correction – Array with shape [n_probes, 2]. Additive correction values of probe positions.
  • this_ind_batch – List of Int. Current batch of tile indices.
  • tilt_ls – Array with shape [3, n_theta]. 3-axis tilt to be applied before propagation.
Returns:

Array with shape [minibatch_size, len_probe_y, len_probe_x]. Magnitude of detected wavefields.

class adorym.forward_model.SingleBatchPtychographyModel(loss_function_type='lsq', distribution_mode=None, device=None, common_vars_dict=None, raw_data_type='magnitude', simulation_mode=False)

Bases: adorym.forward_model.PtychographyModel

predict(obj, probe_real, probe_imag, probe_defocus_mm, probe_pos_offset, this_i_theta, this_pos_batch, prj, probe_pos_correction, this_ind_batch, tilt_ls, prj_pos_offset)

Calculated predicted measurment. The signature of this function exactly matches the function returned by the get_loss_function method.

Parameters:
  • obj – Array with shape [obj_size_y, obj_size_x, obj_size_z, 2]. Object function.
  • probe_real – Array with shape [n_probe_modes, len_probe_y, len_probe_x]. Preal part of the probe.
  • probe_imag – Array with shape [n_probe_modes, len_probe_y, len_probe_x]. Imaginary part of the probe.
  • probe_defocus_mm – Probe defocus in mm.
  • probe_pos_offset – Array with shape [n_theta, 2]. Probe position offset for each angle, in pixels.
  • this_i_theta – Int. Current angle index.
  • this_pos_batch – Array with shape [minibatch_size, 2]. Current batch of probe positions.
  • prj – HDF5 measurement dataset handler.
  • probe_pos_correction – Array with shape [n_probes, 2]. Additive correction values of probe positions.
  • this_ind_batch – List of Int. Current batch of tile indices.
  • tilt_ls – Array with shape [3, n_theta]. 3-axis tilt to be applied before propagation.
Returns:

Array with shape [minibatch_size, len_probe_y, len_probe_x]. Magnitude of detected wavefields.

class adorym.forward_model.SparseMultisliceModel(loss_function_type='lsq', distribution_mode=None, device=None, common_vars_dict=None, raw_data_type='magnitude', simulation_mode=False)

Bases: adorym.forward_model.ForwardModel

get_loss_function()

Overwrite this function for each sub-class, but make sure it contains the explicitly listed arguments. Do not keep differentiable arguments as **kwargs since it will not be recognized by Autograd.

predict(obj, probe_real, probe_imag, probe_defocus_mm, probe_pos_offset, this_i_theta, this_pos_batch, prj, probe_pos_correction, this_ind_batch, slice_pos_cm_ls, prj_pos_offset)

Calculated predicted measurment. The signature of this function exactly matches the function returned by the get_loss_function method.

Parameters:
  • obj – Array with shape [obj_size_y, obj_size_x, obj_size_z, 2]. Object function.
  • probe_real – Array with shape [n_probe_modes, len_probe_y, len_probe_x]. Preal part of the probe.
  • probe_imag – Array with shape [n_probe_modes, len_probe_y, len_probe_x]. Imaginary part of the probe.
  • probe_defocus_mm – Probe defocus in mm.
  • probe_pos_offset – Array with shape [n_theta, 2]. Probe position offset for each angle, in pixels.
  • this_i_theta – Int. Current angle index.
  • this_pos_batch – Array with shape [minibatch_size, 2]. Current batch of probe positions.
  • prj – HDF5 measurement dataset handler.
  • probe_pos_correction – Array with shape [n_probes, 2]. Additive correction values of probe positions.
  • this_ind_batch – List of Int. Current batch of tile indices.
  • slice_pos_cm_ls – Array of Float. Positions of object slices in cm.
  • prj_pos_offset – Array with shape [n_theta, 2]. Projection position offset for each angle, in pixels. Note that this is different from probe_pos_offset - shifting is applied after passing through the object.
Returns:

Array with shape [minibatch_size, len_probe_y, len_probe_x]. Magnitude of detected wavefields.

adorym.regularizers module

class adorym.regularizers.CorrRegularizer(gamma, unknown_type='delta_beta')

Bases: adorym.regularizers.Regularizer

Pearson correlation regularizer along z axis of object.

Parameters:gamma – Weight of correlation term.
get_value(obj, distribution_mode=None, device=None, **kwargs)
class adorym.regularizers.GradCorrRegularizer(gamma, unknown_type='delta_beta')

Bases: adorym.regularizers.Regularizer

Pearson correlation regularizer of the gradients maps of all slices along z axis of object.

Parameters:gamma – Weight of correlation term.
get_value(obj, distribution_mode=None, device=None, **kwargs)
class adorym.regularizers.L1Regularizer(alpha_d, alpha_b, unknown_type='delta_beta')

Bases: adorym.regularizers.Regularizer

L1-norm regularizer.

Parameters:
  • alpha_d – Weight of l1-norm of delta or real part.
  • alpha_b – Weight of l1-norm of beta or imaginary part.
get_value(obj, device=None, **kwargs)
class adorym.regularizers.Regularizer(unknown_type='delta_beta')

Bases: object

Parent regularizer class.

Parameters:
  • unknown_type – String. Can be 'delta_beta' or 'real_imag'.
  • device – Device object or None.
get_value(obj, device=None, **kwargs)
class adorym.regularizers.ReweightedL1Regularizer(alpha_d, alpha_b, unknown_type='delta_beta')

Bases: adorym.regularizers.Regularizer

Reweighted l1-norm regularizer.

Parameters:
  • alpha_d – Weight of l1-norm of delta or real part.
  • alpha_b – Weight of l1-norm of beta or imaginary part.
get_value(obj, device=None, **kwargs)
update_l1_weight(weight_l1)
class adorym.regularizers.TVRegularizer(gamma, unknown_type='delta_beta')

Bases: adorym.regularizers.Regularizer

Total variation regularizer.

Parameters:gamma – Weight of TV term.
get_value(obj, distribution_mode=None, device=None, **kwargs)

adorym.global_settings module

adorym.linesearch module

class adorym.linesearch.BackTrackingLineSearch(contraction_factor: float = 0.5, optimism: float = 3.0, suff_decr: float = 0.0001, initial_stepsize: float = 10.0, stepsize_threshold_low: float = 1e-10, dtype: numpy.dtype = <class 'numpy.float32'>, maxiter: int = None, name='backtracking_linesearch', normalize_alpha=True)

Bases: object

Adapted from the backtracking line search in the manopt package

search(objective_and_update: Callable, x0, descent_dir, gradient, f0=None)
class adorym.linesearch.AdaptiveLineSearch(contraction_factor: float = 0.5, optimism: float = 2.0, suff_decr: float = 0.0001, initial_stepsize: float = 10.0, stepsize_threshold_low: float = 1e-10, dtype: numpy.dtype = <class 'numpy.float32'>, maxiter: int = None, name='backtracking_linesearch', normalize_alpha=True)

Bases: object

Adapted from the backtracking line search in the manopt package

search(objective_and_update: Callable, x0, descent_dir, gradient, f0=None)

adorym.misc module

adorym.misc.check_config_indept_mpi()
adorym.misc.create_directory_multirank(path)

Due to the presence of comm.Barrier(), always use this function collectively!

adorym.misc.create_summary(save_path, locals_dict, var_list=None, preset=None, verbose=True)
adorym.misc.parse_source_folder(src_dir, prefix)
adorym.misc.print_flush(a, designate_rank=None, this_rank=None, save_stdout=False, same_line=None, output_folder='', timestamp='', **kwargs)
adorym.misc.restore_checkpoint(output_folder, distribution_mode=None, optimizer=None, dtype='float32')
adorym.misc.save_checkpoint(i_epoch, i_batch, output_folder, distribution_mode=None, obj_array=None, optimizer=None)

adorym.optimizers module

class adorym.optimizers.AdamOptimizer(name, output_folder='.', distribution_mode=None, options_dict=None, forward_model=None)

Bases: adorym.optimizers.Optimizer

apply_gradient(x, gradient, i_batch, step_size=0.001, b1=0.9, b2=0.999, eps=1e-07, distribution_mode=False, m=None, v=None, return_moments=False, update_batch_count=True, use_numpy=False, params_slicer=None, **kwargs)

Use calculated gradient to update the variable being optimized. :param x: Array or Tensor of the optimized variable. :param gradient: Array or adorym.Gradient. If optimizer is CG, the ForwardModel instance (which is needed for

providing loss function for line search) can be supplied through the Gradient instance. Otherwise, it must be specified when the optimizer is instantiated.
Parameters:i_batch – Int. User-specifiable step number. When minibatching localized data using optimizers like Adam, i_batch may be preferably up-counted only when all voxels of the object are updated with non-zero gradient.
apply_gradient_to_file(obj, gradient, i_batch=None, step_size=0.001, b1=0.9, b2=0.999, eps=1e-07, **kwargs)
class adorym.optimizers.CGOptimizer(name, output_folder='.', distribution_mode=None, options_dict=None, forward_model=None)

Bases: adorym.optimizers.Optimizer

apply_gradient(x, gradient, i_batch=None, step_size=1.0, linesearch_type='adaptive', max_backtracking_iter=None, normalize_alpha=True, params_slicer=None)

Use calculated gradient to update the variable being optimized. :param x: Array or Tensor of the optimized variable. :param gradient: Array or adorym.Gradient. If optimizer is CG, the ForwardModel instance (which is needed for

providing loss function for line search) can be supplied through the Gradient instance. Otherwise, it must be specified when the optimizer is instantiated.
Parameters:i_batch – Int. User-specifiable step number. When minibatching localized data using optimizers like Adam, i_batch may be preferably up-counted only when all voxels of the object are updated with non-zero gradient.
linesearch_map = {'adaptive': <class 'adorym.linesearch.AdaptiveLineSearch'>, 'backtracking': <class 'adorym.linesearch.BackTrackingLineSearch'>}
class adorym.optimizers.CurveballOptimizer(name, output_folder='.', distribution_mode=None, options_dict=None, forward_model=None)

Bases: adorym.optimizers.Optimizer

Gauss-Newton second-order optimizer implemented using the Curveball algorithm: Henriques, J. F., Ehrhardt, S., Albanie, S. & Vedaldi, A. Small steps and giant leaps: Minimal Newton solvers for Deep Learning. arXiv (2018). This code is adapted from https://github.com/saugatkandel/sopt. When working with DO, dz is synchronized in place of gradient.

apply_gradient(x, gradient, i_batch, alpha=1, use_numpy=False, params_slicer=None)

Use calculated gradient to update the variable being optimized. :param x: Array or Tensor of the optimized variable. :param gradient: Array or adorym.Gradient. If optimizer is CG, the ForwardModel instance (which is needed for

providing loss function for line search) can be supplied through the Gradient instance. Otherwise, it must be specified when the optimizer is instantiated.
Parameters:i_batch – Int. User-specifiable step number. When minibatching localized data using optimizers like Adam, i_batch may be preferably up-counted only when all voxels of the object are updated with non-zero gradient.
calculate_beta_rho(differentiator, use_numpy=False)

Parameters are calculated using chunks when working with DO. In DP mode, self.dz_chunk and self.z_chunk should match object size.

calculate_dz(differentiator, use_numpy=False)

In DO, dz will be synchronized as Gradient class after this step.

calculate_update_vector(dz, ss)

In DO, this is done for slabs.

update_lambda(forward_model, forward_args)
class adorym.optimizers.GDOptimizer(name, output_folder='.', distribution_mode=None, options_dict=None, forward_model=None)

Bases: adorym.optimizers.Optimizer

apply_gradient(x, gradient, i_batch, step_size=0.001, dynamic_rate=True, first_downrate_iteration=92, use_numpy=False, verbose=False, **kwargs)

Use calculated gradient to update the variable being optimized. :param x: Array or Tensor of the optimized variable. :param gradient: Array or adorym.Gradient. If optimizer is CG, the ForwardModel instance (which is needed for

providing loss function for line search) can be supplied through the Gradient instance. Otherwise, it must be specified when the optimizer is instantiated.
Parameters:i_batch – Int. User-specifiable step number. When minibatching localized data using optimizers like Adam, i_batch may be preferably up-counted only when all voxels of the object are updated with non-zero gradient.
apply_gradient_to_file(obj, gradient, i_batch=None, step_size=0.001, dynamic_rate=True, first_downrate_iteration=92, **kwargs)
class adorym.optimizers.MomentumOptimizer(name, output_folder='.', distribution_mode=None, options_dict=None, forward_model=None)

Bases: adorym.optimizers.Optimizer

apply_gradient(x, gradient, i_batch, step_size=0.001, gamma=0.9, use_numpy=False, params_slicer=None, **kwargs)

Use calculated gradient to update the variable being optimized. :param x: Array or Tensor of the optimized variable. :param gradient: Array or adorym.Gradient. If optimizer is CG, the ForwardModel instance (which is needed for

providing loss function for line search) can be supplied through the Gradient instance. Otherwise, it must be specified when the optimizer is instantiated.
Parameters:i_batch – Int. User-specifiable step number. When minibatching localized data using optimizers like Adam, i_batch may be preferably up-counted only when all voxels of the object are updated with non-zero gradient.
apply_gradient_to_file(obj, gradient, i_batch=None, step_size=0.001, gamma=0.9, **kwargs)
class adorym.optimizers.Optimizer(name, output_folder='.', params_list=(), distribution_mode=None, options_dict=None, forward_model=None)

Bases: object

Parent class of optimizers.

Parameters:
  • name – Name of the optimizer. It is currently used to (1) match the optimizer to special handling rules defined in optimizers.update_parameters, optimizers.update_parameter_gradients, optimizers.create_parameter_output_folders, and optimizers.output_intermediate_parameters, and (2) to locate the optimized variable in predict function’s argument list in ScipyOptmizer. If the optimizer is created for preset variables (e.g., probe_pos_correction), the name can be any arbitrary string since Adorym will forcefully set the names to the default names for these variables. If the optimizer if created for user-defined optimizable parameters, make sure the name is the same as the name of the variable being optimized, and matches the rules defined in the aforementioned functions, if any.
  • output_folder – String. Path to the output folder. This should be the combination of save_path and output_folder passed to reconstruct_ptytchography. This path will be the location to save/read checkpoints of optimizer parameters.
  • distribution_mode – None or String. Should match the value passed to reconstruct_ptychography.
  • options_dict – Dict. A dictionary of optimizer hyperparameters. The options differ depending on the type of optimizers. See table below for a thorough reference.
  • params_list – List of str; a list of optimizer parameters provided in strings. (Only used for parent class. Child Optimizer classes do NOT take this argument.)
convert_gradient(gradient)
create_container(whole_object_size, use_checkpoint, device_obj, use_numpy=False, dtype='float32')
Parameters:whole_object_size – List of int; 4-D vector for object function (including 2 channels), or a 3-D vector for probe, or a 1-D scalar for other variables. Channel must be the last domension. Parameter arrays will be created following exactly whole_object_size.
create_distributed_param_arrays(whole_object_size, use_numpy=False, dtype='float32')
create_file_objects(whole_object_size, use_checkpoint=False)
create_param_arrays(whole_object_size, device=None, use_numpy=False)
get_array_slicer(slicer)
get_params_from_file(this_pos_batch=None, probe_size=None)
read_chunks_from_distributed_object(probe_pos, this_ind_batch_allranks, minibatch_size, probe_size, device=None, unknown_type='delta_beta', apply_to_arr_rot=False, dtype='float32', n_split='auto')
restore_distributed_param_arrays_from_checkpoint(device=None, use_numpy=False, dtype='float32')
restore_param_arrays_from_checkpoint(device=None, use_numpy=False)
rotate_arrays(coords, interpolation='bilinear', overwrite_arr=False)
rotate_files(coords, interpolation='bilinear')
save_distributed_param_arrays_to_checkpoint(use_numpy=True)
save_param_arrays_to_checkpoint(use_numpy=False)
set_index_in_grad_return(ind)
sync_chunks_to_distributed_object(arr, probe_pos, this_ind_batch_allranks, minibatch_size, probe_size, dtype='float32', n_split='auto')
write_params_to_file(this_pos_batch=None, probe_size=None, n_ranks=1)
class adorym.optimizers.ScipyOptimizer(name, output_folder='.', distribution_mode=None, options_dict=None)

Bases: adorym.optimizers.Optimizer

API binding to scopy.optimizer.minimize. WORKS FOR DATA-PARALLELISM MODE AND AUTOGRAD ONLY. Upon calling the apply_gradient method, the scipy optimizer performs multiple inner optimization iterations. Note that for many algorithms (e.g., conjugate gradient) convergence is proven only for batch minimization – that means these algorithm works well only when there is just 1 minibatch. In that case, also set n_epochs to 1 since there is no need for an outer loop.

apply_gradient(x, step_size=100.0, method='CG', forward_model=None, differentiator=None, options=None)
adorym.optimizers.apply_gradient_adam(x, g, i_batch, m=None, v=None, step_size=0.001, b1=0.9, b2=0.999, eps=1e-07, **kwargs)
adorym.optimizers.apply_gradient_gd(x, g, step_size=0.001, dynamic_rate=True, i_batch=0, first_downrate_iteration=92)
adorym.optimizers.create_and_initialize_parameter_optimizers(optimizable_params, kwargs)
adorym.optimizers.create_parameter_output_folders(opt_ls, output_folder)
adorym.optimizers.initialize_parameter_gradients(opt_ls, device=None, use_numpy=False)
adorym.optimizers.load_params_checkpoint(path)
adorym.optimizers.output_intermediate_parameters(opt_ls, optimizable_params, kwargs)
adorym.optimizers.save_params_checkpoint(path, params)
adorym.optimizers.update_parameter_gradients(opt_ls, grads, use_numpy=False)
adorym.optimizers.update_parameters(opt_ls, optimizable_params, kwargs)

adorym.propagate module

adorym.propagate.ctf(u, v, probe_real, probe_imag, dist_nm, lmbda_nm, voxel_nm, h=None, device=None, override_backend=None, sign_convention=1)

Calculate the Fourier transform of the wavefront intensity after Fresnel propagation using F[I] = [Phi’ H] * [Phi H’], where * denotes convolution and ‘ denotes complex conjugate.

adorym.propagate.fresnel_propagate(probe_real, probe_imag, dist_nm, lmbda_nm, voxel_nm, h=None, device=None, override_backend=None, sign_convention=1)
Parameters:h – A List of the real part and imaginary part of the transfer function kernel.
adorym.propagate.fresnel_propagate_wrapped(u, v, probe_real, probe_imag, dist_nm, lmbda_nm, voxel_nm, h=None, device=None, override_backend=None, sign_convention=1)
Parameters:h – A List of the real part and imaginary part of the transfer function kernel.
adorym.propagate.gen_freq_mesh(voxel_nm, shape)
adorym.propagate.gen_mesh(max, shape)

Generate mesh grid.

adorym.propagate.get_kernel(dist_nm, lmbda_nm, voxel_nm, grid_shape, fresnel_approx=True, sign_convention=1)

Get unshifted Fresnel propagation kernel for TF algorithm.

Parameters:
  • v (u,) – Reciprocal space meshgrids.
  • dist_nm – Propagation distance in nm.
adorym.propagate.get_kernel_ir(dist_nm, lmbda_nm, voxel_nm, grid_shape, sign_convention=1)

Get Fresnel propagation kernel for IR algorithm.

simulator : acquisition.Simulator
The Simulator object.
dist : float
Propagation distance in cm.
adorym.propagate.get_kernel_wrapped(u, v, dist_nm, lmbda_nm, voxel_nm, grid_shape, fresnel_approx=True, device=None, sign_convention=1)

Get unshifted Fresnel propagation kernel for TF algorithm.

Parameters:
  • v (u,) – Reciprocal space meshgrids.
  • dist_nm – Propagation distance in nm.
adorym.propagate.modulate_and_get_ctf(grid_batch, energy_ev, free_prop_cm, u_free=None, v_free=None, kappa=50.0)
adorym.propagate.multislice_backpropagate_batch(grid_batch, probe_real, probe_imag, energy_ev, psize_cm, delta_cm=None, free_prop_cm=None, obj_batch_shape=None, kernel=None, fresnel_approx=True, pure_projection=False, binning=1, device=None, type='delta_beta', normalize_fft=False, sign_convention=1, optimize_free_prop=False, u_free=None, v_free=None, scale_ri_by_k=True, is_minus_logged=False, pure_projection_return_sqrt=False, kappa=None, repeating_slice=None, return_fft_time=False, shift_exit_wave=None, return_intermediate_wavefields=False)
adorym.propagate.multislice_propagate_batch(grid_batch, probe_real, probe_imag, energy_ev, psize_cm, delta_cm=None, free_prop_cm=None, obj_batch_shape=None, kernel=None, fresnel_approx=True, pure_projection=False, binning=1, device=None, type='delta_beta', normalize_fft=False, sign_convention=1, optimize_free_prop=False, u_free=None, v_free=None, scale_ri_by_k=True, is_minus_logged=False, pure_projection_return_sqrt=False, kappa=None, repeating_slice=None, return_fft_time=False, shift_exit_wave=None, return_intermediate_wavefields=False)
adorym.propagate.pure_phase_ctf(u, v, delta_slice, beta_slice, dist_nm, lmbda_nm, kappa=50.0, alpha=1e-10, override_backend=None)
adorym.propagate.realign_image_fourier(a_real, a_imag, shift, axes=(0, 1), device=None)

Returns real and imaginary parts as a list.

adorym.propagate.sparse_multislice_propagate_batch(u, v, grid_batch, probe_real, probe_imag, energy_ev, psize_cm, slice_pos_cm_ls, free_prop_cm=None, obj_batch_shape=None, fresnel_approx=True, device=None, type='delta_beta', normalize_fft=False, sign_convention=1, scale_ri_by_k=True, shift_exit_wave=None)

adorym.pseudo module

class adorym.pseudo.Comm

Bases: object

Allreduce(a)
Barrier()
Bcast(a, root=0)
Get_rank()
Get_size()
allreduce(a)
alltoall(a)
bcast(a, root=0)
class adorym.pseudo.Hvd

Bases: object

DistributedOptimizer(op, name=None)
broadcast_global_variables(a)
init()
local_rank()
rank()
size()
class adorym.pseudo.MPI

Bases: object

COMM_WORLD = <adorym.pseudo.Comm object>

adorym.ptychography module

adorym.ptychography.reconstruct_ptychography(fname, obj_size, probe_pos=None, theta_st=0, theta_end=3.1415927, n_theta=None, theta_downsample=None, energy_ev=None, psize_cm=None, free_prop_cm=None, raw_data_type='magnitude', is_minus_logged=False, slice_pos_cm_ls=None, n_epochs='auto', crit_conv_rate=0.03, max_nepochs=200, regularizers=None, alpha_d=None, alpha_b=None, gamma=1e-06, minibatch_size=None, multiscale_level=1, n_epoch_final_pass=None, initial_guess=None, random_guess_means_sigmas=(8.7e-07, 5.1e-08, 1e-07, 1e-08), n_batch_per_update=1, reweighted_l1=False, interpolation='bilinear', update_scheme='immediate', unknown_type='delta_beta', randomize_probe_pos=False, common_probe_pos=True, fix_object=False, optimize_object=True, optimizer='adam', learning_rate=1e-05, update_using_external_algorithm=None, optimizer_batch_number_increment='angle', finite_support_mask_path=None, shrink_cycle=None, shrink_threshold=1e-09, object_type='normal', non_negativity=False, forward_model='auto', forward_algorithm='fresnel', ctf_lg_kappa=1.7, binning=1, fresnel_approx=True, pure_projection=False, two_d_mode=False, probe_type='gaussian', probe_initial=None, probe_extra_defocus_cm=None, n_probe_modes=1, shared_probe_among_angles=True, rescale_probe_intensity=False, loss_function_type='lsq', poisson_multiplier=1.0, beamstop=None, normalize_fft=False, safe_zone_width=0, scale_ri_by_k=True, sign_convention=1, fourier_disparity=False, save_path='.', output_folder=None, save_intermediate=False, save_intermediate_level='batch', save_history=False, store_checkpoint=True, use_checkpoint=True, force_to_use_checkpoint=False, n_batch_per_checkpoint=10, save_stdout=False, cpu_only=False, core_parallelization=True, gpu_index=0, n_dp_batch=20, distribution_mode=None, dist_mode_n_batch_per_update=None, precalculate_rotation_coords=True, cache_dtype='float32', rotate_out_of_loop=False, n_split_mpi_ata='auto', optimize_probe=False, probe_learning_rate=1e-05, optimizer_probe=None, probe_update_delay=0, probe_update_limit=None, optimize_probe_defocusing=False, probe_defocusing_learning_rate=1e-05, optimizer_probe_defocusing=None, optimize_probe_pos_offset=False, probe_pos_offset_learning_rate=0.01, optimizer_probe_pos_offset=None, optimize_prj_pos_offset=False, prj_pos_offset_learning_rate=0.01, optimizer_prj_pos_offset=None, optimize_all_probe_pos=False, all_probe_pos_learning_rate=0.01, optimizer_all_probe_pos=None, optimize_slice_pos=False, slice_pos_learning_rate=0.0001, optimizer_slice_pos=None, optimize_free_prop=False, free_prop_learning_rate=0.01, optimizer_free_prop=None, optimize_prj_affine=False, prj_affine_learning_rate=0.001, optimizer_prj_affine=None, optimize_tilt=False, tilt_learning_rate=0.001, optimizer_tilt=None, initial_tilt=None, optimize_ctf_lg_kappa=False, ctf_lg_kappa_learning_rate=0.001, optimizer_ctf_lg_kappa=None, other_params_update_delay=0, use_epie=False, epie_alpha=0.8, dynamic_rate=True, pupil_function=None, probe_circ_mask=0.9, dynamic_dropping=False, dropping_threshold=8e-05, backend='autograd', debug=False, t_max_min=None, **kwargs)
Notes:
  1. Input data are assumed to be contained in an HDF5 under ‘exchange/data’, as a 4D dataset of shape [n_theta, n_spots, detector_size_y, detector_size_x].
  2. Full-field reconstruction is treated as ptychography. If the image is not divided, the programs runs as if it is dealing with ptychography with only 1 spot per angle.
  3. Full-field reconstruction with minibatch_size > 1 but without image dividing is not supported. In this case, minibatch_size will be forced to be 1, so that each rank process only one rotation angle’s image at a time. To perform large fullfield reconstruction efficiently, divide the data into sub-chunks.
  4. Full-field reconstruction using shared_file_mode but without image dividing is not recommended even if minibatch_size is 1. In shared_file_mode, all ranks process data from the same rotation angle in each synchronized batch. Doing this will cause all ranks to process the same data. To perform large fullfield reconstruction efficiently, divide the data into sub-chunks.

adorym.simulation module

adorym.simulation.simulate_ptychography(fname, obj_size, probe_pos=None, probe_pos_ls=None, probe_size=(256, 256), theta_st=0, theta_end=3.1415927, n_theta=None, theta_downsample=None, energy_ev=None, psize_cm=None, free_prop_cm=None, raw_data_type='magnitude', is_minus_logged=False, slice_pos_cm_ls=None, n_epochs='auto', crit_conv_rate=0.03, max_nepochs=200, alpha_d=None, alpha_b=None, gamma=1e-06, minibatch_size=None, multiscale_level=1, n_epoch_final_pass=None, initial_guess=None, random_guess_means_sigmas=(8.7e-07, 5.1e-08, 1e-07, 1e-08), n_batch_per_update=1, reweighted_l1=False, interpolation='bilinear', update_scheme='immediate', unknown_type='delta_beta', randomize_probe_pos=False, common_probe_pos=True, fix_object=False, optimize_object=True, optimizer='adam', learning_rate=1e-05, update_using_external_algorithm=None, finite_support_mask_path=None, shrink_cycle=None, shrink_threshold=1e-09, object_type='normal', non_negativity=False, forward_model='auto', forward_algorithm='fresnel', ctf_lg_kappa=1.7, binning=1, fresnel_approx=True, pure_projection=False, two_d_mode=False, probe_type='gaussian', probe_initial=None, probe_extra_defocus_cm=None, n_probe_modes=1, rescale_probe_intensity=False, loss_function_type='lsq', poisson_multiplier=1.0, beamstop=None, normalize_fft=False, safe_zone_width=0, scale_ri_by_k=True, sign_convention=1, fourier_disparity=False, save_path='.', output_folder=None, phantom_path='phantom', save_intermediate=False, save_intermediate_level='batch', save_history=False, store_checkpoint=True, use_checkpoint=True, force_to_use_checkpoint=False, n_batch_per_checkpoint=10, save_stdout=False, cpu_only=False, core_parallelization=True, gpu_index=0, n_dp_batch=20, distribution_mode=None, dist_mode_n_batch_per_update=None, precalculate_rotation_coords=True, cache_dtype='float32', rotate_out_of_loop=False, optimize_probe=False, probe_learning_rate=1e-05, optimizer_probe=None, probe_update_delay=0, probe_update_limit=None, optimize_probe_defocusing=False, probe_defocusing_learning_rate=1e-05, optimizer_probe_defocusing=None, optimize_probe_pos_offset=False, probe_pos_offset_learning_rate=0.01, optimizer_probe_pos_offset=None, optimize_prj_pos_offset=False, probe_prj_offset_learning_rate=0.01, optimizer_prj_pos_offset=None, optimize_all_probe_pos=False, all_probe_pos_learning_rate=0.01, optimizer_all_probe_pos=None, optimize_slice_pos=False, slice_pos_learning_rate=0.0001, optimizer_slice_pos=None, optimize_free_prop=False, free_prop_learning_rate=0.01, optimizer_free_prop=None, optimize_prj_affine=False, prj_affine_learning_rate=0.001, optimizer_prj_affine=None, optimize_tilt=False, tilt_learning_rate=0.001, optimizer_tilt=None, initial_tilt=None, optimize_ctf_lg_kappa=False, ctf_lg_kappa_learning_rate=0.001, optimizer_ctf_lg_kappa=None, other_params_update_delay=0, use_epie=False, epie_alpha=0.8, dynamic_rate=True, pupil_function=None, probe_circ_mask=0.9, dynamic_dropping=False, dropping_threshold=8e-05, backend='autograd', debug=False, t_max_min=None, **kwargs)
Notes:
  1. This simulation function uses the predict method of the selected forward model. Make sure to check the return of the predict method for the type of data returned (i.e., magnitude or intensity).

adorym.util module

adorym.util.apply_rotation(obj, coord_old, interpolation='bilinear', axis=0, device=None, reverse=False, override_backend=None)
adorym.util.apply_rotation_primitive(obj, coord_old, interpolation='bilinear', axis=0, device=None, override_backend=None)
adorym.util.apply_rotation_to_hdf5(dset, coord_old, rank, n_ranks, interpolation='bilinear', monochannel=False, dset_2=None, precalculate_rotation_coords=True)

If another dataset is used to store the rotated object, pass the dataset object to dset_2. If dset_2 is None, rotated object will overwrite the original dataset.

adorym.util.apply_rotation_transpose(obj, coord_old, interpolation='bilinear', axis=0, device=None, override_backend=None)

Find the result of applying the transpose of the rotation-interpolation matrix defined by coord_old. Used to calculate the VJP of rotation operation. :param obj: Tensor. :param coord_old: The same variable as is passed to apply_rotation.

adorym.util.calculate_original_coordinates_for_rotation(array_size, coord_new, theta, override_backend=None, device=None)
adorym.util.calculate_pad_len(this_obj_size, probe_pos, probe_size, unknown_type='delta_beta')

Pad the object with 0 if any of the probes’ extents go beyond the object boundary. :return: padded object and padding lengths.

adorym.util.convert_to_hdf5_indexing(inds)
adorym.util.create_batches(arr, batch_size)
adorym.util.create_probe_initial_guess(data_fname, dist_nm, energy_ev, psize_nm, raw_data_type='intensity')
adorym.util.create_probe_initial_guess_ptycho(data_fname, noise=False, raw_data_type='intensity', beamstop=None, sign_convention=1)
adorym.util.fourier_ring_correlation(obj, ref, step_size=1, save_path='frc', save_mask=False)
adorym.util.fourier_shell_correlation(obj, ref, step_size=1, save_path='fsc', save_mask=True)
adorym.util.generate_disk(shape, radius, **kwargs)
adorym.util.generate_gaussian_map(size, mag_max, mag_sigma, phase_max, phase_sigma)
adorym.util.generate_ring(shape, radius, **kwargs)
adorym.util.generate_shell(shape, radius, **kwargs)
adorym.util.generate_sphere(shape, radius, anti_aliasing=5)
adorym.util.get_block_division(original_grid_shape, n_ranks)
adorym.util.get_block_range(i_pos, n_blocks_x, block_size)
adorym.util.get_cooridnates_stack_for_rotation(array_size, axis=0)
adorym.util.get_multiprocess_distribution_index(size, n_ranks)
adorym.util.get_process_memory_usage()

Return CPU memory in MB (Linux).

adorym.util.get_rotated_subblocks(dset, this_pos_batch, probe_size, whole_object_size, monochannel=False, mode='hdf5', interpolation='bilinear', unknown_type='delta_beta')

Get rotated subblocks centering this_pos_batch directly from hdf5. :return: [n_pos, y, x, z, 2]

adorym.util.get_rotated_subblocks_with_tilt(dset, this_pos_batch, coord_old, probe_size, whole_object_size, monochannel=False, mode='hdf5', interpolation='bilinear')

Get rotated subblocks centering this_pos_batch directly from hdf5. :return: [n_pos, y, x, z, 2]

adorym.util.get_subblocks_from_distributed_object(obj, slice_catalog, probe_pos, this_ind_batch_allranks, minibatch_size, probe_size, whole_object_size, unknown_type='delta_beta', output_folder='.', dtype='float32')
adorym.util.get_subblocks_from_distributed_object_mpi(obj, slice_catalog, probe_pos, this_ind_batch_allranks, minibatch_size, probe_size, whole_object_size, unknown_type='delta_beta', output_folder='.', n_split='auto', dtype='float32', debug=False)
adorym.util.get_subdividing_params(image_shape, n_blocks_y, n_blocks_x, **kwargs)

Calculate block arrangement and locations when a large 2D image is to be divided into square sub-blocks. :param image_shape: shape of original image. :param n_blocks: total number of blocks. :param safe_zone_width: overlapping length between adjacent blocks. If None, estimate using the sqrt(lambda * z) rule. :return: An array of [n_blocks, 4].

adorym.util.image_gradient(arr, axes=())

Calculate the squared magnitude of image gradient in specified axes.

Parameters:
  • arr – Tensor.
  • axes – List.
Returns:

Gradient map.

adorym.util.initialize_hdf5_with_arrays(dset, rank, n_ranks, init_delta, init_beta, dtype='float32')
adorym.util.initialize_hdf5_with_constant(dset, rank, n_ranks, constant_value=0, dtype='float32')
adorym.util.initialize_hdf5_with_gaussian(dset, rank, n_ranks, delta_mu, delta_sigma, beta_mu, beta_sigma, unknown_type='delta_beta', dtype='float32', non_negativity=False)
adorym.util.initialize_object_for_do(this_obj_size, slice_catalog=None, ds_level=1, object_type='normal', initial_guess=None, output_folder=None, save_stdout=False, timestr='', not_first_level=False, random_guess_means_sigmas=(8.7e-07, 5.1e-08, 1e-07, 1e-08), unknown_type='delta_beta', dtype='float32', non_negativity=False)
adorym.util.initialize_object_for_dp(this_obj_size, dset=None, ds_level=1, object_type='normal', initial_guess=None, output_folder=None, save_stdout=False, timestr='', not_first_level=False, random_guess_means_sigmas=(8.7e-07, 5.1e-08, 1e-07, 1e-08), unknown_type='delta_beta', non_negativity=False, verbose=True)
adorym.util.initialize_object_for_sf(this_obj_size, dset=None, ds_level=1, object_type='normal', initial_guess=None, output_folder=None, save_stdout=False, timestr='', not_first_level=False, random_guess_means_sigmas=(8.7e-07, 5.1e-08, 1e-07, 1e-08), unknown_type='delta_beta', dtype='float32', non_negativity=False)
adorym.util.initialize_probe(probe_size, probe_type, pupil_function=None, probe_initial=None, rescale_intensity=False, save_stdout=None, output_folder=None, timestr=None, save_path=None, fname=None, extra_defocus_cm=None, invert_phase=False, sign_convention=1, **kwargs)
adorym.util.mag_phase_to_real_imag(mag, phase)
adorym.util.multidistance_ctf(prj_ls, dist_cm_ls, psize_cm, energy_kev, kappa=50, sigma_cut=0.01, alpha_1=0.0005, alpha_2=1e-16)
adorym.util.output_object(obj, distribution_mode, output_folder, unknown_type='delta_beta', full_output=True, ds_level=1, i_epoch=0, i_batch=0, save_history=True)
adorym.util.output_probe(probe_real, probe_imag, output_folder, full_output=True, ds_level=1, i_epoch=0, i_batch=0, save_history=True, custom_name=None)
adorym.util.pad_object(obj_rot, this_obj_size, probe_pos, probe_size, mode='constant', unknown_type='delta_beta', override_backend=None)

Pad the object with 0 if any of the probes’ extents go beyond the object boundary.

Returns:padded object and padding lengths.
adorym.util.pad_object_edge(obj_rot, this_obj_size, probe_pos, probe_size, override_backend=None, pad_arr=None)

Pad the object with 0 if any of the probes’ extents go beyond the object boundary, using edge values.

Returns:padded object and padding lengths.
adorym.util.phase_correlation(img, ref, upsample_factor=1)

An adaption of skimage.registration.phase_cross_correlation for Pytorch, enabling GPU support. Perform phase correlation to find relative translational shift.

Parameters:
  • img – Tensor. In shape [y, x, 2], where the last dimension holds real and imaginary parts.
  • ref – Tensor. In shape [y, x, 2], where the last dimension holds real and imaginary parts.
  • upsample_factor – Int. Images will be registered to within 1 / upsample_factor of a pixel.
Returns:

Shift as [dy, dx]. It is the relative shift of img with regards to ref. In other words, you can shift img by -shifts to get ref.

adorym.util.preprocess(dat, blur=None, normalize_bg=False)
adorym.util.print_alltoall_data_shape(chunk_batch_ls_ls, i_split=0)
adorym.util.read_all_origin_coords(src_folder, theta_ls)
adorym.util.read_origin_coords(src_folder, theta, reverse=False)
adorym.util.real_imag_to_mag_phase(realpart, imagpart)
adorym.util.realign_image(arr, shift)

Translate and rotate image via Fourier

arr : ndarray
Image array.
shift: tuple
Mininum and maximum values to rescale data.
angle: float, optional
Mininum and maximum values to rescale data.
ndarray
Output array.
adorym.util.realign_image_fourier(a_real, a_imag, shift, axes=(0, 1), device=None)

Returns real and imaginary parts as a list.

adorym.util.reconstruct_hdf5_takeouts(block, repeats, sorted_ind)
adorym.util.rescale(arr, scale, device=None, override_backend=None)
adorym.util.revert_rotation_to_hdf5(dset, coord_old, rank, n_ranks, interpolation='bilinear', monochannel=False, precalculate_rotation_coords=True)
adorym.util.rotate_no_grad(obj, theta, axis=0, override_backend=None, interpolation='bilinear', device=None)

Only the VJP with regards to obj is possible. To differentiate with regards to theta, use wrappers.rotate.

adorym.util.save_rotation_lookup(array_size, theta_ls, dest_folder=None, override_backend=None)
adorym.util.split_tasks(arr, split_size)
adorym.util.subdivide_image(img, block_range_ls, override_backend=None)
adorym.util.sync_subblocks_among_distributed_object(obj, slice_catalog, probe_pos, this_ind_batch_allranks, minibatch_size, probe_size, whole_object_size, output_folder='.')
adorym.util.sync_subblocks_among_distributed_object_mpi(obj, my_slab, slice_catalog, probe_pos, this_ind_batch_allranks, minibatch_size, probe_size, whole_object_size, output_folder='.', n_split='auto', dtype='float32', debug=False)
adorym.util.timeit(fun)
adorym.util.total_variation(arr, axes=())

Calculate total variation of an array.

Parameters:arr – 3D Tensor.
Returns:Scalar.
adorym.util.total_variation_3d(arr, axis_offset=0)

Calculate total variation of a 3D array.

Parameters:arr – 3D Tensor.
Returns:Scalar.
adorym.util.upsample_2x(arr)
adorym.util.write_subblocks_to_file(dset, this_pos_batch, obj_delta, obj_beta, probe_size, whole_object_size, monochannel=False, interpolation='bilinear', dtype='float32')

Write data back in the npy. If monochannel, give None to obj_beta.

adorym.util.write_subblocks_to_file_with_tilt(dset, this_pos_batch, obj_delta, obj_beta, coord_old, coord_new, probe_size, whole_object_size, monochannel=False, interpolation='bilinear')

Write data back in the npy. If monochannel, give None to obj_beta.

adorym.visualization module

adorym.visualization.parse_loss_data(src_dir)

adorym.wrappers module

class adorym.wrappers.EmptyWith

Bases: object

adorym.wrappers.abs(*args, override_backend=None, **kwargs)
adorym.wrappers.affine_transform(*args, override_backend=None, **kwargs)
adorym.wrappers.arange(*args, override_backend=None, **kwargs)
adorym.wrappers.arctan2(*args, override_backend=None, **kwargs)
adorym.wrappers.argmax(*args, override_backend=None, **kwargs)
adorym.wrappers.cast(*args, override_backend=None, **kwargs)
adorym.wrappers.ceil(*args, override_backend=None, **kwargs)
adorym.wrappers.ceil_and_cast(*args, override_backend=None, **kwargs)
adorym.wrappers.clip(*args, override_backend=None, **kwargs)
adorym.wrappers.collect_gpu_garbage(*args, override_backend=None, **kwargs)
adorym.wrappers.complex_mul(*args, override_backend=None, **kwargs)
adorym.wrappers.concatenate(*args, override_backend=None, **kwargs)
adorym.wrappers.convolve_with_impulse_response(*args, override_backend=None, **kwargs)
adorym.wrappers.convolve_with_transfer_function(*args, override_backend=None, **kwargs)
adorym.wrappers.cos(*args, override_backend=None, **kwargs)
adorym.wrappers.create_constant(*args, override_backend=None, **kwargs)
adorym.wrappers.create_variable(*args, override_backend=None, **kwargs)
adorym.wrappers.detach(*args, override_backend=None, **kwargs)
adorym.wrappers.exp(*args, override_backend=None, **kwargs)
adorym.wrappers.exp_complex(*args, override_backend=None, **kwargs)
adorym.wrappers.fft(*args, override_backend=None, **kwargs)
adorym.wrappers.fft2(*args, override_backend=None, **kwargs)
adorym.wrappers.fft2_and_shift(*args, override_backend=None, **kwargs)
adorym.wrappers.fftshift(*args, override_backend=None, **kwargs)
adorym.wrappers.fix(*args, override_backend=None, **kwargs)
adorym.wrappers.flip(*args, override_backend=None, **kwargs)
adorym.wrappers.floor(*args, override_backend=None, **kwargs)
adorym.wrappers.floor_and_cast(*args, override_backend=None, **kwargs)
adorym.wrappers.get_allocated_tensors(*args, override_backend=None, **kwargs)
adorym.wrappers.get_device(*args, override_backend=None, **kwargs)
adorym.wrappers.get_dtype(*args, override_backend=None, **kwargs)
adorym.wrappers.get_gpu_memory_cache_mb(*args, override_backend=None, **kwargs)
adorym.wrappers.get_gpu_memory_usage_mb(*args, override_backend=None, **kwargs)
adorym.wrappers.get_gradients(*args, override_backend=None, **kwargs)
adorym.wrappers.get_peak_gpu_memory_usage_mb(*args, override_backend=None, **kwargs)
adorym.wrappers.get_var_device(*args, override_backend=None, **kwargs)
adorym.wrappers.get_var_device_type(*args, override_backend=None, **kwargs)
adorym.wrappers.grid_sample(*args, override_backend=None, **kwargs)
adorym.wrappers.hvp(*args, override_backend=None, **kwargs)
adorym.wrappers.ifft(*args, override_backend=None, **kwargs)
adorym.wrappers.ifft2(*args, override_backend=None, **kwargs)
adorym.wrappers.ifft2_and_shift(*args, override_backend=None, **kwargs)
adorym.wrappers.ifftshift(*args, override_backend=None, **kwargs)
adorym.wrappers.imag(*args, override_backend=None, **kwargs)
adorym.wrappers.ishift_and_ifft2(*args, override_backend=None, **kwargs)
adorym.wrappers.isnan(*args, override_backend=None, **kwargs)
adorym.wrappers.jvp(*args, override_backend=None, **kwargs)
adorym.wrappers.log(*args, override_backend=None, **kwargs)
adorym.wrappers.matmul(*args, override_backend=None, **kwargs)
adorym.wrappers.max(*args, override_backend=None, **kwargs)
adorym.wrappers.mean(*args, override_backend=None, **kwargs)
adorym.wrappers.min(*args, override_backend=None, **kwargs)
adorym.wrappers.no_grad(*args, override_backend=None, **kwargs)
adorym.wrappers.nonzero(*args, override_backend=None, **kwargs)
adorym.wrappers.norm(*args, override_backend=None, **kwargs)
adorym.wrappers.ones(*args, override_backend=None, **kwargs)
adorym.wrappers.ones_like(*args, override_backend=None, **kwargs)
adorym.wrappers.pad(*args, override_backend=None, **kwargs)
adorym.wrappers.pcc(*args, override_backend=None, **kwargs)
adorym.wrappers.permute_axes(*args, override_backend=None, **kwargs)
adorym.wrappers.prepare_loss_node(*args, override_backend=None, **kwargs)
adorym.wrappers.prod(*args, override_backend=None, **kwargs)
adorym.wrappers.real(*args, override_backend=None, **kwargs)
adorym.wrappers.reattach(*args, override_backend=None, **kwargs)
adorym.wrappers.repeat(*args, override_backend=None, **kwargs)
adorym.wrappers.reshape(*args, override_backend=None, **kwargs)
adorym.wrappers.roll(*args, override_backend=None, **kwargs)
adorym.wrappers.rotate(*args, override_backend=None, **kwargs)
adorym.wrappers.round(*args, override_backend=None, **kwargs)
adorym.wrappers.round_and_cast(*args, override_backend=None, **kwargs)
adorym.wrappers.set_bn(f)
adorym.wrappers.set_device(*args, override_backend=None, **kwargs)
adorym.wrappers.sign(*args, override_backend=None, **kwargs)
adorym.wrappers.sin(*args, override_backend=None, **kwargs)
adorym.wrappers.split_channel(*args, override_backend=None, **kwargs)
adorym.wrappers.sqrt(*args, override_backend=None, **kwargs)
adorym.wrappers.stack(*args, override_backend=None, **kwargs)
adorym.wrappers.std(*args, override_backend=None, **kwargs)
adorym.wrappers.sum(*args, override_backend=None, **kwargs)
adorym.wrappers.swap_axes(*args, override_backend=None, **kwargs)
adorym.wrappers.tensordot(*args, override_backend=None, **kwargs)
adorym.wrappers.tile(*args, override_backend=None, **kwargs)
adorym.wrappers.to_cpu(*args, override_backend=None, **kwargs)
adorym.wrappers.to_gpu(*args, override_backend=None, **kwargs)
adorym.wrappers.to_numpy(*args, override_backend=None, **kwargs)
adorym.wrappers.tomography_filter(*args, override_backend=None, **kwargs)
adorym.wrappers.vec_norm(*args, override_backend=None, **kwargs)
adorym.wrappers.vjp(*args, override_backend=None, **kwargs)
adorym.wrappers.zeros(*args, override_backend=None, **kwargs)
adorym.wrappers.zeros_like(*args, override_backend=None, **kwargs)

Module contents