Exemplo n.º 1
1
def get_data(name):
    """Get the resource from a JSON-encoded file"""
    return loads(rs(SOURCE, '{}.json'.format(name)).decode())
Exemplo n.º 2
0
    def test_check_face_dimension_dimensions(self):
        ncd = self.nc(
            rs('cc_plugin_sgrid', os.path.join('resources', 'roms.nc')))

        r = self.check.check_face_dimensions_dimensions(ncd)
        assert r.value == (1, 1)

        ncd.variables['grid'].face_dimensions = 'hi: bye (padding: foo)'
        r = self.check.check_face_dimensions_dimensions(ncd)
        assert r is None  # Size doesn't match, which is a dependency

        ncd.variables[
            'grid'].face_dimensions = 'xi_rho: xi_psi (padding: NOTCORRECT) eta_rho: eta_psi (padding: both)'
        r = self.check.check_face_dimensions_dimensions(ncd)
        assert r.value == (0, 1)

        ncd.variables[
            'grid'].face_dimensions = 'xi_rho: xi_psi (NOTPADDING: both) eta_rho: eta_psi (padding: both)'
        r = self.check.check_face_dimensions_dimensions(ncd)
        assert r.value == (0, 1)

        ncd.variables[
            'grid'].face_dimensions = 'xi_rho: xi_psi (padding: low) eta_rho: eta_psi (padding: high)'
        r = self.check.check_face_dimensions_dimensions(ncd)
        assert r.value == (1, 1)
Exemplo n.º 3
0
    def test_check_node_dimension_dimensions(self):
        ncd = self.nc(rs('cc_plugin_sgrid', os.path.join('resources', 'roms.nc')))

        r = self.check.check_node_dimensions_dimensions(ncd)
        assert r.value == (1, 1)

        ncd.variables['grid'].node_dimensions = 'hi bye'
        r = self.check.check_node_dimensions_dimensions(ncd)
        assert r.value == (0, 1)
Exemplo n.º 4
0
    def test_check_node_dimension_dimensions(self):
        ncd = self.nc(
            rs('cc_plugin_sgrid', os.path.join('resources', 'roms.nc')))

        r = self.check.check_node_dimensions_dimensions(ncd)
        assert r.value == (1, 1)

        ncd.variables['grid'].node_dimensions = 'hi bye'
        r = self.check.check_node_dimensions_dimensions(ncd)
        assert r.value == (0, 1)
Exemplo n.º 5
0
    def test_check_face_dimension(self):
        """
        Tests whether the check_face_dimension method works properly.
        """

        ncd = self.nc(
            rs('cc_plugin_ugrid', os.path.join('resources', 'ugrid.nc')))

        r = self.check.check_face_dimension(ncd)
        assert r.value == (1, 1)
Exemplo n.º 6
0
    def test_check_node_coordinates_exist(self):
        ncd = self.nc(
            rs('cc_plugin_ugrid', os.path.join('resources', 'ugrid.nc')))

        r = self.check.check_node_coordinates_exist(ncd)
        assert r.value == (1, 1)

        mt = ncd.get_variables_by_attributes(cf_role='mesh_topology')[0]

        mt.node_coordinates = 'foo bar'
        r = self.check.check_node_coordinates_exist(ncd)
        assert r.value == (0, 1)
Exemplo n.º 7
0
    def test_check_topology_dimension(self):
        ncd = self.nc(rs('cc_plugin_sgrid', os.path.join('resources', 'roms.nc')))

        r = self.check.check_topology_dimension(ncd)
        assert r.value == (1, 1)

        ncd.variables['grid'].topology_dimension = 0
        r = self.check.check_topology_dimension(ncd)
        assert r.value == (0, 1)

        ncd.variables['grid'].topology_dimension = 9
        r = self.check.check_topology_dimension(ncd)
        assert r.value == (0, 1)
Exemplo n.º 8
0
    def test_check_topology_dimension(self):
        ncd = self.nc(
            rs('cc_plugin_sgrid', os.path.join('resources', 'roms.nc')))

        r = self.check.check_topology_dimension(ncd)
        assert r.value == (1, 1)

        ncd.variables['grid'].topology_dimension = 0
        r = self.check.check_topology_dimension(ncd)
        assert r.value == (0, 1)

        ncd.variables['grid'].topology_dimension = 9
        r = self.check.check_topology_dimension(ncd)
        assert r.value == (0, 1)
Exemplo n.º 9
0
    def test_check_node_dimension_size(self):
        ncd = self.nc(rs('cc_plugin_sgrid', os.path.join('resources', 'roms.nc')))

        r = self.check.check_node_dimensions_size(ncd)
        assert r.value == (1, 1)

        ncd.variables['grid'].topology_dimension = 3
        r = self.check.check_node_dimensions_size(ncd)
        assert r.value == (0, 1)

        ncd.variables['grid'].topology_dimension = 2
        ncd.variables['grid'].node_dimensions = 'first second third'
        r = self.check.check_node_dimensions_size(ncd)
        assert r.value == (0, 1)
Exemplo n.º 10
0
    def test_check_location_mesh_in_variables(self):
        """
        Tests the check_location_loop method.
        """

        ncd = self.nc(
            rs('cc_plugin_ugrid', os.path.join('resources', 'ugrid.nc')))
        r = self.check.check_location_mesh_in_variables(ncd)
        assert r.value == (8, 8)

        # make junk variable
        ncd.createVariable('junk', 'c', dimensions=('nfaces', 'nnodes'))

        r = self.check.check_location_mesh_in_variables(ncd)
        assert r.value == (8, 10)
Exemplo n.º 11
0
    def test_check_node_dimension_size(self):
        ncd = self.nc(
            rs('cc_plugin_sgrid', os.path.join('resources', 'roms.nc')))

        r = self.check.check_node_dimensions_size(ncd)
        assert r.value == (1, 1)

        ncd.variables['grid'].topology_dimension = 3
        r = self.check.check_node_dimensions_size(ncd)
        assert r.value == (0, 1)

        ncd.variables['grid'].topology_dimension = 2
        ncd.variables['grid'].node_dimensions = 'first second third'
        r = self.check.check_node_dimensions_size(ncd)
        assert r.value == (0, 1)
Exemplo n.º 12
0
    def test_check_topology_dimension(self):
        ncd = self.nc(
            rs('cc_plugin_ugrid', os.path.join('resources', 'ugrid.nc')))

        r = self.check.check_topology_dimension(ncd)
        assert r.value == (1, 1)

        mt = ncd.get_variables_by_attributes(cf_role='mesh_topology')[0]

        mt.topology_dimension = 0
        r = self.check.check_topology_dimension(ncd)
        assert r.value == (0, 1)

        mt.topology_dimension = 9
        r = self.check.check_topology_dimension(ncd)
        assert r.value == (0, 1)
Exemplo n.º 13
0
    def test_check_face_coordinates(self):
        """
        Tests the check_face_coordinates method.
        """

        ncd = self.nc(
            rs('cc_plugin_ugrid', os.path.join('resources', 'ugrid.nc')))

        r = self.check.check_face_coordinates(ncd)
        assert r.value == (1, 1)

        mt = ncd.get_variables_by_attributes(cf_role='mesh_topology')[0]

        mt.face_coordinates = 'lon lat'
        r = self.check.check_face_coordinates(ncd)
        assert r.value == (0, 1)
Exemplo n.º 14
0
    def test_check_edge_dimension(self):
        """
        Tests whether the check_edge_dimension method works properly.
        """

        ncd = self.nc(
            rs('cc_plugin_ugrid', os.path.join('resources', 'ugrid.nc')))

        r = self.check.check_edge_dimension(ncd)
        assert r.value == (1, 1)

        mt = ncd.get_variables_by_attributes(cf_role='mesh_topology')[0]

        mt.edge_dimension = 'nonexistent'
        r = self.check.check_edge_dimension(ncd)
        assert r.value == (0, 1)
Exemplo n.º 15
0
    def test_check_connectivity(self):
        ncd = self.nc(
            rs('cc_plugin_ugrid', os.path.join('resources', 'ugrid.nc')))

        r = self.check.check_connectivity(ncd)
        assert r.value == (1, 1)

        mt = ncd.get_variables_by_attributes(cf_role='mesh_topology')[0]

        mt.face_node_connectivity = 'FAIL'
        r = self.check.check_connectivity(ncd)
        assert r.value == (0, 1)

        del mt.face_node_connectivity
        r = self.check.check_connectivity(ncd)
        assert r.value == (0, 1)
