fitscube 2.9.0__tar.gz → 2.10.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. {fitscube-2.9.0 → fitscube-2.10.0}/PKG-INFO +99 -12
  2. {fitscube-2.9.0 → fitscube-2.10.0}/README.md +98 -11
  3. {fitscube-2.9.0 → fitscube-2.10.0}/fitscube/_version.py +2 -2
  4. {fitscube-2.9.0 → fitscube-2.10.0}/fitscube/cli.py +20 -0
  5. {fitscube-2.9.0 → fitscube-2.10.0}/fitscube/combine_fits.py +20 -56
  6. fitscube-2.10.0/fitscube/compress.py +634 -0
  7. {fitscube-2.9.0 → fitscube-2.10.0}/fitscube/extract.py +4 -0
  8. fitscube-2.10.0/tests/test_compress.py +234 -0
  9. {fitscube-2.9.0 → fitscube-2.10.0}/tests/test_extract.py +6 -0
  10. fitscube-2.9.0/tests/test_compress.py +0 -39
  11. {fitscube-2.9.0 → fitscube-2.10.0}/.github/CONTRIBUTING.md +0 -0
  12. {fitscube-2.9.0 → fitscube-2.10.0}/.github/dependabot.yml +0 -0
  13. {fitscube-2.9.0 → fitscube-2.10.0}/.github/release.yml +0 -0
  14. {fitscube-2.9.0 → fitscube-2.10.0}/.github/workflows/cd.yml +0 -0
  15. {fitscube-2.9.0 → fitscube-2.10.0}/.github/workflows/ci.yml +0 -0
  16. {fitscube-2.9.0 → fitscube-2.10.0}/.gitignore +0 -0
  17. {fitscube-2.9.0 → fitscube-2.10.0}/.pre-commit-config.yaml +0 -0
  18. {fitscube-2.9.0 → fitscube-2.10.0}/CHANGELOG.md +0 -0
  19. {fitscube-2.9.0 → fitscube-2.10.0}/LICENSE +0 -0
  20. {fitscube-2.9.0 → fitscube-2.10.0}/fitscube/__init__.py +0 -0
  21. {fitscube-2.9.0 → fitscube-2.10.0}/fitscube/asyncio.py +0 -0
  22. {fitscube-2.9.0 → fitscube-2.10.0}/fitscube/bounding_box.py +0 -0
  23. {fitscube-2.9.0 → fitscube-2.10.0}/fitscube/exceptions.py +0 -0
  24. {fitscube-2.9.0 → fitscube-2.10.0}/fitscube/logging.py +0 -0
  25. {fitscube-2.9.0 → fitscube-2.10.0}/fitscube/version.pyi +0 -0
  26. {fitscube-2.9.0 → fitscube-2.10.0}/noxfile.py +0 -0
  27. {fitscube-2.9.0 → fitscube-2.10.0}/pyproject.toml +0 -0
  28. {fitscube-2.9.0 → fitscube-2.10.0}/tests/__init__.py +0 -0
  29. {fitscube-2.9.0 → fitscube-2.10.0}/tests/conftest.py +0 -0
  30. {fitscube-2.9.0 → fitscube-2.10.0}/tests/data/cube.zip +0 -0
  31. {fitscube-2.9.0 → fitscube-2.10.0}/tests/data/images.zip +0 -0
  32. {fitscube-2.9.0 → fitscube-2.10.0}/tests/data/time_images.zip +0 -0
  33. {fitscube-2.9.0 → fitscube-2.10.0}/tests/data/timecube.zip +0 -0
  34. {fitscube-2.9.0 → fitscube-2.10.0}/tests/test_bb.py +0 -0
  35. {fitscube-2.9.0 → fitscube-2.10.0}/tests/test_combine.py +0 -0
  36. {fitscube-2.9.0 → fitscube-2.10.0}/tests/test_combine_guards.py +0 -0
  37. {fitscube-2.9.0 → fitscube-2.10.0}/tests/test_combine_layouts.py +0 -0
  38. {fitscube-2.9.0 → fitscube-2.10.0}/tests/test_frequencies.py +0 -0
  39. {fitscube-2.9.0 → fitscube-2.10.0}/tests/test_package.py +0 -0
  40. {fitscube-2.9.0 → fitscube-2.10.0}/tests/test_times.py +0 -0
  41. {fitscube-2.9.0 → fitscube-2.10.0}/tests/test_zero_beams.py +0 -0
  42. {fitscube-2.9.0 → fitscube-2.10.0}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: fitscube
