Пример #1
0
def specsheet_from_parax_data(opt_model, specsheet):
    """ update specsheet to contents of opt_model, while preserving inputs """
    if opt_model is None:
        return None
    seq_model = opt_model.seq_model
    optical_spec = opt_model.optical_spec
    fod = optical_spec.parax_data.fod
    conj_type = 'finite'
    if seq_model.gaps[0].thi > 10e8:
        conj_type = 'infinite'

    specsheet.conjugate_type = conj_type

    # specsheet.imager_inputs contains values of independent variables of
    # the optical system. Augment these as needed to get a defined imager.
    imager_inputs = dict(specsheet.imager_inputs)
    num_imager_inputs = len(imager_inputs)
    if num_imager_inputs == 0:
        # no user inputs, use model values
        if conj_type == 'finite':
            imager_inputs['m'] = fod.m
            imager_inputs['f'] = fod.efl
            specsheet.frozen_imager_inputs = [False] * 5
        else:  # conj_type == 'infinite'
            imager_inputs['s'] = -math.inf
            if fod.efl != 0:
                imager_inputs['f'] = fod.efl
            specsheet.frozen_imager_inputs = [True, True, True, True, False]
    elif num_imager_inputs == 1:
        # some/partial user input specification
        if conj_type == 'finite':
            # make sure that m is specified
            if 'm' in imager_inputs:
                imager_inputs['f'] = fod.efl
            else:
                imager_inputs['m'] = fod.m
            specsheet.frozen_imager_inputs = [False] * 5
        else:  # conj_type == 'infinite'
            imager_inputs['s'] = -math.inf
            if fod.efl != 0:
                imager_inputs['f'] = fod.efl
            specsheet.frozen_imager_inputs = [True, True, True, True, False]

    specsheet.imager = ideal_imager_setup(**imager_inputs)

    ape_key, ape_value = optical_spec.pupil.get_input_for_specsheet()
    fld_key, fld_value = optical_spec.field_of_view.get_input_for_specsheet()

    etendue_inputs = specsheet.etendue_inputs
    etendue_inputs[ape_key[0]][ape_key[1]][ape_key[2]] = ape_value
    etendue_inputs[fld_key[0]][fld_key[1]][fld_key[2]] = fld_value
    specsheet.generate_from_inputs(imager_inputs, etendue_inputs)

    return specsheet
Пример #2
0
def create_new_optical_system(efl=10.0, fov=1.0):
    imager_inputs = {'s': -math.inf, 'f': efl}
    inf_conj_imgr = ideal_imager_setup(**imager_inputs)

    ei = create_etendue_dict()
    ei['field']['object']['angle'] = fov
    ssi = SpecSheet('infinite',
                    imager=inf_conj_imgr,
                    imager_inputs=imager_inputs,
                    etendue_inputs=ei)

    opt_model = create_new_optical_model_from_specsheet(ssi)

    return opt_model
Пример #3
0
def test_ideal_imager_setup(**kwargs):
    m1 = -0.5
    s1 = -10.
    m1s1 = ideal_imager_setup(m=m1, s=s1)
    sp1 = m1s1.sp
    tt1 = m1s1.tt
    f1 = m1s1.f
    assert ideal_imager_setup(m=m1, s=s1) == ideal_imager_setup(s=s1, m=m1)
    assert ideal_imager_setup(m=m1, sp=sp1) == ideal_imager_setup(sp=sp1, m=m1)
    assert ideal_imager_setup(m=m1, tt=tt1) == ideal_imager_setup(tt=tt1, m=m1)
    assert ideal_imager_setup(m=m1, f=f1) == ideal_imager_setup(f=f1, m=m1)

    tt2 = 4.0
    f2 = 1.0
    tt2f2 = ideal_imager_setup(tt=tt2, f=f2)
    assert tt2f2.m == -1
    assert tt2f2.s == -2
    assert tt2f2.sp == 2
    f3 = 2.0
    with pytest.raises(ValueError):
        ideal_imager_setup(tt=tt2, f=f3)

    s_inf = -math.inf
    efl = 25.0
    s_inf_efl = ideal_imager_setup(s=s_inf, f=efl)
    assert s_inf_efl.m == -0
    assert s_inf_efl.s == -math.inf
    assert s_inf_efl.sp == efl
Пример #4
0
    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