예제 #1
0
 def test_missing_temporal_extent_but_start_and_end_provided_as_kwargs(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader)
     nc2mmd = Nc_to_mmd('tests/data/reference_nc_missing_attrs.nc')
     with self.assertRaises(AttributeError):
         nc2mmd.to_mmd(time_coverage_start='1850-01-01T00:00:00Z', time_coverage_end='1950-01-01T00:00:00Z')
     self.assertEqual(nc2mmd.metadata['temporal_extent']['start_date'], '1850-01-01T00:00:00Z')
     self.assertEqual(nc2mmd.metadata['temporal_extent']['end_date'], '1950-01-01T00:00:00Z')
예제 #2
0
 def test_missing_temporal_extent(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader)
     nc2mmd = Nc_to_mmd('tests/data/reference_nc_missing_attrs.nc')
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_temporal_extents(mmd_yaml['temporal_extent'], ncin)
     self.assertEqual(value, [])
     self.assertEqual(nc2mmd.missing_attributes['errors'][0], 'time_coverage_start is a required ACDD attribute')
예제 #3
0
 def test_temporal_extent(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader)
     nc2mmd = Nc_to_mmd('tests/data/reference_nc.nc')
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_temporal_extents(mmd_yaml['temporal_extent'], ncin)
     self.assertEqual(value[0]['start_date'], '2020-11-27T13:40:02.019817Z')
     self.assertEqual(value[0]['end_date'], '2020-11-27T13:51:24.401505Z')
예제 #4
0
 def test_last_metadata_update(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'),
             Loader=yaml.FullLoader)
     nc2mmd = Nc_to_mmd('tests/data/reference_nc.nc')
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_metadata_updates(mmd_yaml['last_metadata_update'], ncin)
     self.assertEqual(value['update'][0]['datetime'], '2020-11-27T14:05:56Z')
예제 #5
0
 def test__to_mmd__get_correct_id_from_ncfile(self):
     tested = tempfile.mkstemp()[1]
     # The id attribute is a uuid
     nc2mmd = Nc_to_mmd('tests/data/reference_nc.nc', output_file=tested)
     nc2mmd.to_mmd()
     self.assertEqual(nc2mmd.missing_attributes['warnings'][0], 'Using default value Active for metadata_status')
     self.assertEqual(nc2mmd.missing_attributes['errors'], [])
예제 #6
0
 def test_create_mmd_2(self):
     """ToDo: Add docstring"""
     self.maxDiff = None
     tested = tempfile.mkstemp()[1]
     md = Nc_to_mmd(self.fail_nc, output_file=tested)
     with self.assertRaises(AttributeError):
         md.to_mmd()
예제 #7
0
 def test_keywords_vocabulary_missing(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'), 
             Loader=yaml.FullLoader)
     nc2mmd = Nc_to_mmd('tests/data/reference_nc_missing_keywords_vocab.nc')
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_keywords(mmd_yaml['keywords'], ncin)
     self.assertEqual(nc2mmd.missing_attributes['errors'][0], 'keywords_vocabulary is a required ACDD attribute')
예제 #8
0
 def test_metadata_status_is_active(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'),
             Loader=yaml.FullLoader)
     nc2mmd = Nc_to_mmd('tests/data/reference_nc.nc')
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_acdd_metadata(mmd_yaml['metadata_status'], ncin, 'metadata_status')
     self.assertEqual(value, 'Active')
