Skip to content

Instantly share code, notes, and snippets.

@ColinTalbert
Last active July 19, 2017 16:17
Show Gist options
  • Save ColinTalbert/64dcb40c8596ac4363a60b30e1e80fcb to your computer and use it in GitHub Desktop.
Save ColinTalbert/64dcb40c8596ac4363a60b30e1e80fcb to your computer and use it in GitHub Desktop.
habanero example
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from habanero import cn"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"pub_doi = '10.1642/AUK-16-195.1' #insert DOI here!"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Cade, B. S., Noon, B. R., Scherer, R. D., & Keane, J. J. (2017). Logistic quantile regression provides improved estimates for bounded avian counts: A case study of California Spotted Owl fledgling production. The Auk, 134(4), 783–801. doi:10.1642/auk-16-195.1\n",
"\n"
]
}
],
"source": [
"#verify=False is only needed if your USGS ssl cert is missing\n",
"citation = cn.content_negotiation(ids = pub_doi, format = \"text\", style=\"apa\", verify=False) \n",
"print(bytearray(citation, 'Latin-1').decode()) #this awkwardness is need to display the em-dash correctly"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Cade, B.S., Noon, B.R., Scherer, R.D., and Keane, J.J., 2017, Logistic quantile regression provides improved estimates for bounded avian counts: A case study of California Spotted Owl fledgling production: The Auk, v. 134, no. 4, p. 783–801.\n",
"\n"
]
}
],
"source": [
"#verify=False is only needed if your USGS ssl cert is missing\n",
"citation = cn.content_negotiation(ids = pub_doi, format = \"text\", style=\"us-geological-survey\", verify=False)\n",
"citation = bytearray(citation, 'Latin-1').decode()\n",
"print(citation) #this awkwardness is need to display the em-dash correctly"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pysb\n",
"import getpass"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"········\n"
]
}
],
"source": [
"username = \"talbertc@usgs.gov\"\n",
"password = getpass.getpass()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<pysb.SbSession.SbSession at 0x5a8e320>"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sb = pysb.SbSession()\n",
"sb.login(username, password)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'body': 'This is a comma separated values (csv) file used to conduct the logistic quantile regression analyses in R provided by Cade et al. (2017.&nbsp;&nbsp;Logistic quantile regression provides improved estimates for bounded avian counts: A case study of California spotted owl fledgling production. The Auk: Ornithological Advances.&nbsp;&nbsp;In press).&nbsp;&nbsp;The data set consists of records of California spotted owl fledgling counts on 88 territories on the Lassen National Forest, CA from 1991-2010.&nbsp;&nbsp;Climatic conditions for various time periods by year for each territory were obtained from PRISM and landscape habitat conditions surrounding owl territories were obtained from LANDFIRE.&nbsp;&nbsp;The owl data were provided by J. J. Keane of the U.S. Forest Service, the climate and habitat data were compiled and meshed with the owl data by B. R. Noon and R. D. Scherer of Colorado State University, and the final data set used for analyses were compiled by B. S. Cade of the U. S. Geological Survey.',\n",
" 'browseCategories': ['Data'],\n",
" 'citation': 'Cade B.S., 2017, California spotted owl fledgling counts, climate, and landscape habitat at territories on the Lassen National Forest, CA 1991-2010: U.S. Geological Survey data release, https://doi.org/10.5066/F7DR2SZR.',\n",
" 'contacts': [{'active': True,\n",
" 'contactType': 'person',\n",
" 'email': 'cadeb@usgs.gov',\n",
" 'firstName': 'Brian',\n",
" 'jobTitle': 'Research Statistician (Biology)',\n",
" 'lastName': 'Cade',\n",
" 'middleName': 'S',\n",
" 'name': 'Brian S Cade',\n",
" 'oldPartyId': 1467,\n",
" 'organization': {'displayText': 'Fort Collins Science Center'},\n",
" 'primaryLocation': {'building': 'NRRC Bldg C',\n",
" 'buildingCode': 'KBA',\n",
" 'faxPhone': '9702269230',\n",
" 'mailAddress': {'city': 'Fort Collins',\n",
" 'country': 'USA',\n",
" 'line1': '2150 Centre Avenue, Building C',\n",
" 'state': 'CO',\n",
" 'zip': '80526-8118'},\n",
" 'name': 'Brian S Cade/BRD/USGS/DOI - Primary Location',\n",
" 'officePhone': '9702269326',\n",
" 'streetAddress': {'city': 'Fort Collins',\n",
" 'line1': '2150 Centre Avenue Bldg C',\n",
" 'state': 'CO',\n",
" 'zip': '80526'}},\n",
" 'type': 'Point of Contact'},\n",
" {'active': True,\n",
" 'contactType': 'person',\n",
" 'email': 'cadeb@usgs.gov',\n",
" 'firstName': 'Brian',\n",
" 'jobTitle': 'Research Statistician (Biology)',\n",
" 'lastName': 'Cade',\n",
" 'middleName': 'S',\n",
" 'name': 'Brian S Cade',\n",
" 'oldPartyId': 1467,\n",
" 'organization': {'displayText': 'Fort Collins Science Center'},\n",
" 'primaryLocation': {'building': 'NRRC Bldg C',\n",
" 'buildingCode': 'KBA',\n",
" 'faxPhone': '9702269230',\n",
" 'mailAddress': {'city': 'Fort Collins',\n",
" 'country': 'USA',\n",
" 'line1': '2150 Centre Avenue, Building C',\n",
" 'state': 'CO',\n",
" 'zip': '80526-8118'},\n",
" 'name': 'Brian S Cade/BRD/USGS/DOI - Primary Location',\n",
" 'officePhone': '9702269326',\n",
" 'streetAddress': {'city': 'Fort Collins',\n",
" 'line1': '2150 Centre Avenue Bldg C',\n",
" 'state': 'CO',\n",
" 'zip': '80526'}},\n",
" 'type': 'Process Contact'},\n",
" {'active': True,\n",
" 'contactType': 'person',\n",
" 'email': 'cadeb@usgs.gov',\n",
" 'firstName': 'Brian',\n",
" 'jobTitle': 'Research Statistician (Biology)',\n",
" 'lastName': 'Cade',\n",
" 'middleName': 'S',\n",
" 'name': 'Brian S Cade',\n",
" 'oldPartyId': 1467,\n",
" 'organization': {'displayText': 'Fort Collins Science Center'},\n",
" 'primaryLocation': {'building': 'NRRC Bldg C',\n",
" 'buildingCode': 'KBA',\n",
" 'faxPhone': '9702269230',\n",
" 'mailAddress': {'city': 'Fort Collins',\n",
" 'country': 'USA',\n",
" 'line1': '2150 Centre Avenue, Building C',\n",
" 'state': 'CO',\n",
" 'zip': '80526-8118'},\n",
" 'name': 'Brian S Cade/BRD/USGS/DOI - Primary Location',\n",
" 'officePhone': '9702269326',\n",
" 'streetAddress': {'city': 'Fort Collins',\n",
" 'line1': '2150 Centre Avenue Bldg C',\n",
" 'state': 'CO',\n",
" 'zip': '80526'}},\n",
" 'type': 'Originator'},\n",
" {'active': True,\n",
" 'contactType': 'person',\n",
" 'email': 'cadeb@usgs.gov',\n",
" 'firstName': 'Brian',\n",
" 'jobTitle': 'Research Statistician (Biology)',\n",
" 'lastName': 'Cade',\n",
" 'middleName': 'S',\n",
" 'name': 'Brian S Cade',\n",
" 'oldPartyId': 1467,\n",
" 'organization': {'displayText': 'Fort Collins Science Center'},\n",
" 'primaryLocation': {'building': 'NRRC Bldg C',\n",
" 'buildingCode': 'KBA',\n",
" 'faxPhone': '9702269230',\n",
" 'mailAddress': {'city': 'Fort Collins',\n",
" 'country': 'USA',\n",
" 'line1': '2150 Centre Avenue, Building C',\n",
" 'state': 'CO',\n",
" 'zip': '80526-8118'},\n",
" 'name': 'Brian S Cade/BRD/USGS/DOI - Primary Location',\n",
" 'officePhone': '9702269326',\n",
" 'streetAddress': {'city': 'Fort Collins',\n",
" 'line1': '2150 Centre Avenue Bldg C',\n",
" 'state': 'CO',\n",
" 'zip': '80526'}},\n",
" 'type': 'Metadata Contact'},\n",
" {'contactType': 'organization',\n",
" 'email': 'sciencebase@usgs.gov',\n",
" 'name': 'U.S. Geological Survey - ScienceBase',\n",
" 'oldPartyId': 70157,\n",
" 'onlineResource': 'https://www.sciencebase.gov',\n",
" 'organization': {},\n",
" 'primaryLocation': {'mailAddress': {'city': 'Denver',\n",
" 'country': 'United States',\n",
" 'line1': 'Denver Federal Center',\n",
" 'line2': 'Building 810',\n",
" 'mailStopCode': '302',\n",
" 'state': 'CO',\n",
" 'zip': '80225'},\n",
" 'name': 'U.S. Geological Survey - ScienceBase - Location',\n",
" 'officePhone': '18882758747',\n",
" 'streetAddress': {}},\n",
" 'type': 'Distributor'},\n",
" {'contactType': 'organization',\n",
" 'name': 'Ecosystems',\n",
" 'organization': {'directoryId': '17044', 'displayText': 'Ecosystems'},\n",
" 'primaryLocation': {'mailAddress': {}, 'streetAddress': {}},\n",
" 'type': 'USGS Mission Area'},\n",
" {'active': True,\n",
" 'aliases': ['FT COLLINS SCI CTR', 'FORT', 'FORT COLLINS SCIENCE CENTER'],\n",
" 'contactType': 'organization',\n",
" 'name': 'Fort Collins Science Center',\n",
" 'oldPartyId': 17368,\n",
" 'onlineResource': 'http://www.fort.usgs.gov/',\n",
" 'organization': {},\n",
" 'primaryLocation': {'building': 'NRRC BLDG C',\n",
" 'buildingCode': 'KBA',\n",
" 'latitude': 40.55771,\n",
" 'longitude': -105.087357,\n",
" 'mailAddress': {'city': 'Fort Collins',\n",
" 'country': 'USA',\n",
" 'line1': '2150 Centre Avenue',\n",
" 'line2': 'Building C',\n",
" 'state': 'CO',\n",
" 'zip': '80526-8118'},\n",
" 'name': 'Fort Collins Science Center - NRRC BLDG C [KBA]',\n",
" 'streetAddress': {'city': 'Fort Collins',\n",
" 'country': 'USA',\n",
" 'line1': '2150C Centre Avenue',\n",
" 'state': 'CO',\n",
" 'zip': '80526-8118'}},\n",
" 'type': 'SDC Data Owner'}],\n",
" 'dates': [{'dateString': '2017-06-13',\n",
" 'label': 'Publication Date',\n",
" 'type': 'Publication'},\n",
" {'dateString': '1991', 'label': '', 'type': 'Start'},\n",
" {'dateString': '2010', 'label': '', 'type': 'End'}],\n",
" 'distributionLinks': [{'files': '',\n",
" 'name': 'Californiaspott.zip',\n",
" 'rel': 'alternate',\n",
" 'title': 'Download Attached Files',\n",
" 'type': 'downloadLink',\n",
" 'typeLabel': 'Download Link',\n",
" 'uri': 'https://www.sciencebase.gov/catalog/file/get/596e28dae4b0d1f9f062c358'}],\n",
" 'hasChildren': False,\n",
" 'id': '596e28dae4b0d1f9f062c358',\n",
" 'link': {'rel': 'self',\n",
" 'url': 'https://www.sciencebase.gov/catalog/item/596e28dae4b0d1f9f062c358'},\n",
" 'locked': False,\n",
" 'parentId': '4ff5c8f9e4b03b1a74b5782d',\n",
" 'permissions': {'read': {'acl': [],\n",
" 'inherited': True,\n",
" 'inheritsFromId': '4ff5c8f9e4b03b1a74b5782d'},\n",
" 'write': {'acl': ['USER:talbertc@usgs.gov'],\n",
" 'inherited': True,\n",
" 'inheritsFromId': '4ff5c8f9e4b03b1a74b5782d'}},\n",
" 'previewImage': {'from': 'mapPreview',\n",
" 'original': {'height': 240,\n",
" 'size': 195869,\n",
" 'uri': 'https://www.sciencebase.gov/catalog/file/get/596e28dae4b0d1f9f062c358?f=__disk__ba%2Fdf%2F25%2Fbadf253ff6a6fae3b8c4aded21dc460b0277b735',\n",
" 'viewUri': 'https://www.sciencebase.gov/catalog/file/get/596e28dae4b0d1f9f062c358?f=__disk__ba%2Fdf%2F25%2Fbadf253ff6a6fae3b8c4aded21dc460b0277b735&width=360&height=240',\n",
" 'viewUrl': 'https://www.sciencebase.gov/catalog/file/get/596e28dae4b0d1f9f062c358?f=__disk__ba%2Fdf%2F25%2Fbadf253ff6a6fae3b8c4aded21dc460b0277b735&width=360&height=240',\n",
" 'width': 360},\n",
" 'thumbnail': {'height': 100,\n",
" 'uri': 'https://www.sciencebase.gov/catalog/file/get/596e28dae4b0d1f9f062c358?f=__disk__ba%2Fdf%2F25%2Fbadf253ff6a6fae3b8c4aded21dc460b0277b735&width=150&height=100',\n",
" 'width': 150}},\n",
" 'provenance': {'annotation': 'Created from Item #5910958ce4b0e541a03a85c1',\n",
" 'createdBy': 'talbertc@usgs.gov',\n",
" 'dateCreated': '2017-07-18T15:27:22Z',\n",
" 'lastUpdated': '2017-07-19T16:16:18Z',\n",
" 'lastUpdatedBy': 'talbertc@usgs.gov'},\n",
" 'purpose': 'testing weblinks3',\n",
" 'relatedItems': {'link': {'rel': 'related',\n",
" 'url': 'https://www.sciencebase.gov/catalog/itemLinks?itemId=596e28dae4b0d1f9f062c358'}},\n",
" 'spatial': {'boundingBox': {'maxX': -120.5,\n",
" 'maxY': 40.83,\n",
" 'minX': -121.66,\n",
" 'minY': 40.0}},\n",
" 'summary': 'This is a comma separated values (csv) file used to conduct the logistic quantile regression analyses in R provided by Cade et al. (2017. Logistic quantile regression provides improved estimates for bounded avian counts: A case study of California spotted owl fledgling production. The Auk: Ornithological Advances. In press). The data set consists of records of California spotted owl fledgling counts on 88 territories on the Lassen National Forest, CA from 1991-2010. Climatic conditions for various time periods by year for each territory were obtained from PRISM and landscape habitat conditions surrounding owl territories were obtained from LANDFIRE. The owl data were provided by J. J. Keane of the U.S. Forest Service, the climate [...]',\n",
" 'tags': [{'name': 'biota',\n",
" 'scheme': 'ISO 19115 Topic Category',\n",
" 'type': 'Theme'},\n",
" {'name': 'bounded counts', 'scheme': 'None', 'type': 'Theme'},\n",
" {'name': 'logistic quantile regression', 'scheme': 'None', 'type': 'Theme'},\n",
" {'name': 'spotted owls', 'scheme': 'None', 'type': 'Theme'},\n",
" {'name': 'regression analysis', 'scheme': 'USGS Thesaurus', 'type': 'Theme'},\n",
" {'name': 'Lassen', 'scheme': 'Common geographic areas', 'type': 'Place'},\n",
" {'name': 'California', 'scheme': 'Common geographic areas', 'type': 'Place'},\n",
" {'name': 'USGS Science Data Catalog (SDC)', 'type': 'Harvest Set'}],\n",
" 'title': 'California spotted owl fledgling counts, climate, and landscape habitat at territories on the Lassen National Forest, CA 1991-2010 (COPY)',\n",
" 'webLinks': [{'hidden': False,\n",
" 'title': 'Cade, B.S., Noon, B.R., Scherer, R.D., and Keane, J.J., 2017, Logistic quantile regression provides improved estimates for bounded avian counts: A case study of California Spotted Owl fledgling production: The Auk, v. 134, no. 4, p. 783–801.\\n',\n",
" 'type': 'publicationReferenceSource',\n",
" 'typeLabel': 'Publication that references this resource',\n",
" 'uri': 'https://doi.org/10.1642/AUK-16-195.1'}]}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sb_datarelease = '596e28dae4b0d1f9f062c358'\n",
"\n",
"item_json = sb.get_item(sb_datarelease)\n",
"item_json['webLinks'] = [{'hidden': False,\n",
" 'title': citation,\n",
" 'type': 'publicationReferenceSource',\n",
" 'typeLabel': 'Publication that references this resource',\n",
" 'uri': 'https://doi.org/{}'.format(pub_doi)}]\n",
"sb.update_item(item_json)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment