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

Issues spotted by debian report #572

Merged
merged 14 commits into from
Jul 2, 2024
19 changes: 14 additions & 5 deletions build-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,15 @@ build_deb() {
echo "Build for debian 9 or newer using actual packaging"
tarname=${project}_${debianversion}.orig.tar.gz
clean_up
python -m build -s
ln -s ${source_project}-${strictversion}.tar.gz dist/${tarname}
directory=${source_project}-${strictversion}
if [ $debian_version -le 11 ]
then
python3 setup.py debian_src
directory=${project}-${strictversion}
else
python3 -m build -s
ln -s ${source_project}-${strictversion}.tar.gz dist/${tarname}
directory=${source_project}-${strictversion}
fi
cp -f dist/${tarname} ${build_directory}
if [ -f dist/${project}-testimages.tar.gz ]
then
Expand Down Expand Up @@ -236,10 +242,13 @@ build_deb() {
11)
debian_name=bullseye
;;
12)
debian_name=bookworm
;;
esac

dch -v ${debianversion}-1 "upstream development build of ${project} ${version}" --force-distribution
dch -D ${debian_name}-backports -l~bpo${debian_version}+ "${project} snapshot ${version} built for ${target_system}" --force-distribution
dch --force-distribution -v ${debianversion}-1 "upstream development build of ${project} ${version}"
dch --force-distribution -D ${debian_name}-backports -l~bpo${debian_version}+ "${project} snapshot ${version} built for ${target_system}"
#dch --bpo "${project} snapshot ${version} built for ${target_system}"
dpkg-buildpackage -r
rc=$?
Expand Down
14 changes: 8 additions & 6 deletions src/fabio/binaryimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
__contact__ = "[email protected]"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__version__ = "17/10/2012"
__date__ = "30/05/2024"

import io
from .fabioimage import FabioImage
Expand Down Expand Up @@ -84,17 +84,21 @@ def read(self, fname, dim1, dim2, offset=0, bytecode="int32", endian="<"):
:param int dim2: image dimensions (Slow index)
:param int offset: starting position of the data-block. If negative, starts at the end.
:param bytecode: can be "int8","int16","int32","int64","uint8","uint16","uint32","uint64","float32","float64",...
:param endian: among short or long endian ("<" or ">")
:param endian: among litte or big endian ("<" or ">")

"""
assert endian in ('<', '>', '=')
bytecode = numpy.dtype(bytecode)
if not bytecode.str.startswith(endian):
bytecode = numpy.dtype(endian + bytecode.str[1:])
self.filename = fname
self._shape = dim2, dim1
self._bytecode = bytecode
with open(self.filename, "rb") as f:
with open(self.filename, "rb") as f:
dims = [dim2, dim1]
bpp = numpy.dtype(bytecode).itemsize
size = dims[0] * dims[1] * bpp

if offset >= 0:
f.seek(offset)
else:
Expand All @@ -107,8 +111,6 @@ def read(self, fname, dim1, dim2, offset=0, bytecode="int32", endian="<"):
logger.error('Uncommon error encountered when reading file')
rawData = f.read(size)
data = numpy.frombuffer(rawData, bytecode).copy().reshape(tuple(dims))
if self.swap_needed(endian):
data.byteswap(True)
self.data = data
self._shape = None
return self
Expand Down
4 changes: 2 additions & 2 deletions src/fabio/compression/agi_bitfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
__author__ = ["Florian Plaswig", "Jérôme Kieffer"]
__contact__ = "[email protected]"
__license__ = "MIT"
__date__ = "13/11/2020"
__date__ = "30/05/2024"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"

import logging
Expand Down Expand Up @@ -79,7 +79,7 @@ def compress(frame):
if numpy.little_endian:
buffer.write(row_start.tobytes())
else:
buffer.write(row_start.byteswap.tobytes())
buffer.write(row_start.byteswap().tobytes())

return data_size + buffer.getvalue()

Expand Down
11 changes: 6 additions & 5 deletions src/fabio/dm3image.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

+ Jon Wright, ESRF
"""

import sys
import logging
import numpy
from .fabioimage import FabioImage
Expand Down Expand Up @@ -93,11 +93,12 @@ def __init__(self, *args, **kwargs):
self.tag_label_length = None

def _readheader(self):
BE_uint32 = numpy.dtype('>u4')
self.infile.seek(0)
file_format = self.readbytes(4, numpy.uint32)[0] # should be 3
assert file_format == 3, 'Wrong file type '
self.bytes_in_file = self.readbytes(4, numpy.uint32)[0]
self.byte_order = self.readbytes(4, numpy.uint32)[0] # 0 = big, 1= little
file_format = self.readbytes(4, BE_uint32, swap=False)[0] # should be 3
assert file_format == 3, 'Wrong file type'
self.bytes_in_file = self.readbytes(4, BE_uint32, swap=False)[0]
self.byte_order = self.readbytes(4, BE_uint32, swap=False)[0] # 0 = big, 1= little
logger.debug('read dm3 file - file format %s' % file_format)
logger.debug('Bytes in file: %s' % self.bytes_in_file)
logger.debug('Byte order: %s - 0 = bigEndian , 1 = littleEndian' % self.byte_order)
Expand Down
19 changes: 14 additions & 5 deletions src/fabio/ext/src/columnfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ FILE* fn_fopen(const char* fname, const char* mode)

#include "columnfile.h"

static char hdr_ctl[]="# %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s";
/* 32 conversions for sscanf below = 8*4 */
static char hdr_ctl[]="# "
"%s %s %s %s "
"%s %s %s %s "
"%s %s %s %s "
"%s %s %s %s "
"%s %s %s %s "
"%s %s %s %s "
"%s %s %s %s "
"%s %s %s %s ";



