Search code examples
arraysidllarge-data

Extract individual columns from an array in IDL


I'm working with SDSS spectra, I read a fits file using mrdfits, it says the data is stored in 8 columns and 3838 rows which is the correct dimension of the data.

But when I seek out a specific column using print spec[0,1] it returns an error of out of bound. If I use print spec[0*1] it gives an output of

{11.7020 3.58080 0.0990829 0 0 1.49589 15.6233 10.8985}

Which I think is one element and not 8. How can i separate these columns into individual ones from this array?


Solution

  • I am not familiar with your exact data format, but it seems like each row is a structure with 8 fields. The HELP command will be useful to you here:

    IDL> help, spec[0]
    

    should give you some output on how to access the columns of data. For example, I can make an example spec to show you (don't worry about this command, you already have a spec!):

    IDL> spec = replicate({a: 0, b:0, c:0, d:0, e:0, f:0, g:0, h:0}, 3838)
    

    HELP will tell you that you have an array of structures:

    IDL> help, spec
    SPEC            STRUCT    = -> <Anonymous> Array[3838]
    

    HELP on an individual row will tell you the names of the fields (columns):

    IDL> help, spec[0]
    ** Structure <170b6a8>, 8 tags, length=16, data length=16, refs=2:
       A               INT              0
       B               INT              0
       C               INT              0
       D               INT              0
       E               INT              0
       F               INT              0
       G               INT              0
       H               INT              0
    

    You can also access an entire column:

    IDL> help, spec.a
    <Expression>    INT       = Array[3838]
    

    You can slice and dice your data in a variety of ways, check out spec[100], spec[100].a, spec.a, or spec.a[100]. You can also use normal array indexing, such as spec[10:19].a.