Esempio n. 1
0
def open_model(file_name, info=False, **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
        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 == '.seq':
        opm, import_info = cvp.read_lens(file_name, **kwargs)
        create_specsheet_from_model(opm)
        if info:
            return opm, import_info
    elif file_extension == '.roa':
        opm = open_roa(file_name, **kwargs)
    elif file_extension == '.zmx':
        opm, import_info = zmxread.read_lens_file(file_name, **kwargs)
        if info:
            return opm, import_info
    return opm
Esempio n. 2
0
def create_new_ideal_imager(**inputs):
    conj_type = (inputs['conjugate_type'] if 'conjugate_type' in inputs
                 else 'finite')
    specsheets = create_specsheets()
    if 'opt_model' in inputs:
        opt_model = inputs['opt_model']
        specsheet = create_specsheet_from_model(opt_model,
                                                specsheets=specsheets)
        conj_type = specsheet.conjugate_type
        specsheets[conj_type] = specsheet

    if 'gui_parent' in inputs:
        gui_parent = inputs['gui_parent']
        opt_model = gui_parent.app_manager.model
        iid = IdealImagerDialog(conj_type, specsheets,
                                cmd_fct=gui_parent.handle_ideal_imager_command,
                                parent=gui_parent)

        gui_parent.add_subwindow(iid, ModelInfo(gui_parent.app_manager.model,
                                                update_specsheet,
                                                (iid, opt_model)))
        iid.update_values()
        iid.show()
    else:
        iid = IdealImagerDialog(conj_type, specsheets)
        iid.update_values()
        iid.exec_()
Esempio n. 3
0
 def update_model(self):
     self.seq_model.update_model()
     self.optical_spec.update_model()
     self.parax_model.update_model()
     self.ele_model.update_model()
     if self.specsheet is None:
         self.specsheet = create_specsheet_from_model(self)
 def update_model(self, **kwargs):
     self.seq_model.update_model(**kwargs)
     self.optical_spec.update_model(**kwargs)
     self.parax_model.update_model(**kwargs)
     self.ele_model.update_model(**kwargs)
     self.part_tree.update_model(**kwargs)
     if self.specsheet is None:
         self.specsheet = create_specsheet_from_model(self)
         self.map_submodels()
Esempio n. 5
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
Esempio n. 6
0
def open_model(file_name, **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
        kwargs (dict): keyword args passed to the reader functions

    Returns:
        if successful, an OpticalModel instance, otherwise, None
    """
    file_extension = os.path.splitext(file_name)[1]
    opm = None
    if file_extension == '.seq':
        opm = cvp.read_lens(file_name, **kwargs)
        create_specsheet_from_model(opm)
    elif file_extension == '.roa':
        opm = open_roa(file_name, **kwargs)

    return opm