3
- Version: 2.9.0
3
+ Version: 2.10.0
4
4
  Summary: A package to produce produce FITS cubes.
5
5
  Project-URL: Homepage, https://github.com/AlecThomson/fitscube
6
6
  Project-URL: Bug Tracker, https://github.com/AlecThomson/fitscube/issues
@@ -151,17 +151,19 @@ Command line:
151
151
 
152
152
  ```
153
153
  ❯ fitscube -h
154
- usage: fitscube [-h] {combine,extract} ...
154
+ usage: fitscube [-h] {combine,extract,compress,decompress} ...
155
155
 
156
156
  Tooling to create fitscubes
157
157
 
158
158
  positional arguments:
159
- {combine,extract}
160
- combine Combine FITS images together into a cube
161
- extract Extract a plane from an existing cube
159
+ {combine,extract,compress,decompress}
160
+ combine Combine FITS images together into a cube
161
+ extract Extract a plane from an existing cube
162
+ compress Compress a cube to .fits.gz or .fits.fz
163
+ decompress Turn a .fits.gz or .fits.fz cube back into plain FITS
162
164
 
163
165
  options:
164
- -h, --help show this help message and exit
166
+ -h, --help show this help message and exit
165
167
  ```
166
168
 
167
169
  ```
@@ -170,7 +172,8 @@ usage: fitscube combine [-h] [-o] [--create-blanks] [--time-domain]
170
172
  [--spec-file SPEC_FILE | --specs SPECS [SPECS ...] | --ignore-spec] [-v]
171
173
  [--max-workers MAX_WORKERS] [--bounding-box] [--invalidate-zeros]
172
174
  [--no-blank-zero-beams] [--floating {32,64}] [--compress]
173
- [--compress-method {gzip,pgzip}]
175
+ [--compress-method {gzip,pgzip,tile-gzip,tile-rice}]
176
+ [--quantize-level QUANTIZE_LEVEL]
174
177
  file_list [file_list ...] out_cube
175
178
 
176
179
  positional arguments:
@@ -202,11 +205,16 @@ options:
202
205
  --floating {32,64}
203
206
  The number of floating point bits to use in the out cube. If None the
204
207
  input data precision is used.
205
- --compress Gzip-compress the output cube
206
- --compress-method {gzip,pgzip}
207
- Compression backend for --compress. 'gzip' is stdlib and needs nothing
208
- extra. 'pgzip' parallelizes across --max-workers threads but requires the
209
- 'pgzip' extra: pip install fitscube[pgzip]
208
+ --compress Compress the output cube once written
209
+ --compress-method {gzip,pgzip,tile-gzip,tile-rice}
210
+ How --compress compresses. 'gzip' and 'pgzip' gzip the whole file to
211
+ .fits.gz; 'pgzip' parallelizes across --max-workers threads but requires
212
+ the 'pgzip' extra. 'tile-gzip' (lossless) and 'tile-rice' (lossy, see
213
+ --quantize-level) tile-compress to .fits.fz, as fpack does, so single
214
+ planes can be read without decompressing the whole cube
215
+ --quantize-level QUANTIZE_LEVEL
216
+ Quantization steps per noise sigma for 'tile-rice'. Higher keeps more
217
+ precision and compresses less
210
218
  ```
211
219
 
