コード例 #1
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)
コード例 #2
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'))