Skip to content

Commit b210ff9

Browse files
authored
Merge pull request astropy#58 from Cadair/pre-pr
Make whole tiled_compression module private and cleanup
2 parents 8ac61d9 + a9421e4 commit b210ff9

26 files changed

Lines changed: 94 additions & 55 deletions
File renamed without changes.

astropy/io/fits/tiled_compression/_codecs.py renamed to astropy/io/fits/_tiled_compression/codecs.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
"""
2-
This file contains the FITS compression algorithms in numcodecs style Codecs.
3-
4-
This module is currently private as these classes have not been tested
5-
externally to Astropy and their behaviour may have to change.
2+
This module contains the FITS compression algorithms in numcodecs style Codecs.
63
"""
74
from gzip import compress as gzip_compress
85
from gzip import decompress as gzip_decompress
96

107
import numpy as np
118

12-
from astropy.io.fits.tiled_compression._compression import (
9+
from astropy.io.fits._tiled_compression._compression import (
1310
compress_hcompress_1_c,
1411
compress_plio_1_c,
1512
compress_rice_1_c,
@@ -63,7 +60,7 @@ def decode(self, buf):
6360
"""
6461
cbytes = np.frombuffer(buf, dtype=np.uint8).tobytes()
6562
dbytes = gzip_decompress(cbytes)
66-
return np.frombuffer(dbytes, dtype=np.uint8).data
63+
return np.frombuffer(dbytes, dtype=np.uint8)
6764

6865
def encode(self, buf):
6966
"""
@@ -117,7 +114,7 @@ class Gzip2(Codec):
117114

118115
codec_id = "FITS_GZIP2"
119116

120-
def __init__(self, itemsize: int):
117+
def __init__(self, *, itemsize: int):
121118
super().__init__()
122119
self.itemsize = itemsize
123120

@@ -139,7 +136,7 @@ def decode(self, buf):
139136
# Start off by unshuffling buffer
140137
unshuffled_buffer = gzip_decompress(cbytes)
141138
array = np.frombuffer(unshuffled_buffer, dtype=np.uint8)
142-
return array.reshape((self.itemsize, -1)).T.ravel().data
139+
return array.reshape((self.itemsize, -1)).T.ravel()
143140

144141
def encode(self, buf):
145142
"""
@@ -191,7 +188,7 @@ class Rice1(Codec):
191188

192189
codec_id = "FITS_RICE1"
193190

194-
def __init__(self, blocksize: int, bytepix: int, tilesize: int):
191+
def __init__(self, *, blocksize: int, bytepix: int, tilesize: int):
195192
self.blocksize = blocksize
196193
self.bytepix = bytepix
197194
self.tilesize = tilesize
@@ -214,7 +211,7 @@ def decode(self, buf):
214211
dbytes = decompress_rice_1_c(
215212
cbytes, self.blocksize, self.bytepix, self.tilesize
216213
)
217-
return np.frombuffer(dbytes, dtype=f"i{self.bytepix}").data
214+
return np.frombuffer(dbytes, dtype=f"i{self.bytepix}")
218215

219216
def encode(self, buf):
220217
"""
@@ -248,7 +245,7 @@ class PLIO1(Codec):
248245

249246
codec_id = "FITS_PLIO1"
250247

251-
def __init__(self, tilesize: int):
248+
def __init__(self, *, tilesize: int):
252249
self.tilesize = tilesize
253250

254251
def decode(self, buf):
@@ -267,7 +264,7 @@ def decode(self, buf):
267264
"""
268265
cbytes = np.frombuffer(buf, dtype=np.uint8).tobytes()
269266
dbytes = decompress_plio_1_c(cbytes, self.tilesize)
270-
return np.frombuffer(dbytes, dtype="i4").data
267+
return np.frombuffer(dbytes, dtype="i4")
271268

272269
def encode(self, buf):
273270
"""
@@ -316,7 +313,7 @@ class HCompress1(Codec):
316313

317314
codec_id = "FITS_HCOMPRESS1"
318315

319-
def __init__(self, scale: int, smooth: bool, bytepix: int, nx: int, ny: int):
316+
def __init__(self, *, scale: int, smooth: bool, bytepix: int, nx: int, ny: int):
320317
self.scale = scale
321318
self.smooth = smooth
322319
self.bytepix = bytepix
@@ -342,7 +339,7 @@ def decode(self, buf):
342339
dbytes = decompress_hcompress_1_c(
343340
cbytes, self.nx, self.ny, self.scale, self.smooth, self.bytepix
344341
)
345-
return np.frombuffer(dbytes, dtype=f"i{self.bytepix}").data
342+
return np.frombuffer(dbytes, dtype=f"i{self.bytepix}")
346343

347344
def encode(self, buf):
348345
"""

astropy/io/fits/tiled_compression/_quantization.py renamed to astropy/io/fits/_tiled_compression/quantization.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"""
44
import numpy as np
55

6-
from astropy.io.fits.hdu.base import BITPIX2DTYPE
7-
from astropy.io.fits.tiled_compression._compression import (
6+
from astropy.io.fits._tiled_compression._compression import (
87
quantize_double_c,
98
quantize_float_c,
109
unquantize_double_c,
1110
unquantize_float_c,
1211
)
12+
from astropy.io.fits.hdu.base import BITPIX2DTYPE
1313

1414
__all__ = ["Quantize"]
1515

@@ -26,7 +26,9 @@ class Quantize:
2626
Quantization of floating-point data following the FITS standard.
2727
"""
2828

29-
def __init__(self, row: int, dither_method: int, quantize_level: int, bitpix: int):
29+
def __init__(
30+
self, *, row: int, dither_method: int, quantize_level: int, bitpix: int
31+
):
3032
super().__init__()
3133
self.row = row
3234
# TODO: pass dither method as a string instead of int?

astropy/io/fits/tiled_compression/setup_package.py renamed to astropy/io/fits/_tiled_compression/setup_package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def get_extensions():
1111
return [
1212
Extension(
13-
"astropy.io.fits.tiled_compression._compression",
13+
"astropy.io.fits._tiled_compression._compression",
1414
sources=[
1515
os.path.join(SRC_DIR, "compression.c"),
1616
os.path.join("cextern", "cfitsio", "lib", "pliocomp.c"),
File renamed without changes.

astropy/io/fits/tiled_compression/src/fits_hcompress.h renamed to astropy/io/fits/_tiled_compression/src/fits_hcompress.h

File renamed without changes.

astropy/io/fits/tiled_compression/src/fits_hdecompress.h renamed to astropy/io/fits/_tiled_compression/src/fits_hdecompress.h

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)