cihologramas / pyoptools

Python tools for optical design
GNU General Public License v3.0
137 stars 46 forks source link

AttributeError when using 'CCD.get_optical_path_data()' #83

Closed oeolartep closed 3 years ago

oeolartep commented 4 years ago

This error message pops up when running the first example of the section optical maps at the Tutorial.1 notebook:

image

Way to reproduce

from pyoptools.all import *

C=CCD()
S=System(complist=[(C,(0,0,5),(0,0,0))])
R=parallel_beam_c()
S.ray_add(R)
S.propagate()
C.get_optical_path_data()

Version information

Python 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] Linux-4.19.0-9-amd64-x86_64-with-debian-10.4 cython version: 0.16.2 pyoptools version: 1.18.2

oeolartep commented 4 years ago

The problem is that when the optical path calculation function is called, a comparison between a Ray and a NoneType object is raised (at least once), but this comparison is not implemented at the __eq__ method.

A workaround for this problem is to modify the __eq__ method (at ray.pyx) like this:

def __eq__(self, other):
    if isinstance(other, Ray):
        return np.array_equal(self.pos, other.pos) and\
        np.array_equal(self.dir, other.dir) and\
        self.intensity == other.intensity and\
        self.wavelength == other.wavelength and\
        self.n == other.n and\
        self.label == other.label and\
        self.order == other.order and\
        self.orig_surf == other.orig_surf
    else:
        return NotImplemented

Original implementation:

def __eq__(self, other):
    return np.array_equal(self.pos, other.pos) and\
    np.array_equal(self.dir, other.dir) and\
    self.intensity == other.intensity and\
    self.wavelength == other.wavelength and\
    self.n == other.n and\
    self.label == other.label and\
    self.order == other.order and\
    self.orig_surf == other.orig_surf

Reference: https://github.com/googleapis/google-cloud-python/blob/26214d229860c5ec128d0d767f1d302f588d49ec/bigquery/google/cloud/bigquery/schema.py#L103-L113

ramezquitao commented 3 years ago

The solution proposed may wirk, but the real problem was that the method optical path parent had a line:

if self.parent != None:

and it should be:

if self.parent is not None:

I already corrected it in my own fork, and will merge to master later today.

Will close the issue after the merge.

ramezquitao commented 3 years ago

Solved