@@ -116,10 +116,7 @@ class CurrentClampSeries(PatchClampSeries):
116116 'default' : 'volts' })
117117 def __init__ (self , ** kwargs ):
118118 name , data , unit , electrode , gain = popargs ('name' , 'data' , 'unit' , 'electrode' , 'gain' , kwargs )
119- if unit != 'volts' :
120- warnings .warn ("Unit for %s '%s' is ignored and will be set to 'volts' as per NWB 2.1.0."
121- % (self .__class__ .__name__ , name ))
122- unit = 'volts'
119+ unit = ensure_unit (self , name , unit , 'volts' , '2.1.0' )
123120 bias_current , bridge_balance , capacitance_compensation = popargs (
124121 'bias_current' , 'bridge_balance' , 'capacitance_compensation' , kwargs )
125122 super ().__init__ (name , data , unit , electrode , gain , ** kwargs )
@@ -170,10 +167,7 @@ class CurrentClampStimulusSeries(PatchClampSeries):
170167 'default' : 'amperes' })
171168 def __init__ (self , ** kwargs ):
172169 name , data , unit , electrode , gain = popargs ('name' , 'data' , 'unit' , 'electrode' , 'gain' , kwargs )
173- if unit != 'amperes' :
174- warnings .warn ("Unit for %s '%s' is ignored and will be set to 'amperes' as per "
175- "NWB 2.1.0." % (self .__class__ .__name__ , name ))
176- unit = 'amperes'
170+ unit = ensure_unit (self , name , unit , 'amperes' , '2.1.0' )
177171 super ().__init__ (name , data , unit , electrode , gain , ** kwargs )
178172
179173
@@ -209,10 +203,7 @@ class VoltageClampSeries(PatchClampSeries):
209203 'default' : 'amperes' })
210204 def __init__ (self , ** kwargs ):
211205 name , data , unit , electrode , gain = popargs ('name' , 'data' , 'unit' , 'electrode' , 'gain' , kwargs )
212- if unit != 'amperes' :
213- warnings .warn ("Unit for %s '%s' is ignored and will be set to 'amperes' as per NWB 2.1.0."
214- % (self .__class__ .__name__ , name ))
215- unit = 'amperes'
206+ unit = ensure_unit (self , name , unit , 'amperes' , '2.1.0' )
216207 capacitance_fast , capacitance_slow , resistance_comp_bandwidth , resistance_comp_correction , \
217208 resistance_comp_prediction , whole_cell_capacitance_comp , whole_cell_series_resistance_comp = popargs (
218209 'capacitance_fast' , 'capacitance_slow' , 'resistance_comp_bandwidth' ,
@@ -245,10 +236,7 @@ class VoltageClampStimulusSeries(PatchClampSeries):
245236 'default' : 'volts' })
246237 def __init__ (self , ** kwargs ):
247238 name , data , unit , electrode , gain = popargs ('name' , 'data' , 'unit' , 'electrode' , 'gain' , kwargs )
248- if unit != 'volts' :
249- warnings .warn ("Unit for %s '%s' is ignored and will be set to 'volts' as per "
250- "NWB 2.1.0." % (self .__class__ .__name__ , name ))
251- unit = 'volts'
239+ unit = ensure_unit (self , name , unit , 'volts' , '2.1.0' )
252240 super ().__init__ (name , data , unit , electrode , gain , ** kwargs )
253241
254242
@@ -309,3 +297,17 @@ def __get_row_ids(self, sweep_number):
309297 """
310298
311299 return [index for index , elem in enumerate (self ['sweep_number' ].data ) if elem == sweep_number ]
300+
301+
302+ def ensure_unit (self , name , current_unit , unit , nwb_version ):
303+ """A helper to ensure correct unit used.
304+
305+ Issues a warning with details if `current_unit` is to be ignored, and
306+ `unit` to be used instead.
307+ """
308+ if current_unit != unit :
309+ warnings .warn (
310+ "Unit '%s' for %s '%s' is ignored and will be set to '%s' "
311+ "as per NWB %s."
312+ % (current_unit , self .__class__ .__name__ , name , unit , nwb_version ))
313+ return unit
0 commit comments