def open_model(file_name): """ 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 Returns: if successful, an OpticalModel instance, otherwise, None """ file_extension = os.path.splitext(file_name)[1] opm = None if file_extension == '.seq': opm = OpticalModel() cvp.read_lens(opm, file_name) create_specsheet_from_model(opm) elif file_extension == '.roa': with open(file_name, 'r') as f: obj_dict = json_tricks.load(f) if 'optical_model' in obj_dict: opm = obj_dict['optical_model'] opm.sync_to_restore() return opm
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
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
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