fintrace.model ============== .. py:module:: fintrace.model .. autoapi-nested-parse:: This module creates the Fintrace model, which inherits all attributes and methods of a finesse model while populating a dictionary with gtrace objects for ray-tracing and rendering. Classes ------- .. autoapisummary:: fintrace.model.FintraceModel Module Contents --------------- .. py:class:: FintraceModel Bases: :py:obj:`finesse.Model` Optical configuration class for handling models of interferometers. This class stores the interferometer configuration as a directed graph and contains methods to interface with this data structure. :param \*katscripts: KatScripts to parse, parsed in order. :type \*katscripts: str :param loadfile: If present, this file will be loaded and parsed before parsing the katscripts. :type loadfile: Optional[str | PathLike] .. py:attribute:: gtrace_dict .. py:attribute:: laser_beam :value: None .. py:attribute:: laser_width :value: None .. py:attribute:: laser_length :value: None .. py:attribute:: laser_gauss :value: None .. py:attribute:: yamlfile :value: '' .. py:method:: __str__() Prints current model info. .. py:method:: handle_shapes(shape, gtrace_dict) .. py:method:: build_from_yaml(yamlfile, gtrace=None, verbose=False) Builds a finesse model from input yamlfile. .. py:method:: save_to_yaml(filename) :abstractmethod: .. py:method:: save_to_csv(filename) Prints current model info. .. py:method:: print_model_info() .. py:method:: gtrace_plot(gtrace_dict: dict, finesse_cavities: dict, finesse_detectors: list, render=True, beam_origin='laser', skip_optics=[], grid=False, draw_width: bool | float = True, savefile=None, img_res=600, power_threshold=0.001, keep_dxf=False, keep_svg=False) Plots the gtrace rendering of current finesse model. :param gtrace_dict: Dictionary with populated gtrace objects generated during model initialization. :type gtrace_dict: dict :param finesse_cavities: List of cavities to plot and analyze. :type finesse_cavities: list :param finesse_detectors: List of detectors to draw. :type finesse_detectors: list :param render: Whether or not to render the gtrace model upon completion, or just return the unrendered Canvas object. Defaults to True. :type render: bool, optional :param beam_origin: Whether to use laser as initial beam origin or to create a beam with calculated cavity eigenmodes. Defaults to 'laser'. :type beam_origin: str, optional :param grid: Whether or not to draw prewritten/ dynamic grid. Defaults to False. :type grid: bool, optional :param draw_width: Whether or not to draw :type draw_width: bool | float, optional :param beamwidths throughout the rendering. If True: :param uses a default: :param sigma of 2.63. If a float: :param uses that value as sigma.: :param Defaults to True.: :param savefile: Path to save rendered (if applicable) drawing, **without extensions!**. If none is provided, it will produce gtrace.png in your current working directory. Defaults to None. :type savefile: _type_, optional :param img_res: Choice of image resolution. Defaults to 600. :type img_res: int, optional :param power_threshold: Threshold to use in the nonsequential beamtrace, which plots all beams until a beam falls below the set power threshold. Defaults to 1e-3. :type power_threshold: float, optional :param keep_dxf: Whether to save the originally rendered dxf file. Defaults to False. :type keep_dxf: bool, optional :param keep_svg: Whether to save rendered svg file. Defaults to False. :type keep_svg: bool, optional :returns: If render is set to false, will return populated Canvas object for rendering. :rtype: Canvas .. py:method:: trace_cavities(cavity_traces: list = ['all'], savepath=None, q_at=None, imshow=False, show=False, plot=['all'], direction=None, astig_difference=True, verbose=False) -> None Draws beam trace(s) of each cavity specified by args, that are also specified in the .yaml config file. :param cavity_trace: list of cavities you wish to trace. Defaults to ['all']. :type cavity_trace: list, optional :param savepath: Path to where you'd like to save the figures produced. Defaults to None. :type savepath: str, optional :param q_at: Node to print the q-parameter within an eigenmode. :type q_at: str, optional :param imshow: When true, will plot beam intensity at given q_at on image. Defaults to False. :type imshow: bool, optional :param show: When true, will call `plt.show()` and bring up the figures of each plot. Defaults to False. :type show: bool, optional :raises KeyError: If cavity name listed is not found yamlfile. .. py:method:: trace_beam(beamtrace: list, q_at=None, q_in=None, plot=False, imshow=False, show: bool = False, savepath: str = None, direction: str = 'both', astig_difference: bool = True, **kwargs) -> None Performs a beam trace from a given starting point and end point. The syntax for start and end nodes uses the finesse style. Can only have a start and end node no more, no less. :param beamtrace: Start and end nodes, with optional via node. List should be a maximum of 3 nodes, minimum of 2. :type beamtrace: list :param q_at: Node to print the q-parameter within an optical path generated with beamtrace. :type q_at: str, optional :param q_in: initial q to use beam propagation for beamtrace. :type q_in: complex, optional :param plot: whether or not to plot the beam trace. Defaults to False. :type plot: bool, optional :param imshow: When true, will plot beam intensity at given q_at on image. Defaults to False. :type imshow: bool, optional :param show: When true, will call `plt.show()` and bring up the figures of each plot. Defaults to False. :type show: bool, optional :param savepath: Path to where you'd like to save the figures produced. Defaults to None. :type savepath: str, optional :param direction: Direction to do beam trace. Defaults to 'both'. :type direction: str, optional :raises ValueError: Must define a start and end node. :raises AttributeError: The node does not have this port. .. py:method:: scan_cavity(cavity_names: list = ['all'], savepath=None, show=False, nm=7, yscale='linear') Scans the cavity for higher-order mode resonance, normalizing each succesive HOM by 1/(n+m+1). :param cavity_names: List of cavities :type cavity_names: list, optional :param you wish to scan. Defaults to ['all'].: :param savepath: Place to save produced plot. :type savepath: _type_, optional :param Defaults to None.: :param show: Whether or not to display plot. :type show: bool, optional :param Defaults to False.: :param nm: Total number of HOMs to include. :type nm: int, optional :param Defaults to 7.: .. py:method:: calculate_matched_mode(laser, cav: str) Calculates the needed q-parameter for laser given a cavity to be matched to. :param laser: Laser object, as a model object :type laser: Laser :param cav: Name of cavity to match to. :type cav: str :returns: needed q parameters in x and y direction. :rtype: (qx, qy) .. py:method:: match_beam(target_q: finesse.gaussian.BeamParam, from_node, match_node, start_q: finesse.gaussian.BeamParam, params, guess, dir=None) Runs minimization function on mode mismatch with parameters set in arguments, which must be syntaxed the FINESSE way. :param target_q: Target q that you are trying to mode match to. :type target_q: BeamParam :param from_node: OpticalNode to start beam propagation to. :type from_node: OpticalNode :param match_node: OpticalNode to end at and evaluate mode match at. :type match_node: OpticalNode :param start_q: Initial q to start beam propagation with. :type start_q: BeamParam :param params: List of parameters (FINESSE syntax) in minimization function. :type params: list :param guess: List of initial guesses for parameters that give minima. :type guess: list :param dir: either 'x' or 'y' to use mode matching direction. default is 'x'. :type dir: str .. py:method:: plot_beam_trace(sol, *args, direction='both', astig_difference=True, filename=None, show=False)