Exemplo n.º 1
0
def main():

    print("""
    --------------------------------------------------------------
    Example file for using PyKat to automate Finesse simulations
    Finesse: http://www.gwoptics.org/finesse
    PyKat:   http://www.gwoptics.org/pykat

    The file runs through the various Finesse simulations
    to generate the Finesse results reported in the document:
    `Comparing Finesse simulations, analytical solutions and OSCAR 
    simulations of Fabry-Perot alignment signals', LIGO-T1300345,
    freely available online: http://arxiv.org/abs/1401.5727

    Run this file after master2.py to create data which can be
    plotted using master3_plot.py. Results are saved after 
    each step and plots can be created at any time.
    
    Andreas Freise 16.01.2014    
    --------------------------------------------------------------
    """)

    # shall we clear the workspace?
    # %reset -f

    # making these global during testing and debugging
    #global kat, out

    kat = finesse.kat(tempdir=".", tempname="test")
    kat.verbose = False

    tmpresultfile = 'myshelf2.dat'

    # loading data saved by master.py
    kat.loadKatFile('asc_base3.kat')
    try:
        with open(tmpresultfile, 'rb') as handle:
            result = pickle.load(handle)
    except:
        raise Exception(
            "Could not open temprary results file {0}".format(tmpresultfile))

    kat.PDrefl_q.enabled = False
    kat.WFS1_Q.enabled = False
    kat.WFS2_Q.enabled = False

    print("--------------------------------------------------------")
    print(" 9. ASC signals for large misalignments (ITM)")
    asc_large(kat, 'ITM')

    print("--------------------------------------------------------")
    print(" 10. ASC signals for large misalignments (ETM)")
    asc_large(kat, 'ETM')
Exemplo n.º 2
0
def test_string(_str):
    kat = finesse.kat()  # create a fresh cat object
    _str = _str.strip()
    kat.parse(_str)

    # remove extra kat info produced by pykat
    katfile = ''.join(kat.generateKatScript()[1:-1]).strip()
    try:
        assert katfile == _str
    except AssertionError as e:
        print('Input string {} does not match output string {}'.format(
            _str, katfile))
        raise e
def simulation_and_save(filename):
    kat = finesse.kat()  # create a fresh cat object
    kat.verbose = verbose
    kat.parse("""
    l laser 1 0 n0
    s s_in 0.1 n0 n1
    m m_in 0.99 0.01 0 n1 n2
    s s_1 1 n2 n3
    m m_c 0.5 0.5 0 n3 n4
    s s_2 1 n4 n5
    m m_out 0.99 0.01 0 n5 n6
    pd trans n6
    xaxis m_in phi lin 0 180 360
    x2axis m_out phi lin 0 180 360
    """)
    out = kat.run()
    out.saveKatRun(filename + '.katrun')
Exemplo n.º 4
0
def main():
    print("""
        --------------------------------------------------------------
        Template file for using PyKat to automate Finesse simulations
        Finesse: http://www.gwoptics.org/finesse
        PyKat:   http://www.gwoptics.org/pykat
                
        Andreas Freise 19.05.2015
        --------------------------------------------------------------
        """)

    # for debugging we might need to see the temporay file:
    global kat
    kat = finesse.kat(tempdir=".", tempname="test")
    kat.verbose = False
    code1 = """
		l l1 1 0 0 n1
		s s1 1 n1 n2
		pd power n2
		xaxis l1 P lin 1 2 4
		"""
    kat.parseKatCode(code1)
    out = kat.run()
    print("result = {}".format(out.y))
s cav1 $test n2 n3
m m2 0.99 0.01 -0.1 n3 n4

attr m2 m 1  # mech sus1

const test 1200
ad up_refl 0 n1
ad low_refl 0 n1

qd refl_A 0 0 n1
qd refl_Q 0 90 n1
qd tran_A 0 0 n4
qd tran_Q 0 90 n4

put up_refl f $x1
put low_refl f $mx1

yaxis log re:im