예제 #9
0
 def test_personnel_acdd_roles_not_list(self):
     """Test that we can have multiple people in MMD personnel field"""
     mmd_yaml = yaml.load(
         resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader
     )
     nc2mmd = Nc_to_mmd(
         'tests/data/reference_nc_attrs_multiple_and_contributor.nc',
         check_only=True
     )
     ncin = Dataset(nc2mmd.netcdf_product)
     mmd_yaml['personnel']['name']['acdd'].pop(-1)
     mmd_yaml['personnel']['name']['acdd'] = mmd_yaml['personnel']['name']['acdd'][0]
     mmd_yaml['personnel']['role']['acdd'].pop(-1)
     mmd_yaml['personnel']['role']['acdd'] = mmd_yaml['personnel']['role']['acdd'][0]
     mmd_yaml['personnel']['email'].pop('acdd_ext')
     mmd_yaml['personnel']['organisation'].pop('acdd_ext')
     value = nc2mmd.get_personnel(mmd_yaml['personnel'], ncin)
     self.assertEqual(value[0]['name'], 'Trygve')
     self.assertEqual(value[1]['name'], 'Nina')
     self.assertEqual(value[0]['role'], 'Investigator')
     self.assertEqual(value[1]['role'], 'Technical contact')
     self.assertEqual(value[0]['email'], '*****@*****.**')
     self.assertEqual(value[1]['email'], '*****@*****.**')
     self.assertEqual(value[0]['organisation'], 'Norwegian Meteorological Institute')
     self.assertEqual(value[1]['organisation'], 'Norwegian Meteorological Institute')
예제 #10
0
 def test_create_mmd_1(self):
     """Test MMD creation from a valid netcdf file, validation
     with the mmd_strict.xsd, and that some fields are as expected.
     Please add new fields to test as needed..
     """
     tested = tempfile.mkstemp()[1]
     # md = Nc_to_mmd(self.reference_nc, output_file=tested)
     md = Nc_to_mmd('tests/data/reference_nc_with_altID_multiple.nc', output_file=tested)
     md.to_mmd()
     xsd_obj = etree.XMLSchema(etree.parse(self.reference_xsd))
     xml_doc = etree.ElementTree(file=tested)
     valid = xsd_obj.validate(xml_doc)
     self.assertTrue(valid)
     """ Check content of the xml_doc """
     # alternate_identifier
     self.assertEqual(
         xml_doc.getroot().find(
             "{http://www.met.no/schema/mmd}alternate_identifier[@type='dummy_type']"
         ).text,
         "dummy_id_no1"
     )
     self.assertEqual(
         xml_doc.getroot().find(
             "{http://www.met.no/schema/mmd}alternate_identifier[@type='other_type']"
         ).text,
         "dummy_id_no2"
     )
예제 #11
0
 def test_alternate_identifier(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'),
             Loader=yaml.FullLoader)
     nc2mmd = Nc_to_mmd('tests/data/reference_nc.nc')
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_acdd_metadata(mmd_yaml['alternate_identifier'], ncin, 'alternate_identifier')
     self.assertEqual(value, [])
예제 #12
0
 def test_spatial_repr(self):
     """ToDo: Add docstring"""
     tempfile.mkstemp()[1]
     nc2mmd = Nc_to_mmd('tests/data/reference_nc.nc', check_only=True)
     nc2mmd.to_mmd()
     spatial_repr = nc2mmd.metadata['spatial_representation']
     self.assertEqual(spatial_repr, 'grid')
예제 #13
0
 def test_access_constraint(self):
     """ToDo: Add docstring"""
     tempfile.mkstemp()[1]
     nc2mmd = Nc_to_mmd('tests/data/reference_nc.nc', check_only=True)
     nc2mmd.to_mmd()
     spatial_repr = nc2mmd.metadata['access_constraint']
     self.assertEqual(spatial_repr, 'Open')
예제 #14
0
 def test_missing_vocabulary_platform(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'), 
             Loader=yaml.FullLoader)
     nc2mmd = Nc_to_mmd('tests/data/reference_nc_missing_keywords_vocab.nc')
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_platforms(mmd_yaml['platform'], ncin)
     self.assertEqual(value[0]['resource'], '')
예제 #15
0
 def test_missing_geographic_extent(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader)
     nc2mmd = Nc_to_mmd('tests/data/reference_nc_missing_attrs.nc')
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_acdd_metadata(mmd_yaml['geographic_extent'], ncin, 'geographic_extent')
     self.assertEqual(value['rectangle']['north'], None)
     self.assertEqual(nc2mmd.missing_attributes['errors'][0], 'geospatial_lat_max is a required attribute')
