@@ -74,7 +74,7 @@ def __init__(
7474 self ,
7575 fetch_api : EcephysProjectApi = EcephysProjectWarehouseApi .default (),
7676 fetch_tries : int = 2 ,
77- stream_writer : Callable = write_from_stream ,
77+ stream_writer : Optional [ Callable ] = None ,
7878 manifest : Optional [Union [str , Path ]] = None ,
7979 version : Optional [str ] = None ,
8080 cache : bool = True ):
@@ -83,6 +83,9 @@ def __init__(
8383 summaries of sessionwise data and provides tools for downloading detailed
8484 sessionwise data (such as spike times).
8585
86+ To ensure correct configuration, it is recommended to use one of the
87+ class constructors rather than to initialize this class directly.
88+
8689 Parameters
8790 ==========
8891 fetch_api :
@@ -100,6 +103,14 @@ def __init__(
100103 fetch_tries : int
101104 Maximum number of times to attempt a download before giving up and
102105 raising an exception. Note that this is total tries, not retries
106+ stream_writer: Callable
107+ The method used to write from stream. Depends on whether the
108+ engine is synchronous or asynchronous. If not set, will use the
109+ `write_bytes` method native to the `fetch_api`'s `rma_engine`.
110+ If the method is incompatible with the `fetch_api`'s `rma_engine`,
111+ will likely encounter errors. For this reason it is recommended
112+ to leave this field unspecified, or to use one of the class
113+ constructors.
103114 manifest : str or Path
104115 full path at which manifest json will be stored (default =
105116 "ecephys_project_manifest.json" in the local directory.)
@@ -108,6 +119,43 @@ def __init__(
108119 recorded in the file at manifest, an error will be raised.
109120 cache: bool
110121 Whether to write to the cache (default=True)
122+
123+ Notes
124+ =====
125+ It is highly recommended to construct an instance of this class
126+ using one of the following constructor methods:
127+
128+ from_warehouse(scheme: Optional[str] = None,
129+ host: Optional[str] = None,
130+ asynchronous: bool = True,
131+ manifest: Optional[Union[str, Path]] = None,
132+ version: Optional[str] = None,
133+ cache: bool = True,
134+ fetch_tries: int = 2)
135+ Create an instance of EcephysProjectCache with an
136+ EcephysProjectWarehouseApi. Retrieves released data stored
137+ in the warehouse. Suitable for all users downloading
138+ published Allen Institute data.
139+ from_lims(lims_credentials: Optional[DbCredentials] = None,
140+ scheme: Optional[str] = None,
141+ host: Optional[str] = None,
142+ asynchronous: bool = True,
143+ manifest: Optional[str] = None,
144+ version: Optional[str] = None,
145+ cache: bool = True,
146+ fetch_tries: int = 2)
147+ Create an instance of EcephysProjectCache with an
148+ EcephysProjectLimsApi. Retrieves bleeding-edge data stored
149+ locally on Allen Institute servers. Suitable for internal
150+ users on-site at the Allen Institute or using the corporate
151+ vpn. Requires Allen Institute database credentials.
152+ fixed(manifest: Optional[Union[str, Path]] = None,
153+ version: Optional[str] = None)
154+ Create an instance of EcephysProjectCache that will only
155+ use locally stored data, downloaded previously from LIMS
156+ or warehouse using the EcephysProjectCache.
157+ Suitable for users who want to analyze a fixed dataset they
158+ have previously downloaded using EcephysProjectCache.
111159 """
112160 manifest_ = manifest or "ecephys_project_manifest.json"
113161 version_ = version or self .MANIFEST_VERSION
@@ -117,7 +165,24 @@ def __init__(
117165 cache = cache )
118166 self .fetch_api = fetch_api
119167 self .fetch_tries = fetch_tries
120- self .stream_writer = stream_writer
168+ self .stream_writer = (stream_writer
169+ or self .fetch_api .rma_engine .write_bytes )
170+ if stream_writer is not None :
171+ self .stream_writer = stream_writer
172+ else :
173+ if hasattr (self .fetch_api , "rma_engine" ): # EcephysProjectWarehouseApi # noqa
174+ self .stream_writer = self .fetch_api .rma_engine .write_bytes
175+ # TODO: Make these names consistent in the different fetch apis
176+ elif hasattr (self .fetch_api , "app_engine" ): # EcephysProjectLimsApi # noqa
177+ self .stream_writer = self .fetch_api .app_engine .write_bytes
178+ else :
179+ raise ValueError (
180+ "Must either set value for `stream_writer`, or use a "
181+ "`fetch_api` with an rma_engine or app_engine attribute "
182+ "that implements `write_bytes`. See `HttpEngine` and "
183+ "`AsyncHttpEngine` from "
184+ "allensdk.brain_observatory.ecephys.ecephys_project_api."
185+ "http_engine for examples." )
121186
122187 def _get_sessions (self ):
123188 path = self .get_cache_path (None , self .SESSIONS_KEY )
@@ -531,8 +596,8 @@ def _from_http_source_default(cls, fetch_api_cls, fetch_api_kwargs, **kwargs):
531596 def from_lims (cls , lims_credentials : Optional [DbCredentials ] = None ,
532597 scheme : Optional [str ] = None ,
533598 host : Optional [str ] = None ,
534- asynchronous : bool = True ,
535- manifest : Optional [str ] = None ,
599+ asynchronous : bool = False ,
600+ manifest : Optional [Union [ str , Path ] ] = None ,
536601 version : Optional [str ] = None ,
537602 cache : bool = True ,
538603 fetch_tries : int = 2 ):
@@ -557,7 +622,7 @@ def from_lims(cls, lims_credentials: Optional[DbCredentials] = None,
557622 value if unspecified. Will not be used unless `scheme` is
558623 also specified.
559624 asynchronous : bool
560- Whether to fetch file asynchronously. Defaults to True .
625+ Whether to fetch file asynchronously. Defaults to False .
561626 manifest : str or Path
562627 full path at which manifest json will be stored
563628 version : str
@@ -586,7 +651,7 @@ def from_lims(cls, lims_credentials: Optional[DbCredentials] = None,
586651 def from_warehouse (cls ,
587652 scheme : Optional [str ] = None ,
588653 host : Optional [str ] = None ,
589- asynchronous : bool = True ,
654+ asynchronous : bool = False ,
590655 manifest : Optional [Union [str , Path ]] = None ,
591656 version : Optional [str ] = None ,
592657 cache : bool = True ,
@@ -607,7 +672,7 @@ def from_warehouse(cls,
607672 value if unspecified. Will not be used unless `scheme` is also
608673 specified.
609674 asynchronous : bool
610- Whether to fetch file asynchronously. Defaults to True .
675+ Whether to fetch file asynchronously. Defaults to False .
611676 manifest : str or Path
612677 full path at which manifest json will be stored
613678 version : str
@@ -623,14 +688,15 @@ def from_warehouse(cls,
623688 app_kwargs = {"scheme" : scheme , "host" : host ,
624689 "asynchronous" : asynchronous }
625690 else :
626- app_kwargs = None
691+ app_kwargs = { "asynchronous" : asynchronous }
627692 return cls ._from_http_source_default (
628693 EcephysProjectWarehouseApi , app_kwargs , manifest = manifest ,
629694 version = version , cache = cache , fetch_tries = fetch_tries
630695 )
631696
632697 @classmethod
633- def fixed (cls , manifest = None , version = None ):
698+ def fixed (cls , manifest : Optional [Union [str , Path ]] = None ,
699+ version : Optional [str ] = None ):
634700 """
635701 Creates a EcephysProjectCache that refuses to fetch any data
636702 - only the existing local cache is accessible. Useful if you
@@ -701,5 +767,4 @@ def read_nwb(path):
701767 reader = pynwb .NWBHDF5IO (str (path ), 'r' )
702768 nwbfile = reader .read ()
703769 nwbfile .identifier # if the file is corrupt, make sure an exception gets raised during read
704- return nwbfile
705-
770+ return nwbfile
0 commit comments