def test_dist_file(self): test = PFData(('press.init.pfb')) test.distFile(P=2, Q=2, R=1, outFile=('press.init.pfb.tmp')) out_file = PFData(('press.init.pfb.tmp')) dist_file = open(('press.init.pfb.tmp.dist'), 'r') dist_lines = dist_file.readlines() [ self.assertEqual(int(line.rstrip('\n')), val) for line, val in zip( dist_lines, [0, 176500, 344536, 512572, 672608]) ] self.assertEqual(0, out_file.loadHeader(), 'should load distributed file header') self.assertEqual(0, out_file.loadData(), 'should load distributed data') self.assertIsNone( np.testing.assert_array_equal(test.getDataAsArray(), out_file.getDataAsArray()), 'should find matching data values in original and distributed files' ) test.close() out_file.close() dist_file.close() os.remove(('press.init.pfb.tmp')) os.remove(('press.init.pfb.tmp.dist'))
def test_dist_nldas_file(self): test = PFData(('NLDAS.APCP.000001_to_000024.pfb')) test.distFile(P=2, Q=2, R=1, outFile=('NLDAS.APCP.000001_to_000024.pfb.tmp')) out_file = PFData(('NLDAS.APCP.000001_to_000024.pfb.tmp')) dist_file = open(('NLDAS.APCP.000001_to_000024.pfb.tmp.dist'), 'r') dist_lines = dist_file.readlines() [ self.assertEqual(int(line.rstrip('\n')), val) for line, val in zip( dist_lines, [0, 84772, 165448, 246124, 322960]) ] self.assertEqual(0, out_file.loadHeader(), 'should load distributed file header') self.assertEqual(0, out_file.loadData(), 'should load distributed data') self.assertIsNone( np.testing.assert_array_equal(test.getDataAsArray(), out_file.getDataAsArray()), 'should find matching data values in original and distributed files' ) test.close() out_file.close() dist_file.close() os.remove(('NLDAS.APCP.000001_to_000024.pfb.tmp')) os.remove(('NLDAS.APCP.000001_to_000024.pfb.tmp.dist'))
def dist(self, pfb_file, **kwargs): """Distribute a PFB file using the P/Q/R settings from the run or override them with the provided arguments. We can also use the kwargs to set other properties such as: - NX, NY, NZ... """ # Any provided args should override the scripts ones update_run_from_args(self, self._process_args_) pfb_file_full_path = get_absolute_path(pfb_file) p = self.Process.Topology.P q = self.Process.Topology.Q r = self.Process.Topology.R if 'P' in kwargs: p = kwargs['P'] if 'Q' in kwargs: q = kwargs['Q'] if 'R' in kwargs: r = kwargs['R'] from parflowio.pyParflowio import PFData pfb_data = PFData(pfb_file_full_path) pfb_data.distFile(p, q, r, pfb_file_full_path)