refnx/util/general.py
def slit_optimiser(
    footprint,
    resolution,
    angle=1.0,
    L12=2859.5,
    L2S=180,
    LS3=290.5,
    LSD=2500,
    verbose=True,
):
    """
    Optimise slit settings for a given angular resolution, and a given
    footprint.

    footprint: float
        maximum footprint onto sample (mm)
    resolution: float
        fractional dtheta/theta resolution (FWHM)
    angle: float, optional
        angle of incidence in degrees
    """
    if verbose:
        print("_____________________________________________")
        print("FOOTPRINT calculator - Andrew Nelson 2013")
        print("INPUT")
        print("footprint:", footprint, "mm")
        print("fractional angular resolution (FWHM):", resolution)
        print("theta:", angle, "degrees")

    def d1star(d2star):
        return np.sqrt(1 - np.power(d2star, 2))

    L1star = 0.68 * footprint / L12 / resolution

    def gseekfun(d2star):
        return np.power(
            (d2star + L2S / L12 * (d2star + d1star(d2star))) - L1star, 2
        )

    res = optimize.minimize_scalar(gseekfun, method="bounded", bounds=(0, 1))
    if res["success"] is False:
        print("ERROR: Couldnt find optimal solution, sorry")
        return None

    optimal_d2star = res["x"]
    optimal_d1star = d1star(optimal_d2star)
    if optimal_d2star > optimal_d1star:
        # you found a minimum, but this may not be the optimum size of the
        # slits.
        multfactor = 1
        optimal_d2star = 1 / np.sqrt(2)
        optimal_d1star = 1 / np.sqrt(2)
    else:
        multfactor = optimal_d2star / optimal_d1star

    d1 = optimal_d1star * resolution / 0.68 * np.radians(angle) * L12
    d2 = d1 * multfactor

    tmp, height_at_S4 = height_of_beam_after_dx(d1, d2, L12, L2S + LS3)
    tmp, height_at_detector = height_of_beam_after_dx(d1, d2, L12, L2S + LSD)
    tmp, _actual_footprint = actual_footprint(d1, d2, L12, L2S, angle)

    if verbose:
        print("OUTPUT")
        if multfactor == 1:
            print(
                "Your desired resolution results in a smaller footprint than"
                " the sample supports."
            )
            suggested_resolution = resolution * footprint / _actual_footprint
            print(
                "You can increase flux using a resolution of",
                suggested_resolution,
                "and still keep the same footprint.",
            )
        print("d1", d1, "mm")
        print("d2", d2, "mm")
        print("footprint:", _actual_footprint, "mm")
        print("height at S4:", height_at_S4, "mm")
        print("height at detector:", height_at_detector, "mm")
        print("[d2star", optimal_d2star, "]")
        print("_____________________________________________")

    return d1, d2

    Optimise slit settings for a given angular resolution, and a given
    footprint.

    footprint: float
        maximum footprint onto sample (mm)
    resolution: float
        fractional dtheta/theta resolution (FWHM)
    angle: float, optional
        angle of incidence in degrees
    
Optimise slit settings for a given angular resolution, and a given
footprint.

