Skip to content

Commit

Permalink
Merge pull request #23 from davemfish/feature/17-url-citation
Browse files Browse the repository at this point in the history
Add url, citation, doi metadata properties
  • Loading branch information
phargogh authored Mar 20, 2024
2 parents 66ffccd + cd2735d commit ce1801e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ for path, dirs, files in os.walk(data_dir):
mc.validate()
mc.write()
```

#### For a complete list of methods:
https://geometamaker.readthedocs.io/en/latest/api/geometamaker.html
45 changes: 45 additions & 0 deletions src/geometamaker/geometamaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def ignore_aliases(self, data):
# users to use.
MCF_SCHEMA['required'].append('content_info')
MCF_SCHEMA['required'].append('dataquality')
MCF_SCHEMA['properties']['identification']['properties'][
'citation'] = {
'type': 'string',
'description': 'a biobliographic citation for the dataset'
}
MCF_SCHEMA['properties']['identification']['required'].append('citation')
MCF_SCHEMA['properties']['identification']['properties'][
'keywords']['patternProperties']['^.*'][
'required'] = ['keywords', 'keywords_type']
Expand Down Expand Up @@ -266,6 +272,19 @@ def get_abstract(self):
"""Get the abstract for the dataset."""
return self.mcf['identification']['abstract']

def set_citation(self, citation):
"""Add a citation string for the dataset.
Args:
citation (str)
"""
self.mcf['identification']['citation'] = citation

def get_citation(self):
"""Get the citation for the dataset."""
return self.mcf['identification']['citation']

def set_contact(self, organization=None, individualname=None, positionname=None,
email=None, section='default', **kwargs):
"""Add a contact section.
Expand Down Expand Up @@ -308,6 +327,19 @@ def get_contact(self, section='default'):
"""
return self.mcf['contact'].get(section)

def set_doi(self, doi):
"""Add a doi string for the dataset.
Args:
doi (str)
"""
self.mcf['identification']['doi'] = doi

def get_doi(self):
"""Get the doi for the dataset."""
return self.mcf['identification']['doi']

def set_edition(self, edition):
"""Set the edition for the dataset.
Expand Down Expand Up @@ -437,6 +469,19 @@ def get_purpose(self):
"""
return self.mcf['identification'].get('purpose')

def set_url(self, url):
"""Add a url for the dataset.
Args:
url (str)
"""
self.mcf['identification']['url'] = url

def get_url(self):
"""Get the url for the dataset."""
return self.mcf['identification']['url']

def set_band_description(self, band_number, name=None, title=None,
abstract=None, units=None, type=None):
"""Define metadata for a raster band.
Expand Down
1 change: 1 addition & 0 deletions tests/data/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ distribution:
identification:
abstract: ''
accessconstraints: ''
citation: ''
dates:
creation: ''
publication: ''
Expand Down
30 changes: 30 additions & 0 deletions tests/test_geometamaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,16 @@ def test_set_abstract(self):
mc.set_abstract(abstract)
self.assertEqual(mc.get_abstract(), abstract)

def test_set_citation(self):
"""MetadataControl: set and get a citation."""

from geometamaker import MetadataControl

citation = 'foo bar'
mc = MetadataControl()
mc.set_citation(citation)
self.assertEqual(mc.get_citation(), citation)

def test_set_contact(self):
"""MetadataControl: set and get a contact section."""

Expand Down Expand Up @@ -396,6 +406,16 @@ def test_set_contact_validates(self):
with self.assertRaises(ValidationError):
mc.set_contact(postalcode=postalcode)

def test_set_doi(self):
"""MetadataControl: set and get a doi."""

from geometamaker import MetadataControl

doi = '10.foo/bar'
mc = MetadataControl()
mc.set_doi(doi)
self.assertEqual(mc.get_doi(), doi)

def test_set_get_edition(self):
"""MetadataControl: set and get dataset edition."""

Expand Down Expand Up @@ -554,6 +574,16 @@ def test_set_and_get_purpose(self):
mc.set_purpose(purpose)
self.assertEqual(mc.get_purpose(), purpose)

def test_set_url(self):
"""MetadataControl: set and get a url."""

from geometamaker import MetadataControl

url = 'http://foo/bar'
mc = MetadataControl()
mc.set_url(url)
self.assertEqual(mc.get_url(), url)

def test_preexisting_mc_raster(self):
"""MetadataControl: test reading and ammending an existing MCF raster."""
from geometamaker import MetadataControl
Expand Down

0 comments on commit ce1801e

Please sign in to comment.