1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
|
# -*- coding: utf-8 -*-
'''
Created on Fri Sep 30 09:44:09 2016
@author: Robert A. McLeod
'''
import mrcz
import numpy as np
import numpy.testing as npt
import os, os.path, sys
import subprocess as sub
import tempfile
import unittest
from logging import Logger
from enum import Enum
log = Logger(__name__)
def which(program):
# Tries to locate a program
import os
if os.name == 'nt':
program_ext = os.path.splitext(program)[1]
if program_ext == '':
prog_exe = which(program + '.exe')
if prog_exe != None:
return prog_exe
return which(program + '.com')
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ['PATH'].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
float_dtype = 'float32'
fftw_dtype = 'complex64'
tmpDir = tempfile.gettempdir()
#==============================================================================
# ioMRC Test
#
# Internal python-only test. Build a random image and save and re-load it.
#==============================================================================
class PythonMrczTests(unittest.TestCase):
def setUp(self):
pass
def compReadWrite(self, testMage, casttype=None, compressor=None, clevel = 1):
# This is the main functions which reads and writes from disk.
mrcName = os.path.join(tmpDir, 'testMage.mrc')
pixelsize = np.array([1.2, 2.6, 3.4])
mrcz.writeMRC(testMage, mrcName, dtype=casttype,
pixelsize=pixelsize, pixelunits=u'\AA',
voltage=300.0, C3=2.7, gain=1.05,
compressor=compressor, clevel=clevel)
rereadMage, rereadHeader = mrcz.readMRC(mrcName, pixelunits=u'\AA')
# `tempfile.TemporaryDirectory` would be better but Python 2.7 doesn't support it
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
npt.assert_array_almost_equal(testMage, rereadMage)
npt.assert_array_almost_equal(rereadHeader['pixelsize'], pixelsize)
assert(rereadHeader['pixelunits'] == u'\AA')
npt.assert_almost_equal(rereadHeader['voltage'], 300.0)
npt.assert_almost_equal(rereadHeader['C3'], 2.7)
npt.assert_almost_equal(rereadHeader['gain'], 1.05)
def test_MRC_uncompressed(self):
log.info('Testing uncompressed MRC, float-32')
testMage0 = np.random.normal(size=[2,128,96]).astype(float_dtype)
self.compReadWrite(testMage0, compressor=None)
log.info('Testing uncompressed MRC, uint-4')
testMage1 = np.random.randint(10, size=[2,128,96], dtype='int8')
self.compReadWrite(testMage1, casttype='uint4', compressor=None)
log.info('Testing uncompressed MRC, int-8')
testMage2 = np.random.randint(10, size=[2,128,96], dtype='int8')
self.compReadWrite(testMage2, compressor=None)
log.info('Testing uncompressed MRC, int-16')
testMage3 = np.random.randint(10, size=[2,128,96], dtype='int16')
self.compReadWrite(testMage3, compressor=None)
log.info('Testing uncompressed MRC, uint-16')
testMage4 = np.random.randint(10, size=[2,128,96], dtype='uint16')
self.compReadWrite(testMage4, compressor=None)
log.info('Testing uncompressed MRC, complex-64')
testMage5 = np.random.uniform(10, size=[2,128,96]).astype('float32') + \
1j * np.random.uniform(10, size=[2,128,96] ).astype('float32')
self.compReadWrite(testMage5, compressor=None)
def test_MRCZ_zstd1(self):
log.info('Testing zstd_1 MRC, float-32')
testMage0 = np.random.normal(size=[2,128,96]).astype(float_dtype)
self.compReadWrite(testMage0, compressor='zstd', clevel=1)
log.info('Testing zstd_1 MRC, int-8')
testMage2 = np.random.randint(10, size=[2,128,96], dtype='int8')
self.compReadWrite(testMage2, compressor='zstd', clevel=1)
log.info('Testing zstd_1 MRC, int-16')
testMage3 = np.random.randint(10, size=[2,128,96], dtype='int16')
self.compReadWrite(testMage3, compressor='zstd', clevel=1)
log.info('Testing zstd_1 MRC, uint-16')
testMage4 = np.random.randint(10, size=[2,128,96], dtype='uint16')
self.compReadWrite(testMage4, compressor='zstd', clevel=1)
log.info('Testing zstd_1 MRC, complex-64')
testMage5 = np.random.normal(10, size=[2,128,96]).astype('float32') + \
1j * np.random.normal(10, size=[2,128,96] ).astype('float32')
self.compReadWrite(testMage5, compressor='zstd', clevel=1)
def test_MRCZ_lz9(self):
log.info('Testing lz4_9 MRC, float-32')
testMage0 = np.random.normal(size=[2,128,96]).astype(float_dtype)
self.compReadWrite(testMage0, compressor='lz4', clevel=9)
log.info('Testing lz4_9 MRC, int-8')
testMage2 = np.random.randint(10, size=[2,128,96], dtype='int8')
self.compReadWrite(testMage2, compressor='lz4', clevel=9)
log.info('Testing lz4_9 MRC, int-16')
testMage3 = np.random.randint(10, size=[2,128,96], dtype='int16')
self.compReadWrite(testMage3, compressor='lz4', clevel=9)
log.info('Testing lz4_9 MRC, uint-16')
testMage4 = np.random.randint(10, size=[2,128,96], dtype='uint16')
self.compReadWrite(testMage4, compressor='lz4', clevel=9)
log.info('Testing lz4_9 MRC, complex-64')
testMage5 = np.random.normal(10, size=[2,128,96]).astype('float32') + \
1j * np.random.normal(10, size=[2,128,96] ).astype('float32')
self.compReadWrite(testMage5, compressor='lz4', clevel=9)
def test_JSON(self):
testMage = np.random.uniform(high=10, size=[3,128,64]).astype('int8')
meta = {'foo': 5, 'bar': 42}
mrcName = os.path.join(tmpDir, 'testMage.mrcz')
pixelsize = [1.2, 5.6, 3.4]
mrcz.writeMRC(testMage, mrcName, meta=meta,
pixelsize=pixelsize, pixelunits=u'\AA',
voltage=300.0, C3=2.7, gain=1.05,
compressor='zstd', clevel=1, n_threads=1)
rereadMage, rereadHeader = mrcz.readMRC(mrcName, pixelunits=u'\AA')
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
assert(np.all(testMage.shape == rereadMage.shape))
assert(testMage.dtype == rereadMage.dtype)
for key in meta:
assert(meta[key] == rereadHeader[key])
npt.assert_array_almost_equal(testMage, rereadMage)
npt.assert_almost_equal(rereadHeader['voltage'], 300.0)
npt.assert_array_almost_equal(rereadHeader['pixelsize'], pixelsize)
assert(rereadHeader['pixelunits'] == u'\AA')
npt.assert_almost_equal(rereadHeader['C3'], 2.7)
npt.assert_almost_equal(rereadHeader['gain'], 1.05)
def test_async(self):
testMage = np.random.uniform(high=10, size=[3,128,64]).astype('int8')
meta = {'foo': 5, 'bar': 42}
mrcName = os.path.join(tmpDir, 'testMage.mrcz')
pixelsize = [1.2, 5.6, 3.4]
worker = mrcz.asyncWriteMRC(testMage, mrcName, meta=meta,
pixelsize=pixelsize, pixelunits=u'\AA',
voltage=300.0, C3=2.7, gain=1.05,
compressor='zstd', clevel=1, n_threads=1)
worker.result() # Wait for write to finish
worker = mrcz.asyncReadMRC(mrcName, pixelunits=u'\AA')
rereadMage, rereadHeader = worker.result()
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
assert(np.all(testMage.shape == rereadMage.shape))
assert(testMage.dtype == rereadMage.dtype)
for key in meta:
assert(meta[key] == rereadHeader[key])
npt.assert_array_almost_equal(testMage, rereadMage)
npt.assert_almost_equal(rereadHeader['voltage'], 300.0)
npt.assert_array_almost_equal(rereadHeader['pixelsize'], pixelsize)
assert(rereadHeader['pixelunits'] == u'\AA')
npt.assert_almost_equal(rereadHeader['C3'], 2.7)
npt.assert_almost_equal(rereadHeader['gain'], 1.05)
def test_list_2d(self):
testMage = [np.random.uniform(high=10, size=[32,16]).astype('int8')] * 3
mrcName = os.path.join(tmpDir, 'testMage.mrcz')
pixelsize = [5.6, 3.4]
mrcz.writeMRC(testMage, mrcName, pixelsize=pixelsize, compressor=None)
rereadMage, _ = mrcz.readMRC(mrcName, pixelunits=u'\AA')
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
assert(isinstance(rereadMage, list))
assert(len(rereadMage) == len(testMage))
for testFrame, rereadFrame in zip(testMage, rereadMage):
assert(testFrame.dtype == rereadFrame.dtype)
npt.assert_array_almost_equal(testFrame, rereadFrame)
def test_list_2d_compressed(self):
testMage = [np.random.uniform(high=10, size=[32,16]).astype('int8')] * 3
mrcName = os.path.join(tmpDir, 'testMage.mrcz')
pixelsize = [5.6, 3.4]
mrcz.writeMRC(testMage, mrcName, pixelsize=pixelsize,
compressor='zstd', clevel=1, n_threads=1)
rereadMage, _ = mrcz.readMRC(mrcName, pixelunits=u'\AA')
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
assert(isinstance(rereadMage, list))
assert(len(rereadMage) == len(testMage))
for testFrame, rereadFrame in zip(testMage, rereadMage):
assert(testFrame.dtype == rereadFrame.dtype)
npt.assert_array_almost_equal(testFrame, rereadFrame)
def test_list_3d(self):
testMage = [np.random.uniform(high=10, size=[3,32,32]).astype('int8')] * 3
mrcName = os.path.join(tmpDir, 'testMage.mrcz')
pixelsize = [5.6, 3.4]
mrcz.writeMRC(testMage, mrcName, pixelsize=pixelsize, compressor=None)
rereadMage, _ = mrcz.readMRC(mrcName, pixelunits=u'\AA')
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
assert(isinstance(rereadMage, list))
assert(len(rereadMage) == len(testMage))
for testFrame, rereadFrame in zip(testMage, rereadMage):
assert(testFrame.dtype == rereadFrame.dtype)
npt.assert_array_almost_equal(testFrame, rereadFrame)
def test_list_3d_compressed(self):
testMage = [np.random.uniform(high=10, size=[3,32,32]).astype('int8')] * 3
mrcName = os.path.join(tmpDir, 'testMage.mrcz')
pixelsize = [5.6, 3.4]
mrcz.writeMRC(testMage, mrcName, pixelsize=pixelsize,
compressor='zstd', clevel=1, n_threads=1)
rereadMage, _ = mrcz.readMRC(mrcName, pixelunits=u'\AA')
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
assert(isinstance(rereadMage, list))
assert(len(rereadMage) == len(testMage))
for testFrame, rereadFrame in zip(testMage, rereadMage):
assert(testFrame.dtype == rereadFrame.dtype)
npt.assert_array_almost_equal(testFrame, rereadFrame)
def test_list_change_output_shape(self):
testMage = np.random.uniform(high=10, size=[6,32,32]).astype('int8')
pixelsize = [5.6, 3.4]
mrcName = os.path.join(tmpDir, 'testMage.mrcz')
for slices in (1, 2):
mrcz.writeMRC(testMage, mrcName, pixelsize=pixelsize,
compressor=None)
rereadMage, _ = mrcz.readMRC(mrcName, pixelunits=u'\AA', slices=slices)
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
assert(isinstance(rereadMage, list))
assert(len(rereadMage) == testMage.shape[0] // slices)
def test_list_change_output_shape_compressed(self):
testMage = np.random.uniform(high=10, size=[6,32,32]).astype('int8')
pixelsize = [5.6, 3.4]
mrcName = os.path.join(tmpDir, 'testMage.mrcz')
for slices in (1, 2):
mrcz.writeMRC(testMage, mrcName, pixelsize=pixelsize,
compressor='zstd', clevel=1, n_threads=1)
rereadMage, _ = mrcz.readMRC(mrcName, pixelunits=u'\AA', slices=slices)
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
assert(isinstance(rereadMage, list))
assert(len(rereadMage) == testMage.shape[0] // slices)
def test_strided_array(self):
log.info('Testing strided array MRC')
testMage0 = np.random.randint(32, size=[2,128,96]).astype(np.int8)
testMage0 = testMage0[:,::2,::2]
self.compReadWrite(testMage0, compressor='zstd', clevel=1)
def test_cast_array_from_f64(self):
log.info('Testing float-64 casting')
f64_mage = np.random.normal(size=[2,128,96]).astype(np.float64)
f32_mage = f64_mage.astype(np.float32)
mrcName = os.path.join(tmpDir, 'testMage.mrc')
mrcz.writeMRC(f64_mage, mrcName, compressor='zstd', clevel=1)
rereadMage, rereadHeader = mrcz.readMRC(mrcName)
# `tempfile.TemporaryDirectory` would be better but Python 2.7 doesn't support it
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
npt.assert_array_almost_equal(f32_mage, rereadMage)
def test_cast_list_from_f64(self):
log.info('Testing float-64 list casting')
f64_mage = [np.random.normal(size=[128,96]).astype(np.float64) for I in range(2)]
f32_mage = [frame.astype(np.float32) for frame in f64_mage]
mrcName = os.path.join(tmpDir, 'testMage.mrc')
mrcz.writeMRC(f64_mage, mrcName, compressor='zstd', clevel=1)
rereadMage, rereadHeader = mrcz.readMRC(mrcName)
# `tempfile.TemporaryDirectory` would be better but Python 2.7 doesn't support it
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
npt.assert_array_almost_equal(f32_mage[0], rereadMage[0])
npt.assert_array_almost_equal(f32_mage[1], rereadMage[1])
def test_cast_array_from_c128(self):
log.info('Testing complex-128 casting')
c128_mage = np.random.normal(size=[2,128,96]).astype(np.float64) + \
1j * np.random.normal(size=[2,128,96]).astype(np.float64)
c64_mage = c128_mage.astype(np.complex64)
mrcName = os.path.join(tmpDir, 'testMage.mrc')
mrcz.writeMRC(c128_mage, mrcName, compressor='zstd', clevel=1)
rereadMage, rereadHeader = mrcz.readMRC(mrcName)
# `tempfile.TemporaryDirectory` would be better but Python 2.7 doesn't support it
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
npt.assert_array_almost_equal(c64_mage, rereadMage)
def test_cast_list_from_c128(self):
log.info('Testing complex-128 casting')
c128_mage = [np.random.normal(size=[128,96]).astype(np.float64) + \
1j * np.random.normal(size=[128,96]).astype(np.float64) for I in range(2)]
c64_mage = [frame.astype(np.complex64) for frame in c128_mage]
mrcName = os.path.join(tmpDir, 'testMage.mrc')
mrcz.writeMRC(c128_mage, mrcName, compressor='zstd', clevel=1)
rereadMage, rereadHeader = mrcz.readMRC(mrcName)
# `tempfile.TemporaryDirectory` would be better but Python 2.7 doesn't support it
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
npt.assert_array_almost_equal(c64_mage[0], rereadMage[0])
npt.assert_array_almost_equal(c64_mage[1], rereadMage[1])
def test_numpy_metadata(self):
log.info('Testing NumPy types in meta-data')
meta = {
'zoo': np.float64(1.0),
'foo': [
np.ones(16),
np.ones(16),
np.ones(16)],
'bar': {
# Note: no support in JSON for complex numbers.
'moo': np.uint64(42),
'boo': np.full(8, 3, dtype=np.int32)
}
}
mage = np.zeros([32, 32], dtype=np.float32)
mrcName = os.path.join(tmpDir, 'testMage.mrc')
mrcz.writeMRC(mage, mrcName, meta=meta)
re_mage, re_meta = mrcz.readMRC(mrcName)
# `tempfile.TemporaryDirectory` would be better but Python 2.7 doesn't support it
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
npt.assert_array_equal(re_meta['foo'][0], meta['foo'][0])
npt.assert_array_equal(re_meta['bar']['boo'], meta['bar']['boo'])
def test_enum_metadata(self):
log.info('Testing Enum types in meta-data')
class Axis(Enum):
X = 0
Y = 1
meta = {
'axes': [Axis.Y, Axis.X]
}
mage = np.zeros([4, 4], dtype=np.float32)
mrcName = os.path.join(tmpDir, 'testMage.mrc')
mrcz.writeMRC(mage, mrcName, meta=meta)
re_mage, re_meta = mrcz.readMRC(mrcName)
# `tempfile.TemporaryDirectory` would be better but Python 2.7 doesn't support it
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
assert('Enum.Axis.X' in re_meta['axes'])
assert('Enum.Axis.Y' in re_meta['axes'])
def test_MRC_append(self):
log.info('Testing appending to existing MRC stack, float-32')
f32_stack = [np.random.normal(size=[128,96]).astype(np.float32) for I in range(2)]
mrcName = os.path.join(tmpDir, 'testStack.mrcs')
pixelsize = [5.6, 3.4]
for j,I in enumerate(f32_stack):
mrcz.writeMRC(I, mrcName, pixelsize=pixelsize, compressor=None, idx = j)
rereadMage, _ = mrcz.readMRC(mrcName, pixelunits=u'\AA')
try: os.remove(mrcName)
except IOError: log.info('Warning: file {} left on disk'.format(mrcName))
assert(rereadMage.shape[0] == len(f32_stack))
for testFrame, rereadFrame in zip(f32_stack, rereadMage):
assert(testFrame.dtype == rereadFrame.dtype)
npt.assert_array_almost_equal(testFrame, rereadFrame)
cmrczProg = which('mrcz')
if cmrczProg is None:
log.debug('NOTE: mrcz not found in system path, not testing python-mrcz to c-mrcz cross-compatibility')
else:
class PythonToCMrczTests(unittest.TestCase):
#==============================================================================
# python-mrcz to c-mrcz tests
#
# mrcz executable must be found within the system path.
#
# Cross-compatibility tests between c-mrcz and python-mrcz. Build a random
# image, load and re-save it with c-mrcz, and then reload in Python.
#==============================================================================
def setUp(self):
pass
def crossReadWrite(self, testMage, casttype=None, compressor=None, clevel = 1):
mrcInput = os.path.join(tmpDir, 'testIn.mrcz')
mrcOutput = os.path.join(tmpDir, 'testOut.mrcz')
compressor = None
blocksize = 64
clevel = 1
pixelsize = [1.2, 2.6, 3.4]
mrcz.writeMRC(testMage, mrcInput,
pixelsize=pixelsize, pixelunits=u'\AA',
voltage=300.0, C3=2.7, gain=1.05,
compressor=compressor)
sub.call(cmrczProg + ' -i %s -o %s -c %s -B %d -l %d'
%(mrcInput, mrcOutput, compressor, blocksize, clevel), shell=True)
rereadMage, rereadHeader = mrcz.readMRC(mrcOutput, pixelunits=u'\AA')
os.remove(mrcOutput)
os.remove(mrcInput)
assert(np.all(testMage.shape == rereadMage.shape))
assert(testMage.dtype == rereadMage.dtype)
npt.assert_array_almost_equal(testMage, rereadMage)
npt.assert_array_equal(rereadHeader['voltage'], 300.0)
npt.assert_array_almost_equal(rereadHeader['pixelsize'], pixelsize)
npt.assert_array_equal(rereadHeader['pixelunits'], u'\AA')
npt.assert_array_equal(rereadHeader['C3'], 2.7)
npt.assert_array_equal(rereadHeader['gain'], 1.05)
def test_crossMRC_uncompressed(self):
log.info('Testing cross-compatibility c-mrcz and python-mrcz, uncompressed, int-8')
testMage0 = np.random.randint(10, size=[2,128,64], dtype='int8')
self.crossReadWrite(testMage0, compressor=None, clevel=1)
log.info('Testing cross-compatibility c-mrcz and python-mrcz, uncompressed, int-16')
testMage1 = np.random.randint(10, size=[2,128,64], dtype='int16')
self.crossReadWrite(testMage1, compressor=None, clevel=1)
log.info('Testing cross-compatibility c-mrcz and python-mrcz, uncompressed, float32')
testMage1 = np.random.normal(size=[2,128,64]).astype('float32')
self.crossReadWrite(testMage1, compressor=None, clevel=1)
log.info('Testing cross-compatibility c-mrcz and python-mrcz, uncompressed, uint-16')
testMage4 = np.random.randint(10, size=[2,128,96], dtype='uint16')
self.crossReadWrite(testMage4, compressor=None, clevel=1)
log.info('Testing cross-compatibility c-mrcz and python-mrcz, uncompressed, complex-64')
testMage5 = np.random.normal(10, size=[2,128,96]).astype('float32') + \
1j * np.random.normal(10, size=[2,128,96] ).astype('float32')
self.crossReadWrite(testMage5, compressor=None, clevel=1)
def test_crossMRC_zstd1(self):
log.info('Testing cross-compatibility c-mrcz and python-mrcz, zstd_1, int-8')
testMage0 = np.random.randint(10, size=[2,128,64], dtype='int8')
self.crossReadWrite(testMage0, compressor='zstd', clevel=1)
log.info('Testing cross-compatibility c-mrcz and python-mrcz, zstd_1, int-16')
testMage1 = np.random.randint(10, size=[2,128,64], dtype='int16')
self.crossReadWrite(testMage1, compressor='zstd', clevel=1)
log.info('Testing cross-compatibility c-mrcz and python-mrcz, zstd_1, float32')
testMage1 = np.random.normal(size=[2,128,64]).astype('float32')
self.crossReadWrite(testMage1, compressor='zstd1', clevel=1)
log.info('Testing cross-compatibility c-mrcz and python-mrcz, zstd_1, uint-16')
testMage4 = np.random.randint(10, size=[2,128,96], dtype='uint16')
self.crossReadWrite(testMage4, compressor='zstd', clevel=1)
log.info('Testing cross-compatibility c-mrcz and python-mrcz, zstd_1, complex-64')
testMage5 = np.random.normal(10, size=[2,128,96]).astype('float32') + \
1j * np.random.normal(10, size=[2,128,96] ).astype('float32')
self.crossReadWrite(testMage5, compressor='zstd', clevel=1)
def test_crossMRC_lz4_9(self):
log.info('Testing cross-compatibility c-mrcz and python-mrcz, lz4_9, int-8')
testMage0 = np.random.randint(10, size=[2,128,64], dtype='int8')
self.crossReadWrite(testMage0, compressor='lz4', clevel=9)
log.info('Testing cross-compatibility c-mrcz and python-mrcz, lz4_9, int-16')
testMage1 = np.random.randint(10, size=[2,128,64], dtype='int16')
self.crossReadWrite(testMage1, compressor='lz4', clevel=9)
log.info('Testing cross-compatibility c-mrcz and python-mrcz, lz4_9, float32')
testMage1 = np.random.normal(size=[2,128,64]).astype('float32')
self.crossReadWrite(testMage1, compressor='lz4', clevel=9)
log.info('Testing cross-compatibility c-mrcz and python-mrcz, lz4_9, uint-16')
testMage4 = np.random.randint(10, size=[2,128,96], dtype='uint16')
self.crossReadWrite(testMage4, compressor='lz4', clevel=9)
log.info('Testing cross-compatibility c-mrcz and python-mrcz, lz4_9, complex-64')
testMage5 = np.random.normal(10, size=[2,128,96]).astype('float32') + \
1j * np.random.normal(10, size=[2,128,96] ).astype('float32')
self.crossReadWrite(testMage5, compressor='lz4', clevel=9)
pass
def test(verbosity=2):
'''
test(verbosity=2)
Run ``unittest`` suite for ``mrcz`` package.
'''
from mrcz import __version__
log.info('MRCZ TESTING FOR VERSION %s ' % __version__)
theSuite = unittest.TestSuite()
theSuite.addTest(unittest.makeSuite(PythonMrczTests))
if cmrczProg is not None:
theSuite.addTest(unittest.makeSuite(PythonToCMrczTests))
test_result = unittest.TextTestRunner(verbosity=verbosity).run(theSuite)
return test_result
if __name__ == '__main__':
# Should generally call 'python -m unittest -v mrcz.test' for continuous integration
test()
|