Beispiel #1
0
    def __init__(self, opt_model, is_dark=True, **kwargs):
        self.opt_model = opt_model
        self.ray_table = None

        light_or_dark(is_dark=is_dark)

        seq_model = self.opt_model['seq_model']
        ele_model = self.opt_model['ele_model']
        part_tree = self.opt_model['part_tree']
        if len(part_tree.nodes_with_tag(tag='#element')) == 0:
            parttree.elements_from_sequence(ele_model, seq_model, part_tree)
Beispiel #2
0
def open_model(file_name, info=False, post_process_imports=True, **kwargs):
    """ open a file and populate an optical model with the data

    Args:
        file_name (str): a filename of a supported file type

            - .roa - a rayoptics JSON encoded file
            - .seq - a CODE V (TM) sequence file
            - .zmx - a Zemax (TM) lens file
        info (bool): if true, return an info tuple with import statistics
        post_process_imports (bool): for lens design program file import,
        kwargs (dict): keyword args passed to the reader functions

    Returns:
        if successful, an OpticalModel instance, otherwise, None
    """
    file_name = pathlib.Path(file_name)
    file_extension = file_name.suffix.lower()
    opm = None
    if file_extension == '.roa':
        # if we have a rayoptics file, we just read it
        opm = open_roa(file_name, **kwargs)
    else:
        # if we're importing another program's file, collect import info
        if file_extension == '.seq':
            opm, import_info = cvp.read_lens(file_name, **kwargs)
        elif file_extension == '.zmx':
            opm, import_info = zmxread.read_lens_file(file_name, **kwargs)
        # At this point we have seq_model, opticalspec and sys_model.
        # Generate the remaining databases and relations unless declined.
        if post_process_imports:
            create_specsheet_from_model(opm)
            # create element model and part_tree
            opm.ele_model.reset_serial_numbers()
            pt.elements_from_sequence(opm.ele_model,
                                      opm.seq_model,
                                      opm.part_tree)
        if info:
            return opm, import_info
    return opm
Beispiel #3
0
def create_from_file(filename, **kwargs):
    opm = cmds.open_model(filename)
    sm = opm['seq_model']
    osp = opm['optical_spec']
    em = opm['ele_model']
    pt = opm['part_tree']
    if len(pt.nodes_with_tag(tag='#element')) == 0:
        parttree.elements_from_sequence(em, sm, pt)
    if 'power' in kwargs:
        desired_power = kwargs['power']
        cur_power = osp.parax_data.fod.power
        # scale_factor is linear, power is 1/linear
        #  so use reciprocal of power to compute scale_factor
        scale_factor = cur_power / desired_power
        sm.apply_scale_factor(scale_factor)
    seq = [list(node) for node in sm.path(start=1, stop=-1)]
    seq[-1][2] = None
    sys_nodes = pt.nodes_with_tag(tag='#element#airgap',
                                  not_tag='#object#image')
    eles = [node.id for node in sys_nodes]
    root = Node('file', id=None, tag='#group', children=sys_nodes)
    return seq, eles, root
    def __init__(self, radius_mode=False, specsheet=None, **kwargs):
        self.ro_version = rayoptics.__version__
        self.radius_mode = radius_mode
        
        self.specsheet = specsheet
        self.system_spec = SystemSpec()
        self.seq_model = SequentialModel(self, **kwargs)
        self.optical_spec = OpticalSpecs(self, specsheet=specsheet, **kwargs)
        self.parax_model = ParaxialModel(self, **kwargs)
        self.ele_model = ElementModel(self, **kwargs)
        self.part_tree = PartTree(self, **kwargs)

        self.map_submodels()

        if self.specsheet:
            self.set_from_specsheet()

        if kwargs.get('do_init', True):
            # need to do this after OpticalSpec is initialized
            self.seq_model.update_model()
            elements_from_sequence(self.ele_model,
                                   self.seq_model,
                                   self.part_tree)
 def rebuild_from_seq(self):
     """ Rebuild ele_model and part_tree from seq_model. """
     self['em'].elements = []
     self['pt'].root_node.children = []
     elements_from_sequence(self['em'], self['sm'], self['pt'])