Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in radmc3dPy Read Circular Image #54

Open
jonhulberg opened this issue May 1, 2024 · 0 comments
Open

Bug in radmc3dPy Read Circular Image #54

jonhulberg opened this issue May 1, 2024 · 0 comments

Comments

@jonhulberg
Copy link

jonhulberg commented May 1, 2024

Hello,

I found a small bug in the radmc3Dpy code for reading circular image spectral 'cubes'. It occurs at line 2204 of the image.py file in. the radmc3Dpy module. See the command, and part of the error message below.

Command: im = image.readcircimage('./circimage.out')

Error:

File ~/radmc3d-2.0/python/radmc3dPy/radmc3dPy/image.py:2204, in radmc3dCircimage.readImage(self, filename, old)
   2202 for ir in range(self.nr + 1):
   2203     s = f.readline().split()
-> 2204     self.image[ir, iphi, 0, inu] = float(s[0])
   2205     if self.npol > 1:
   2206         self.image[ir, iphi, 1, inu] = float(s[1])

IndexError: list index out of range

The cause of the problem is that for circle image files containing multiple frequencies, the function readImage doesn't account for a blank line between each set of intensities. So the variable 's' at some point is an empty string, causing the error in line 2204.

To fix this issue, I added an extra s=f.readline() to line 2209 of the file. Currently, lines 2200-2210 look like this.

                for inu in range(self.nfreq):
                    for iphi in range(self.nphi):
                        for ir in range(self.nr + 1):
                            s = f.readline().split()
                            self.image[ir, iphi, 0, inu] = float(s[0])
                            if self.npol > 1:
                                self.image[ir, iphi, 1, inu] = float(s[1])
                                self.image[ir, iphi, 2, inu] = float(s[2])
                                self.image[ir, iphi, 3, inu] = float(s[3])

            psize = self.getPixelSize()

With the fix, it should look like this:

                for inu in range(self.nfreq):
                    for iphi in range(self.nphi):
                        for ir in range(self.nr + 1):
                            s = f.readline().split()
                            self.image[ir, iphi, 0, inu] = float(s[0])
                            if self.npol > 1:
                                self.image[ir, iphi, 1, inu] = float(s[1])
                                self.image[ir, iphi, 2, inu] = float(s[2])
                                self.image[ir, iphi, 3, inu] = float(s[3])
                        s=f.readline()
            psize = self.getPixelSize()

I'm attaching an example image file that you can use to verify. I had to rename it to .txt for github to allow it.
circimage.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant