neurolang.utils.server.responses module

class neurolang.utils.server.responses.CustomQueryResultsEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: JSONEncoder

Methods

default(obj)

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

encode(o)

Return a JSON string representation of a Python data structure.

iterencode(o[, _one_shot])

Encode the given object and yield each string representation as available.

default(obj: Any) Any

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
class neurolang.utils.server.responses.QueryResults(uuid: str, future: Future, symbol: str | None = None, start: int = 0, length: int = 50, sort: int = -1, asc: bool = True, get_values: bool = False)

Bases: object

A representation of query results. This class is returned by the tornado application as a JSON serialized string.

It contains
  • metadata information about the query:
    • cancelled, running, done

  • metadata about the requested information:
    • the specific symbol to return, as well as

    • start, length, sort, asc (parameters for which rows to return)

  • if the query resulted in an error, the error details

  • if the query resulted in data, the details for each requested symbol:
    • its columns, size, & row_type

    • the rows corresponding to the start, length, sort & asc params

Methods

get_result_item(symbol[, get_item_values])

Serialize a symbol into a dict of result values and metadata.

get_result_item_values(row_type, df)

Return the rows of the dataframe corresponding to the requested slice (as specified by start, length & sort values) in a json compatible form.

get_function_metadata

get_result_item_columns

set_error_details

set_results_details

get_function_metadata(symbol: Symbol)
get_result_item(symbol: RelationalAlgebraFrozenSet | Symbol, get_item_values: bool = False) Dict

Serialize a symbol into a dict of result values and metadata.

Parameters:
symbolUnion[RelationalAlgebraFrozenSet, Symbol]

the symbol to parse

get_item_valuesbool

get the values for the item

Returns:
Dict

the parsed result values

get_result_item_columns(symbol: RelationalAlgebraFrozenSet, df) Dict
get_result_item_values(row_type: Any | Type[Tuple] | None, df: DataFrame) List[List]

Return the rows of the dataframe corresponding to the requested slice (as specified by start, length & sort values) in a json compatible form.

Parameters:
row_typeUnion[Any, Type[Tuple], None]

the row_type.

dfpd.DataFrame

the dataframe.

Returns:
List[List]

the values.

set_error_details(error)
set_results_details(results, symbol, get_values)
neurolang.utils.server.responses.base64_encode_nifti(image)

Returns base64 encoded string of the specified image.

Parameters:
imagenibabel.Nifti2Image

image to be encoded.

Returns:
str

base64 encoded string of the image.

neurolang.utils.server.responses.base64_encode_spatial(image: SpatialImage)

Returns base64 encoded string of a spatial image

Parameters:
imagenibabel.spatialimages.SpatialImage

spatial image to be encoded.

Returns:
str

base64 encoded string of the vbr.

neurolang.utils.server.responses.calculate_image_center(image: SpatialImage)

Calculates center coordinates for the specified image.

neurolang.utils.server.responses.serializeVBR(image_row: Series)

Serialize a Volumetric Brain Region object.

Parameters:
vbrUnion[ExplicitVBR, ExplicitVBROverlay]

the volumetric brain region to serialize

Returns:
Dict

a dict containing the base64 encoded image, as well as min and max values, and a hash of the image.

neurolang.utils.server.responses.serialize_mplt_thumbnails(figure: Figure)

Serialize a figure by creating a base64 encoded thumbnail. This is used only to display the figure as a thumbnail in the list of results. The full size figure will be displayed when the user clicks on the thumbnail. See app.MpltFigureHandler.

Parameters:
figurematplotlib.figure.Figure

the figure to serialize

Returns:
str

base64 encoded thumbnail of the figure