Package pypower :: Module run_userfcn
[hide private]
[frames] | no frames]

Source Code for Module pypower.run_userfcn

 1  # Copyright (C) 2009-2011 Power System Engineering Research Center (PSERC) 
 2  # Copyright (C) 2011 Richard Lincoln 
 3  # 
 4  # PYPOWER is free software: you can redistribute it and/or modify 
 5  # it under the terms of the GNU General Public License as published 
 6  # by the Free Software Foundation, either version 3 of the License, 
 7  # or (at your option) any later version. 
 8  # 
 9  # PYPOWER is distributed in the hope that it will be useful, 
10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
12  # GNU General Public License for more details. 
13  # 
14  # You should have received a copy of the GNU General Public License 
15  # along with PYPOWER. If not, see <http://www.gnu.org/licenses/>. 
16   
17  """Runs the userfcn callbacks for a given stage. 
18  """ 
19   
20  from pypower.util import feval 
21   
22   
23 -def run_userfcn(userfcn, stage, *args):
24 """Runs the userfcn callbacks for a given stage. 25 26 Example:: 27 ppc = om.get_mpc() 28 om = run_userfcn(ppc['userfcn'], 'formulation', om) 29 30 @param userfcn: the 'userfcn' field of ppc, populated by L{add_userfcn} 31 @param stage: the name of the callback stage begin executed 32 (additional arguments) some stages require additional arguments. 33 34 @see: L{add_userfcn}, L{remove_userfcn}, L{toggle_reserves}, 35 L{toggle_iflims}, L{runopf_w_res}. 36 37 @author: Ray Zimmerman (PSERC Cornell) 38 @author: Richard Lincoln 39 """ 40 rv = args[0] 41 if (len(userfcn) > 0) and (stage in userfcn): 42 for k in range(len(userfcn[stage])): 43 if 'args' in userfcn[stage][k]: 44 args = userfcn[stage][k]['args'] 45 else: 46 args = [] 47 48 if stage in ['ext2int', 'formulation', 'int2ext']: 49 # ppc = userfcn_*_ext2int(ppc, args) 50 # om = userfcn_*_formulation(om, args) 51 # results = userfcn_*_int2ext(results, args) 52 rv = userfcn[stage][k]['fcn'](rv, args) 53 elif stage in ['printpf', 'savecase']: 54 # results = userfcn_*_printpf(results, fd, ppopt, args) 55 # ppc = userfcn_*_savecase(mpc, fd, prefix, args) 56 rv = feval(userfcn[stage][k]['fcn'], rv, args[1], args[2], args) 57 58 return rv
59