예제 #16
0
 def test_missing_id(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader)
     # nc file is missing the id attribute
     nc2mmd = Nc_to_mmd('tests/data/reference_nc_missing_keywords_vocab.nc')
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_metadata_identifier(mmd_yaml['metadata_identifier'], ncin)
     self.assertTrue(Nc_to_mmd.is_valid_uuid(value))
예제 #17
0
 def test__to_mmd__error_if_accd_id_is_invalid(self):
     """Test that metadata_identifier is set to an empty string, and
     that an exception is raised if the ACDD id is not a valid uuid.
     """
     tested = tempfile.mkstemp()[1]
     # The id attribute is not a uuid
     nc2mmd = Nc_to_mmd('tests/data/reference_nc_id_not_uuid.nc', output_file=tested)
     with self.assertRaises(AttributeError):
         nc2mmd.to_mmd()
     self.assertEqual(
         nc2mmd.missing_attributes['errors'][0], (
             'naming_authority is a required attribute.'
         )
     )
     self.assertEqual(
         nc2mmd.missing_attributes['errors'][1], (
             'id ACDD attribute is not valid.'
         )
     )
     self.assertEqual(nc2mmd.missing_attributes['warnings'], [])
     self.assertFalse(Nc_to_mmd.is_valid_uuid(nc2mmd.metadata['metadata_identifier']))
     ncin = Dataset(nc2mmd.netcdf_product)
     id = ncin.getncattr('id')
     self.assertNotEqual(id, nc2mmd.metadata['metadata_identifier'])
     self.assertEqual(':', nc2mmd.metadata['metadata_identifier'])
예제 #18
0
 def test_related_dataset(self):
     nc2mmd = Nc_to_mmd('tests/data/reference_nc_id_missing.nc')
     ncin = Dataset('tests/data/reference_nc_id_missing.nc')
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader)
     data = nc2mmd.get_related_dataset(mmd_yaml['related_dataset'], ncin)
     self.assertEqual(data[0]['id'], 'b7cb7934-77ca-4439-812e-f560df3fe7eb')
     self.assertEqual(data[0]['relation_type'], 'parent')
예제 #19
0
 def test_get_data_access_dict(self):
     nc2mmd = Nc_to_mmd('tests/data/reference_nc.nc')
     ncin = Dataset(nc2mmd.netcdf_product)
     nc2mmd.netcdf_product = 'https://thredds.met.no/thredds/dodsC/arcticdata/S2S_drift_TCD/SIDRIFT_S2S_SH/2019/07/31/' + nc2mmd.netcdf_product
     data = nc2mmd.get_data_access_dict(ncin)
     self.assertEqual(data[0]['type'], 'OPeNDAP')
     self.assertEqual(data[1]['type'], 'HTTP')
예제 #20
0
 def test_dataset_citation_missing_attrs(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader)
     nc2mmd = Nc_to_mmd('tests/data/reference_nc_missing_keywords_vocab.nc')
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_dataset_citations(mmd_yaml['dataset_citation'], ncin)
     self.assertEqual(value[0]['url'], '')
     self.assertEqual(value[0]['other'], '')
예제 #21
0
 def test_platforms(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader)
     nc2mmd = Nc_to_mmd('tests/data/reference_nc.nc')
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_platforms(mmd_yaml['platform'], ncin)
     self.assertEqual(value[0]['long_name'], 'SNPP')
     self.assertEqual(value[0]['instrument']['long_name'], 'VIIRS')
예제 #22
0
 def test_publication_date(self):
     format = '%Y-%m-%d'
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader)
     nc2mmd = Nc_to_mmd('tests/data/reference_nc.nc')
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_dataset_citations(mmd_yaml['dataset_citation'], ncin)
     dt = datetime.datetime.strptime(value[0]['publication_date'], format)
     self.assertEqual(dt, datetime.datetime(2020, 11, 27, 0, 0))
