示例#1
0
def subtract_background(spec, backp, backm):
    # type: (ReflData, ReflData, ReflData) -> (np.ndarray, np.ndarray)
    """
    Subtract back+ and back- from spec.

    if *offset* is 'auto', guess alignment.

    Interpolates background measurements to align with the specular.  If a
    different interpolation is required, then do so before subtract_background
    so that interp does nothing herein.

    Returns I, varI
    """
    #print "%s - (%s+%s)/2"%(spec.name, (backp.name if backp else "none"), (backm.name if backm else "none"))
    spec_v = U(spec.v, spec.dv**2)
    backp_v = U(backp.v, backp.dv**2) if backp else None
    backm_v = U(backm.v, backm.dv**2) if backm else None

    #print "spec",spec_v,spec.v,spec.dv
    #if backp: print "back+",backp_v,backp.v,backp.dv
    #if backm: print "back-",backm_v,backm.v,backm.dv

    backp_v = interp(_ordinate(spec), _ordinate(backp), backp_v) if backp else None
    backm_v = interp(_ordinate(spec), _ordinate(backm), backm_v) if backm else None

    if backp and backm:
        spec_v -= (backp_v + backm_v)/2
    elif backp:
        spec_v -= backp_v
    elif backm:
        spec_v -= backm_v
    else:
        pass  # no background to subtract

    return spec_v.x, spec_v.variance
示例#2
0
def _apply_footprint(data, footprint):
    refl = U(data.v, data.dv**2)
    # Ignore footprint <= 0
    bad_correction = (footprint.x <= 0.)  # type: np.ndarray
    if bad_correction.any():
        footprint = copy(footprint)
        footprint.x = copy(footprint.x)
        footprint.x[bad_correction] = 1.0
        footprint.variance[bad_correction] = 0.0
    corrected_refl = refl / footprint
    data.v, data.dv = corrected_refl.x, corrected_refl.dx
示例#3
0
def apply_abinitio_footprint(data, Io, width, offset):
    slit1 = (data.slit1.distance, data.slit1.x, data.slit1.y)
    slit2 = (data.slit2.distance, data.slit2.x, data.slit2.y)
    theta = data.sample.angle_x
    if width is None:
        width = data.sample.width
    if offset is None:
        offset = 0.
    if Io is None:
        Io = 1.
    y = Io * _abinitio_footprint(slit1, slit2, theta, width, offset)
    footprint = U(y, 0.0 * y)
    _apply_footprint(data, footprint)
示例#4
0
def _generate_footprint_curve(p, dp, x, xmin, xmax):
    """
    Return the footprint correction for the fitted footprint *p*, *dp*.

    The footprint is calculated at the measured points *x*, and applied
    between *xmin* and *xmax*.
    """
    ## order min and max correctly
    xmin, xmax = abs(xmin), abs(xmax)
    if xmin > xmax:
        xmin, xmax = xmax, xmin

    ## linear between Qmin and Qmax
    y = polyval(p, abs(x))
    var_y = polyval(dp**2, x**2)

    ## ignore values below Qmin
    y[abs(x) < xmin] = 1.
    var_y[abs(x) < xmin] = 0.
    ## stretch Qmax to the end of the range
    y[abs(x) > xmax] = polyval(p, xmax)
    var_y[abs(x) > xmax] = polyval(dp**2, xmax**2)

    return U(y, var_y)
示例#5
0
def apply_measured_footprint(data, measured_footprint):
    x = measured_footprint.Qz
    y = U(measured_footprint.v, measured_footprint.dv**2)
    footprint = interp(data.Qz, x, y, left=U(1.0, 0.0), right=U(1.0, 0.0))
    _apply_footprint(data, footprint)