Can't get figure 1.1 to work in my python environment

21 views
Skip to first unread message

Joshua Bartkoske

unread,
Feb 18, 2021, 9:26:07 PM2/18/21
to astroML-general
Hi there,

I am going through a course based on the astroML textbook and I wanted to ask if anyone knows why my computer might be producing this error when I run the code from the Github file for figure 1.1:

Traceback (most recent call last):

  File "C:\Users\shua4\OneDrive\Documents\Grad School\spring 2021\ASTR Research\untitled2.py", line 89, in <module>
    stars, galaxies = get_stars_and_galaxies()

  File "C:\Users\shua4\OneDrive\Documents\Grad School\spring 2021\ASTR Research\untitled2.py", line 32, in get_stars_and_galaxies
    stars = data[objtype == 6][:Nstars]

IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

For some clarification, when I simply ask for what data looks like, I get an array that puts everything in brackets and I am not sure why. If you have a solution, please let me know. I am using a Windows 10 machine with Anaconda and Spyder Python 3.8 as well.


data
Out[21]: 
array([([0.358174], [-0.508718], [2728], [0.103], [23.255], [22.633], [22.459], [21.911], [21.211], [0.487], [0.126], [0.145], [0.129], [0.264], [23.028], [22.621], [22.563], [22.039], [21.24 ], [0.378], [0.164], [0.14 ], [0.125], [0.248], [3], [1]),
       ([0.358382], [-0.551157], [2728], [0.107], [25.302], [22.345], [20.589], [18.896], [17.984], [0.711], [0.097], [0.031], [0.013], [0.02 ], [24.989], [22.347], [20.617], [18.896], [17.976], [0.793], [0.094], [0.038], [0.035], [0.038], [6], [0]),
       ([0.357898], [-0.570892], [2728], [0.109], [23.025], [22.317], [21.35 ], [21.057], [20.89 ], [0.67 ], [0.159], [0.103], [0.117], [0.359], [23.701], [22.919], [22.26 ], [21.932], [21.797], [0.611], [0.148], [0.111], [0.115], [0.379], [3], [1]),
       ...,
       ([3.843611], [-0.208263], [5052], [0.074], [25.649], [23.077], [22.11 ], [21.658], [21.474], [0.692], [0.227], [0.158], [0.17 ], [0.559], [25.503], [23.537], [22.717], [22.158], [22.294], [0.532], [0.199], [0.168], [0.154], [0.562], [3], [1]),
       ([3.895482], [-0.208669], [5052], [0.076], [21.023], [20.024], [19.563], [19.412], [19.355], [0.076], [0.016], [0.015], [0.018], [0.061], [21.005], [20.024], [19.557], [19.425], [19.357], [0.07 ], [0.025], [0.021], [0.023], [0.059], [6], [1]),
       ([3.881584], [-0.209449], [5052], [0.075], [22.778], [22.741], [22.187], [21.901], [21.29 ], [0.308], [0.128], [0.124], [0.148], [0.345], [22.801], [22.859], [22.291], [22.047], [21.441], [0.285], [0.141], [0.119], [1.056], [0.323], [3], [0])],
      dtype=[('ra', '<f8', (1,)), ('dec', '<f8', (1,)), ('run', '<i2', (1,)), ('rExtSFD', '<f8', (1,)), ('uRaw', '<f8', (1,)), ('gRaw', '<f8', (1,)), ('rRaw', '<f8', (1,)), ('iRaw', '<f8', (1,)), ('zRaw', '<f8', (1,)), ('uErr', '<f8', (1,)), ('gErr', '<f8', (1,)), ('rErr', '<f8', (1,)), ('iErr', '<f8', (1,)), ('zErr', '<f8', (1,)), ('uRawPSF', '<f8', (1,)), ('gRawPSF', '<f8', (1,)), ('rRawPSF', '<f8', (1,)), ('iRawPSF', '<f8', (1,)), ('zRawPSF', '<f8', (1,)), ('upsfErr', '<f8', (1,)), ('gpsfErr', '<f8', (1,)), ('rpsfErr', '<f8', (1,)), ('ipsfErr', '<f8', (1,)), ('zpsfErr', '<f8', (1,)), ('type', '<i2', (1,)), ('ISOLATED', '<i4', (1,))])

Any help or direction would be much appreciated.
Thank you,

Blessings,
JoShua

Brigitta Sipocz

unread,
Feb 19, 2021, 12:57:43 PM2/19/21
to Joshua Bartkoske, astroML-general
Dear Joshua,

The root of this issue appears to be the same, or very similar we saw a few weeks ago. I'll systematically test and update all the examples or astroML itself to get the scripts working again.

For an immediate workaround, you could change the line that defines to "data = Table(fetch_imaging_sample())", after you imported Table: "from astropy.table import Table"

Cheers,
 Brigitta

--
You received this message because you are subscribed to the Google Groups "astroML-general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to astroml-gener...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/astroml-general/b0927c2d-cd07-4bbd-bd2c-efca0b86e7c1n%40googlegroups.com.

Brigitta Sipocz

unread,
Feb 25, 2021, 11:38:24 PM2/25/21
to Joshua Bartkoske, astroML-general
Dear Joshua,

The original plotting script should work again. The regression was due to a recent bugfix in astropy, which meant that a header keyword in the datafile wasn't ignored any more which change the data type of the columns.
To make sure the new version of the datafile is used, it's best to delete the cached version. The cache is located in astroML-data directory, in the user home. Filename is "sgSDSSimagingSample.fit.gz"

This very same issue affected another book figure, 6.12, generated by the script book_figures/chapter6/fig_stellar_XD.py.

Cheers,
 Brigitta

Reply all
Reply to author
Forward
0 new messages