Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seed dithering #411

Merged
merged 12 commits into from
Aug 20, 2024
Merged

Seed dithering #411

merged 12 commits into from
Aug 20, 2024

Conversation

esheldon
Copy link
Owner

closes #351

Add ability to seed the subtractive dither

@esheldon
Copy link
Owner Author

@dstndstn does this work for you?

Copy link
Collaborator

@beckermr beckermr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other parts of the lossy compression seed setting in the fits standard / cfitsio that we should be aware of to make sure our APIs here can support? We need not implement them OFC.

@esheldon
Copy link
Owner Author

Possibly. This code I added only sets the seed when you create the HDU, which seems safe. What other operations should be supported?

@beckermr
Copy link
Collaborator

beckermr commented Aug 20, 2024

The other options allowed by the standard are

-qt <level> - compute the seed from the checksum of the first tile of image pixels
-qN <level> where N is an integer between 1 and 10000 – use seed N (e.g., -q3010 4).

This all gets coupled into the FITS header via

FZDTHRSD - 'CLOCK', 'CHECKSUM', 1 - 10000

and here is the doc string for fits_set_dither_seed

This routine specifies the value of the offset that should be applied when calculating the random dithering when quantizing floating point iamges. A random offset should be applied to each image to avoid quantization effects when taking the difference of 2 images, or co-adding a set of images. Without this random offset, the corresponding pixel in every image will have exactly the same dithering.

offset = 0 means use the default random dithering based on system time offset = negative means randomly chose dithering based on 1st tile checksum offset = [1 - 10000] means use that particular dithering pattern

The default according to the fpackguide is

By default, the initial seed value is randomly chosen based on the
current system clock time.

So we could support the following options for dither_seed at the python level:

  • 0 or 'CLOCK' or 'clock': set seed to 0
  • negative number or 'CHECKSUM' or 'checksum': set seed to -1
  • 1-10000: send seed through
  • error for anything else

@esheldon
Copy link
Owner Author

yikes, I should have red the docs first

Also restrict range of seeds
Copy link
Collaborator

@beckermr beckermr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few tweaks but looking good. We'll need to adjust the tests to cover more cases and not error on -3. We should also test that -3 and -1 give the same answer.

fitsio/fitslib.py Outdated Show resolved Hide resolved
fitsio/fitslib.py Outdated Show resolved Hide resolved
fitsio/fitslib.py Outdated Show resolved Hide resolved
fitsio/fitslib.py Outdated Show resolved Hide resolved
case insensitive, allow all negative
Copy link
Collaborator

@beckermr beckermr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

fitsio/fitslib.py Outdated Show resolved Hide resolved
@esheldon
Copy link
Owner Author

OK, we'll see what Dustin says

fitsio/fitslib.py Outdated Show resolved Hide resolved
fitsio/fitslib.py Outdated Show resolved Hide resolved
fitsio/fitslib.py Outdated Show resolved Hide resolved
fitsio/fitslib.py Outdated Show resolved Hide resolved
fitsio/fitslib.py Outdated Show resolved Hide resolved
@esheldon esheldon merged commit c2d5b5c into master Aug 20, 2024
8 checks passed
@esheldon esheldon deleted the seed-dither branch August 20, 2024 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: allow setting the FPACK dither seed
2 participants