예제 #23
0
 def test_create_mmd_missing_update_times(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'), 
             Loader=yaml.FullLoader)
     md = Nc_to_mmd(self.fail_nc)
     ncin = Dataset(md.netcdf_product)
     value = md.get_metadata_updates(mmd_yaml['last_metadata_update'], ncin)
     self.assertEqual(md.missing_attributes['errors'][0],
             'ACDD attribute date_created or date_metadata_modified is required')
예제 #24
0
 def test_keywords_multiple(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader)
     nc2mmd = Nc_to_mmd('tests/data/reference_nc_attrs_multiple.nc')
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_keywords(mmd_yaml['keywords'], ncin)
     self.assertEqual(value[0]['vocabulary'], 'GCMD')
     self.assertEqual(value[0]['resource'], 'https://gcmdservices.gsfc.nasa.gov/static/kms/')
     self.assertEqual(value[0]['keyword'], 'Earth Science > Atmosphere > Atmospheric radiation')
예제 #25
0
 def test_create_mmd_missing_abstract(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'), 
             Loader=yaml.FullLoader)
     md = Nc_to_mmd(self.fail_nc)
     ncin = Dataset(md.netcdf_product)
     value = md.get_abstracts(mmd_yaml['abstract'], ncin)
     self.assertEqual(md.missing_attributes['errors'][0],
             'summary is a required ACDD attribute')
예제 #26
0
 def test_iso_topic_category(self):
     mmd_yaml = yaml.load(resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader)
     nc2mmd = Nc_to_mmd('tests/data/reference_nc.nc')
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_acdd_metadata(mmd_yaml['iso_topic_category'], ncin, 'iso_topic_category')
     self.assertEqual(value[0], 'climatologyMeteorologyAtmosphere')
     self.assertEqual(value[1], 'environment')
     self.assertEqual(value[2], 'oceans')
예제 #27
0
 def test_missing_temporal_extent_but_start_provided_as_kwarg(self):
     """ToDo: Add docstring"""
     yaml.load(
         resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader
     )
     nc2mmd = Nc_to_mmd('tests/data/reference_nc_missing_attrs.nc', check_only=True)
     with self.assertRaises(AttributeError):
         nc2mmd.to_mmd(time_coverage_start='1850-01-01T00:00:00Z')
     self.assertEqual(nc2mmd.metadata['temporal_extent']['start_date'], '1850-01-01T00:00:00Z')
예제 #28
0
 def test_projects(self):
     """Test getting project information from nc-file"""
     mmd_yaml = yaml.load(
         resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader
     )
     nc2mmd = Nc_to_mmd('tests/data/reference_nc.nc', check_only=True)
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_projects(mmd_yaml['project'], ncin)
     self.assertEqual(value[0]['long_name'], 'MET Norway core services')
예제 #29
0
 def test_personnel(self):
     """Test reading of personnel from nc file into MMD"""
     mmd_yaml = yaml.load(
         resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader
     )
     nc2mmd = Nc_to_mmd('tests/data/reference_nc.nc', check_only=True)
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_personnel(mmd_yaml['personnel'], ncin)
     self.assertEqual(value[0]['email'], '*****@*****.**')
예제 #30
0
 def test_missing_vocabulary_platform_instrument_short_name(self):
     """ToDo: Add docstring"""
     mmd_yaml = yaml.load(
         resource_string('py_mmd_tools', 'mmd_elements.yaml'), Loader=yaml.FullLoader
     )
     nc2mmd = Nc_to_mmd('tests/data/reference_nc_missing_keywords_vocab.nc', check_only=True)
     ncin = Dataset(nc2mmd.netcdf_product)
     value = nc2mmd.get_platforms(mmd_yaml['platform'], ncin)
     self.assertEqual(value[0]['instrument']['short_name'], '')