212
220
  ```
@@ -228,6 +236,45 @@ options:
228
236
  The name of the new output file. If not specified it is generated from the fits cube name
229
237
  ```
230
238
 
239
+ ```
240
+ ❯ fitscube compress -h
241
+ usage: fitscube compress [-h] [--method {gzip,pgzip,tile-gzip,tile-rice}]
242
+ [--quantize-level QUANTIZE_LEVEL] [--max-workers MAX_WORKERS]
243
+ [--allow-requantize] [--remove] [-v]
244
+ cube
245
+
246
+ positional arguments:
247
+ cube An uncompressed FITS cube
248
+
249
+ options:
250
+ -h, --help show this help message and exit
251
+ --method {gzip,pgzip,tile-gzip,tile-rice}
252
+ 'gzip'/'pgzip' gzip the whole file to .fits.gz. 'tile-gzip' (lossless) and
253
+ 'tile-rice' (lossy) tile-compress to .fits.fz, as fpack does
254
+ --quantize-level QUANTIZE_LEVEL
255
+ Quantization steps per noise sigma for 'tile-rice'
256
+ --max-workers MAX_WORKERS
257
+ Compression threads
258
+ --allow-requantize Let 'tile-rice' quantize a cube that was already quantized once
259
+ --remove Delete the input once done
260
+ -v, --verbosity Increase output verbosity
261
+ ```
262
+
263
+ ```
264
+ ❯ fitscube decompress -h
265
+ usage: fitscube decompress [-h] [-o OUTPUT] [--overwrite] [--remove] [-v] cube
266
+
267
+ positional arguments:
268
+ cube A .fits.gz or tile-compressed .fits.fz cube
269
+
270
+ options:
271
+ -h, --help show this help message and exit
272
+ -o, --output OUTPUT Output path. Defaults to the input without .gz/.fz
273
+ --overwrite Replace the output if it exists
274
+ --remove Delete the compressed input once done
275
+ -v, --verbosity Increase output verbosity
276
+ ```
277
+
231
278
  Python:
232
279
 
233
280
  ```python
@@ -242,6 +289,46 @@ frequencies = combine_fits(
242
289
  )
243
290
  ```
244
291
 
