diff --git a/caveclient/materializationengine.py b/caveclient/materializationengine.py index a7e9377f..d88a323d 100644 --- a/caveclient/materializationengine.py +++ b/caveclient/materializationengine.py @@ -1,27 +1,29 @@ +import itertools +import json +import logging import re -from urllib.error import HTTPError import warnings -import pytz -import pandas as pd -from IPython.display import HTML -from .mytimer import MyTimeIt -from typing import Union, Iterable -import itertools -import pyarrow as pa from datetime import datetime, timezone +from typing import Iterable, Union +from urllib.error import HTTPError + import numpy as np -import json -from .endpoints import materialization_api_versions, materialization_common +import pandas as pd +import pyarrow as pa +import pytz +from cachetools import TTLCache, cached +from IPython.display import HTML + from .auth import AuthClient from .base import ( - ClientBase, BaseEncoder, + ClientBase, _api_endpoints, handle_response, ) -from cachetools import cached, TTLCache +from .endpoints import materialization_api_versions, materialization_common +from .mytimer import MyTimeIt from .tools.table_manager import TableManager, ViewManager -import logging logger = logging.getLogger(__name__) @@ -213,7 +215,7 @@ def MaterializationClient( ) -class MaterializatonClientV2(ClientBase): +class MaterializationClientV2(ClientBase): def __init__( self, server_address, @@ -232,7 +234,7 @@ def __init__( over_client=None, desired_resolution=None, ): - super(MaterializatonClientV2, self).__init__( + super(MaterializationClientV2, self).__init__( server_address, auth_header, api_version, @@ -747,7 +749,6 @@ def query_table( df = deserialize_query_response(response) if desired_resolution is not None: if not response.headers.get("dataframe_resolution", None): - if len(desired_resolution) != 3: raise ValueError( "desired resolution needs to be of length 3, for xyz" @@ -1287,7 +1288,6 @@ def live_live_query( warnings.simplefilter(action="ignore", category=DeprecationWarning) df = deserialize_query_response(response) if desired_resolution is not None: - if len(desired_resolution) != 3: raise ValueError( "desired resolution needs to be of length 3, for xyz" @@ -1528,7 +1528,6 @@ def live_query( df = deserialize_query_response(response) if desired_resolution is not None: if not response.headers.get("dataframe_resolution", None): - if len(desired_resolution) != 3: raise ValueError( "desired resolution needs to be of length 3, for xyz" @@ -1761,9 +1760,9 @@ def _assemble_attributes( return attrs -class MaterializatonClientV3(MaterializatonClientV2): +class MaterializationClientV3(MaterializationClientV2): def __init__(self, *args, **kwargs): - super(MaterializatonClientV3, self).__init__(*args, **kwargs) + super(MaterializationClientV3, self).__init__(*args, **kwargs) @cached(cache=TTLCache(maxsize=100, ttl=60 * 60 * 12)) def get_tables_metadata( @@ -1962,7 +1961,6 @@ def live_live_query( df = deserialize_query_response(response) if desired_resolution is not None: if not response.headers.get("dataframe_resolution", None): - if len(desired_resolution) != 3: raise ValueError( "desired resolution needs to be of length 3, for xyz" @@ -2291,8 +2289,13 @@ def get_unique_string_values(self, table: str, datastack_name: str = None): return response.json() +# included for historical reasons, there was a typo in the class name +MaterializatonClientV2 = MaterializationClientV2 + +MaterializatonClientV3 = MaterializationClientV3 + client_mapping = { - 2: MaterializatonClientV2, - 3: MaterializatonClientV3, - "latest": MaterializatonClientV2, + 2: MaterializationClientV2, + 3: MaterializationClientV3, + "latest": MaterializationClientV2, } diff --git a/docs/guide/materialization.rst b/docs/guide/materialization.rst index afe04fbd..87606daf 100644 --- a/docs/guide/materialization.rst +++ b/docs/guide/materialization.rst @@ -5,7 +5,7 @@ The Materialization client allows one to interact with the materialized annotation tables, that were posted to the annotation service (see :doc:`annotation`). -To see the entire class visit the API doc :class:`~caveclient.materializationengine.MaterializatonClientV2` +To see the entire class visit the API doc :class:`~caveclient.materializationengine.MaterializationClientV2` The service regularly looks up all annotations and the segids underneath all the boundspatialpoints. You can then query these tables to find out @@ -30,7 +30,7 @@ materialization version available. This may or may not be desirable depending o use case. If your code involves using specific IDs then you should be using a specific version that is tied to a timepoint where those IDs are valid. -To see what versions are available, use the :func:`~caveclient.materializationengine.MaterializatonClientV2.get_versions` +To see what versions are available, use the :func:`~caveclient.materializationengine.MaterializationClientV2.get_versions` .. code:: python @@ -38,9 +38,9 @@ To see what versions are available, use the :func:`~caveclient.materializationen Each version has a timestamp it was run on as well as a date when it will expire. You can query all this metadata for a specific version using -:func:`~caveclient.materializationengine.MaterializatonClientV2.get_version_metadata` +:func:`~caveclient.materializationengine.MaterializationClientV2.get_version_metadata` or all versions using -:func:`~caveclient.materializationengine.MaterializatonClientV2.get_versions_metadata` +:func:`~caveclient.materializationengine.MaterializationClientV2.get_versions_metadata` To change the default version, alter the .version property of the materialization client. @@ -54,7 +54,7 @@ or specify the version when making a particular call. Browsing versions ^^^^^^^^^^^^^^^^^ To see what tables are available in a version you can use -:func:`~caveclient.materializationengine.MaterializatonClientV2.get_tables` +:func:`~caveclient.materializationengine.MaterializationClientV2.get_tables` If you want to read about the description of what that table is, use the annotationengine client :func:`~caveclient.annotationengine.AnnotationClientV2.get_table_metadata` @@ -79,7 +79,7 @@ To see how many annotations are in a particular table use Querying tables ^^^^^^^^^^^^^^^ To query a small table, you can just download the whole thing using -:func:`~caveclient.materializationengine.MaterializatonClientV2.query_table` +:func:`~caveclient.materializationengine.MaterializationClientV2.query_table` which will return a dataframe of the table. Note however, some tables, such as the synapse table might be very large 200-300 million rows @@ -149,7 +149,7 @@ You can also filter columns that are associated with spatial locations based upo This is done by adding a filter_spatial_dict argument to query_table. The units of the bounding box should be in the units of the voxel_resolution of the table -(which can be obtained from :func:`~caveclient.materializationengine.MaterializatonClientV2.get_table_metadata`). +(which can be obtained from :func:`~caveclient.materializationengine.MaterializationClientV2.get_table_metadata`). .. code:: python @@ -164,7 +164,7 @@ The units of the bounding box should be in the units of the voxel_resolution of Synapse Query ^^^^^^^^^^^^^ For synapses in particular, we have a simplified method for querying them with a reduced syntax. -:func:`~caveclient.materializationengine.MaterializatonClientV2.synapse_query` +:func:`~caveclient.materializationengine.MaterializationClientV2.synapse_query` lets you specify pre and post synaptic partners as keyword arguments and bounding boxes. The defaults make reasonable assumptions about what you want to query, namely that the synapse_table is the table that the info service advertises, and that if you specify a bounding box, that you want the post_pt_position. @@ -208,7 +208,7 @@ object in the most recent materialization. However, sometimes you might be browsing and proofreadding the data and get an ID that is more recent that the most recent version available. For convience, you can use -:func:`~caveclient.materializationengine.MaterializatonClientV2.live_query`. +:func:`~caveclient.materializationengine.MaterializationClientV2.live_query`. to automatically update the results of your query to a time in the future, such as now.