예제 #1
0
파일: test.py 프로젝트: psavery/parflowio
    def test_compare(self):
        test1 = PFData(('press.init.pfb'))
        test1.loadHeader()
        test1.loadData()

        test2 = PFData(('press.init.pfb'))
        test2.loadHeader()
        test2.loadData()

        self.assertEqual(PFData.differenceType_none,
                         test1.compare(test2)[0],
                         "test1 and test2 are the same")

        test1.setX(test1.getX() + 1.0)
        self.assertEqual(PFData.differenceType_x,
                         test1.compare(test2)[0], "The x values differ")
        test1.setX(test1.getX() - 1.0)

        arr = test1.getDataAsArray()
        arr[1][2][3] += 1.0
        ret, zyx = test1.compare(test2)
        self.assertEqual(PFData.differenceType_data, ret,
                         "The data values differ")
        self.assertEqual((1, 2, 3), zyx,
                         "The differing data's coordinates are correct")
        arr[1][2][3] -= 1.0

        test1.close()
        test2.close()
예제 #2
0
파일: io.py 프로젝트: arezaii/subsetter
def write_pfb(data, outfile, x0=0, y0=0, z0=0, dx=1000, dz=1000):
    """Write a 3d numpy array to a PFB output file

    Parameters
    ----------
    data : ndarray
        3d numpy data array to write to pfb !(x,y,z)!
    outfile : str
        filename and path to write output
    x0 : int, optional
        initial x location (Default value = 0)
    y0 : int, optional
        initial y location (Default value = 0)
    z0 : int, optional
        initial z location (Default value = 0)
    dx : int, optional
        horizontal resolution (Default value = 1000)
    dz : int, optional
        vertical resolution (Default value = 1000)

    Returns
    -------
    None

    """
    logging.info(f'wrote pfb file {outfile}, (z,y,x)={data.shape}')
    pf_data = PFData()
    pf_data.setDataArray(data)
    pf_data.setDX(dx)
    pf_data.setDY(dx)
    pf_data.setDZ(dz)
    pf_data.setX(x0)
    pf_data.setY(y0)
    pf_data.setZ(z0)
    pf_data.writeFile(outfile)
예제 #3
0
파일: test.py 프로젝트: psavery/parflowio
 def test_assign_data(self):
     test = PFData()
     data = np.random.random_sample((50, 49, 31))
     test.setDataArray(data)
     self.assertEqual(31, test.getNX())
     self.assertEqual(49, test.getNY())
     self.assertEqual(50, test.getNZ())
     test.setDX(1)
     test.setDY(1)
     test.setDZ(1)
     test.setX(0)
     test.setY(0)
     test.setZ(0)
     test.setP(1)
     test.setQ(1)
     test.setR(1)
     test.writeFile(('test_write_raw.pfb'))
     test_read = PFData(('test_write_raw.pfb'))
     test_read.loadHeader()
     test_read.loadData()
     self.assertEqual(0, test_read.getX())
     self.assertEqual(0, test_read.getY())
     self.assertEqual(0, test_read.getZ())
     self.assertEqual(31, test_read.getNX())
     self.assertEqual(49, test_read.getNY())
     self.assertEqual(50, test_read.getNZ())
     self.assertEqual(1, test_read.getP())
     self.assertEqual(1, test_read.getQ())
     self.assertEqual(1, test_read.getR())
     test_data = test_read.getDataAsArray()
     self.assertIsNone(
         np.testing.assert_array_equal(data, test_data),
         'Data written to array should exist in '
         'written PFB file.')
     del data
     test.close()
     test_read.close()
     os.remove(('test_write_raw.pfb'))