Skip to content

Commit

Permalink
fix bug when getting first column from bintable
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit Kapadia committed Nov 23, 2013
1 parent 3945bbe commit b8d64b0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fits",
"version": "0.6.2",
"version": "0.6.4",
"author": "Amit Kapadia <amit@zooniverse.org>",
"description": "Library for reading the FITS astronomical file format",
"repository": {
Expand Down
14 changes: 9 additions & 5 deletions src/fits.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Parser extends Base
if typeof(@arg) is 'string'

# Define function at runtime for getting next block
@readNextBlock = @readBlock
@readNextBlock = @_readBlockFromBuffer

# Get the remote file as an arraybuffer
xhr = new XMLHttpRequest()
Expand Down Expand Up @@ -99,6 +99,9 @@ class Parser extends Base
# Store the file byte length
@length = @arg.size

# Define function at runtime for getting next block
@readNextBlock = @_readBlockFromFile

# Get the local file as an arraybuffer
@readFromFile()

Expand All @@ -120,9 +123,6 @@ class Parser extends Base
# Initialize a new FileReader
@reader = new FileReader()

# Define function at runtime for getting next block
@readNextBlock = @reader.readAsArrayBuffer

# Set reader handler
@reader.onloadend = (e) =>
@readBlock(e.target.result)
Expand Down Expand Up @@ -220,6 +220,10 @@ class Parser extends Base
@readNextBlock(block)
return

# Use one of these depending on the initialization parameter (File or ArrayBuffer)
_readBlockFromBuffer: (block) -> @readBlock(block)
_readBlockFromFile: (block) -> @reader.readAsArrayBuffer(block)

# Create the appropriate data unit based on info from header
createDataUnit: (header, blob) ->
type = header.getDataType()
Expand Down Expand Up @@ -261,5 +265,5 @@ class FITS extends Base
getDataUnit: (index) -> return @getHDU(index).data


FITS.version = '0.6.2'
FITS.version = '0.6.4'
@astro.FITS = FITS
9 changes: 6 additions & 3 deletions src/tabular.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Tabular extends DataUnit

# Get column of data specified by parameters.
getColumn: (name, callback, opts) ->

console.log 'getColumn'
# Check for blob
if @blob?

Expand All @@ -76,7 +76,11 @@ class Tabular extends DataUnit
descriptor = @descriptors[index]
accessor = @accessors[index]
elementByteLength = @elementByteLengths[index]
elementByteOffset = @elementByteLengths[0..index - 1].reduce( (a, b) -> a + b )
elementByteOffset = @elementByteLengths.slice(0, index)
if elementByteOffset.length is 0
elementByteOffset = 0
else
elementByteOffset = elementByteOffset.reduce( (a, b) -> a + b)

column = if @typedArray[descriptor]? then new @typedArray[descriptor](@rows) else []

Expand All @@ -93,7 +97,6 @@ class Tabular extends DataUnit
# Define callback to pass to getRows
cb = (buffer, opts) =>
nRows = buffer.byteLength / @rowByteSize

view = new DataView(buffer)
offset = elementByteOffset

Expand Down
17 changes: 15 additions & 2 deletions test/FileSpec.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,20 @@
// });

// specObj-dr10
table.getColumn("PLUG_RA", function(column) {
console.log("PLUG_RA", column.length);
// table.getColumn("PLUG_RA", function(column) {
// console.log("PLUG_RA", column.length);
// console.log(new Date() - start);
// });

// spec-0406-51869-0012
table.getColumn("flux", function(column) {
console.log("flux", column.length, column);
console.log(new Date() - start);
});
// table.getRows(0, 10, function(rows) {
// console.table(rows);
// });


// table.getRows(0, 10, function(rows) {
// console.log(rows);
Expand Down Expand Up @@ -197,6 +207,9 @@
case "specObj-dr10.fits":
testBinaryTable(fits);
break;
case "spec-0406-51869-0012":
testBinaryTable(fits);
break;
default:
console.log(fits);
}
Expand Down

0 comments on commit b8d64b0

Please sign in to comment.