Skip to content

Commit

Permalink
Doi (#657)
Browse files Browse the repository at this point in the history
* ENH: AirNow API must have updating some algorithms.  What it's displaying now is what I would have assumed would be the closed reported station.

* ENH: Adding feature for users to be able to get the citation for a datastream.  Also adds text after data are done downloading from ARM to please reference the citation of the datastream

* ENH: Changing doi.org to just doi
  • Loading branch information
AdamTheisen authored Apr 12, 2023
1 parent aa4e908 commit 1ca86cd
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion act/discovery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
__name__,
submodules=['get_armfiles', 'get_cropscape', 'get_airnow', 'get_noaa_psl', 'get_neon'],
submod_attrs={
'get_armfiles': ['download_data'],
'get_armfiles': ['download_data', 'get_arm_doi'],
'get_asos': ['get_asos'],
'get_airnow': ['get_airnow_bounded_obs', 'get_airnow_obs', 'get_airnow_forecast'],
'get_cropscape': ['croptype'],
Expand Down
56 changes: 56 additions & 0 deletions act/discovery/get_armfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import os
import sys
from datetime import timedelta
import requests
import textwrap

try:
from urllib.request import urlopen
Expand Down Expand Up @@ -166,4 +168,58 @@ def download_data(username, token, datastream, startdate, enddate, time=None, ou
'No files returned or url status error.\n' 'Check datastream name, start, and end date.'
)

# Get ARM DOI and print it out
doi = get_arm_doi(datastream, start_datetime.strftime('%Y-%m-%d'), end_datetime.strftime('%Y-%m-%d'))
print('\nIf you use these data to prepare a publication, please cite:\n')
print(textwrap.fill(doi, width=80))
print('')

return file_names


def get_arm_doi(datastream, startdate, enddate):
"""
This function will return a citation with DOI, if available, for specified
datastream and date range
Parameters
----------
datastream : str
The name of the datastream to get a DOI for. This must be ARM standard names
startdate : str
Start date for the citation in the format YY-MM-DD
enddate : str
End date for the citation in the format YY-MM-DD
Returns
-------
doi : str
Returns the citation as a string
"""

site = datastream[0:3]
level = datastream.split('.')[-1]

# Get the instrument class code from the datastream name
metadata_url = 'https://adc.arm.gov/solr8/metadata/select?q=datastream%3A' + datastream
r = requests.get(url=metadata_url)
response = r.json()['response']
if len(response['docs']) == 0:
raise ValueError('Check parameters')
response = response['docs'][0]
inst_class = response['instrument_class_code']

# Get the DOI information
doi_url = 'https://adc.arm.gov/citationservice/citation/inst-class?id=' + inst_class + '&citationType=apa'
doi_url += '&site=' + site
doi_url += '&dataLevel=' + level
doi_url += '&startDate=' + startdate
doi_url += '&endDate=' + enddate
doi = requests.get(url=doi_url)
if len(doi.text) > 0:
doi = doi.json()['citation']
else:
doi = 'N/A'

return doi
15 changes: 15 additions & 0 deletions act/tests/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,18 @@ def test_neon():
assert len(result) == 40
assert any('readme' in r for r in result)
assert any('sensor_position' in r for r in result)


def test_arm_doi():
datastream = 'sgpmetE13.b1'
startdate = '2022-01-01'
enddate = '2022-12-31'
doi = act.discovery.get_arm_doi(datastream, startdate, enddate)

assert len(doi) > 10
assert isinstance(doi, str)
assert 'doi' in doi
assert 'Kyrouac' in doi

with np.testing.assert_raises(ValueError):
doi = act.discovery.get_arm_doi('test', startdate, enddate)

0 comments on commit 1ca86cd

Please sign in to comment.