From 109ae710594c9a21cdd5129baad5935ac1b63a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Tue, 24 Dec 2024 15:01:55 +0100 Subject: [PATCH] Separate multi-block comments; update README --- .gitignore | 4 ++++ README.md | 10 ++++++---- src/FitsHeader.php | 7 +++++++ tests/FitsHeaderTest.php | 20 +++++++++++++++----- tests/ImageBlobTest.php | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 tests/ImageBlobTest.php diff --git a/.gitignore b/.gitignore index 427edf4..dcaf15e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# Vim stuff +*.swp +*.swo + composer.lock vendor/ docs/ diff --git a/README.md b/README.md index 9aceec9..6541bcf 100644 --- a/README.md +++ b/README.md @@ -72,8 +72,10 @@ echo $blob->bitpix->type(); //int32 ## TODO -- [x] Read keywords from the FITS header - [x] Separate the main data table (actual image data) from the header (partly done? Who knows...) -- [ ] Actually display the image in the standard output -- [ ] Save the image to PNG and JPG -- [ ] Manipulate the bits using basic processing algorithms?? +- [x] Read keywords from the FITS header (but consider values and comments could be more than 80-bytes long) +- [ ] History keywords? +- [ ] FITS extensions? What to do with NAXIS > 2? +- [ ] Actually display the image in the standard output (with SVG?) +- [ ] Save the image to PNG and JPG +- [ ] Manipulate the bits using basic processing algorithms?? diff --git a/src/FitsHeader.php b/src/FitsHeader.php index 3fefac3..2890b1e 100644 --- a/src/FitsHeader.php +++ b/src/FitsHeader.php @@ -28,6 +28,8 @@ class FitsHeader * * From the spec: each keyword record, including * any comments, is at most 80 bytes long + * @todo Comments and keyword values could span more + than one 80-bytes block... * @return Keyword[] */ private function readKeywords(): array @@ -50,6 +52,11 @@ class FitsHeader $name = $keyVal[0]; $value = $keyVal[1] ?? ''; + if (str_starts_with($name, 'COMMENT')) { + $value = explode('COMMENT', $name)[1]; + $name = 'COMMENT'; + } + $keywords[] = new Keyword( name : $name, value : $value, diff --git a/tests/FitsHeaderTest.php b/tests/FitsHeaderTest.php index 57af8fe..2c8c961 100644 --- a/tests/FitsHeaderTest.php +++ b/tests/FitsHeaderTest.php @@ -6,19 +6,29 @@ use PHPUnit\Framework\TestCase; final class FitsHeaderTest extends TestCase { - public function testKeywordValue(): void + private Dumbastro\FitsPhp\Fits $fits; + private Dumbastro\FitsPhp\FitsHeader $header; + + protected function setUp(): void { - $fits = new Dumbastro\FitsPhp\Fits(__DIR__ . '/test_orion.fit'); - $header = new Dumbastro\FitsPhp\FitsHeader($fits->headerBlock); + $this->fits = new Dumbastro\FitsPhp\Fits(__DIR__ . '/test_orion.fit'); + $this->header = new Dumbastro\FitsPhp\FitsHeader($this->fits->headerBlock); + } + public function testKeywordValues(): void + { $this->assertSame( - trim($header->getKeywordValue('BITPIX')), + trim($this->header->getKeywordValue('BITPIX')), '16' ); $this->assertSame( - trim($header->getKeywordValue('NAXIS')), + trim($this->header->getKeywordValue('NAXIS')), '3' ); + $this->assertSame( + trim($this->header->getKeywordValue('STACKCNT')), + '86' + ); } } diff --git a/tests/ImageBlobTest.php b/tests/ImageBlobTest.php new file mode 100644 index 0000000..314cd1f --- /dev/null +++ b/tests/ImageBlobTest.php @@ -0,0 +1,33 @@ +fits = new Dumbastro\FitsPhp\Fits(__DIR__ . '/test_orion.fit'); + $this->header = $this->fits->header(); + $blob = $this->fits->imageBlob; + + $this->imageBlob = new Dumbastro\FitsPhp\ImageBlob($this->header, $blob); + } + + public function testBitpixValue(): void + { + $this->assertSame($this->imageBlob->bitpix->value, 16); + } + + public function testDataBitsLength(): void + { + $this->assertSame($this->imageBlob->dataBits, 16*2448*1669); + } +} + +