UNPKG

slimfits

Version:

Package for loading data stored in FITS data format

49 lines 2.63 kB
import { Constants } from '../interfaces'; import { KeywordsManager } from '../utils/KeywordsManager'; import { AsciiConverter } from '../utils/AsciiConverter'; var AsciiTableDataReader = /** @class */ (function () { function AsciiTableDataReader() { } Object.defineProperty(AsciiTableDataReader.prototype, "name", { get: function () { return 'ASCII table data'; }, enumerable: true, configurable: true }); AsciiTableDataReader.prototype.canReadData = function (header) { return KeywordsManager.hasValue(header, 'XTENSION', 'TABLE'); }; AsciiTableDataReader.prototype.readDataSize = function (header) { var rowsCount = KeywordsManager.getValue(header, 'NAXIS2', 1); var rowLength = KeywordsManager.getValue(header, 'NAXIS1', 1); return Math.ceil(rowLength * rowsCount / Constants.blockLength) * Constants.blockLength; }; AsciiTableDataReader.prototype.readDataAsync = function (file, offsetBytes, header) { var rowsCount = KeywordsManager.getValue(header, 'NAXIS2', 1); var rowLength = KeywordsManager.getValue(header, 'NAXIS1', 1); var fieldsCount = KeywordsManager.getValue(header, 'TFIELDS', 0); var tforms = header.filter(function (k) { return k.key.indexOf('TFORM') === 0; }) .map(function (k) { return AsciiConverter.getConverterFor(k.value, rowsCount); }); var asciiconverters = tforms.map(function (x) { return x.converter; }); var resultList = tforms.map(function (x) { return x.array; }); var positions = header.filter(function (k) { return k.key.indexOf('TBCOL') === 0; }) .map(function (k) { return k.value - 1; }).concat([rowLength]); if ((positions.length + 1) !== fieldsCount) { throw new Error("There are " + positions.length + " TBCOL# keywords whereas TFIELDS specifies " + fieldsCount); } return file.getStringAsync(offsetBytes, rowLength * rowsCount).then(function (data) { for (var rowIdx = 0; rowIdx < rowsCount; rowIdx++) { var line = data.substr(rowIdx * rowLength, rowLength); for (var posIdx = 0; posIdx < fieldsCount; posIdx++) { var chunk = line.substr(positions[posIdx], positions[posIdx + 1] - positions[posIdx]); resultList[posIdx][rowIdx] = asciiconverters[posIdx](chunk.trim()); } } return resultList; }); }; return AsciiTableDataReader; }()); export { AsciiTableDataReader }; //# sourceMappingURL=AsciiTableDataReader.js.map