コード例 #1
0
def process_glass_data(glass_data):
    """ process GLA string for fictitious, catalog or private catalog glass """
    if isanumber(glass_data):  # process as fictitious glass code
        n, v = fictitious_glass_decode(float(glass_data))
        medium = Glass(n, v, '')

    else:  # look for glass name and optional catalog
        name_cat = glass_data.split('_')
        if len(name_cat) == 2:
            name, cat = name_cat
        elif len(name_cat) == 1:
            name, cat = glass_data, None
        if cat is not None:
            if cat.upper() == 'SCHOTT' and name[:1].upper() == 'N':
                name = name[:1] + '-' + name[1:]
            elif cat.upper() == 'OHARA' and name[:1].upper() == 'S':
                name = name[:1] + '-' + name[1:]
                if not name[-2:].isdigit() and name[-1].isdigit():
                    name = name[:-1] + ' ' + name[-1]
            try:
                medium = gfact.create_glass(name, cat)
            except glasserror.GlassNotFoundError as gerr:
                logging.info('%s glass data type %s not found', gerr.catalog,
                             gerr.name)
                logging.info('Replacing material with air.')
                medium = Air()
        else:  # name with no data. default to crown glass
            global _private_catalog_glasses
            if name in _private_catalog_glasses:
                medium = _private_catalog_glasses[name]
            else:
                medium = Glass(1.5, 60.0, name)
    return medium
コード例 #2
0
def lens_from_power(power=0.,
                    bending=0.,
                    th=None,
                    sd=1.,
                    med=None,
                    nom_wvl='d'):
    if med is None:
        med = Glass()
    rndx = med.rindex(nom_wvl)

    if th is None:
        th = sd / 5

    if bending == -1:
        cv2 = -power / (rndx - 1)
        cv1 = 0
    else:
        B = (bending - 1) / (bending + 1)
        a = (rndx - 1) * (th / rndx) * B
        b = 1 - B
        c = -power / (rndx - 1)
        cv1 = (-b + np.sqrt(b**2 - 4 * a * c)) / (2 * a)
        cv2 = cv1 * B

    return cv1, cv2, th, rndx, sd
コード例 #3
0
def create_lens(power=0., bending=0., th=None, sd=1., med=None):
    if med is None:
        med = Glass()
    rndx = med.rindex('d')
    cv1 = power / (2 * (rndx - 1))
    cv2 = -power / (2 * (rndx - 1))
    s1 = Surface(profile=Spherical(c=cv1), max_ap=sd, delta_n=(rndx - 1))
    s2 = Surface(profile=Spherical(c=cv2), max_ap=sd, delta_n=(1 - rndx))
    if th is None:
        th = sd / 5
    g = Gap(t=th, med=med)
    le = Element(s1, s2, g, sd=sd)
    return [[s1, g, None, rndx, 1], [s2, None, None, 1, 1]], [le]
コード例 #4
0
def create_lens(power=0., bending=0., th=None, sd=1., med=None, **kwargs):
    if med is None:
        med = Glass()
    lens = lens_from_power(power=power, bending=bending, th=th, sd=sd, med=med)
    cv1, cv2, th, rndx, sd = lens

    s1 = Surface(profile=Spherical(c=cv1), max_ap=sd, delta_n=(rndx - 1))
    s2 = Surface(profile=Spherical(c=cv2), max_ap=sd, delta_n=(1 - rndx))
    g = Gap(t=th, med=med)
    le = Element(s1, s2, g, sd=sd)
    tree = le.tree()

    return [[s1, g, None, rndx, 1], [s2, None, None, 1, 1]], [le], tree
コード例 #5
0
ファイル: zmxread.py プロジェクト: Yecoder/ray-optics
    def __call__(self, sm, cur, cmd, inputs):
        """ process GLAS command for fictitious, catalog glass or mirror"""

        if cmd == "GCAT":
            inputs = inputs.split()
            # Check catalog names, only add those we recognize
            for gc in inputs:
                try:
                    gfact.get_glass_catalog(gc)
                except glasserror.GlassCatalogNotFoundError:
                    continue
                else:
                    self.glass_catalogs.append(gc)
            # If no catalogs were recognized, use the default set
            if len(self.glass_catalogs) == 0:
                self.glass_catalogs = gfact._cat_names
            self.track_contents["GCAT"] = inputs
            return True
        elif cmd == "GLAS":
            g = sm.gaps[cur]
            inputs = inputs.split()
            name = inputs[0]
            medium = None
            if name == 'MIRROR':
                sm.ifcs[cur].interact_mode = 'reflect'
                g.medium = sm.gaps[cur - 1].medium
                self.track_contents[name] += 1
                return True
            elif name == '___BLANK':
                nd = float(inputs[3])
                vd = float(inputs[4])
                g.medium = Glass(nd=nd, vd=vd, mat=glass_encode(nd, vd))
                self.track_contents[name] += 1
                return True
            elif isanumber(name):
                # process as a 6 digit code, no decimal point
                m = self.find_6_digit_code(name)
                if m is not None:
                    g.medium = m
                    self.track_contents['6 digit code'] += 1
                    return True
            else:  # must be a glass type
                medium = self.find_glass(name, '')
                g.medium = medium
                return True

        else:
            return False
コード例 #6
0
ファイル: cmdproc.py プロジェクト: imyu37/ray-optics
    def process_glass_data(self, glass_data):
        if isanumber(glass_data):
            # process as a 6 digit code, no decimal point
            medium = self.find_6_digit_code(glass_data)
            if medium is not None:
                self.track_contents['6 digit code'] += 1
                return medium
            else:  # process as fictitious glass code
                nd, vd = fictitious_glass_decode(float(glass_data))
                medium = Glass(nd, vd, mat=glass_data)
                self.track_contents['fictitious glass'] += 1
                return medium
        else:  # look for glass name and optional catalog
            name_cat = glass_data.split('_')
            if len(name_cat) == 2:
                name, catalog = name_cat
            elif len(name_cat) == 1:
                name, catalog = glass_data, None

            if catalog is not None:
                if catalog.upper() == 'SCHOTT' and name[:1].upper() == 'N':
                    name = name[:1] + '-' + name[1:]
                elif catalog.upper() == 'OHARA' and name[:1].upper() == 'S':
                    name = name[:1] + '-' + name[1:]
                    if not name[-2:].isdigit() and name[-1].isdigit():
                        name = name[:-1] + ' ' + name[-1]

            medium = self.find_glass(name, catalog, always=False)
            if medium:
                return medium
            else:  # name with no data. default to crown glass
                global _private_catalog_glasses
                if name in _private_catalog_glasses:
                    medium = _private_catalog_glasses[name]
                else:
                    medium = Medium(1.5, 'not ' + name)
                return medium