Exemplo n.º 16
0
    def test_check_grid_variable(self):
        ncd = self.nc(rs('cc_plugin_sgrid', os.path.join('resources', 'roms.nc')))

        r = self.check.check_grid_variable(ncd)
        assert r.value == (1, 1)

        ncd.variables['grid'].cf_role = 'blah'
        r = self.check.check_grid_variable(ncd)
        assert r.value == (0, 1)

        ncd.variables['grid'].cf_role = 'mesh_toplogy'
        r = self.check.check_grid_variable(ncd)
        assert r.value == (0, 1)        

        del ncd.variables['grid'].cf_role
        r = self.check.check_grid_variable(ncd)
        assert r.value == (0, 1)        
Exemplo n.º 17
0
    def test_check_node_coordinates_size(self):
        ncd = self.nc(
            rs('cc_plugin_ugrid', os.path.join('resources', 'ugrid.nc')))

        r = self.check.check_node_coordinates_size(ncd)
        assert r.value == (1, 1)

        mt = ncd.get_variables_by_attributes(cf_role='mesh_topology')[0]

        mt.topology_dimension = 3
        r = self.check.check_node_coordinates_size(ncd)
        assert r.value == (0, 1)

        mt.topology_dimension = 2
        mt.node_coordinates = 'first second third'
        r = self.check.check_node_coordinates_size(ncd)
        assert r.value == (0, 1)
Exemplo n.º 18
0
    def test_check_grid_variable(self):
        ncd = self.nc(
            rs('cc_plugin_sgrid', os.path.join('resources', 'roms.nc')))

        r = self.check.check_grid_variable(ncd)
        assert r.value == (1, 1)

        ncd.variables['grid'].cf_role = 'blah'
        r = self.check.check_grid_variable(ncd)
        assert r.value == (0, 1)

        ncd.variables['grid'].cf_role = 'mesh_toplogy'
        r = self.check.check_grid_variable(ncd)
        assert r.value == (0, 1)

        del ncd.variables['grid'].cf_role
        r = self.check.check_grid_variable(ncd)
        assert r.value == (0, 1)
Exemplo n.º 19
0
    def test_check_mesh_topology_variable(self):
        ncd = self.nc(
            rs('cc_plugin_ugrid', os.path.join('resources', 'ugrid.nc')))

        r = self.check.check_mesh_topology_variable(ncd)
        assert r.value == (1, 1)

        mt = ncd.get_variables_by_attributes(cf_role='mesh_topology')[0]

        mt.cf_role = 'must fail'
        r = self.check.check_mesh_topology_variable(ncd)
        assert r.value == (0, 1)

        mt.cf_role = 'grid_toplogy'
        r = self.check.check_mesh_topology_variable(ncd)
        assert r.value == (0, 1)

        del mt.cf_role
        r = self.check.check_mesh_topology_variable(ncd)
        assert r.value == (0, 1)
Exemplo n.º 20
0
    def test_check_face_dimension_dimensions(self):
        ncd = self.nc(rs('cc_plugin_sgrid', os.path.join('resources', 'roms.nc')))

        r = self.check.check_face_dimensions_dimensions(ncd)
        assert r.value == (1, 1)

        ncd.variables['grid'].face_dimensions = 'hi: bye (padding: foo)'
        r = self.check.check_face_dimensions_dimensions(ncd)
        assert r is None  # Size doesn't match, which is a dependency

        ncd.variables['grid'].face_dimensions = 'xi_rho: xi_psi (padding: NOTCORRECT) eta_rho: eta_psi (padding: both)'
        r = self.check.check_face_dimensions_dimensions(ncd)
        assert r.value == (0, 1)

        ncd.variables['grid'].face_dimensions = 'xi_rho: xi_psi (NOTPADDING: both) eta_rho: eta_psi (padding: both)'
        r = self.check.check_face_dimensions_dimensions(ncd)
        assert r.value == (0, 1)

        ncd.variables['grid'].face_dimensions = 'xi_rho: xi_psi (padding: low) eta_rho: eta_psi (padding: high)'
        r = self.check.check_face_dimensions_dimensions(ncd)
        assert r.value == (1, 1)