コード例 #1
0
def do_etendue_via_imager(conj_type,
                          imager,
                          etendue_inputs,
                          etendue_grid,
                          n_0=1,
                          n_k=1):
    imager_inputs = {}
    li = dict2d.num_items_by_type(etendue_inputs, fld_ape_set, obj_img_set)
    if li['field'] == 1:
        row = dict2d.row(etendue_inputs, 'field')
        obj_img_key = 'object' if len(row['object']) else 'image'
        do_field_via_imager(conj_type,
                            imager,
                            etendue_inputs,
                            obj_img_key,
                            etendue_grid,
                            n_0=n_0,
                            n_k=n_k)

    if li['aperture'] == 1:
        row = dict2d.row(etendue_inputs, 'aperture')
        obj_img_key = 'object' if len(row['object']) else 'image'
        do_aperture_via_imager(conj_type, imager, etendue_inputs, obj_img_key,
                               etendue_grid)

    if li['field'] == 2 or li['aperture'] == 2:
        fld_ape_key = 'field' if li['field'] == 2 else 'aperture'
        # solve for imager
        imager_inputs = do_etendue_to_imager(fld_ape_key,
                                             etendue_inputs,
                                             etendue_grid,
                                             n_0=n_0,
                                             n_k=n_k)

    return imager_inputs
コード例 #2
0
ファイル: specsheet.py プロジェクト: mniehus/ray-optics
    def generate_from_inputs(self, imgr_inputs, etendue_inputs):
        """ compute imager and etendue values given input dicts """
        max_partition, max_num_inputs = self.partition_defined()
        num_imager_inputs = self.partitions['imager']
        num_field_inputs = self.partitions['field']
        num_aperture_inputs = self.partitions['aperture']

        conj_type = self.conjugate_type

        imager_inputs = {}
        if max_num_inputs <= 1:
            # fill in imager_inputs with any previous calculations for m or f
            if conj_type == 'finite':
                if num_imager_inputs < 2 and self.imager.m is not None:
                    imager_inputs['m'] = self.imager.m
            else:
                if num_imager_inputs < 2 and self.imager.f is not None:
                    imager_inputs['f'] = self.imager.f

        # update imager_inputs with user entries
        imager_inputs.update(imgr_inputs)
        imager_inputs = {
            k: v
            for (k, v) in imager_inputs.items() if v is not None
        }

        # calculate an ideal imager for imager_inputs
        imager = ideal_imager_setup(**imager_inputs)

        if conj_type == 'finite':
            imager_defined = True if imager.m is not None else False
        else:
            imager_defined = True if imager.f is not None else False

        etendue_values = self.etendue_values

        for fa_key, fa_value in etendue_inputs.items():
            for oi_key, oi_value in fa_value.items():
                etendue.fill_in_etendue_data(imager, fa_key,
                                             etendue_inputs[fa_key][oi_key],
                                             etendue_values[fa_key][oi_key])

        if imager_defined:
            if num_field_inputs >= 1 and num_aperture_inputs >= 1:
                # we have enough data to calculate all of the etendue grid
                ii = etendue.do_etendue_via_imager(conj_type, imager,
                                                   etendue_inputs,
                                                   etendue_values)

                if ii:
                    imager_inputs[ii[0]] = ii[1]
                    imager = ideal_imager_setup(**imager_inputs)
                    etendue.do_etendue_via_imager(conj_type, imager,
                                                  etendue_inputs,
                                                  etendue_values)
            elif num_field_inputs == 1:
                # we have enough data to calculate all of the etendue grid
                row = dict2d.row(etendue_inputs, 'field')
                obj_img_key = 'object' if len(row['object']) else 'image'
                etendue.do_field_via_imager(conj_type, imager, etendue_inputs,
                                            obj_img_key, etendue_values)
            elif num_aperture_inputs == 1:
                # we have enough data to calculate all of the etendue grid
                row = dict2d.row(etendue_inputs, 'aperture')
                obj_img_key = 'object' if len(row['object']) else 'image'
                etendue.do_aperture_via_imager(conj_type, imager,
                                               etendue_inputs, obj_img_key,
                                               etendue_values)
        else:  # imager not specified
            if num_field_inputs == 2 or num_aperture_inputs == 2:
                fld_ape_key = 'field' if num_field_inputs == 2 else 'aperture'
                # solve for imager
                ii = etendue.do_etendue_to_imager(fld_ape_key, etendue_inputs,
                                                  etendue_values)
                imager_inputs[ii[0]] = ii[1]
                imager = ideal_imager_setup(**imager_inputs)
                # update etendue grid
                etendue.do_etendue_via_imager(conj_type, imager,
                                              etendue_inputs, etendue_values)

        self.imager = imager
        self.etendue_values = etendue_values
        return imager, etendue_values