Example #1
0
 def para_seqtrace(
     self,
     pilotbundle,
     initialbundle,
     elementsequence,
     pilotraypathsequence=None,
     use6x6=True
 ):  # [("elem1", [1, 3, 4]), ("elem2", [1,4,4]), ("elem1", [4, 3, 1])]
     rpath = RayPath(initialbundle)
     pilotpath = RayPath(pilotbundle)
     if pilotraypathsequence is None:
         pilotraypathsequence = tuple(
             [0 for i in range(len(elementsequence))])
         # choose first pilotray in every element by default
     print("pilot ray path sequence")
     print(pilotraypathsequence)
     for ((elem, subseq), prp_nr) in zip(elementsequence,
                                         pilotraypathsequence):
         (append_pilotpath,
          append_rpath) = self.elements[elem].para_seqtrace(
              pilotpath.raybundles[-1],
              rpath.raybundles[-1],
              subseq,
              self.material_background,
              pilotraypath_nr=prp_nr,
              use6x6=use6x6)
         rpath.appendRayPath(append_rpath)
         pilotpath.appendRayPath(append_pilotpath)
     return (pilotpath, rpath)
Example #2
0
    def extractXYUV(self, pilotbundle, elementsequence, pilotraypathsequence=None, use6x6=True):
        pilotpath = RayPath(pilotbundle)
        if pilotraypathsequence is None:
            pilotraypathsequence = tuple([0 for i in range(len(elementsequence))])
            # choose first pilotray in every element by default
        print("pilot ray path sequence")
        print(pilotraypathsequence)

        stops_found = 0

        for (elem, subseq) in elementsequence:
            for (surfname, options_dict) in subseq:
                if options_dict.get("is_stop", False):
                    stops_found += 1

        if stops_found != 1:
            print("WARNING: %d stops found. need exactly 1!" % (stops_found,))
            print("Returning None.")
            return None

        lst_matrix_pairs = []

        for ((elem, subseq), prp_nr) in zip(elementsequence, pilotraypathsequence):
            #print(subseq)            
            (hitlist, optionshitlist_dict) = self.elements[elem].sequence_to_hitlist(subseq)
            # hitlist may contain exactly one stophit
            
            (append_pilotpath, elem_matrices) = self.elements[elem].calculateXYUV(pilotpath.raybundles[-1], subseq, self.material_background, pilotraypath_nr=prp_nr, use6x6=use6x6)
            pilotpath.appendRayPath(append_pilotpath) 
            
            ls1 = []
            ls2 = []
            found_stop = False

            for h in hitlist:
                (d1, d2) = optionshitlist_dict[h]
                if d1.get("is_stop", False) and not d2.get("is_stop", False):
                    found_stop = True
                if not found_stop:
                    ls1.append(elem_matrices[h])
                else:
                    ls2.append(elem_matrices[h])
            
            if not use6x6:
                m1 = np.eye(4, dtype=complex)
                m2 = np.eye(4, dtype=complex)
            else:
                m1 = np.eye(6)
                m2 = np.eye(6)
                
            for m in ls1:
                m1 = np.dot(m, m1)
            for m in ls2:
                m2 = np.dot(m, m2)

            lst_matrix_pairs.append((m1, m2, found_stop))
        
        if not use6x6:
            m_obj_stop = np.eye(4, dtype=complex)
            m_stop_img = np.eye(4, dtype=complex)
        else:
            m_obj_stop = np.eye(6)
            m_stop_img = np.eye(6)

        obj_stop_branch = True
        for (m1, m2, found_stop) in lst_matrix_pairs:
            if obj_stop_branch:
                m_obj_stop = np.dot(m1, m_obj_stop)
                if found_stop:
                    m_stop_img = np.dot(m2, m_stop_img)
                    obj_stop_branch = False
            else:
                m_stop_img = np.dot(m1, m_stop_img)
            
        return (m_obj_stop, m_stop_img)