Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
filename.seek(0)
data = filename.read()
actual_filename = fabioutils.BytesIO(data)
# Back to the location before the read
filename.seek(0)
else:
if os.path.exists(filename):
# Already a valid filename
actual_filename = filename
elif "::" in filename:
actual_filename = filename.split("::")[0]
else:
actual_filename = filename
try:
imo = FabioImage()
with imo._open(actual_filename) as f:
magic_bytes = f.read(18)
except IOError:
logger.debug("Backtrace", exc_info=True)
raise
else:
imo = None
filetype = None
try:
filetype = do_magic(magic_bytes, filename)
except Exception:
logger.debug("Backtrace", exc_info=True)
try:
file_obj = FilenameObject(filename=filename)
if file_obj is None:
Frederiksborgvej 399
DK-4000 Roskilde
email:erik.knudsen@risoe.dk
+ mods for fabio by JPW
"""
# Get ready for python3:
from __future__ import with_statement, print_function
import numpy, logging
from fabio.fabioimage import FabioImage
from fabio.fabioutils import to_str
logger = logging.getLogger("adscimage")
class AdscImage(FabioImage):
""" Read an image in ADSC format (quite similar to edf?) """
def __init__(self, *args, **kwargs):
FabioImage.__init__(self, *args, **kwargs)
def read(self, fname, frame=None):
""" read in the file """
with self._open(fname, "rb") as infile:
try:
self._readheader(infile)
except:
raise Exception("Error processing adsc header")
# banned by bzip/gzip???
try:
infile.seek(int(self.header['HEADER_BYTES']), 0)
except TypeError:
# Gzipped does not allow a seek and read header is not
__authors__ = ["Jérôme Kieffer"]
__contact__ = "Jerome.Kieffer@terre-adelie.org"
__license__ = "MIT"
__copyright__ = "Jérôme Kieffer"
__date__ = "03/04/2020"
import logging
import numpy
from .fabioimage import FabioImage
from .fabioutils import previous_filename, next_filename
logger = logging.getLogger(__name__)
class MrcImage(FabioImage):
"""
FabIO image class for Images from a mrc image stack
"""
DESCRIPTION = "Medical Research Council file format for 3D electron density and 2D images"
DEFAULT_EXTENSIONS = ["mrc", "map", "fei"]
KEYS = ("NX", "NY", "NZ", "MODE", "NXSTART", "NYSTART", "NZSTART",
"MX", "MY", "MZ", "CELL_A", "CELL_B", "CELL_C",
"CELL_ALPHA", "CELL_BETA", "CELL_GAMMA",
"MAPC", "MAPR", "MAPS", "DMIN", "DMAX", "DMEAN", "ISPG", "NSYMBT",
"EXTRA", "ORIGIN", "MAP", "MACHST", "RMS", "NLABL")
_MODE_TO_DTYPE = {
0: numpy.int8,
__status__ = "stable"
import logging
import numpy
logger = logging.getLogger(__name__)
from .fabioimage import FabioImage
from .fabioutils import six
SUBFORMATS = [six.b(i) for i in ('P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7')]
HEADERITEMS = [six.b(i) for i in ('SUBFORMAT', 'WIDTH', 'HEIGHT', 'MAXVAL')]
P7HEADERITEMS = [six.b(i) for i in ('WIDTH', 'HEIGHT', 'DEPTH', 'MAXVAL', 'TUPLTYPE', 'ENDHDR')]
class PnmImage(FabioImage):
DESCRIPTION = "PNM file format"
DEFAULT_EXTENSIONS = ["pnm", "pgm", "pbm"]
def __init__(self, *arg, **kwargs):
FabioImage.__init__(self, *arg, **kwargs)
self.header['Subformat'] = 'P5'
def _readheader(self, f):
# pnm images have a 3-line header but ignore lines starting with '#'
# 1st line contains the pnm image sub format
# 2nd line contains the image pixel dimension
# 3rd line contains the maximum pixel value (at least for grayscale - check this)
line = f.readline().strip()