88NS_BASE = "https://neurostore.org/api"
99
1010
11+ class ContextSchema (Schema ):
12+ def __init__ (self , * args , ** kwargs ):
13+ context = kwargs .pop ("context" , {})
14+ super ().__init__ (* args , ** kwargs )
15+ self .context = context or {}
16+
17+
1118class BytesField (fields .Field ):
1219 def _deserialize (self , value , attr , data , ** kwargs ):
1320 if isinstance (value , str ):
@@ -29,7 +36,7 @@ def _deserialize(self, value, attr, data, **kwargs):
2936 return result .replace ("\x00 " , "\uFFFD " )
3037
3138
32- class ResultInitSchema (Schema ):
39+ class ResultInitSchema (ContextSchema ):
3340 meta_analysis_id = fields .String (load_only = True )
3441 meta_analysis = fields .Pluck (
3542 "MetaAnalysisSchema" , "id" , attribute = "meta_analysis" , dump_only = True
@@ -39,15 +46,15 @@ class ResultInitSchema(Schema):
3946 specification_snapshot = fields .Dict ()
4047
4148
42- class ResultUploadSchema (Schema ):
43- statistical_maps = fields .Raw (
44- metadata = {"type" : "string" , "format" : "binary" }, many = True
49+ class ResultUploadSchema (ContextSchema ):
50+ statistical_maps = fields .List (
51+ fields . Raw ( metadata = {"type" : "string" , "format" : "binary" })
4552 )
46- cluster_tables = fields .Raw (
47- metadata = {"type" : "string" , "format" : "binary" }, many = True
53+ cluster_tables = fields .List (
54+ fields . Raw ( metadata = {"type" : "string" , "format" : "binary" })
4855 )
49- diagnostic_tables = fields .Raw (
50- metadata = {"type" : "string" , "format" : "binary" }, many = True
56+ diagnostic_tables = fields .List (
57+ fields . Raw ( metadata = {"type" : "string" , "format" : "binary" })
5158 )
5259 method_description = fields .String ()
5360
@@ -59,6 +66,23 @@ class StringOrNested(fields.Nested):
5966 "invalid_utf8" : "Not a valid utf-8 string." ,
6067 }
6168
69+ def __init__ (self , nested , * args , ** kwargs ):
70+ super ().__init__ (nested , ** kwargs )
71+ self ._explicit_context = {}
72+
73+ @property
74+ def context (self ):
75+ if self ._explicit_context :
76+ return self ._explicit_context
77+ parent = getattr (self , "parent" , None )
78+ if parent is not None and hasattr (parent , "context" ):
79+ return parent .context
80+ return {}
81+
82+ @context .setter
83+ def context (self , value ):
84+ self ._explicit_context = value or {}
85+
6286 def _serialize (self , value , attr , obj , ** kwargs ):
6387 if value is None :
6488 return None
@@ -127,7 +151,7 @@ def _deserialize(self, value, attr, data, **kwargs):
127151 raise self .make_error ("invalid_utf8" ) from error
128152
129153
130- class BaseSchema (Schema ):
154+ class BaseSchema (ContextSchema ):
131155 id = PGSQLString (metadata = {"info_field" : True })
132156 created_at = fields .DateTime ()
133157 updated_at = fields .DateTime (allow_none = True )
@@ -137,7 +161,7 @@ class BaseSchema(Schema):
137161 )
138162
139163
140- class ConditionSchema (Schema ):
164+ class ConditionSchema (ContextSchema ):
141165 id = PGSQLString ()
142166 created_at = fields .DateTime ()
143167 updated_at = fields .DateTime (allow_none = True )
@@ -147,15 +171,15 @@ class ConditionSchema(Schema):
147171
148172class SpecificationConditionSchema (BaseSchema ):
149173 condition = fields .Pluck (ConditionSchema , "name" )
150- weight = fields .Number ()
174+ weight = fields .Float ()
151175
152176
153- class EstimatorSchema (Schema ):
177+ class EstimatorSchema (ContextSchema ):
154178 type = fields .String ()
155179 args = fields .Dict ()
156180
157181
158- class StudysetReferenceSchema (Schema ):
182+ class StudysetReferenceSchema (ContextSchema ):
159183 id = PGSQLString ()
160184 created_at = fields .DateTime ()
161185 updated_at = fields .DateTime (allow_none = True )
@@ -168,7 +192,7 @@ class StudysetReferenceSchema(Schema):
168192 )
169193
170194
171- class AnnotationReferenceSchema (Schema ):
195+ class AnnotationReferenceSchema (ContextSchema ):
172196 id = PGSQLString ()
173197
174198
@@ -177,6 +201,8 @@ class SpecificationSchema(BaseSchema):
177201 mask = PGSQLString (allow_none = True )
178202 transformer = PGSQLString (allow_none = True )
179203 estimator = fields .Nested ("EstimatorSchema" )
204+ name = PGSQLString (allow_none = True )
205+ description = PGSQLString (allow_none = True )
180206 database_studyset = PGSQLString (allow_none = True )
181207 contrast = PGSQLString (allow_none = True )
182208 filter = PGSQLString (allow_none = True )
@@ -208,10 +234,6 @@ class SpecificationSchema(BaseSchema):
208234 attribute = "weights" ,
209235 )
210236
211- class Meta :
212- additional = ("name" , "description" )
213- allow_none = ("name" , "description" )
214-
215237 @post_dump
216238 def to_bool (self , data , ** kwargs ):
217239 conditions = data .get ("conditions" , None )
0 commit comments