Commit 20c8e3e6 authored by Smith, Robert's avatar Smith, Robert
Browse files

Added Example Custom Model/Constraint Functions

Added example function files for QClimax. DeltaCustom is a model
function while FirstOrderSphericalBessel is a constraint function.
parent 541aca88
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
import numpy as np

def DeltaCustom(parameters, parameter_names, x, resolution, Q):
    """Calculate the Elastic line for values within +/- 100 of the peak maximum.
        Parameters:
        0: Center
        1: Amplitude
    """
    
    xx0 = parameters[parameter_names[0]].value
    AMP = parameters[parameter_names[1]].value
    
    delta=np.zeros(len(x))
    
    jlower = 0
    jupper = len(x) - 1
    
    while (jupper - jlower > 1 ):
        jmedium = (jupper+jlower) >> 1 
        if ( xx0 >= x[jmedium]):
            jlower = jmedium
        else:
            jupper = jmedium
    delta[jupper] = (xx0 - x[jlower])/(x[jupper] - x[jlower])        
    delta[jlower] = (x[jupper] - xx0)/(x[jupper] - x[jlower]) 
    
    delta[jupper] = delta[jupper] * AMP / (x[jupper] - x[jlower])
    delta[jlower] = delta[jlower] * AMP / (x[jupper] - x[jlower])
    
    """
    
    idx = (np.abs(x-xx0)).argmin()
    pirulo=(x[idx]-xx0)/(x[idx+1]-x[idx])

    if pirulo>0:
        delta[idx-1]=pirulo
        delta[idx]=1-pirulo
    else:
        delta[idx]=1+pirulo
        delta[idx+1]=-pirulo        
    """
    
    return delta

def get_parameters():
    """Returns the string description of the parameters for this function. The strings start with the parameter name, then
    followed by a comma are keyword arguments in the form "keyword=value", separated by commas. This function must return at
    least one keyword argument in the string, "value", to set the initial value. Example: "center,value=0.5"
    
    """
    
    return "cen,value=0.0,min=-3900,max=3900 amp,value=1.0,min=0.0,vary=True"
+4 −0
Original line number Diff line number Diff line
def FirstOrderSphericalBessel(symtable, X, sin, cos):
    """Performs the first order spherical bessel function on the given variable.
    """
    return (sin(X) / (X**2)) - (cos(X) / X)