float
maximum footprint onto sample (mm)
resolution: float
fractional dtheta/theta resolution (FWHM)
angle: float, optional
angle of incidence in degrees
Optimise slit settings for a given angular resolution and a given footprint . float maximum footprint onto sample ( mm ) resolution : float fractional dtheta / theta resolution ( FWHM ) angle : float optional angle of incidence in degrees
def slit_optimiser(
    footprint,
    resolution,
    angle=1.0,
    L12=2859.5,
    L2S=180,
    LS3=290.5,
    LSD=2500,
    verbose=True,
):
    if verbose:
        print("_____________________________________________")
        print("FOOTPRINT calculator - Andrew Nelson 2013")
        print("INPUT")
        print("footprint:", footprint, "mm")
        print("fractional angular resolution (FWHM):", resolution)
        print("theta:", angle, "degrees")
    def d1star(d2star):
        return np.sqrt(1 - np.power(d2star, 2))
    L1star = 0.68 * footprint / L12 / resolution
    def gseekfun(d2star):
        return np.power(
            (d2star + L2S / L12 * (d2star + d1star(d2star))) - L1star, 2
        )
    res = optimize.minimize_scalar(gseekfun, method="bounded", bounds=(0, 1))
    if res["success"] is False:
        print("ERROR: Couldnt find optimal solution, sorry")
        return None
    optimal_d2star = res["x"]
    optimal_d1star = d1star(optimal_d2star)
    if optimal_d2star > optimal_d1star:
        multfactor = 1
        optimal_d2star = 1 / np.sqrt(2)
        optimal_d1star = 1 / np.sqrt(2)
    else:
        multfactor = optimal_d2star / optimal_d1star
    d1 = optimal_d1star * resolution / 0.68 * np.radians(angle) * L12
    d2 = d1 * multfactor
    tmp, height_at_S4 = height_of_beam_after_dx(d1, d2, L12, L2S + LS3)
    tmp, height_at_detector = height_of_beam_after_dx(d1, d2, L12, L2S + LSD)
    tmp, _actual_footprint = actual_footprint(d1, d2, L12, L2S, angle)
    if verbose:
        print("OUTPUT")
        if multfactor == 1:
            print(
                "Your desired resolution results in a smaller footprint than"
                " the sample supports."
            )
            suggested_resolution = resolution * footprint / _actual_footprint
            print(
                "You can increase flux using a resolution of",
                suggested_resolution,
                "and still keep the same footprint.",
            )
        print("d1", d1, "mm")
        print("d2", d2, "mm")
        print("footprint:", _actual_footprint, "mm")
        print("height at S4:", height_at_S4, "mm")
        print("height at detector:", height_at_detector, "mm")
        print("[d2star", optimal_d2star, "]")
        print("_____________________________________________")
    return d1, d2
def slit_optimiser ( footprint , resolution , angle = 1.0 , L12 = 2859.5 , L2S = 180 , LS3 = 290.5 , LSD = 2500 , verbose = True , ) : if verbose : print ( "_____________________________________________" ) print ( "FOOTPRINT calculator - Andrew Nelson 2013" ) print ( "INPUT" ) print ( "footprint:" , footprint , "mm" ) print ( "fractional angular resolution (FWHM):" , resolution ) print ( "theta:" , angle , "degrees" ) def d1star ( d2star ) : return np . sqrt ( 1 - np . power ( d2star , 2 ) ) L1star = 0.68 * footprint / L12 / resolution def gseekfun ( d2star ) : return np . power ( ( d2star + L2S / L12 * ( d2star + d1star ( d2star ) ) ) - L1star , 2 ) res = optimize . minimize_scalar ( gseekfun , method = "bounded" , bounds = ( 0 , 1 ) ) if res [ "success" ] is False : print ( "ERROR: Couldnt find optimal solution, sorry" ) return None optimal_d2star = res [ "x" ] optimal_d1star = d1star ( optimal_d2star ) if optimal_d2star > optimal_d1star : multfactor = 1 optimal_d2star = 1 / np . sqrt ( 2 ) optimal_d1star = 1 / np . sqrt ( 2 ) else : multfactor = optimal_d2star / optimal_d1star d1 = optimal_d1star * resolution / 0.68 * np . radians ( angle ) * L12 d2 = d1 * multfactor tmp , height_at_S4 = height_of_beam_after_dx ( d1 , d2 , L12 , L2S + LS3 ) tmp , height_at_detector = height_of_beam_after_dx ( d1 , d2 , L12 , L2S + LSD ) tmp , _actual_footprint = actual_footprint ( d1 , d2 , L12 , L2S , angle ) if verbose : print ( "OUTPUT" ) if multfactor == 1 : print ( "Your desired resolution results in a smaller footprint than" " the sample supports." ) suggested_resolution = resolution * footprint / _actual_footprint print ( "You can increase flux using a resolution of" , suggested_resolution , "and still keep the same footprint." , ) print ( "d1" , d1 , "mm" ) print ( "d2" , d2 , "mm" ) print ( "footprint:" , _actual_footprint , "mm" ) print ( "height at S4:" , height_at_S4 , "mm" ) print ( "height at detector:" , height_at_detector , "mm" ) print ( "[d2star" , optimal_d2star , "]" ) print ( "_____________________________________________" ) return d1 , d2
Optimise slit settings for a given angular resolution, and a given
footprint.
Optimise slit settings for a given angular resolution and a given footprint .
"""
    Optimise slit settings for a given angular resolution, and a given
    footprint.

    footprint: float
        maximum footprint onto sample (mm)
    resolution: float
        fractional dtheta/theta resolution (FWHM)
    angle: float, optional
        angle of incidence in degrees
    """ # you found a minimum, but this may not be the optimum size of the # slits.
footprint
resolution
angle
L12
L2S
LS3
LSD
verbose