Separate multi-block comments; update README

This commit is contained in:
Nicolò P 2024-12-24 15:01:55 +01:00
parent 623b939df1
commit 109ae71059
5 changed files with 65 additions and 9 deletions

4
.gitignore vendored
View File

@ -1,3 +1,7 @@
# Vim stuff
*.swp
*.swo
composer.lock
vendor/
docs/

View File

@ -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??

View File

@ -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,

View File

@ -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'
);
}
}

33
tests/ImageBlobTest.php Normal file
View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class ImageBlobTest extends TestCase
{
private Dumbastro\FitsPhp\ImageBlob $imageBlob;
private Dumbastro\FitsPhp\Fits $fits;
private Dumbastro\FitsPhp\FitsHeader $header;
protected function setUp(): void
{
$this->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);
}
}