def test_nArrayFile(self): _, array_filename = tempfile.mkstemp(suffix='.oa', dir=tempfile.tempdir) oapackage.writearrayfile(array_filename, [oapackage.exampleArray(4, 0)]) self.assertEqual(oapackage.oahelper.nArrayFile(array_filename), 1) self.assertEqual(oapackage.oahelper.nArrayFile('notavalidfile.oa'), -1)
def test_findfiles(self): _, array_filename = tempfile.mkstemp(suffix='.oa', dir=tempfile.tempdir) lst = [oapackage.exampleArray(4, 0)] oapackage.writearrayfile(array_filename, lst) lst = oapackage.oahelper.findfiles(tempfile.tempdir, '.*oa') self.assertIn(os.path.split(array_filename)[-1], lst)
def test_write_latex_format(self): lst = [oapackage.exampleArray(2, 0)] filename = tempfile.mktemp(suffix='.tex') oapackage.writearrayfile(filename, oapackage.arraylist_t(lst), oapackage.ALATEX) with open(filename, 'rt') as fid: latex = fid.read() self.assertIsInstance(latex, str)
def test_misc_file_operations(self): _, array_filename = tempfile.mkstemp(suffix='.oa') lst = [oapackage.exampleArray(4, 0)] oapackage.writearrayfile(array_filename, lst) assert (oapackage.oahelper.oaIsBinary(array_filename) is False) oapackage.writearrayfile(array_filename, oapackage.exampleArray(4, 0), oapackage.ABINARY) assert (oapackage.oahelper.oaIsBinary(array_filename)) oapackage.oahelper.oainfo(array_filename) _ = oapackage.oahelper.compressOAfile(array_filename)
def randomizearrayfile(afile, afileout, verbose=1): """ Randomize a file with arrays """ lst = oapackage.readarrayfile(afile) rlst = oapackage.oalib.arraylist_t() for ii, al in enumerate(lst): adata = oalib.arraylink2arraydata(al) trans = oalib.array_transformation_t(adata) if verbose >= 2: print('randomizing array %d\n' % ii) trans.randomize() alr = trans.apply(al) rlst.push_back(alr) oapackage.writearrayfile(afileout, rlst)
def test_selectArrays(self): _, array_filename = tempfile.mkstemp(suffix='.oa', dir=tempfile.tempdir) _, array_filename_out = tempfile.mkstemp(suffix='.oa', dir=tempfile.tempdir) oapackage.writearrayfile( array_filename, [oapackage.exampleArray(4, 0), oapackage.exampleArray(4, 0)]) oapackage.oahelper.selectArraysInFile(array_filename, array_filename_out, [1], afmode=oalib.ABINARY, verbose=1, cache=0) oapackage.oahelper.selectArraysInFile(array_filename, array_filename_out, [-1], afmode=oalib.ABINARY, verbose=1, cache=0)
def randomizearrayfile(input_filename, output_filename, verbose=1): """ Randomize a file with orthogonal arrays Each array is transformed with a random transformation Args: afile (str): input file afileout (str): output file """ lst = oapackage.readarrayfile(input_filename) rlst = oapackage.oalib.arraylist_t() for ii, al in enumerate(lst): adata = oalib.arraylink2arraydata(al) trans = oalib.array_transformation_t(adata) if verbose >= 2: print('randomizing array %d\n' % ii) trans.randomize() alr = trans.apply(al) rlst.push_back(alr) oapackage.writearrayfile(output_filename, rlst)
def randomizearrayfile(input_filename, output_filename, verbose=1): """ Randomize a file with orthogonal arrays Each array is transformed with a random transformation Args: afile (str): input file afileout (str): output file """ lst = oapackage.readarrayfile(input_filename) rlst = oapackage.oalib.arraylist_t() for ii, al in enumerate(lst): adata = oalib.arraylink2arraydata(al) trans = oalib.array_transformation_t(adata) if verbose >= 2: print('randomizing array %d\n' % ii) trans.randomize() alr = trans.apply(al) rlst.push_back(alr) oapackage.writearrayfile(output_filename, rlst)
raise Exception('could not open file %s' % inputfile) print('oaselect: reading %d arrays from %s' % (infile.narrays, inputfile) ) #%% Loop over the arrays outlist=[] if narrays==-1: narrays=oapackage.arrayfile_t.NARRAYS_MAX for ii in range(narrays): oapackage.tprint('oaselect: parse array %d/%d' % (ii, narrays) ) al=infile.readnext() if al.index==-1: break if verbose>=3: print(' index %d' % al.index) if fname=='subset': if ii%args.nsubset==0: outlist.append(al) else: if filterArray(al, fname, verbose=0): outlist.append(al) if narrays>0: oapackage.tprint('oaselect: parse array %d/%d' % (ii, narrays), dt=-1 ) oapackage.writearrayfile(outputfile, outlist, fmode, infile.nrows, infile.ncols) #%% #outfile.closefile() print('oaselect: done (selected %d arrays)' % len(outlist))