<s> import numpy as np <EOL> from scipy . signal import deconvolve <EOL> from larch import ValidateLarchPlugin , parse_group_args <EOL> from larch_plugins . math import ( gaussian , lorentzian , _interp , <EOL> index_of , index_nearest , remove_dups ) <EOL> from larch_plugins . xafs import set_xafsGroup <EOL> MODNAME = '<STR_LIT>' <EOL> @ ValidateLarchPlugin <EOL> def xas_deconvolve ( energy , norm = None , group = None , form = '<STR_LIT>' , <EOL> esigma = <NUM_LIT:1.0> , eshift = <NUM_LIT:0.0> , _larch = None ) : <EOL> """<STR_LIT>""" <EOL> if _larch is None : <EOL> raise Warning ( "<STR_LIT>" ) <EOL> energy , mu , group = parse_group_args ( energy , members = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> defaults = ( norm , ) , group = group , <EOL> fcn_name = '<STR_LIT>' ) <EOL> eshift = eshift + <NUM_LIT:0.5> * esigma <EOL> en = remove_dups ( energy ) <EOL> en = en - en [ <NUM_LIT:0> ] <EOL> estep = max ( <NUM_LIT> , <NUM_LIT> * int ( min ( en [ <NUM_LIT:1> : ] - en [ : - <NUM_LIT:1> ] ) * <NUM_LIT> ) ) <EOL> npts = <NUM_LIT:1> + int ( max ( en ) / estep ) <EOL> x = np . arange ( npts ) * estep <EOL> y = _interp ( en , mu , x , kind = '<STR_LIT>' , _larch = _larch ) <EOL> kernel = gaussian <EOL> if form . lower ( ) . startswith ( '<STR_LIT>' ) : <EOL> kernel = lorentzian <EOL> yext = np . concatenate ( ( y , np . arange ( len ( y ) ) * y [ - <NUM_LIT:1> ] ) ) <EOL> ret , err = deconvolve ( yext , kernel ( x , <NUM_LIT:0> , esigma ) ) <EOL> nret = min ( len ( x ) , len ( ret ) ) <EOL> ret = ret [ : nret ] * yext [ nret - <NUM_LIT:1> ] / ret [ nret - <NUM_LIT:1> ] <EOL> out = _interp ( x + eshift , ret , en , kind = '<STR_LIT>' , _larch = _larch ) <EOL> group = set_xafsGroup ( group , _larch = _larch ) <EOL> group . deconv = out <EOL> def registerLarchPlugin ( ) : <EOL> return ( MODNAME , { '<STR_LIT>' : xas_deconvolve } ) </s>
