utils¶
-
bigfeta.utils.
blocks_from_tilespec_pair
(ptspec, qtspec, match, pcol, qcol, ncol, matrix_assembly)¶ create sparse matrix block from tilespecs and pointmatch
Parameters: - ptspec (
renderapi.tilespec.TileSpec
) – ptspec.tforms[-1] is an AlignerTransform object - qtspec (
renderapi.tilespec.TileSpec
) – qtspec.tforms[-1] is an AlignerTransform object - match (dict) – pointmatch between tilepairs
- pcol (int) – index for start of column entries for p
- qcol (int) – index for start of column entries for q
- ncol (int) – total number of columns in sparse matrix
- matrix_assembly (dict) – see class matrix_assembly in schemas, sets npts
Returns: - pblock (
scipy.sparse.csr_matrix
) – block for the p tilespec/match entry. The full block can be had from pblock - qblock, but, it is a little faster to do vstack and then subtract, so p and q remain separate - qblock (
scipy.sparse.csr_matrix
) – block for the q tilespec/match entry - w (
numpy.ndarray
) – weights for the rows in pblock and qblock
- ptspec (
-
bigfeta.utils.
concatenate_results
(results, pop_rhs=False, pop_zlist=False)¶ row concatenates sparse matrix blocks and associated vectors
Parameters: results (list) – dict with keys “block”, “weights”, “rhs”, “zlist” Returns: - A (
scipy.sparse.csr_matrix
) – the concatenated matrix, N x M - weights (
scipy.sparse.csr_matrix
) – diagonal matrix containing concatenated weights N x N - rhs (
numpy.ndarray
) – concatenated rhs vector(s) float. N x nsolve - zlist (
numpy.ndarray
) – float concatenated z list
- A (
-
bigfeta.utils.
create_or_set_loading
(stack)¶ creates a new stack or sets existing stack to state LOADING
Parameters: stack ( bigfeta.schemas.output_stack
) –
-
bigfeta.utils.
determine_zvalue_pairs
(resolved, depths)¶ creates a lidt of pairs by z that will be included in the solve
Parameters: - resolved (
renderapi.resolvedtiles.ResolvedTiles
) – input tilespecs - depths (List) – depths (z-differences) that will be included in the matrix
Returns: pairs – keys are z values and sectionIds for each pair
Return type: List of dict
- resolved (
-
bigfeta.utils.
get_matches
(iId, jId, collection, dbconnection)¶ retrieve point correspondences
Parameters: - iId (str) – sectionId for 1st section
- jId (str) – sectionId for 2nd section
- collection (
bigfeta.schemas.pointmatch
) – - dbconnection (object returned by
bigfeta.utils.make_dbconnection()
) –
Returns: matches – standard render/mongo representation of point matches
Return type: List of dict
-
bigfeta.utils.
get_resolved_from_z
(stack, tform_name, fullsize, order, z)¶ - retrieves a ResolvedTiles object from some source and mutates the
- final transform for each tilespec into an AlignerTransform object
Parameters: - stack (
bigfeta.schemas.input_stack
) – - tform_name (str) – specifies which transform to mutate into (solve for)
- fullsize (bool) – passed as kwarg to the bigfeta.transform.AlignerTransform
- order (int) – passed as kwarg to the bigfeta.transform.AlignerTransform
- z (int or float) – z value for one section
Returns: resolved
Return type:
-
bigfeta.utils.
get_resolved_tilespecs
(stack, tform_name, pool_size, zvals, fullsize=False, order=2)¶ - retrieves ResolvedTiles objects from some source and mutates the
- final transform for each tilespec into an AlignerTransform object
Parameters: - stack (
bigfeta.schemas.input_stack
) – - tform_name (str) – specifies which transform to mutate into (solve for)
- pool_size (int) – level of parallelization for parallel reads
- fullsize (bool) – passed as kwarg to the bigfeta.transform.AlignerTransform
- order (int) – passed as kwarg to the bigfeta.transform.AlignerTransform
- zvals (
numpy.ndarray
) – z values for desired sections
Returns: resolved
Return type:
-
bigfeta.utils.
get_stderr_stdout
(outarg)¶ helper function for suppressing render output
Parameters: outarg (str) – from input schema “render_output” Returns: stdeo – destination for stderr and stdout Return type: file handle or None
-
bigfeta.utils.
get_z_values_for_stack
(stack, zvals)¶ - multi-interface wrapper to find overlapping z values
- between a stack and the requested range.
Parameters: - stack (
bigfeta.schema.input_stack
) – - zvals (
numpy.ndarray
) – int or float. input z values
Returns: zvals – int or float. overlapping z values
Return type:
-
bigfeta.utils.
make_dbconnection
(collection, which='tile', interface=None)¶ creates a multi-interface object for stacks and collections
Parameters: Returns: dbconnection – a multi-interface object used by other functions in
bigfeta.utils
Return type: obj
-
bigfeta.utils.
message_from_solve_results
(results)¶ - create summarizing string message about solve for
- logging
Parameters: results (dict) – returned from bigfeta.utils.solve()
or read from external solver resultsReturns: message – human-readable summary message Return type: str
-
bigfeta.utils.
ready_transforms
(tilespecs, tform_name, fullsize, order)¶ mutate last transform in each tilespec to be an AlignerTransform
Parameters: - tilespecs (List) –
renderapi.tilespec.TileSpec
objects. - tform_name (str) – intended destination type for the mutation
- fullsize (bool) – passed as kwarg to AlignerTransform
- order (int) – passed as kwarg to AlignerTransform
- tilespecs (List) –
-
bigfeta.utils.
set_complete
(stack)¶ set stack state to COMPLETE
Parameters: stack ( bigfeta.schemas.output_stack
) –
-
bigfeta.utils.
transform_match
(match, ptspec, qtspec, apply_list, tforms)¶ - transform the match coordinates through a subset of the
- tilespec transform list
Parameters: - match (dict) – one match object
- ptspec (
renderapi.tilespec.TileSpec
) – the tilespec for the p coordinates - qtspec (
renderapi.tilespec.TileSpec
) – the tilespec for the q coordinates - apply_list (list) – list of indices for the transforms
- tforms (list) – list of reference transforms
Returns: match – one match object, with p and q transformed
Return type:
-
bigfeta.utils.
update_tilespecs
(resolved, x)¶ update tilespecs with new solution
Parameters: - resolved (
renderapi.resolvedtiles.ResolvedTiles
) – resolved tilespecs to update - x (
numpy.ndarray
) – results of solve
- resolved (
-
bigfeta.utils.
write_chunk_to_file
(fname, c, file_weights, rhs)¶ write a sub-matrix to an hdf5 file for an external solve
Parameters: - fname (str) – path to output file
- c (
scipy.sparse.csr_matrix
) – N x M matrix sub block - file_weights (
numpy.ndarray
) – length N array of weights - rhs (
numpy.ndarray
) – N x nsolve right hand sides
-
bigfeta.utils.
write_reg_and_tforms
(args, resolved, metadata, tforms, reg)¶ write regularization and transforms (x0) to hdf5
Parameters: - args (dict) – passed from bigfeta object
- resolved (
renderapi.resolvedtiles.ResolvedTiles
) – resolved tilespec object to output - metadata (dict) – helper values about matrix for external solver
- tforms (
numpy.ndarray
) – M x nsolve starting values (x0) - reg (
scipy.sparse.csr_matrix
) – M x M diagonal regularization values
-
bigfeta.utils.
write_to_new_stack
(resolved, output_stack, outarg, overwrite_zlayer, args, results)¶ write results to render or file output
Parameters: - resolved (
renderapi.resolvedtiles.ResolvedTiles
) – resolved tilespecs containing tilespecs to write - output_stack (dict) – from
bigfeta.schemas.output_stack
- outarg (str) – render_output argument
- overwrite_zlayer (bool) – delete section first before overwriting?
- args (dict) – from
bigfeta.schemas.BigFetaSchema
- results (dict) – results from
bigfeta.utils.solve()
Returns: output_stack – representation of
bigfeta.schemas.output_stack
Return type: - resolved (