示例#1
0
    def test_create_weights_file(self):
        path_in_source = os.path.join(
            self.path_bin, 'precipitation_synthetic-20160310-1909.nc')
        path_in_shp = os.path.join(self.path_bin, 'nhd_catchments_texas',
                                   'nhd_catchments_texas.shp')
        name_uid = 'GRIDCODE'
        esmf_exe_path = check_output(['which', 'ESMF_RegridWeightGen']).strip()
        mpirun_exe_path = check_output(['which', 'mpirun']).strip()
        path_in_esmf_format = self.get_temporary_file_path(
            'test_esmf_format.nc')
        path_out_weights_nc = self.get_temporary_file_path('test_weights.nc')
        path_output_data = self.get_temporary_file_path(
            'weighted_esmf_format.nc')

        convert_to_esmf_format(path_in_esmf_format, path_in_shp, name_uid)
        create_weights_file(mpirun_exe_path,
                            esmf_exe_path,
                            path_in_source,
                            path_in_esmf_format,
                            path_out_weights_nc,
                            n=8)
        create_weighted_output(path_in_esmf_format, path_in_source,
                               path_out_weights_nc, path_output_data, 'pr')

        validate_weighted_output(path_output_data)
示例#2
0
def apply(source, name, weights, esmf_format, output):
    from utools.regrid.core_esmf import create_weighted_output

    log_entry('info',
              'Starting weight application for "weights": {}'.format(weights),
              rank=0)
    create_weighted_output(esmf_format, source, weights, output, name)
    log_entry('info',
              'Finished weight application for "weights": {}'.format(weights),
              rank=0)
示例#3
0
    def test_weighted_output(self):
        path_in_shp = os.path.join(self.path_bin, 'nhd_catchments_texas',
                                   'nhd_catchments_texas.shp')
        name_uid = 'GRIDCODE'
        esmf_exe_path = env.TEST_ESMF_EXE
        mpirun_exe_path = env.TEST_MPIRUN_EXE
        variable_name = 'exact'

        path_output_data = self.get_temporary_file_path(
            'weighted_esmf_format.nc')
        path_in_esmf_format = self.get_temporary_file_path(
            'test_esmf_weights.nc')
        # path_linked_shp = self.get_temporary_file_path('test_linked.shp')
        path_out_weights_nc = self.get_temporary_file_path(
            'output_weights_file.nc')
        path_src = self.get_temporary_file_path('exact.nc')

        # Test root mean squared error.
        row = np.arange(32.0012, 32.4288 + 0.01, 0.01)
        col = np.arange(-95.0477, -94.7965 + 0.01, 0.01)
        ttime = np.array([100, 200, 300], dtype=np.float32)

        create_source_netcdf_data(path_src,
                                  col,
                                  row,
                                  ttime,
                                  variable_name=variable_name)
        convert_to_esmf_format(path_in_esmf_format, path_in_shp, name_uid)
        create_weights_file(mpirun_exe_path,
                            esmf_exe_path,
                            path_src,
                            path_in_esmf_format,
                            path_out_weights_nc,
                            n=1)
        create_weighted_output(path_in_esmf_format, path_src,
                               path_out_weights_nc, path_output_data,
                               variable_name)

        # create_linked_shapefile(name_uid, variable_name, path_in_shp, path_linked_shp, path_output_data)

        max_se = 1e-4
        max_rmse = 1e-4
        with self.nc_scope(path_output_data) as ds:
            exact = ds.variables[variable_name][0, :]
            coords = ds.variables['centerCoords'][:]
        exact_centers = get_exact_field(coords[:, 0], coords[:, 1])
        se = (exact - exact_centers)**2
        mse = np.mean(se)
        rmse = np.sqrt(mse)

        self.assertLessEqual(rmse, max_rmse)
        self.assertLessEqual(se.max(), max_se)
示例#4
0
    def test_create_weighted_output(self):
        path_esmf_format = os.path.join(self.path_bin, 'test_esmf_format.nc')
        path_weights_nc = os.path.join(self.path_bin, 'test_weights.nc')
        path_in_source = os.path.join(self.path_bin, 'precipitation_synthetic-20160310-1909.nc')

        if MPI_RANK == 0:
            path_output_data = self.get_temporary_file_path('weighted_esmf_format.nc')
        else:
            path_output_data = None

        path_output_data = MPI_COMM.bcast(path_output_data)

        create_weighted_output(path_esmf_format, path_in_source, path_weights_nc, path_output_data, 'pr')

        if MPI_RANK == 0:
            validate_weighted_output(path_output_data)

        MPI_COMM.Barrier()