292
+ ## Compressed cubes
293
+
294
+ `fitscube compress`, or `combine --compress`, writes the cube in one of three ways:
295
+
296
+ | Method | Output | |
297
+ |---|---|---|
298
+ | `gzip`, `pgzip` | `.fits.gz` | The whole file gzipped. Lossless. |
299
+ | `tile-gzip` | `.fits.fz` | [Tile compressed](https://heasarc.gsfc.nasa.gov/fitsio/fpack/) with GZIP_2. Lossless. |
300
+ | `tile-rice` | `.fits.fz` | Tile compressed with RICE_1, after quantising to `--quantize-level` steps per noise sigma. Lossy. |
301
+
302
+ `.fits.fz` files are what `fpack` writes, so DS9, CARTA, `funpack` and astropy can all
303
+ read them. The image is in HDU 1, and `.section` only decompresses the tiles it needs:
304
+
305
+ ```python
306
+ from astropy.io import fits
307
+
308
+ with fits.open("cube.fits.fz") as hdul:
309
+ plane = hdul[1].section[10]
310
+ ```
311
+
312
+ `.data` and `fits.getdata` decompress the whole cube into memory, for both `.fits.gz`
313
+ and `.fits.fz`. A `.fits.gz` cube has no cheap way to read part of it. CARTA (6.0) also
314
+ reads the whole cube into memory when it opens either kind, so decompress large cubes
315
+ before viewing them there.
316
+
317
+ To compress an existing cube, and to get plain FITS back:
318
+
319
+ ```
320
+ fitscube compress cube.fits --method tile-rice
321
+ fitscube decompress cube.fits.fz
322
+ ```
323
+
324
+ `funpack` works too, though `funpack` from CFITSIO 4.3.1 mis-decodes RICE files whose
325
+ tiles are narrower than a row. fitscube always writes full-width tiles.
326
+
327
+ Quantise once. Every decompress and recompress with `tile-rice` adds a new error, so
328
+ `fitscube decompress` marks lossy cubes with `FCLOSSY`, and `tile-rice` refuses them
329
+ unless given `allow_requantize=True`. Smooth images such as weights do not shrink under
330
+ RICE; use `tile-gzip` for them.
331
+
245
332
  ## Zero-sized beams
246
333
 
247
334
  wsclean writes `BMAJ = BMIN = 0` into an image when no PSF was fitted for that
@@ -78,17 +78,19 @@ Command line:
78
78
 
79
79
  ```
80
80
  ❯ fitscube -h
81
- usage: fitscube [-h] {combine,extract} ...
81
+ usage: fitscube [-h] {combine,extract,compress,decompress} ...
82
82
 
83
83
  Tooling to create fitscubes
84
84
 
85
85
  positional arguments:
86
- {combine,extract}
87
- combine Combine FITS images together into a cube
88
- extract Extract a plane from an existing cube
86
+ {combine,extract,compress,decompress}
87
+ combine Combine FITS images together into a cube
88
+ extract Extract a plane from an existing cube
89
+ compress Compress a cube to .fits.gz or .fits.fz
90
+ decompress Turn a .fits.gz or .fits.fz cube back into plain FITS
89
91
 
90
92
  options:
91
- -h, --help show this help message and exit
93
+ -h, --help show this help message and exit
92
94
  ```
93
95
 
94
96
  ```
@@ -97,7 +99,8 @@ usage: fitscube combine [-h] [-o] [--create-blanks] [--time-domain]
97
99
  [--spec-file SPEC_FILE | --specs SPECS [SPECS ...] | --ignore-spec] [-v]
98
100
  [--max-workers MAX_WORKERS] [--bounding-box] [--invalidate-zeros]
99
101
  [--no-blank-zero-beams] [--floating {32,64}] [--compress]
100
- [--compress-method {gzip,pgzip}]
102
+ [--compress-method {gzip,pgzip,tile-gzip,tile-rice}]
103
+ [--quantize-level QUANTIZE_LEVEL]
101
104
  file_list [file_list ...] out_cube
102
105
 
103
106
  positional arguments:
@@ -129,11 +132,16 @@ options:
129
132
  --floating {32,64}
130
133
  The number of floating point bits to use in the out cube. If None the
131
134
  input data precision is used.
132
- --compress Gzip-compress the output cube
133
- --compress-method {gzip,pgzip}
134
- Compression backend for --compress. 'gzip' is stdlib and needs nothing
135
- extra. 'pgzip' parallelizes across --max-workers threads but requires the
136
- 'pgzip' extra: pip install fitscube[pgzip]
135
+ --compress Compress the output cube once written
136
+ --compress-method {gzip,pgzip,tile-gzip,tile-rice}
137
+ How --compress compresses. 'gzip' and 'pgzip' gzip the whole file to
138
+ .fits.gz; 'pgzip' parallelizes across --max-workers threads but requires
139
+ the 'pgzip' extra. 'tile-gzip' (lossless) and 'tile-rice' (lossy, see
140
+ --quantize-level) tile-compress to .fits.fz, as fpack does, so single
141
+ planes can be read without decompressing the whole cube
142
+ --quantize-level QUANTIZE_LEVEL
143
+ Quantization steps per noise sigma for 'tile-rice'. Higher keeps more
144
+ precision and compresses less
137
145
  ```
138
146
 
139
147
  ```
@@ -155,6 +163,45 @@ options:
155
163
  The name of the new output file. If not specified it is generated from the fits cube name
156
164
  ```
157
165
 
166
+ ```
167
+ ❯ fitscube compress -h
168
+ usage: fitscube compress [-h] [--method {gzip,pgzip,tile-gzip,tile-rice}]
169
+ [--quantize-level QUANTIZE_LEVEL] [--max-workers MAX_WORKERS]
170
+ [--allow-requantize] [--remove] [-v]
171
+ cube
172
+
173
+ positional arguments:
174
+ cube An uncompressed FITS cube
175
+
176
+ options:
177
+ -h, --help show this help message and exit
178
+ --method {gzip,pgzip,tile-gzip,tile-rice}
179
+ 'gzip'/'pgzip' gzip the whole file to .fits.gz. 'tile-gzip' (lossless) and
180
+ 'tile-rice' (lossy) tile-compress to .fits.fz, as fpack does
181
+ --quantize-level QUANTIZE_LEVEL
182
+ Quantization steps per noise sigma for 'tile-rice'
183
+ --max-workers MAX_WORKERS
184
+ Compression threads
185
+ --allow-requantize Let 'tile-rice' quantize a cube that was already quantized once
186
+ --remove Delete the input once done
187
+ -v, --verbosity Increase output verbosity
188
+ ```
189
+
190
+ ```
191
+ ❯ fitscube decompress -h
192
+ usage: fitscube decompress [-h] [-o OUTPUT] [--overwrite] [--remove] [-v] cube
193
+
194
+ positional arguments:
195
+ cube A .fits.gz or tile-compressed .fits.fz cube
196
+
197
+ options:
198
+ -h, --help show this help message and exit
199
+ -o, --output OUTPUT Output path. Defaults to the input without .gz/.fz
200
+ --overwrite Replace the output if it exists
201
+ --remove Delete the compressed input once done
202
+ -v, --verbosity Increase output verbosity
203
+ ```
204
+
158
205
  Python:
159
206
 
160
207
  ```python
@@ -169,6 +216,46 @@ frequencies = combine_fits(
169
216
  )
170
217
  ```
171
218
 
219
+ ## Compressed cubes
220
+
221
+ `fitscube compress`, or `combine --compress`, writes the cube in one of three ways:
222
+
223
+ | Method | Output | |
224
+ |---|---|---|
225
+ | `gzip`, `pgzip` | `.fits.gz` | The whole file gzipped. Lossless. |
226
+ | `tile-gzip` | `.fits.fz` | [Tile compressed](https://heasarc.gsfc.nasa.gov/fitsio/fpack/) with GZIP_2. Lossless. |
227
+ | `tile-rice` | `.fits.fz` | Tile compressed with RICE_1, after quantising to `--quantize-level` steps per noise sigma. Lossy. |
228
+
229
+ `.fits.fz` files are what `fpack` writes, so DS9, CARTA, `funpack` and astropy can all
230
+ read them. The image is in HDU 1, and `.section` only decompresses the tiles it needs:
231
+
232
+ ```python
233
+ from astropy.io import fits
234
+
235
+ with fits.open("cube.fits.fz") as hdul:
236
+ plane = hdul[1].section[10]
237
+ ```
238
+
239
+ `.data` and `fits.getdata` decompress the whole cube into memory, for both `.fits.gz`
240
+ and `.fits.fz`. A `.fits.gz` cube has no cheap way to read part of it. CARTA (6.0) also
241
+ reads the whole cube into memory when it opens either kind, so decompress large cubes
242
+ before viewing them there.
243
+
244
+ To compress an existing cube, and to get plain FITS back:
245
+
246
+ ```
247
+ fitscube compress cube.fits --method tile-rice
248
+ fitscube decompress cube.fits.fz
249
+ ```
250
+
251
+ `funpack` works too, though `funpack` from CFITSIO 4.3.1 mis-decodes RICE files whose
252
+ tiles are narrower than a row. fitscube always writes full-width tiles.
253
+
254
+ Quantise once. Every decompress and recompress with `tile-rice` adds a new error, so
255
+ `fitscube decompress` marks lossy cubes with `FCLOSSY`, and `tile-rice` refuses them
256
+ unless given `allow_requantize=True`. Smooth images such as weights do not shrink under
257
+ RICE; use `tile-gzip` for them.
258
+
172
259
  ## Zero-sized beams
173
260
 
174
261
  wsclean writes `BMAJ = BMIN = 0` into an image when no PSF was fitted for that
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '2.9.0'
22
- __version_tuple__ = version_tuple = (2, 9, 0)
21
+ __version__ = version = '2.10.0'
22
+ __version_tuple__ = version_tuple = (2, 10, 0)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -6,6 +6,12 @@ from argparse import ArgumentParser
6
6
 
7
7
  from fitscube.combine_fits import cli as combine_cli
8
8
  from fitscube.combine_fits import get_parser as combine_get_parser
9
+ from fitscube.compress import (
10
+ compress_cli,
11
+ decompress_cli,
12
+ get_compress_parser,
13
+ get_decompress_parser,
14
+ )
9
15
  from fitscube.extract import cli as extract_cli
10
16
  from fitscube.extract import get_parser as extract_get_parser
11
17
  from fitscube.logging import logger
@@ -26,6 +32,16 @@ def get_parser() -> ArgumentParser:
26
32
  )
27
33
  extract_parser = extract_get_parser(parser=extract_parser)
28
34
 
35
+ compress_parser = subparser.add_parser(
36
+ "compress", help="Compress a cube to .fits.gz or .fits.fz"
37
+ )
38
+ compress_parser = get_compress_parser(parser=compress_parser)
39
+
40
+ decompress_parser = subparser.add_parser(
41
+ "decompress", help="Turn a .fits.gz or .fits.fz cube back into plain FITS"
42
+ )
43
+ decompress_parser = get_decompress_parser(parser=decompress_parser)
44
+
29
45
  return parser
30
46
 
31
47
 
@@ -38,6 +54,10 @@ def cli() -> None:
38
54
  combine_cli(args=args)
39
55
  elif args.mode == "extract":
40
56
  extract_cli(args=args)
57
+ elif args.mode == "compress":
58
+ compress_cli(args=args)
59
+ elif args.mode == "decompress":
60
+ decompress_cli(args=args)
41
61
  else:
42
62
  logger.critical(f"Unknown mode {args.mode=}")
43
63
 
@@ -15,14 +15,11 @@ from __future__ import annotations
15
15
 
16
16
  import argparse
17
17
  import asyncio
18
- import gzip
19
- import shutil
20
18
  import warnings
21
19
  from collections.abc import Callable
22
- from functools import partial
23
20
  from io import BufferedRandom
24
21
  from pathlib import Path
25
- from typing import IO, Any, Literal, NamedTuple, TypeVar, cast, get_args
22
+ from typing import Any, Literal, NamedTuple, TypeVar, get_args
26
23
 
27
24
  import astropy.units as u
28
25
  import numpy as np
@@ -42,6 +39,7 @@ from fitscube.bounding_box import (
42
39
  BoundingBox,
43
40
  get_common_bounding_box_coro,
44
41
  )
42
+ from fitscube.compress import CompressMethod, compress_cube
45
43
  from fitscube.exceptions import (
46
44
  AxisMismatchException,
47
45
  AxisOrderException,
@@ -51,11 +49,6 @@ from fitscube.exceptions import (
51
49
  )
52
50
  from fitscube.logging import TQDM_OUT, logger, set_verbosity
53
51
 
54
- try:
55
- import pgzip
56
- except ImportError:
57
- pgzip = None
58
-
59
52
  T = TypeVar("T")
60
53
 
61
54
  # store the number of bytes per value in a dictionary
@@ -1428,47 +1421,6 @@ async def combine_fits_coro(
1428
1421
  combine_fits = sync_wrapper(combine_fits_coro)
1429
1422
 
1430
1423
 
1431
- COMPRESS_METHOD = Literal["gzip", "pgzip"]
1432
-
1433
-
1434
- def compress_cube(
1435
- out_cube: Path,
1436
- method: COMPRESS_METHOD = "gzip",
1437
- max_workers: int | None = None,
1438
- ) -> Path:
1439
- """Gzip-compress a finished cube in place, streaming to avoid loading it into memory.
1440
-
1441
- Args:
1442
- out_cube (Path): Path of the already-written, uncompressed cube. Deleted on success.
1443
- method (COMPRESS_METHOD): 'gzip' uses the stdlib and needs nothing extra.
1444
- 'pgzip' parallelizes compression across `max_workers` threads but
1445
- requires the 'pgzip' extra.
1446
- max_workers (int | None): Thread count passed to `pgzip`; ignored for 'gzip'.
1447
-
1448
- Returns:
1449
- Path: Path of the compressed output, `out_cube` with a '.gz' suffix appended.
1450
- """
1451
- compressed_path = out_cube.with_suffix(out_cube.suffix + ".gz")
1452
- msg = f"Compressing {out_cube} to {compressed_path} via {method}"
1453
- logger.info(msg)
1454
-
1455
- if method == "pgzip":
1456
- if pgzip is None:
1457
- msg = (
1458
- "method='pgzip' requires the 'pgzip' extra: pip install fitscube[pgzip]"
1459
- )
1460
- raise ImportError(msg)
1461
- opener: Callable[..., IO[bytes]] = partial(pgzip.open, thread=max_workers)
1462
- else:
1463
- opener = cast("Callable[..., IO[bytes]]", gzip.open)
1464
-
1465
- with out_cube.open("rb") as src, opener(compressed_path, "wb") as dst:
1466
- shutil.copyfileobj(src, dst)
1467
-
1468
- out_cube.unlink()
1469
- return compressed_path
1470
-
1471
-
1472
1424
  def get_parser(
1473
1425
  parser: argparse.ArgumentParser | None = None,
1474
1426
  ) -> argparse.ArgumentParser:
@@ -1555,15 +1507,24 @@ def get_parser(
1555
1507
  parser.add_argument(
1556
1508
  "--compress",
1557
1509
  action="store_true",
1558
- help="Gzip-compress the output cube",
1510
+ help="Compress the output cube once written",
1559
1511
  )
1560
1512
  parser.add_argument(
1561
1513
  "--compress-method",
1562
- choices=("gzip", "pgzip"),
1514
+ choices=get_args(CompressMethod),
1563
1515
  default="gzip",
1564
- help="Compression backend for --compress. 'gzip' is stdlib and needs nothing "
1565
- "extra. 'pgzip' parallelizes across --max-workers threads but requires the "
1566
- "'pgzip' extra: pip install fitscube[pgzip]",
1516
+ help="How --compress compresses. 'gzip' and 'pgzip' gzip the whole file to "
1517
+ ".fits.gz; 'pgzip' parallelizes across --max-workers threads but requires the "
1518
+ "'pgzip' extra. 'tile-gzip' (lossless) and 'tile-rice' (lossy, see "
1519
+ "--quantize-level) tile-compress to .fits.fz, as fpack does, so single planes "
1520
+ "can be read without decompressing the whole cube",
1521
+ )
1522
+ parser.add_argument(
1523
+ "--quantize-level",
1524
+ type=float,
1525
+ default=4.0,
1526
+ help="Quantization steps per noise sigma for 'tile-rice'. Higher keeps more "
1527
+ "precision and compresses less",
1567
1528
  )
1568
1529
 
1569
1530
  return parser
@@ -1613,7 +1574,10 @@ def cli(args: argparse.Namespace | None = None) -> None:
1613
1574
 
1614
1575
  if args.compress:
1615
1576
  out_cube = compress_cube(
1616
- out_cube, method=args.compress_method, max_workers=args.max_workers
1577
+ out_cube,
1578
+ method=args.compress_method,
1579
+ max_workers=args.max_workers,
1580
+ quantize_level=args.quantize_level,
1617
1581
  )
1618
1582
 
1619
1583
  spequency = "times" if time_domain_mode else "frequencies"