crantpy.utils.helpers module#
This module contains helper functions for crantpy.
- crantpy.utils.helpers.create_sql_query(table_name, fields, condition=None, limit=None, start=None)[source]#
Creates a SQL query to get the specified fields from the specified table.
- Parameters:
table_name (str) – The name of the table to query.
fields (List[str]) – The list of field names to include in the query.
condition (str, optional) – The WHERE clause of the query.
limit (int, optional) – The maximum number of rows to return.
start (int, optional) – The number of rows to skip (OFFSET).
- Returns:
The constructed SQL query string.
- Return type:
- crantpy.utils.helpers.filter_df(df, column, value, regex=False, case=False, match_all=False, exact=True)[source]#
This function filters a df based on a column and a value. It can handle string, numeric, and list-containing columns.
- Parameters:
(pd.DataFrame) (df)
(str) (column)
(Any) (value)
(bool) (exact)
(bool)
(bool) – if True, requires all filter values to be present in the cell’s list. If False, requires at least one filter value to be present. Defaults to False.
(bool)
df (pandas.DataFrame)
column (str)
value (Any)
regex (bool)
case (bool)
match_all (bool)
exact (bool)
- Returns:
pd.DataFrame
- Return type:
The filtered df.
- crantpy.utils.helpers.make_iterable(x, force_type=None)[source]#
Convert input to an numpy array.
- Parameters:
x (Any) – The input to convert.
force_type (Optional[type]) – If specified, the input will be cast to this type.
- Returns:
The converted numpy array.
- Return type:
np.ndarray
- crantpy.utils.helpers.match_dtype(value, dtype)[source]#
Match the dtype of a value to a given dtype.
- Parameters:
- Returns:
The converted value.
- Return type:
Any
- Raises:
ValueError – If the dtype is not supported.
- crantpy.utils.helpers.parse_root_ids(neurons)[source]#
Parse various neuron input types to a list of root ID strings. :param neurons: The neuron(s) to parse. Can be a single root ID (int or str),
a list of root IDs, or a NeuronCriteria object.
- crantpy.utils.helpers.parse_timestamp(x)[source]#
Parse a timestamp string to Unix timestamp.
- Parameters:
x (Timestamp) – The timestamp string to parse. Int must be unix timestamp. String must be ISO 8601 - e.g. ‘2021-11-15’. datetime, np.datetime64, pd.Timestamp are also accepted.
- Returns:
The Unix timestamp.
- Return type:
- crantpy.utils.helpers.plot_em_image(x, y, z, size=1000)[source]#
Fetch and return an EM image slice from the precomputed CloudVolume. Currently only supports slices through the Z axis (i.e. XY plane).
- Parameters:
- Returns:
The EM image slice as a numpy array.
- Return type:
np.ndarray