How_can_I_obtain_the_value_of_a_MeqParm_for_use_in_my_MeqTree_script?
Gijs Molenaar edited this page Feb 13, 2014
·
2 revisions
I would like to be able to write a script containing something like
ns.parm << ....
if Meq.Abs(ns.parm) > 0:
do this
else:
do that
Here the parm has a single value which is constant over time and frequency.
Does MeqTrees let me do something like the above?
Answer from Sarod: Here is a little utility function that will do what you want:
#
# utility to extract the default parms (if any) of a given MeqParm
# node. It will return the following in the given order, if they
# exist.
# 1. default_value
# 2. First coefficient of init_funklet
# 3. First coefficient of funklet
# 4. 0.0
def get_default_parms(nd):
# get initrec
irec=nd.initrec()
#print irec
# try to get default_value
if irec.has_key('default_value'):
cf=irec['default_value']
# this need to be a scalar
if cf.nelements()>=1:
#my_val=cf.tolist().pop(0)
my_val=numarray.ravel(cf)[0]
else: #scalar
my_val=float(cf)
elif irec.has_key('init_funklet'):
# get coeff array (or scalar)
fn=irec['init_funklet']
if(is_meqpolc(fn)):
cf=fn['coeff']
if cf.nelements()>=1:
my_val=numarray.ravel(cf)[0]
else: #scalar
my_val=float(cf)
elif(is_meqpolclog(fn)):
cf=fn['coeff']
if cf.nelements()>=1:
my_val=numarray.ravel(cf)[0]
else: #scalar
my_val=float(cf)
# return exponent
my_val=math.pow(10,my_val)
else: # error
print "WARNING: unable to find a value for funklet",fn
my_val=-1
else: # error
my_val=-1
return my_val
You can use it like
value = get_default_parms(ns.parm)
if value > 0:
etc
NOTE: According to Oleg, this solution will only work for compile-time values: you get out what you put in there to begin with. A new node needs to be developed for run-time decision making.