Expand Down Expand Up @@ -158,8 +167,8 @@ void *cf_read_ascii(void *fp, void *dest, unsigned int FLAGS){/*{{{*/
}

/*try to sscanf it using 32 conversions - if that doesn't work use pedestrian version*/
ncols=sscanf_s(line,hdr_ctl,repeat16_inc(clabels,0),repeat16_inc(clabels,16),*(clabels+32));
if (ncols==32+1 || ncols==0){
ncols=sscanf_s(line,hdr_ctl,repeat16_inc(clabels,0),repeat16_inc(clabels,16));
if (ncols==32 || ncols==0){
/*aha we probably didn't get it all*/
/*step through buffer with char ptr and check for whitespace->non-ws slopes. when one is found read from pc-1 into header storage. exit when line is exhausted*/
/*count the number of entries*/
Expand Down Expand Up @@ -193,11 +202,11 @@ void *cf_read_ascii(void *fp, void *dest, unsigned int FLAGS){/*{{{*/
if ((gzgets((gzFile )fp,line,2048))==Z_NULL) {fprintf(stderr,"zlib io error reading file at %s\n",__LINE__);return -1;}
if(gzeof((gzFile)fp)) break;
}else{
fgets(line,2048,(FILE *)fp);
if fgets(line,2048,(FILE *)fp) == NULL) break;
if (feof((FILE *)fp)) break;
}
#else
fgets(line,2048,(FILE *)fp);
if (fgets(line,2048,(FILE *)fp) == NULL) break;
if (feof((FILE *)fp)) break;
#endif

Expand Down
4 changes: 1 addition & 3 deletions src/fabio/fit2dmaskimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ def _readheader(self, infile):
(b"K", 12)]:
if header[j] != i[0]:
raise Exception("Not a fit2d mask file")
fit2dhdr = numpy.frombuffer(header, numpy.int32)
# Enforce little endian
if not numpy.little_endian:
fit2dhdr.byteswap(True)
fit2dhdr = numpy.frombuffer(header, numpy.dtype("<i4"))
dim1 = fit2dhdr[4] # 1 less than Andy's fortran
dim2 = fit2dhdr[5]
self._shape = dim2, dim1
Expand Down
6 changes: 3 additions & 3 deletions src/fabio/pixiimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
__contact__ = "[email protected]"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "03/04/2020"
__date__ = "30/05/2024"

import numpy
import os
Expand Down Expand Up @@ -71,7 +71,7 @@ def _readheader(self, infile):
infile.seek(0)
self.header = self.check_header()
byt = infile.read(4)
framesize = numpy.frombuffer(byt, numpy.int32)
framesize = numpy.frombuffer(byt, numpy.dtype("<i4"))
if framesize * 2 == self._FRAME_SIZE - self._MAGIC_SIZE:
self.header['framesize'] = framesize
self.header['width'] = self._IMAGE_WIDTH
Expand Down Expand Up @@ -123,7 +123,7 @@ def _readdata(self, filepointer, img_num):
imgstart = self.header['offset'] + img_num * self._FRAME_SIZE
filepointer.seek(imgstart, 0)
data = numpy.frombuffer(filepointer.read(self._IMAGE_SIZE),
numpy.uint16).copy()
numpy.dtype("<u2")).copy()
data.shape = self.header['height'], self.header['width']
return data

Expand Down
8 changes: 3 additions & 5 deletions src/fabio/test/codecs/test_binaryimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,16 @@ def test_read(self):
self.assertEqual(e.shape, f.shape)
self.assertEqual(e.bpp, f.bpp, "bpp OK")
print(self.fn3)
self.assertEqual(abs(e.data-f.data).max(), 0, "data OK")


self.assertEqual(abs(e.data - f.data).max(), 0, "data OK")

def test_write(self):
fn = os.path.join(UtilsTest.tempdir, "binary_write.h5")
ary = numpy.random.randint(0, 100, size=self.shape)
e = BinaryImage(data = ary)
e = BinaryImage(data=ary)
e.save(fn)
self.assertTrue(os.path.exists(fn), "file exists")
f = BinaryImage()
f.read(fn, self.shape[1], self.shape[0], offset=0, bytecode=ary.dtype)
f.read(fn, self.shape[1], self.shape[0], offset=0, bytecode=ary.dtype, endian=ary.dtype.str[0])
self.assertEqual(str(f.__class__.__name__), "BinaryImage", "Used the write reader")
self.assertEqual(self.shape, f.shape, "shape matches")
self.assertEqual(abs(f.data - ary).max(), 0, "first frame matches")
Expand Down
13 changes: 11 additions & 2 deletions src/fabio/test/test_fabio_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import numpy
import copy
import logging
import numbers

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -229,15 +230,23 @@ class TestPilImage2(TestPilImage):

def mkdata(self, shape, typ):
""" positive and big"""
return (numpy.random.random(shape) * sys.maxsize / 10).astype(typ)
if numpy.issubdtype(typ, numpy.integer):
maxi = numpy.iinfo(typ).max
else:
maxi = numpy.iinfo(numpy.integer).max
return (numpy.random.random(shape) * maxi / 10).astype(typ)


class TestPilImage3(TestPilImage):
""" check with different numbers"""

def mkdata(self, shape, typ):
""" positive, negative and big"""
return ((numpy.random.random(shape) - 0.5) * sys.maxsize / 10).astype(typ)
if numpy.issubdtype(typ, numpy.integer):
maxi = numpy.iinfo(typ).max
else:
maxi = numpy.iinfo(numpy.integer).max
return ((numpy.random.random(shape) - 0.5) * maxi / 10).astype(typ)


class TestDeprecatedFabioImage(unittest.TestCase):
Expand Down
Loading