@@ -161,9 +161,8 @@ def inst_distribution(self):
161161 # Use this special formatting to bypass missing keys
162162 return string .Formatter ().vformat (self .distribution , (), dist_dict )
163163
164- def eval_dist (self , values , distance ):
165- """Create the final dist string"""
166-
164+ def scale_dict (self , values , distance ):
165+ """Create scale disctionary"""
167166 scale_dict = {}
168167 if isinstance (values , dict ):
169168 for k , v in values .items ():
@@ -172,6 +171,12 @@ def eval_dist(self, values, distance):
172171 scale_dict ["value" ] = format_float (values )
173172 scale_dict ["distance" ] = format_float (distance )
174173
174+ return scale_dict
175+
176+ def eval_dist (self , values , distance ):
177+ """Create the final dist string"""
178+ scale_dict = self .scale_dict (values , distance )
179+
175180 return self .inst_distribution .format (** scale_dict )
176181
177182 def scale (self , values , segment , sim = None ):
@@ -262,3 +267,51 @@ def acc_scale_iexpr(self, value, constant_formatter=format_float):
262267 ArbFileMorphology .region_labels ['somatic' ].ref
263268 )
264269 return generate_acc_scale_iexpr (iexpr , variables , constant_formatter )
270+
271+
272+ class NrnSegmentSomaDistanceStepScaler (NrnSegmentSomaDistanceScaler ,
273+ ParameterScaler , DictMixin ):
274+
275+ """Scaler based on distance from soma with a step function"""
276+ SERIALIZED_FIELDS = ('name' , 'comment' , 'distribution' , )
277+
278+ def __init__ (
279+ self ,
280+ name = None ,
281+ distribution = None ,
282+ comment = '' ,
283+ dist_param_names = None ,
284+ soma_ref_location = 0.5 ,
285+ step_begin = None ,
286+ step_end = None ):
287+ """Constructor
288+ Args:
289+ name (str): name of this object
290+ distribution (str): distribution of parameter dependent on distance
291+ from soma. string can contain `distance` and/or `value` as
292+ placeholders for the distance to the soma and parameter value
293+ respectivily
294+ dist_param_names (list): list of names of parameters that
295+ parametrise the distribution. These names will become
296+ attributes of this object.
297+ The distribution string should contain these names, and they
298+ will be replaced by values of the corresponding attributes
299+ soma_ref_location (float): location along the soma used as origin
300+ from which to compute the distances. Expressed as a fraction
301+ (between 0.0 and 1.0).
302+ step_begin (float): distance at which the step begins
303+ step_end (float): distance at which the step ends
304+ """
305+
306+ super (NrnSegmentSomaDistanceStepScaler , self ).__init__ (
307+ name , distribution , comment , dist_param_names ,
308+ soma_ref_location = soma_ref_location )
309+ self .step_begin = step_begin
310+ self .step_end = step_end
311+
312+ def scale_dict (self , values , distance ):
313+ scale_dict = super ().scale_dict (values , distance )
314+ scale_dict ["step_begin" ] = self .step_begin
315+ scale_dict ["step_end" ] = self .step_end
316+
317+ return scale_dict
0 commit comments