fsig noise 1
"""

kat = finesse.kat(kat_code=code)

kat.signals.apply(kat.l1.P, 1, 0)
kat.signals.apply(kat.m1.phi, 1, 90)

kat.add(xaxis('log', [1, 1000], kat.signals.f, 100))

out = kat.run(printout=0, printerr=0)
Exemplo n.º 6
0
def make_kat(katfile=None,
             verbose=False,
             debug=False,
             keepComments=False,
             preserveConstants=False):
    """
    Returns a kat object and fills in the kat.IFO property for storing
    the associated interferometer data.

    keepComments: If true it will keep the original comments from the file
    preserveComments: If true it will keep the const commands in the kat
    """
    names = ['design']

    if debug:
        kat = finesse.kat(tempdir=".", tempname="test")
    else:
        kat = finesse.kat()

    kat.verbose = verbose

    # Create empty object to just store whatever DOFs, port, variables in
    # that will be used by processing functions
    kat.IFO = APLUS_IFO(
        kat,
        # Define which keys are used for a tuning description
        ["maxtem", "phase"],
        # Define which mirrors create the tuning description
        ["PRM", "ITMX", "ETMX", "ITMY", "ETMY", "BS", "SRM"])

    kat.IFO._data_path = pkg_resources.resource_filename(
        'pykat.ifo', os.path.join('aplus', 'files'))

    kat.IFO.rawBlocks = BlockedKatFile()

    if katfile:
        kat.load(katfile,
                 keepComments=keepComments,
                 preserveConstants=preserveConstants)
        kat.IFO.rawBlocks.read(katfile)
    else:
        katkile = os.path.join(kat.IFO._data_path, "design.kat")

        kat.load(katkile,
                 keepComments=keepComments,
                 preserveConstants=preserveConstants)
        kat.IFO.rawBlocks.read(katkile)

    # ----------------------------------------------------------------------
    # get and derive parameters from the kat file

    # get main frequencies
    if "f1" in kat.constants.keys():
        kat.IFO.f1 = float(kat.constants["f1"].value)
    else:
        kat.IFO.f1 = 9099471.0

    if "f2" in kat.constants.keys():
        kat.IFO.f2 = float(kat.constants["f2"].value)
    else:
        kat.IFO.f2 = 5.0 * kat.IFO.f1

    # TODO add else here!
    # check modultion frequencies
    if (5 * kat.IFO.f1 != kat.IFO.f2):
        print(" ** Warning: modulation frequencies do not match: 5*f1!=f2")

    # defining a dicotionary for the main mirror positions (tunings),
    # keys should include maxtem, phase and all main optics names
    #kat.IFO.tunings = get_tunings(dict.fromkeys(["maxtem", "phase", "PRM", "ITMX", "ETMX", "ITMY", "ETMY", "BS", "SRM"]))
    kat.IFO.compute_derived_lengths()

    # ----------------------------------------------------------------------
    # define ports and signals

    # useful ports
    kat.IFO.POP_f1 = Output(kat.IFO, "POP_f1", "nPOP", "f1", phase=101)
    kat.IFO.POP_f2 = Output(kat.IFO, "POP_f2", "nPOP", "f2", phase=13)
    kat.IFO.REFL_f1 = Output(kat.IFO, "REFL_f1", "nREFL", "f1", phase=101)
    kat.IFO.REFL_f2 = Output(kat.IFO, "REFL_f2", "nREFL", "f2", phase=14)

    kat.IFO.AS_DC = Output(kat.IFO, "AS_DC", "nAS")
    kat.IFO.AS_f1 = Output(kat.IFO, "AS_f1", "nAS", "f1", phase=101)
    kat.IFO.AS_f2 = Output(kat.IFO, "AS_f2", "nAS", "f2", phase=14)
    kat.IFO.AS_f36 = Output(kat.IFO, "AS_f36", "nAS", "f36M", phase=14)

    kat.IFO.BHD = Output(kat.IFO, "BHD", ["nBHD1", "nBHD2"])
    kat.IFO.POW_BS = Output(kat.IFO, "PowBS", "nPRBS*")
    kat.IFO.POW_X = Output(kat.IFO, "PowX", "nITMX2")
    kat.IFO.POW_Y = Output(kat.IFO, "PowY", "nITMY2")
    kat.IFO.TRX = Output(kat.IFO, "TRX", "nETMX2")
    kat.IFO.TRY = Output(kat.IFO, "TRY", "nETMY2")

    # pretune LSC DOF
    kat.IFO.preARMX = DOF(kat.IFO,
                          "ARMX",
                          kat.IFO.POW_X,
                          "",
                          "ETMX",
                          1,
                          1.0,
                          sigtype="z")
    kat.IFO.preARMY = DOF(kat.IFO,
                          "ARMY",
                          kat.IFO.POW_Y,
                          "",
                          "ETMY",
                          1,
                          1.0,
                          sigtype="z")
    kat.IFO.preMICH = DOF(kat.IFO,
                          "AS",
                          kat.IFO.AS_DC,
                          "", ["ITMX", "ETMX", "ITMY", "ETMY"], [1, 1, -1, -1],
                          6.0,
                          sigtype="z")
    kat.IFO.prePRCL = DOF(kat.IFO,
                          "PRCL",
                          kat.IFO.POW_BS,
                          "",
                          "PRM",
                          1,
                          10.0,
                          sigtype="z")
    kat.IFO.preSRCL = DOF(kat.IFO,
                          "SRCL",
                          kat.IFO.AS_DC,
                          "",
                          "SRM",
                          1,
                          10.0,
                          sigtype="z")

    # Used by new pretuning scripts DOFs - based on lock aquisition stuff in martynov thesis
    kat.IFO._preMICH = DOF(kat.IFO,
                           "preMICH",
                           kat.IFO.AS_f2,
                           "Q", ["ITMX", "ETMX", "ITMY", "ETMY"],
                           [1, 1, -1, -1],
                           1.0,
                           sigtype="z")
    kat.IFO._preSRCL = DOF(kat.IFO,
                           "preSRCL",
                           kat.IFO.AS_f2,
                           "I",
                           "SRM",
                           1,
                           1.0,
                           sigtype="z")
    kat.IFO._prePRCL = DOF(kat.IFO,
                           "prePRCL",
                           kat.IFO.REFL_f1,
                           "I",
                           "PRM",
                           1,
                           1.0,
                           sigtype="z")

    kat.IFO._preALSX = DOF(kat.IFO,
                           "ALSX",
                           kat.IFO.POW_X,
                           "",
                           "ETMX",
                           1,
                           1.0,
                           sigtype="z")
    kat.IFO._preALSY = DOF(kat.IFO,
                           "ALSY",
                           kat.IFO.POW_Y,
                           "",
                           "ETMY",
                           1,
                           1.0,
                           sigtype="z")

    # control scheme as in [1] Table C.1. Due to Finesse
    # conventions, the overall factor for all but PRCL are multiplied by -1
    # compared to the LIGO defintion, to match the same defintion.
    kat.IFO.PRCL = DOF(kat.IFO,
                       "PRCL",
                       kat.IFO.POP_f1,
                       "I",
                       "PRM",
                       1,
                       100.0,
                       sigtype="z")
    kat.IFO.MICH = DOF(kat.IFO,
                       "MICH",
                       kat.IFO.POP_f2,
                       "Q", ["ITMX", "ETMX", "ITMY", "ETMY"],
                       [-0.5, -0.5, 0.5, 0.5],
                       100.0,
                       sigtype="z")
    kat.IFO.CARM = DOF(kat.IFO,
                       "CARM",
                       kat.IFO.REFL_f1,
                       "I", ["ETMX", "ETMY"], [-1, -1],
                       1.5,
                       sigtype="z")
    kat.IFO.DARM = DOF(kat.IFO,
                       "DARM",
                       kat.IFO.AS_f2,
                       "Q", ["ETMX", "ETMY"], [-1, 1],
                       1.0,
                       sigtype="z")
    kat.IFO.SRCL = DOF(kat.IFO,
                       "SRCL",
                       kat.IFO.REFL_f2,
                       "I",
                       "SRM",
                       -1,
                       1e2,
                       sigtype="z")

    kat.IFO.DARM_h = DOF(kat.IFO,
                         "DARM_h",
                         kat.IFO.BHD,
                         "", ["LY", "LX"], [-1, 1],
                         1.0,
                         sigtype="phase")

    kat.IFO.LSC_DOFs = (kat.IFO.PRCL, kat.IFO.MICH, kat.IFO.CARM, kat.IFO.DARM,
                        kat.IFO.SRCL)
    kat.IFO.CAV_POWs = (kat.IFO.POW_X, kat.IFO.POW_Y, kat.IFO.POW_BS)

    # Ignore angular stuff for now

    # # Pitch DOfs
    # # There is a difference in the way LIGO and Finesse define positive and negative
    # # rotations of the cavity mirrors. For LIGO the rotational DOFs assume ITM + rotation
    # # is clockwise and ETM + rotation is anticlockwise.
    # # I'll be explict here for future reference.
    # cav_mirrors = ["ETMX", "ETMXAR", "ETMY", "ETMYAR", "ITMX", "ITMXAR", "ITMY", "ITMYAR"]
    #
    # # LIGO definitions
    # # Based on figure 7 in T0900511-v4
    # CHARD_factors   = np.array([ 1, 1, 1, 1,-1,-1,-1,-1])
    # DHARD_factors   = np.array([ 1, 1,-1,-1,-1,-1, 1, 1])
    # CSOFT_factors   = np.array([-1,-1,-1,-1,-1,-1,-1,-1])
    # # DSOFT_factors   = np.array([-1,-1, 1, 1, 1, 1,-1,-1])   # Wrong!
    # DSOFT_factors   = np.array([-1,-1, 1, 1,-1,-1, 1, 1])
    #
    # # Finesse definitions
    # # negative for ITM rotations
    # ITMS = np.in1d(cav_mirrors, np.array(["ITMX", "ITMXAR", "ITMY", "ITMYAR"]))
    # CHARD_factors[ITMS] *= -1
    # DHARD_factors[ITMS] *= -1
    # CSOFT_factors[ITMS] *= -1
    # DSOFT_factors[ITMS] *= -1
    #
    # kat.IFO.CHARD_P = DOF(kat.IFO, "CHARD_P", None , None, cav_mirrors, CHARD_factors, 1, sigtype="pitch")
    # kat.IFO.DHARD_P = DOF(kat.IFO, "DHARD_P", None , None, cav_mirrors, DHARD_factors, 1, sigtype="pitch")
    # kat.IFO.CSOFT_P = DOF(kat.IFO, "CSOFT_P", None , None, cav_mirrors, CSOFT_factors, 1, sigtype="pitch")
    # kat.IFO.DSOFT_P = DOF(kat.IFO, "DSOFT_P", None , None, cav_mirrors, DSOFT_factors, 1, sigtype="pitch")
    # kat.IFO.PRM_P   = DOF(kat.IFO, "PRM_P"  , None , None, ["PRM", "PRMAR"], [1,1], 1, sigtype="pitch")
    # kat.IFO.PRC2_P  = DOF(kat.IFO, "PRC2_P" , None , None, ["PR2"], [1], 1, sigtype="pitch")
    # kat.IFO.PRC3_P  = DOF(kat.IFO, "PRC3_P" , None , None, ["PR3"], [1], 1, sigtype="pitch")
    # kat.IFO.SRM_P   = DOF(kat.IFO, "SRM_P"  , None , None, ["SRM", "SRMAR"], [1,1], 1, sigtype="pitch")
    # kat.IFO.SRC2_P  = DOF(kat.IFO, "SRC2_P" , None , None, ["SR2"], [1], 1, sigtype="pitch")
    # kat.IFO.SRC3_P  = DOF(kat.IFO, "SRC3_P" , None , None, ["SR3"], [1], 1, sigtype="pitch")
    # kat.IFO.MICH_P  = DOF(kat.IFO, "MICH_P" , None , None, ["BS", "BSAR1", "BSAR2"], [1,1,1], 1, sigtype="pitch")
    #
    # kat.IFO.ASC_P_DOFs = (kat.IFO.CHARD_P, kat.IFO.DHARD_P,
    #                       kat.IFO.CSOFT_P, kat.IFO.DSOFT_P,
    #                       kat.IFO.PRM_P, kat.IFO.PRC2_P,
    #                       kat.IFO.PRC3_P, kat.IFO.SRM_P,
    #                       kat.IFO.SRC2_P, kat.IFO.SRC3_P,
    #                       kat.IFO.MICH_P)

    kat.IFO.update()

    kat.IFO.lockNames = None

    kat.noxaxis = True

    return kat
Exemplo n.º 7
0
def main():
    print("""
    --------------------------------------------------------------
    Example file for using PyKat to automate Finesse simulations
    Finesse: http://www.gwoptics.org/finesse
    PyKat:	 http://www.gwoptics.org/pykat
    
    The file runs through the various Finesse simulations
    to generate the Finesse results reported in the document:
    `Comparing Finesse simulations, analytical solutions and OSCAR 
    simulations of Fabry-Perot alignment signals', LIGO-T1300345,
    freely available online: http://arxiv.org/abs/1401.5727

    This file is part of a collection; it outputs the results
    shown the document's sections 3 and 4 and saves temporary
    data and a new Finesse input file to be read by master2.py.
    
    Andreas Freise 16.01.2014
    --------------------------------------------------------------
    """)

    # for debugging we might need to see the temporay file:
    global kat
    kat = finesse.kat(tempdir=".", tempname="test")
    kat.verbose = False
    kat.loadKatFile('asc_base.kat')
    kat.maxtem = 3
    Lambda = 1064.0e-9
    result = {}
    # defining variables as global for debugging
    #global kat, out, result

    print("--------------------------------------------------------")
    print(" 1. tunes ETM position to find resonance")
    kat.ETM.phi = resonance(kat)

    print("--------------------------------------------------------")
    print(" 2. print sideband and carrier powers/amplitudes")
    powers(kat)

    print("--------------------------------------------------------")
    print(" 3. determine the optimal phase for the PDH signal")
    (result['p_phase'], result['q_phase']) = pd_phase(kat)

    # setting demodulation phase
    code_det = """
    pd1 PDrefl_p 9M 0 nWFS1
    scale 2 PDrefl_p
    pd1 PDrefl_q 9M 90 nWFS1
    scale 2 PDrefl_q
    """
    kat.parseKatCode(code_det)
    kat.PDrefl_p.phase1 = result['p_phase']
    kat.PDrefl_q.phase1 = result['q_phase']

    print("--------------------------------------------------------")
    print(" 4. adding a 0.1nm offset to ETM and compute PDH signal")
    result['phi_tuned'] = float(kat.ETM.phi)
    result['phi_detuned'] = result['phi_tuned'] + 0.1 * 360.0 / 1064.0

    kat.ETM.phi = result['phi_detuned']
    print(" new ETM phi tuning = %g " % kat.ETM.phi)

    (result['pd_p'], result['pd_q']) = pd_signal(kat)
    print(" PDH inphase     = %e " % result['pd_p'])
    print(" PDH quadrtature = %e " % result['pd_q'])

    print("--------------------------------------------------------")
    print(" Saving results in temp. files to be read by master2.py")
    tmpkatfile = "asc_base2.kat"
    tmpresultfile = "myshelf1.dat"
    print(" kat object saved in: {0}".format(tmpkatfile))
    print(" current results saved in: {0}".format(tmpresultfile))
    # first the current kat file
    kat.saveScript(tmpkatfile)
    with open(tmpresultfile, 'wb') as handle:
        pickle.dump(result, handle)
Exemplo n.º 8
0
def model_DRFPMI():
    #
    # usage: base = utils_DRFPMI.model_DRFPMI()
    # output is the finesse structure with the DRFPMI configuration
    #
    #
    base = finesse.kat()
    base.verbose=False
    base.parse("""
    # ======== Constants ========================
    const f1 16.881M
    const f2 45.0159M
    const mf1 -16.881M
    const mf2 -45.0159M
    const a 0.686
    const pi 3.1415
    
    # ======== Input optics =====================
    l i1 1 0 n0
    s s_eo0 0 n0 n_eo1
    mod eom1 $f1 0.3 1 pm n_eo1 n_eo2
    s s_eo1 0 n_eo2 n_eo3
    mod eom2 $f2 0.3 1 pm n_eo3 n_eo4
    s s_eo2 0 n_eo4 nREFL

    ## ======= PRC each mirror loss 45ppm =======
    # PRC

    m1 PRM 0.1 45e-6 0 nREFL npr1
    s sLpr1 14.7615 npr1 npr2
    bs1 PR2 500e-6 45e-6 0 $a npr3 npr2 nPOP nPOP2
    s sLpr2 11.0661 npr3 npr4
    bs1 PR3 50e-6 45e-6 0 $a dump dump npr4 npr5
    s sLpr3 15.7638 npr5 npr6

    # Michelson
    bs bs1 0.5 0.5 0 45 npr6 n2 n3 n4
    s lx 26.6649 n3 nx1
    s ly 23.3351 n2 ny1

    # X arm
    m ITMX 0.996 0.004 0 nx1 nx2
    s sx1 3000 nx2 nx3
    m ETMX 0.999995 5e-06 0 nx3 nTMSX

    # Y arm
    m ITMY 0.996 0.004 90 ny1 ny2
    s sy1 3000 ny2 ny3
    m ETMY 0.999995 5e-06 90 ny3 nTMSY


    # ========= SRC each mirror loss 45ppm =======
    s sLsr3 15.7386 n4 nsr5
    bs1 SR3 50e-6 45e-6 0 $a nsr5 nsr4 dump dump
    s sLsr2 11.1115 nsr4 nsr3
    bs1 SR2 500e-6 45e-6 0 $a nsr2 nsr3 nPOS dump
    s sLsr1 14.7412 nsr2 nsr1
    m1 SRM 0.3 0e-6 0 nsr1 nAS

    ## ===== amplitude detectors =====
    ad CR_REFL 0 nREFL
    ad SB1p_REFL $f1 nREFL
    ad SB1m_REFL $mf1 nREFL
    ad SB2p_REFL $f2 nREFL
    ad SB2m_REFL $mf2 nREFL
    
    ad CR_POP 0 nPOP
    ad SB1p_POP $f1 nPOP
    ad SB1m_POP $mf1 nPOP
    ad SB2p_POP $f2 nPOP
    ad SB2m_POP $mf2 nPOP

    ad CR_TMSX 0 nTMSX
    ad SB1p_TMSX $f1 nTMSX
    ad SB1m_TMSX $mf1 nTMSX
    ad SB2p_TMSX $f2 nTMSX
    ad SB2m_TMSX $mf2 nTMSX

    ad CR_TMSY   0 nTMSY
    ad SB1p_TMSY $f1 nTMSY
    ad SB1m_TMSY $mf1 nTMSY
    ad SB2p_TMSY $f2 nTMSY
    ad SB2m_TMSY $mf2 nTMSY
    
    ad CR_POS 0 nPOS
    ad SB1p_POS $f1 nPOS
    ad SB1m_POS $mf1 nPOS
    ad SB2p_POS $f2 nPOS
    ad SB2m_POS $mf2 nPOS

    ad CR_AS 0 nAS
    ad SB1p_AS $f1 nAS
    ad SB1m_AS $mf1 nAS
    ad SB2p_AS $f2 nAS
    ad SB2m_AS $mf2 nAS
    
    """)
    return base
Exemplo n.º 9
0
def model_HOM_DRFPMI():
    #
    # usage: base = utils_DRFPMI.model_DRFPMI()
    # output is the finesse structure with the DRFPMI configuration
    #
    #
    base = finesse.kat()
    base.verbose=False
    base.parse("""
    # ======== Constants ========================
    const f1 16.881M
    const f2 45.0159M
    const mf1 -16.881M
    const mf2 -45.0159M
    const a 0.686
    const phi_PRM 90
    const pi 3.1415
    const phi_SRM 90
    
    # ======== Input optics =====================
    l i1 1 0 n0
    s s_eo0 0 n0 n_eo1
    mod eom1 $f1 0.3 1 pm n_eo1 n_eo2
    s s_eo1 0 n_eo2 n_eo3
    mod eom2 $f2 0.3 1 pm n_eo3 n_eo4
    s s_eo2 0 n_eo4 nREFL

    # ======= PRC each mirror loss 45ppm =======
    # PRC
    m1 PRM 0.1 45e-6 $phi_PRM nREFL npr1
    s sLpr1 14.7615 npr1 npr2
    bs1 PR2 500e-6 45e-6 0 $a npr3 npr2 nPOP nPOP2
    s sLpr2 11.0661 npr3 npr4
    bs1 PR3 50e-6 45e-6 0 $a dump dump npr4 npr5
    s sLpr3 15.7638 npr5 npr6

    # ======= Michelson ========================
    bs bs1 0.5 0.5 0 45 npr6 n2 n3 n4
    s lx 26.4018 n3 nx1		#26.6649-thickness*1.754
    s ly 23.072 n2 ny1		#23.3351-thickness*1.754


    # ======== Thick ITMs ======================
    m IXAR 0     1     0 nx1 nx2
    s thick_IX 0.15 1.754 nx2 nx3
    m ITMX 0.996 0.004 0 nx3 nx4

    m IYAR 0     1     0 ny1 ny2
    s thick_IY 0.15 1.754 ny2 ny3
    m ITMY 0.996 0.004 90 ny3 ny4

    # ========== Arm     =======================
    s sx1 3000 nx4 nx5
    m ETMX 0.999995 5e-06 0 nx5 nTMSX

    s sy1 3000 ny4 ny5
    m ETMY 0.999995 5e-06 90 ny5 nTMSY


    # ========= SRC each mirror loss 45ppm =======
    s sLsr3 15.7386 n4 nsr5
    bs1 SR3 50e-6 45e-6 0 $a nsr5 nsr4 dump dump
    s sLsr2 11.1115 nsr4 nsr3
    bs1 SR2 500e-6 45e-6 0 $a nsr2 nsr3 nPOS dump
    s sLsr1 14.7412 nsr2 nsr1
    m1 SRM 0.3 0e-6 $phi_SRM nsr1 nAS

    # =========  HOM Expansion =======
    attr PRM Rc -458.1285
    attr PR2 Rc -3.0764
    attr PR3 Rc -24.9165
    attr bs1 Rc 0
    attr ITMX Rc -1900.   # measured -1904.6
    attr ETMX Rc 1900.    # measured  1908.24
    attr ITMY Rc -1900    # measured -1904.4
    attr ETMY Rc 1900.    # measured  1905.55
    attr SRM Rc 458.1285
    attr SR2 Rc -2.9872
    attr SR3 Rc 24.9165
    attr IXAR Rc 0
    attr IYAR Rc 0

    cav XARM ITMX nx4 ETMX nx5
    cav YARM ITMY ny4 ETMY ny5
    cav PRX PRM npr1 ITMX nx3
    cav PRY PRM npr1 ITMY ny3
    cav SRX SRM nsr1 ITMX nx3
    cav SRY SRM nsr1 ITMY ny3
    
    # ===== amplitude detectors =====
    ad CR_REFL 0 nREFL
    ad SB1p_REFL $f1 nREFL
    ad SB1m_REFL $mf1 nREFL
    ad SB2p_REFL $f2 nREFL
    ad SB2m_REFL $mf2 nREFL
    
    ad CR_POP 0 nPOP
    ad SB1p_POP $f1 nPOP
    ad SB1m_POP $mf1 nPOP
    ad SB2p_POP $f2 nPOP
    ad SB2m_POP $mf2 nPOP

    ad CR_TMSX   0 nTMSX
    ad SB1p_TMSX $f1 nTMSX
    ad SB1m_TMSX $mf1 nTMSX
    ad SB2p_TMSX $f2 nTMSX
    ad SB2m_TMSX $mf2 nTMSX

    ad CR_TMSY   0 nTMSY
    ad SB1p_TMSY $f1 nTMSY
    ad SB1m_TMSY $mf1 nTMSY
    ad SB2p_TMSY $f2 nTMSY
    ad SB2m_TMSY $mf2 nTMSY
    
    ad CR_POS 0 nPOS
    ad SB1p_POS $f1 nPOS
    ad SB1m_POS $mf1 nPOS
    ad SB2p_POS $f2 nPOS
    ad SB2m_POS $mf2 nPOS

    ad CR_AS 0 nAS
    ad SB1p_AS $f1 nAS
    ad SB1m_AS $mf1 nAS
    ad SB2p_AS $f2 nAS
    ad SB2m_AS $mf2 nAS
    
    
    """)
    return base
Exemplo n.º 10
0
from pykat.commands import xaxis
import pylab as pl
import numpy as np
import math

code = """
l l1 1 0 0 n1
s s1 10 1 n1 n2
m m1 1 0 0 n2 n3

pd refl n2

xaxis m1 r_ap lin 0.1e-3 2e-3 10
"""

kat = finesse.kat()
kat.parseCommands(code)

maxtem = np.arange(0, 4)

kat.m1.n2.q = gauss_param(w0=1e-3, z=0)

kat.verbose = False

for tem in maxtem:
    print "Calculating maxtem ", tem, "..."
    kat.maxtem = tem

    r = kat.run()
    pl.plot(r.x/1e-3, r.y, label="maxtem={0}".format(tem))
Exemplo n.º 11
0
def main():

    print("""
	--------------------------------------------------------------
	Example file for using PyKat to automate Finesse simulations
	Finesse: http://www.gwoptics.org/finesse
	PyKat:	 https://pypi.python.org/pypi/PyKat/
	
	The file runs through the various pykat files which are used
	to generate the Finesse results reported in the document:
	`Comparing Finesse simulations, analytical solutions and OSCAR 
	simulations of Fabry-Perot alignment signals', LIGO-T1300345
	
	This file is part of a collection. Run this after master2.py
	
	Andreas Freise 06.12.2013
	--------------------------------------------------------------
	""")

    # shall we clear the workspace?
    # %reset -f

    # making these global during testing and debugging
    global kat
    global out

    kat = finesse.kat(tempdir=".", tempname="test")
    kat.verbose = False

    tmpresultfile = 'myshelf2.dat'

    # loading data saved by master.py
    kat.loadKatFile('asc_base3.kat')
    try:
        tmpfile = shelve.open(tmpresultfile)
        result = tmpfile[str('result')]
        tmpfile.close()
    except:
        raise Exception(
            "Could not open temprary results file {0}".format(tmpresultfile))

    # overwriting some variables
    kat.maxtem = 3
    Lambda = 1064.0e-9

    # this does not work yet due to the scale command
    kat.PDrefl_p.enabled = False
    kat.PDrefl_q.enabled = False
    kat.WFS1_I.enabled = False
    kat.WFS1_Q.enabled = False
    kat.WFS2_I.enabled = False
    kat.WFS2_Q.enabled = False

    kat.ETM.phi = result['phi_tuned']

    (beam1, beam2, beam3) = get_qs(kat)
    """
	print "	 Measured beam parameter:" 
	print "	 - At front of ITM (no thermal lens) q={0}".format(beam1.q)
	print "	   (eqals w0={0}, z={1})".format(beam1.w0, beam1.z)
	print "	 - At pick of mirror 'po' (50k lens) q={0}".format(beam2.q)
	print "	   (eqals w0={0}, z={1})".format(beam2.w0, beam2.z)
	print "	 - At pick of mirror 'po' (5k lens) q={0}".format(beam3.q)
	print "	   (eqals w0={0}, z={1})".format(beam3.w0, beam3.z)
	#print "  Setting these now view Gauss command and adding thermal lens"
	"""
    kat.ITM.nITM1.node.setGauss(kat.ITM, beam1)

    print("--------------------------------------------------------")
    print(" 11. computing beam sizes  with thermal lens")
    #beam_size(kat, beam2, beam3)

    kat.ITM_TL.f = 50e3
    kat.maxtem = 8
    print("--------------------------------------------------------")
    print(" 11. computing beam tilt with thermal lens (f={0}, maxtem={1})".
          format(kat.ITM_TL.f, kat.maxtem))
    #gravity_tilt(kat)

    kat.ITM_TL.f = 5e3
    kat.maxtem = 23

    print("--------------------------------------------------------")
    print(" 12. computing beam tilt with thermal lens (f={0}, maxtem={1})".
          format(kat.ITM_TL.f, kat.maxtem))
    #gravity_tilt(kat)

    print("--------------------------------------------------------")
    print(" 12. compute beam center with thermal lens")

    print("--------------------------------------------------------")
    print(" Saving results in temp. files to be read by master6.py")
    tmpkatfile = "asc_base4.kat"
    tmpresultfile = "myshelf3.dat"
    print(" kat object saved in: {0}".format(tmpkatfile))
    print(" current results saved in: {0}".format(tmpresultfile))
    # first the current kat file
    kat.saveScript(tmpkatfile)
    # now the result variables:
    tmpfile = shelve.open(tmpresultfile)
    tmpfile[str('result')] = result
    tmpfile.close()
Exemplo n.º 12
0
def make_kat(name="voyager_BSAR_LO",
             katfile=None,
             verbose=False,
             debug=False,
             keepComments=False,
             preserveConstants=False):
    """
    Returns a kat object and fills in the kat.IFO property for storing
    the associated interferometer data.
    
    name: Model to load
        - "voyager" base voyager model with IFO, OMC, LMC
    
    keepComments: If true it will keep the original comments from the file
    preserveComments: If true it will keep the const commands in the kat
    """
    names = ['voyager_BSAR_LO', 'voyager_POP_LO']

    if debug:
        kat = finesse.kat(tempdir=".", tempname="test")
    else:
        kat = finesse.kat()

    kat.verbose = verbose

    # Create empty object to just store whatever DOFs, port, variables in
    # that will be used by processing functions
    kat.IFO = VOYAGER_IFO(
        kat,
        # Define which keys are used for a tuning description
        ["maxtem", "phase"],
        # Define which mirrors create the tuning description
        ["PRM", "ITMX", "ETMX", "ITMY", "ETMY", "BS", "SRM"])

    kat.IFO._data_path = pkg_resources.resource_filename(
        'pykat.ifo', os.path.join('voyager', 'files'))

    kat.IFO.rawBlocks = BlockedKatFile()

    if katfile:
        kat.load(katfile,
                 keepComments=keepComments,
                 preserveConstants=preserveConstants)
        kat.IFO.rawBlocks.read(katfile)
    else:
        if name not in names:
            pkex.printWarning(
                "aLIGO name `{}' not recognised, options are {}, using default 'design'"
                .format(name, names))

        katkile = os.path.join(kat.IFO._data_path, name + ".kat")

        kat.load(katkile,
                 keepComments=keepComments,
                 preserveConstants=preserveConstants)
        kat.IFO.rawBlocks.read(katkile)

    # ----------------------------------------------------------------------
    # get and derive parameters from the kat file

    # get main frequencies
    if "f1" in kat.constants.keys():
        kat.IFO.f1 = float(kat.constants["f1"].value)
    else:
        kat.IFO.f1 = 9099471.0

    if "f2" in kat.constants.keys():
        kat.IFO.f2 = float(kat.constants["f2"].value)
    else:
        kat.IFO.f2 = 5.0 * kat.IFO.f1

    if "f3" in kat.constants.keys():
        kat.IFO.f3 = float(kat.constants["f3"].value)

    kat.IFO.f36M = kat.IFO.f2 - kat.IFO.f1

    # TODO add else here!
    # check modultion frequencies
    if (5 * kat.IFO.f1 != kat.IFO.f2):
        print(" ** Warning: modulation frequencies do not match: 5*f1!=f2")

    # defining a dicotionary for the main mirror positions (tunings),
    # keys should include maxtem, phase and all main optics names
    #kat.IFO.tunings = get_tunings(dict.fromkeys(["maxtem", "phase", "PRM", "ITMX", "ETMX", "ITMY", "ETMY", "BS", "SRM"]))
    kat.IFO.compute_derived_lengths()

    # ----------------------------------------------------------------------
    # define ports and signals

    # useful ports
    kat.IFO.POP_f1 = Output(kat.IFO, "POP_f1", "nPOP", "f1", phase=101)
    kat.IFO.POP_f2 = Output(kat.IFO, "POP_f2", "nPOP", "f2", phase=13)
    kat.IFO.REFL_f1 = Output(kat.IFO, "REFL_f1", "nREFL", "f1", phase=101)
    kat.IFO.REFL_f2 = Output(kat.IFO, "REFL_f2", "nREFL", "f2", phase=14)

    kat.IFO.AS_f1 = Output(kat.IFO, "AS_f1", "nSRM2", "f1", phase=101)
    kat.IFO.AS_f2 = Output(kat.IFO, "AS_f2", "nSRM2", "f2", phase=14)
    kat.IFO.AS_f36 = Output(kat.IFO, "AS_f36", "nSRM2", "f36M", phase=14)

    # AS_DC refers to what is coming out of the OMC now
    kat.IFO.AS_DC = Output(kat.IFO, "AS_DC", "nOMC_OCc")
    kat.IFO.POW_BS = Output(kat.IFO, "PowBS", "nPRBS*")
    kat.IFO.POW_X = Output(kat.IFO, "PowX", "nITMX2")
    kat.IFO.POW_Y = Output(kat.IFO, "PowY", "nITMY2")
    kat.IFO.POW_SRC = Output(kat.IFO, "PowSRC", "nSRM1")
    kat.IFO.POW_PRC = Output(kat.IFO, "PowPRC", "nPRM2")

    # pretune LSC DOF
    kat.IFO.preARMX = DOF(kat.IFO,
                          "ARMX",
                          kat.IFO.POW_X,
                          "",
                          "ETMX",
                          1,
                          1.0,
                          sigtype="z")
    kat.IFO.preARMY = DOF(kat.IFO,
                          "ARMY",
                          kat.IFO.POW_Y,
                          "",
                          "ETMY",
                          1,
                          1.0,
                          sigtype="z")
    kat.IFO.preMICH = DOF(kat.IFO,
                          "AS",
                          kat.IFO.AS_DC,
                          "", ["ITMX", "ETMX", "ITMY", "ETMY"], [1, 1, -1, -1],
                          6.0,
                          sigtype="z")
    kat.IFO.prePRCL = DOF(kat.IFO,
                          "PRCL",
                          kat.IFO.POW_BS,
                          "",
                          "PRM",
                          1,
                          10.0,
                          sigtype="z")
    kat.IFO.preSRCL = DOF(kat.IFO,
                          "SRCL",
                          kat.IFO.AS_DC,
                          "",
                          "SRM",
                          1,
                          10.0,
                          sigtype="z")

    # control scheme as in [1] Table C.1. Due to Finesse
    # conventions, the overall factor for all but PRCL are multiplied by -1
    # compared to the LIGO defintion, to match the same defintion.
    kat.IFO.PRCL = DOF(kat.IFO,
                       "PRCL",
                       kat.IFO.POP_f1,
                       "I",
                       "PRM",
                       1,
                       100.0,
                       sigtype="z")
    kat.IFO.MICH = DOF(kat.IFO,
                       "MICH",
                       kat.IFO.POP_f2,
                       "Q", ["ITMX", "ETMX", "ITMY", "ETMY"],
                       [-0.5, -0.5, 0.5, 0.5],
                       100.0,
                       sigtype="z")
    kat.IFO.CARM = DOF(kat.IFO,
                       "CARM",
                       kat.IFO.REFL_f1,
                       "I", ["ETMX", "ETMY"], [-1, -1],
                       1.5,
                       sigtype="z")
    kat.IFO.DARM = DOF(kat.IFO,
                       "DARM",
                       kat.IFO.AS_f2,
                       "Q", ["ETMX", "ETMY"], [-1, 1],
                       1.0,
                       sigtype="z")
    kat.IFO.SRCL = DOF(kat.IFO,
                       "SRCL",
                       kat.IFO.REFL_f2,
                       "I",
                       "SRM",
                       -1,
                       1e2,
                       sigtype="z")

    kat.IFO.DARM_h = DOF(kat.IFO,
                         "DARM_h",
                         None,
                         "", ["LY", "LX"], [-1, 1],
                         1.0,
                         sigtype="phase")

    kat.IFO.LSC_DOFs = (kat.IFO.PRCL, kat.IFO.MICH, kat.IFO.CARM, kat.IFO.DARM,
                        kat.IFO.SRCL)
    kat.IFO.CAV_POWs = (kat.IFO.POW_X, kat.IFO.POW_Y, kat.IFO.POW_BS)

    # Pitch DOfs
    # There is a difference in the way LIGO and Finesse define positive and negative
    # rotations of the cavity mirrors. For LIGO the rotational DOFs assume ITM + rotation
    # is clockwise and ETM + rotation is anticlockwise.
    # I'll be explict here for future reference.
    cav_mirrors = [
        "ETMX", "ETMXAR", "ETMY", "ETMYAR", "ITMX", "ITMXAR", "ITMY", "ITMYAR"
    ]

    # LIGO definitions
    # Based on figure 7 in T0900511-v4
    CHARD_factors = np.array([1, 1, 1, 1, -1, -1, -1, -1])
    DHARD_factors = np.array([1, 1, -1, -1, -1, -1, 1, 1])
    CSOFT_factors = np.array([-1, -1, -1, -1, -1, -1, -1, -1])
    # DSOFT_factors   = np.array([-1,-1, 1, 1, 1, 1,-1,-1])   # Wrong!
    DSOFT_factors = np.array([-1, -1, 1, 1, -1, -1, 1, 1])

    # Finesse definitions
    # negative for ITM rotations
    ITMS = np.in1d(cav_mirrors, np.array(["ITMX", "ITMXAR", "ITMY", "ITMYAR"]))
    CHARD_factors[ITMS] *= -1
    DHARD_factors[ITMS] *= -1
    CSOFT_factors[ITMS] *= -1
    DSOFT_factors[ITMS] *= -1

    kat.IFO.CHARD_P = DOF(kat.IFO,
                          "CHARD_P",
                          None,
                          None,
                          cav_mirrors,
                          CHARD_factors,
                          1,
                          sigtype="pitch")
    kat.IFO.DHARD_P = DOF(kat.IFO,
                          "DHARD_P",
                          None,
                          None,
                          cav_mirrors,
                          DHARD_factors,
                          1,
                          sigtype="pitch")
    kat.IFO.CSOFT_P = DOF(kat.IFO,
                          "CSOFT_P",
                          None,
                          None,
                          cav_mirrors,
                          CSOFT_factors,
                          1,
                          sigtype="pitch")
    kat.IFO.DSOFT_P = DOF(kat.IFO,
                          "DSOFT_P",
                          None,
                          None,
                          cav_mirrors,
                          DSOFT_factors,
                          1,
                          sigtype="pitch")
    kat.IFO.PRM_P = DOF(kat.IFO,
                        "PRM_P",
                        None,
                        None, ["PRM", "PRMAR"], [1, 1],
                        1,
                        sigtype="pitch")
    kat.IFO.PRC2_P = DOF(kat.IFO,
                         "PRC2_P",
                         None,
                         None, ["PR2"], [1],
                         1,
                         sigtype="pitch")
    kat.IFO.PRC3_P = DOF(kat.IFO,
                         "PRC3_P",
                         None,
                         None, ["PR3"], [1],
                         1,
                         sigtype="pitch")
    kat.IFO.SRM_P = DOF(kat.IFO,
                        "SRM_P",
                        None,
                        None, ["SRM", "SRMAR"], [1, 1],
                        1,
                        sigtype="pitch")
    kat.IFO.SRC2_P = DOF(kat.IFO,
                         "SRC2_P",
                         None,
                         None, ["SR2"], [1],
                         1,
                         sigtype="pitch")
    kat.IFO.SRC3_P = DOF(kat.IFO,
                         "SRC3_P",
                         None,
                         None, ["SR3"], [1],
                         1,
                         sigtype="pitch")
    kat.IFO.MICH_P = DOF(kat.IFO,
                         "MICH_P",
                         None,
                         None, ["BS", "BSAR1", "BSAR2"], [1, 1, 1],
                         1,
                         sigtype="pitch")

    kat.IFO.ASC_P_DOFs = (kat.IFO.CHARD_P, kat.IFO.DHARD_P, kat.IFO.CSOFT_P,
                          kat.IFO.DSOFT_P, kat.IFO.PRM_P, kat.IFO.PRC2_P,
                          kat.IFO.PRC3_P, kat.IFO.SRM_P, kat.IFO.SRC2_P,
                          kat.IFO.SRC3_P, kat.IFO.MICH_P)

    kat.IFO.update()

    kat.IFO.lockNames = None

    return kat
Exemplo n.º 13
0
def main():

	print("""
	--------------------------------------------------------------
	Example file for using PyKat to automate Finesse simulations
	Finesse: http://www.gwoptics.org/finesse
	PyKat:	 https://pypi.python.org/pypi/PyKat/

	The file runs through the various Finesse simulations
	to generate the Finesse results reported in the document:
	`Comparing Finesse simulations, analytical solutions and OSCAR 
	simulations of Fabry-Perot alignment signals', LIGO-T1300345,
	freely available online: http://arxiv.org/abs/1401.5727

	Run this file after master2.py to create data which can be
	plotted using master4_plot.py. Results are saved after 
	each step and plots can be created at any time.
		
	Andreas Freise 16.01.2014
	--------------------------------------------------------------
	""")
	
	# shall we clear the workspace?
	# %reset -f

	# making these global during testing and debugging
	#global kat, out

	kat = finesse.kat(tempdir=".",tempname="test")
	kat.verbose = False

	tmpresultfile = 'myshelf2.dat'
	
	# loading data saved by master.py
	kat.loadKatFile('asc_base3.kat')
	try:
		with open(tmpresultfile, 'rb') as handle:
			result = pickle.load(handle)
	except: raise Exception("Could not open temprary results file {0}".format(tmpresultfile))
	
	# this does not work yet due to the scale command
	kat.PDrefl_p.enabled = False
	kat.PDrefl_q.enabled = False
	kat.WFS1_I.enabled = False
	kat.WFS1_Q.enabled = False
	kat.WFS2_I.enabled = False
	kat.WFS2_Q.enabled = False

	kat.ETM.phi=result['phi_tuned']

	print("--------------------------------------------------------")
	print(" 11. Do beam tracing to measure beam parameters")
	# get beam parameters at nodes: "npsl", "nITM1", "nWFS1", "nWFS2", "npo2"
	global beam1, beam2, beam3
	beam1 = get_qs(kat,1e13)
	beam2 = get_qs(kat,50e3)
	beam3 = get_qs(kat,5e3)

	# starting with cold beam at npsl
	kat.psl.npsl.node.setGauss(kat.psl, beam1[0])
	kat.parseKatCode("startnode npsl")


	# if we use bs-based cavity we try to set good beam
	# parameter for reflected beam, first by
	# computing 'average' beam from cold and hot beams
	x1=0.70
	x2=0.30
	if "ITM_TL_r" in kat._kat__components:
		beam50 = beam_param(z=(x1*beam1[1].z+x2*beam2[1].z), w0=(x1*beam1[1].w0+x2*beam2[1].w0))
		beam5  = beam_param(z=(x1*beam1[1].z+x2*beam3[1].z), w0=(x1*beam1[1].w0+x2*beam3[1].w0))
		node_text = "at ITM->nITM1r"
		t_comp=kat.ITM
		t_node=kat.ITM.nITM1r
	else:
		beam50 = beam_param(z=(x1*beam1[4].z+x2*beam2[4].z), w0=(x1*beam1[4].w0+x2*beam2[4].w0))
		beam5  = beam_param(z=(x1*beam1[4].z+x2*beam3[4].z), w0=(x1*beam1[4].w0+x2*beam3[4].w0))
		node_text = "at s2->npo2"
		t_comp=kat.s2
		t_node=kat.s2.npo2
	
	kat = set_thermal_lens(kat,50.0e3)

	print("--------------------------------------------------------")
	print(" 12. computing beam tilt with thermal lens (f={0})".format(kat.ITM_TL.f))

	print(" Setting compromise beam parameter {0}:\n w0={1}, z={2}".format(node_text, beam50.w0, beam50.z))
	t_node.node.setGauss(t_comp, beam50)
	kat.maxtem=8
	print(" Calculating maxtem = %d " % kat.maxtem)
	tmp = gravity_tilt(kat)

	kat = set_thermal_lens(kat,5e3)
	print("--------------------------------------------------------")
	print(" 13. computing beam tilt with thermal lens (f={0})".format(kat.ITM_TL.f))
	print(" Setting compromise beam parameter {0}:\n w0={1}, z={2}".format(node_text, beam5.w0, beam5.z))
	t_node.node.setGauss(t_comp, beam5)
	#maxtems = [1, 3, 5, 9, 11, 13, 15, 19, 23, 25, 27, 29]
	#maxtems = [1, 3, 5, 9, 11, 13, 15]
	maxtems = [1, 3, 5, 7]
	converge_tilt(kat, maxtems)
   
	kat.PDrefl_p.enabled = True
	kat.WFS1_I.enabled = True
	kat.WFS2_I.enabled = True
	
	kat = set_thermal_lens(kat,50e3)
	print("--------------------------------------------------------")
	print(" 12. computing alignment signal with thermal lens (f={0})".format(kat.ITM_TL.f))
	t_node.node.setGauss(t_comp, beam50)
	#maxtems = [1, 3, 5, 9, 11, 13, 15, 17, 19]
	#maxtems = [1, 3, 5, 9, 11, 13, 15]
	maxtems = [1, 3, 5, 7]
	converge_asc(kat, maxtems, 'asc_signals_50.txt')

	kat = set_thermal_lens(kat,5e3)
	print("--------------------------------------------------------")
	print(" 13. computing alignment signal with thermal lens (f={0})".format(kat.ITM_TL.f))
	t_node.node.setGauss(t_comp, beam5)
	#maxtems = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]
	#maxtems = [1, 3, 5, 9, 11, 13, 15]
	maxtems = [1, 3, 5, 7]
	converge_asc(kat, maxtems, 'asc_signals_5.txt')
# -*- coding: utf-8 -*-
import pykat
from pykat import finesse

result = []  # prepare for the result
kat = finesse.kat()  # create a fresh cat object
kat.verbose = False
kat.load("LHO_IFO_maxtem2.kat")  # load the conf

##############################################
## set excitationas, sensors, and some settings
##############################################
kat.parse("fsig sig1 ETMXHR 10 180")
kat.parse("fsig sig1 ETMYHR 10 0")
kat.parse("pd1 myomc 10  nOMC_HROC_trans")
kat.parse("xaxis sig1 f log 10 1k 10")
kat.parse("put myomc f1 $x1")  # to follow
kat.parse("yaxis abs:deg")
kat.verbose = True
out = kat.run()  # do the computation
result.append(out['myomc'])  # append the result

print("PASSED")
Exemplo n.º 15
0
def main():
    print("""
	--------------------------------------------------------------
	Example file for using PyKat to automate Finesse simulations
	Finesse: http://www.gwoptics.org/finesse
	PyKat:	 http://www.gwoptics.org/pykat

	The file runs through the various Finesse simulations
	to generate the Finesse results reported in the document:
	`Comparing Finesse simulations, analytical solutions and OSCAR 
	simulations of Fabry-Perot alignment signals', LIGO-T1300345,
	freely available online: http://arxiv.org/abs/1401.5727

	This file is part of a collection; it outputs the results
	shown the document's sections 5 and 6 and saves temporary
	data and a new Finesse input file to be read by master3.py,
	and master4.py.
	
	Andreas Freise 16.01.2014
	--------------------------------------------------------------
	""")

    # shall we clear the workspace?
    # %reset -f

    # making these global during testing and debugging
    #global kat, out

    kat = finesse.kat(tempdir=".", tempname="test")
    kat.verbose = False

    tmpresultfile = "myshelf1.dat"

    # loading data saved by master.py
    kat.loadKatFile('asc_base2.kat')
    try:
        with open(tmpresultfile, 'rb') as handle:
            result = pickle.load(handle)
    except:
        raise Exception(
            "Could not open temprary results file {0}".format(tmpresultfile))

    # overwriting some variables
    kat.maxtem = 3
    Lambda = 1064.0e-9

    # disable PDH photo diode as we won't need it for most of this
    kat.PDrefl_p.enabled = False
    kat.PDrefl_q.enabled = False

    # simulating a tuned cavity
    kat.ETM.phi = result['phi_tuned']

    print("--------------------------------------------------------")
    print(" 5. checking wavefronts for ITM/ETM tilt of 0.1nrad")
    tilt(kat)

    print("--------------------------------------------------------")
    print(" 6. compute beam tilt from beam propogation")
    gravity_tilt(kat)

    print("--------------------------------------------------------")
    print(" 7. compute optimal demodulation phase of WFS1 and WFS2")

    # adding wave front sensors to global kat object, will need them later
    # on as well.

    code_WFS1 = """
	pd1 WFS1_I 9M 0 nWFS1
	pdtype WFS1_I y-split
	pd1 WFS1_Q 9M 90 nWFS1
	pdtype WFS1_Q y-split
	scale 2 WFS1_I % compensate the 0.5 gain of the demodulation
	scale 2 WFS1_Q % compensate the 0.5 gain of the demodulation
	"""
    code_WFS2 = """
	pd1 WFS2_I 9M 0 nWFS2
	pdtype WFS2_I y-split
	pd1 WFS2_Q 9M 90 nWFS2
	pdtype WFS2_Q y-split
	scale 2 WFS2_I % compensate the 0.5 gain of the demodulation
	scale 2 WFS2_Q % compensate the 0.5 gain of the demodulation
	"""
    kat.parseKatCode(code_WFS1)
    kat.parseKatCode(code_WFS2)

    (WFS1_phase, WFS2_phase) = asc_phases(kat)
    kat.WFS1_I.phase1 = WFS1_phase
    kat.WFS1_Q.phase1 = WFS1_phase + 90.0
    kat.WFS2_I.phase1 = WFS2_phase
    kat.WFS2_Q.phase1 = WFS2_phase + 90.0
    result['WFS1_phase'] = WFS1_phase
    result['WFS2_phase'] = WFS2_phase

    print("--------------------------------------------------------")
    print(" 8. compute ASC signal matrix at WFS1 and WFS2")
    signal = asc_signal(kat)

    print("--------------------------------------------------------")
    print(" Saving results in temp. files to be read by master3.py")
    # re-enable PDH photo diode for saving of kat file for next script
    kat.PDrefl_p.enabled = True
    kat.PDrefl_q.enabled = True

    tmpkatfile = "asc_base3.kat"
    tmpresultfile = "myshelf2.dat"
    print(" kat object saved in: {0}".format(tmpkatfile))
    print(" current results saved in: {0}".format(tmpresultfile))
    kat.saveScript(tmpkatfile)
    with open(tmpresultfile, 'wb') as handle:
        pickle.dump(result, handle)
Exemplo n.º 16
0
def main():
    print("""
	--------------------------------------------------------------
	Example file for using PyKat to automate Finesse simulations
	Finesse: http://www.gwoptics.org/finesse
	PyKat:   http://www.gwoptics.org/pykat
	
	The file runs through some Finesse simulations for the
	Glasgow speedmeter experiment, using the file:
	sagnac_base.kat
	
	Andreas Freise 30.10.2014
	--------------------------------------------------------------
	""")
    # defining variables as global for debugging
    global kat
    global out
    global result
    global legend

    # for debugging we might need to see the temporay file:
    kat = finesse.kat(tempdir=".", tempname="test")
    kat.verbose = False

    kat.loadKatFile('sagnac_base.kat')
    extra = kat._kat__blocks['NO_BLOCK']

    # adding homodyne detector
    #kat.addLine('qhdS sens 180 nout1 nout2')
    extra.contents.append('qhdS sens 180 nout1 nout2')
    extra.contents.append('scale meter sens')

    kat.maxtem = 'off'
    Lambda = 1064.0e-9
    result = OrderedDict()
    legend = {}

    # getting mass of the light mirror of cavity a
    global m

    m = kat.M1a.mass.value
    AoI2 = float(kat.constants['AoI2'].value) / 180. * np.pi
    global f
    f = namedtuple('f', ('start', 'stop', 'points', 'data'))
    f.start = 100
    f.stop = 2e4
    f.points = 100
    kat.parseKatCode('xaxis sig1 f log {0} {1} {2}'.format(
        f.start, f.stop, f.points - 1))

    # Reading Haixing Miao's reference data:
    datah1 = np.loadtxt('QN_Sagnac_lossless.dat')
    datah2 = np.loadtxt('QN_Sagnac_25ppm_loss.dat')

    # Reading Stefan D. example data:
    data = np.loadtxt('Stefan_data.txt')

    print("--------------------------------------------------------")
    print(" Run default file (no loss)")
    out = kat.run()
    #f.data = np.logspace(np.log10(f.start), np.log10(f.stop), f.points)
    f.data = out.x  # getting frequency vector from Finesse instead

    print("--------------------------------------------------------")
    print(" Computing SQL")
    hbar = 6.62606957E-34 / (2.0 * np.pi)
    SQL_x = np.sqrt(4 * hbar / (m * f.data**2 * 4 * np.pi * np.pi))
    legend['SQL'] = mylegend('SQL', 'k')
    result['SQL'] = SQL_x

    result['H1'] = datah1[:, 1]
    legend['H1'] = mylegend('Haixing, no loss', 'g')
    legend['H1'].lt = '--.'
    legend['H1'].lw = 2

    result['default'] = out.y * np.cos(AoI2)
    legend['default'] = mylegend('no loss', 'm')

    print("--------------------------------------------------------")
    L = 0
    T = 12.5e-6
    R = 1 - T - L
    kat.M2a.R = R
    kat.M3a.R = R
    kat.M2b.R = R
    kat.M3b.R = R
    kat.M2a.T = T
    kat.M3a.T = T
    kat.M2b.T = T
    kat.M3b.T = T
    kat.M2a.L = L
    kat.M3a.L = L
    kat.M2b.L = L
    kat.M3b.L = L
    out = kat.run()

    result['H2'] = datah2[:, 1]
    legend['H2'] = mylegend('Haixing, 25ppm loss', 'g')
    legend['H2'].lt = '-.'
    legend['H2'].lw = 5

    result['loss'] = out.y * np.cos(AoI2)
    legend['loss'] = mylegend('25ppm loss', 'b')

    #result['S_sym']=data[:,1]
    #legend['S_sym']=mylegend('Stefan D, balanced','k')
    #legend['S_sym'].lt='-.'

    print("--------------------------------------------------------")
    print(" 3. Imbalanced BS")
    #result['bs']=imbalanced_bs(kat)*np.cos(AoI2)
    #legend['bs']=mylegend('Imbalanced BS 49:51','r')

    #result['S_imb']=data[:,2]
    #legend['S_imb']=mylegend('Stefan D, imbalanced','k')
    #legend['S_imb'].lt='--.'

    print("--------------------------------------------------------")
    print(" 3. Mass asymmetry")
    #result['mass']=mass(kat)
    #legend['mass']=mylegend('Mass asymmetry 10%','c')

    print("--------------------------------------------------------")
    print(" Plotting results")
    plot_results(f, result, legend)