Commit 5b942980 authored by abuddenberg's avatar abuddenberg
Browse files

Added support for syncing Parents

parent 848d62da
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
__author__ = 'abuddenberg' __author__ = 'abuddenberg'
from gcis_clients import WebformClient, GcisClient, gcis_dev_auth, gcis_stage_auth, webform_token from gcis_clients import WebformClient, GcisClient, gcis_dev_auth, gcis_stage_auth, webform_token
from gcis_clients.sync_utils import move_images_to_gcis, sync_dataset_metadata, realize_contributors from gcis_clients.sync_utils import move_images_to_gcis, sync_dataset_metadata, realize_contributors, realize_parents
from collections import OrderedDict from collections import OrderedDict
webform = WebformClient('http://resources.assessment.globalchange.gov', webform_token) webform = WebformClient('http://resources.assessment.globalchange.gov', webform_token)
...@@ -14,102 +14,104 @@ sync_metadata_tree = { ...@@ -14,102 +14,104 @@ sync_metadata_tree = {
#Reports #Reports
'nca3': OrderedDict([ 'nca3': OrderedDict([
#Chapter 2 #Chapter 2
# ('our-changing-climate', [ ('our-changing-climate', [
# # (webform_url, gcis_id) # (webform_url, gcis_id)
# ('/metadata/figures/3074', 'ten-indicators-of-a-warming-world'), # 2.1 ('/metadata/figures/3074', 'ten-indicators-of-a-warming-world'), # 2.1
# ('/metadata/figures/3293', 'observed-increase-in-frostfree-season-length'), # 2.10 ('/metadata/figures/3293', 'observed-increase-in-frostfree-season-length'), # 2.10
# ('/metadata/figures/3294', 'projected-changes-in-frostfree-season-length'), # 2.11 ('/metadata/figures/3294', 'projected-changes-in-frostfree-season-length'), # 2.11
# ('/metadata/figures/2677', 'observed-us-precipitation-change'), # 2.12 ('/metadata/figures/2677', 'observed-us-precipitation-change'), # 2.12
# ('/metadata/figures/3298', 'observed-us-trend-in-heavy-precipitation'), # 2.16 ('/metadata/figures/3298', 'observed-us-trend-in-heavy-precipitation'), # 2.16
# ('/metadata/figures/2506', 'observed-change-in-very-heavy-precipitation'), # 2.17 ('/metadata/figures/2506', 'observed-change-in-very-heavy-precipitation'), # 2.17
# ('/metadata/figures/2997', 'observed-change-in-very-heavy-precipitation-2'), # 2.18 ('/metadata/figures/2997', 'observed-change-in-very-heavy-precipitation-2'), # 2.18
# ('/metadata/figures/3170', 'global-temperature-and-carbon-dioxide'), # 2.2 ('/metadata/figures/3170', 'global-temperature-and-carbon-dioxide'), # 2.2
# ('/metadata/figures/2939', 'projected-changes-in-soil-moisture-for-the-western-us'), # 2.22 ('/metadata/figures/2939', 'projected-changes-in-soil-moisture-for-the-western-us'), # 2.22
# ('/metadata/figures/3305', 'variation-of-storm-frequency-and-intensity-during-the-cold-season-november--march'), # 2.24 ('/metadata/figures/3305', 'variation-of-storm-frequency-and-intensity-during-the-cold-season-november--march'), # 2.24
# ('/metadata/figures/3067', 'ice-cover-in-the-great-lakes'), # 2.27 ('/metadata/figures/3067', 'ice-cover-in-the-great-lakes'), # 2.27
# ('/metadata/figures/3073', 'projected-arctic-sea-ice-decline'), # 2.29 ('/metadata/figures/3073', 'projected-arctic-sea-ice-decline'), # 2.29
# ('/metadata/figures/2940', 'as-oceans-absorb-co-they-become-more-acidic'), # 2.30 ('/metadata/figures/2940', 'as-oceans-absorb-co-they-become-more-acidic'), # 2.30
# ('/metadata/figures/2523', 'shells-dissolve-in-acidified-ocean-water'), # 2.31 ('/metadata/figures/2523', 'shells-dissolve-in-acidified-ocean-water'), # 2.31
# ('/metadata/figures/3175', 'observed-us-temperature-change'), # 2.7 ('/metadata/figures/3175', 'observed-us-temperature-change'), # 2.7
# ('/metadata/figures/3000', 'projected-temperature-change-by-20712099-cmip5-models'), #2.9
# ]),
# #Chapter 3 ]),
# ('water-resources', [ #Chapter 3
# ('/metadata/figures/2676', 'projected-changes-in-snow-runoff-and-soil-moisture'), # 3.1 ('water-resources', [
# ('/metadata/figures/3303', 'trends-in-flood-magnitude'), # 3.5 ('/metadata/figures/2676', 'projected-changes-in-snow-runoff-and-soil-moisture'), # 3.1
# ]), ('/metadata/figures/3303', 'trends-in-flood-magnitude'), # 3.5
# #Chapter 4 ]),
# ('energy-supply-and-use', [ #Chapter 4
# ('/metadata/figures/3082', 'paths-of-hurricanes-katrina-and-rita-relative-to-oil-and-gas-production-facilities'), # 4.1 ('energy-supply-and-use', [
# ('/metadata/figures/3292', 'cooling-degree-days'), # 4.3 ('/metadata/figures/3082', 'paths-of-hurricanes-katrina-and-rita-relative-to-oil-and-gas-production-facilities'), # 4.1
# ]), ('/metadata/figures/3292', 'cooling-degree-days'), # 4.3
# #Chapter 5 ]),
# ('transportation', [ #Chapter 5
# ('/metadata/figures/3088', 'possible-future-flood-depths-in-mobile-al-with-rising-sea-level'), # 5.1 ('transportation', [
# ('/metadata/figures/2905', 'gulf-coast-transportation-hubs-at-risk'), # 5.3 # ('/metadata/figures/3088', 'possible-future-flood-depths-in-mobile-al-with-rising-sea-level'), # 5.1
# ('/metadata/figures/3568', 'hurricane-sandy-causes-flooding-in-new-york-city-subway-stations'), # 5.4 # ('/metadata/figures/2905', 'gulf-coast-transportation-hubs-at-risk'), # 5.3
# ('/metadata/figures/2952', 'role-of-adaptive-strategies-and-tactics-in-reducing-impacts-and-consequences'), # 5.5 ('/metadata/figures/3568', 'hurricane-sandy-causes-flooding-in-new-york-city-subway-stations'), # 5.4
# ('/metadata/figures/3169', 'tropical-storm-impact-on-vermont-road'), # 5.6 ('/metadata/figures/2952', 'role-of-adaptive-strategies-and-tactics-in-reducing-impacts-and-consequences'), # 5.5
# ]), ('/metadata/figures/3169', 'tropical-storm-impact-on-vermont-road'), # 5.6
# #Chapter 6 ]),
# ('agriculture', [ #Chapter 6
# ('/metadata/figures/2691', 'projected-changes-in-key-climate-variables-affecting-agricultural-productivity'), # 6.5 ('agriculture', [
# ('/metadata/figures/2872', 'drainage-tiles'), # 6.8 ('/metadata/figures/3582', 'crop-yield-response-to-warming-in-californias-central-valley'), #6.4
# ]), ('/metadata/figures/2691', 'projected-changes-in-key-climate-variables-affecting-agricultural-productivity'), # 6.5
# #Chapter 7 ('/metadata/figures/2872', 'drainage-tiles'), # 6.8
# ('forests', [ ]),
# ('/metadata/figures/2887', 'forest-ecosystem-disturbances'), # 7.1 #Chapter 7
# ('/metadata/figures/2977', 'effectiveness-of-forest-management-in-reducing-wildfire-risk'), # 7.2 ('forests', [
# ('/metadata/figures/2978', 'forest-vulnerability-to-changing-climate'), # 7.3 ('/metadata/figures/2887', 'forest-ecosystem-disturbances'), # 7.1
# ('/metadata/figures/2985', 'forests-can-be-a-source--or-a-sink--for-carbon'), # 7.4 ('/metadata/figures/2977', 'effectiveness-of-forest-management-in-reducing-wildfire-risk'), # 7.2
# ('/metadata/figures/3130', 'public-and-private-forestlands'), # 7.8 ('/metadata/figures/2978', 'forest-vulnerability-to-changing-climate'), # 7.3
# ('/metadata/figures/2985', 'forests-can-be-a-source--or-a-sink--for-carbon'), # 7.4
# ]), ('/metadata/figures/3130', 'public-and-private-forestlands'), # 7.8
# #Chapter 8
# ('ecosystems', [ ]),
# ('/metadata/figures/2456', 'adaptation-planning-and-implementation-framework'), # 8.3 #Chapter 8
# ('/metadata/figures/3574', 'biological-responses-to-climate-change'), # 8.4 ('ecosystems', [
# ]), ('/metadata/figures/2456', 'adaptation-planning-and-implementation-framework'), # 8.3
# #Chapter 9 ('/metadata/figures/3574', 'biological-responses-to-climate-change'), # 8.4
# ('human-health', [ ]),
# ('/metadata/figures/3162', 'projected-climate-change-worsens-asthma'), # 9.1 #Chapter 9
# ('/metadata/figures/2896', 'heavy-downpours-disease'), # 9.7 ('human-health', [
# ('/metadata/figures/2897', 'harmful-bloom-of-algae'), # 9.8 ('/metadata/figures/3162', 'projected-climate-change-worsens-asthma'), # 9.1
# ]), ('/metadata/figures/2896', 'heavy-downpours-disease'), # 9.7
# #Chapter 10 ('/metadata/figures/2897', 'harmful-bloom-of-algae'), # 9.8
# ('water-energy-land-use', [ ]),
# ('/metadata/figures/2601', 'energy-water-land-and-climate-interactions'), # 10.1 #Chapter 10
# ('/metadata/figures/2917', 'the-columbia-river-basin-land-use-and-land-cover'), # 10.10 ('water-energy-land-use', [
# ('/metadata/figures/2410', 'coasttocoast-100degree-days-in-2011'), # 10.2 ('/metadata/figures/2601', 'energy-water-land-and-climate-interactions'), # 10.1
# ('/metadata/figures/3158', 'projected-landuse-intensity-in-2030'), # 10.6 ('/metadata/figures/2917', 'the-columbia-river-basin-land-use-and-land-cover'), # 10.10
# ('/metadata/figures/2986', 'hydraulic-fracturing-and-water-use'), # 10.7 ('/metadata/figures/2410', 'coasttocoast-100degree-days-in-2011'), # 10.2
# ('/metadata/figures/2916', 'renewable-energy-and-land-use'), # 10.8 ('/metadata/figures/3158', 'projected-landuse-intensity-in-2030'), # 10.6
# ('/metadata/figures/2918', 'water-stress-in-the-us'), # 10.9 ('/metadata/figures/2986', 'hydraulic-fracturing-and-water-use'), # 10.7
# ('/metadata/figures/2916', 'renewable-energy-and-land-use'), # 10.8
# ]), ('/metadata/figures/2918', 'water-stress-in-the-us'), # 10.9
# #Chapter 11
# ('urban-systems-infrastructure-vulnerability', [ ]),
# ('/metadata/figures/3569', 'urban-support-systems-are-interconnected'), # 11.2 #Chapter 11
# ('/metadata/figures/3090', 'new-york-city-and-sea-level-rise'), # 11.3 ('urban-systems-infrastructure-vulnerability', [
# ]), ('/metadata/figures/3569', 'urban-support-systems-are-interconnected'), # 11.2
# #Chapter 12 ('/metadata/figures/3090', 'new-york-city-and-sea-level-rise'), # 11.3
# ('tribal-indigenous-native-lands-resources', [ ]),
# ('/metadata/figures/3131', 'indigenous-populations-extend-beyond-reservation-lands'), # 12.1 #Chapter 12
# ('/metadata/figures/2594', 'many-tribes-many-climate-change-initiatives'), # 12.2 ('tribal-indigenous-native-lands-resources', [
# ('/metadata/figures/2909', 'sand-dune-expansion'), # 12.3 ('/metadata/figures/3131', 'indigenous-populations-extend-beyond-reservation-lands'), # 12.1
# ('/metadata/figures/2911', 'arctic-marine-food-web'), # 12.5 ('/metadata/figures/2594', 'many-tribes-many-climate-change-initiatives'), # 12.2
# ]), ('/metadata/figures/2909', 'sand-dune-expansion'), # 12.3
# #Chapter 13 ('/metadata/figures/2911', 'arctic-marine-food-web'), # 12.5
# ('land-use-land-cover-change', [ ]),
# ('/metadata/figures/2902', 'building-loss-by-fires-at-california-wildlandurban-interfaces'), # 13.4 #Chapter 13
# ]), ('land-use-land-cover-change', [
# #Chapter 14 ('/metadata/figures/2902', 'building-loss-by-fires-at-california-wildlandurban-interfaces'), # 13.4
# ('rural', [ ]),
# ('/metadata/figures/2662', 'rural-counties'), # 14.1 #Chapter 14
# ('/metadata/figures/2661', 'economic-dependence-varies-by-region'), # 14.2 ('rural', [
# ('/metadata/figures/3306', 'growing-season-lengthens'), # 14.3 ('/metadata/figures/2662', 'rural-counties'), # 14.1
# ('/metadata/figures/2904', 'many-rural-areas-are-losing-population'), # 14.5 ('/metadata/figures/2661', 'economic-dependence-varies-by-region'), # 14.2
# ]), ('/metadata/figures/3306', 'growing-season-lengthens'), # 14.3
('/metadata/figures/2904', 'many-rural-areas-are-losing-population'), # 14.5
]),
# Chapter 15 # Chapter 15
('biogeochemical-cycles', [ ('biogeochemical-cycles', [
('/metadata/figures/2874', 'major-north-american-carbon-dioxide-sources-and-sinks'), # 15.1 ('/metadata/figures/2874', 'major-north-american-carbon-dioxide-sources-and-sinks'), # 15.1
...@@ -198,7 +200,7 @@ sync_metadata_tree = { ...@@ -198,7 +200,7 @@ sync_metadata_tree = {
('/metadata/figures/2865', 'northwoods-climate-change-response-framework'), # 28.6 ('/metadata/figures/2865', 'northwoods-climate-change-response-framework'), # 28.6
]), ]),
#Chapter 33: Climate Science Appendix #Chapter 33: Climate Science Appendix
('appendix-climate-science', [ ('appendix-climate-science-supplement', [
('/metadata/figures/3112', 'indicators-of-warming-from-multiple-data-sets'), # 33.10 ('/metadata/figures/3112', 'indicators-of-warming-from-multiple-data-sets'), # 33.10
('/metadata/figures/3138', 'warming-trend-and-effects-of-el-nino-la-nina'), # 33.14 ('/metadata/figures/3138', 'warming-trend-and-effects-of-el-nino-la-nina'), # 33.14
('/metadata/figures/2798', 'detection-and-attribution-as-forensics'), # 33.16 ('/metadata/figures/2798', 'detection-and-attribution-as-forensics'), # 33.16
...@@ -219,7 +221,7 @@ sync_metadata_tree = { ...@@ -219,7 +221,7 @@ sync_metadata_tree = {
('/metadata/figures/2796', 'development-of-observing-capabilities'), # 33.7 ('/metadata/figures/2796', 'development-of-observing-capabilities'), # 33.7
]), ]),
#Chapter 34: FAQ/CAQ #Chapter 34: FAQ/CAQ
('appendix-climate-science-faqs', [ ('appendix-faqs', [
('/metadata/figures/2663', 'us-annual-temperature'), # 34.1 ('/metadata/figures/2663', 'us-annual-temperature'), # 34.1
('/metadata/figures/3300', 'caq-human-influences-apparent-in-many-aspects-of-the-changing-climate'), # 34.13 ('/metadata/figures/3300', 'caq-human-influences-apparent-in-many-aspects-of-the-changing-climate'), # 34.13
('/metadata/figures/3091', 'published-climate-change-research-papers'), # 34.18 ('/metadata/figures/3091', 'published-climate-change-research-papers'), # 34.18
...@@ -237,18 +239,7 @@ sync_metadata_tree = { ...@@ -237,18 +239,7 @@ sync_metadata_tree = {
def main(): def main():
print gcis.test_login() print gcis.test_login()
# sync_dataset_metadata(gcis, webform.get_aggregated_datasets()) # sync_dataset_metadata(gcis, webform.get_aggregated_datasets())
sync(replace=False)
# sync(replace=False)
# print gcis.associate_figure_with_report('ten-indicators-of-a-warming-world', 'nca3', 'noaa-stateofclim-2009')
# from gcis_clients.domain import Dataset
# for ds in [d['identifier'] for d in gcis.get_dataset_list().json() if 'the-world-climate-research-programme-s--wcrp-s--coupled-model-intercomparison-project-phase-3--cmip3--multi-model-dataset' in d['identifier']]:
# d = Dataset({})
# d.identifier = ds
# print gcis.delete_dataset(d)
print gcis.lookup_publication('report', 'NOAA 2009 State of the Climate Report')
def sync(replace=False): def sync(replace=False):
...@@ -264,6 +255,7 @@ def sync(replace=False): ...@@ -264,6 +255,7 @@ def sync(replace=False):
#Merge data from both systems into one object... #Merge data from both systems into one object...
gcis_fig = gcis.get_figure(report_id, gcis_id, chapter_id=chapter_id) gcis_fig = gcis.get_figure(report_id, gcis_id, chapter_id=chapter_id)
figure_obj = webform.get_webform(webform_url).merge(gcis_fig) figure_obj = webform.get_webform(webform_url).merge(gcis_fig)
realize_parents(gcis, figure_obj.parents)
#Lookup and populate contributor information for figures and images #Lookup and populate contributor information for figures and images
realize_contributors(gcis, figure_obj.contributors) realize_contributors(gcis, figure_obj.contributors)
......
...@@ -61,6 +61,9 @@ class GcisObject(Gcisbase): ...@@ -61,6 +61,9 @@ class GcisObject(Gcisbase):
contrib_list = data.pop('contributors', None) contrib_list = data.pop('contributors', None)
self.contributors = [Contributor(contrib) for contrib in contrib_list] if contrib_list else [] self.contributors = [Contributor(contrib) for contrib in contrib_list] if contrib_list else []
parents_list = data.pop('parents', None)
self.parents = [Parent(parent) for parent in parents_list] if parents_list else []
super(GcisObject, self).__init__(data, **kwargs) super(GcisObject, self).__init__(data, **kwargs)
def add_contributor(self, contributor): def add_contributor(self, contributor):
...@@ -69,6 +72,9 @@ class GcisObject(Gcisbase): ...@@ -69,6 +72,9 @@ class GcisObject(Gcisbase):
def add_person(self, person): def add_person(self, person):
self.contributors.append(Contributor(person, Organization())) self.contributors.append(Contributor(person, Organization()))
def add_parent(self, parent):
self.parents.append(parent)
class Figure(GcisObject): class Figure(GcisObject):
def __init__(self, data): def __init__(self, data):
...@@ -245,7 +251,7 @@ class Dataset(GcisObject): ...@@ -245,7 +251,7 @@ class Dataset(GcisObject):
'NCEP/NCAR Reanalysis': 'nca3-ncep-ncar-r1', 'NCEP/NCAR Reanalysis': 'nca3-ncep-ncar-r1',
'NCDC Global Surface Temperature Anomalies': 'nca3-ncdc-gst-anomalies-r201307', 'NCDC Global Surface Temperature Anomalies': 'nca3-ncdc-gst-anomalies-r201307',
'GRACE Static Field Geopotential Coefficients JPL Release 5.0 GSM': 'nca3-grace-r201307', 'GRACE Static Field Geopotential Coefficients JPL Release 5.0 GSM': 'nca3-grace-r201307',
'UW/NCDC Satellite Derived Hurricane Intensity Dataset': 'nca3-hurricane-intensity-r1', 'UW/NCDC Satellite Derived Hurricane Intensity Dataset': 'nca3-hursat-r1',
'Bias-Corrected and Spatially Downscaled Surface Water Projections Hydrologic Data': 'nca3-water-projections-r201208', 'Bias-Corrected and Spatially Downscaled Surface Water Projections Hydrologic Data': 'nca3-water-projections-r201208',
'International Best Track Archive for Climate Stewardship (IBTrACS)': 'nca3-ibtracs-r201311', 'International Best Track Archive for Climate Stewardship (IBTrACS)': 'nca3-ibtracs-r201311',
'the World Climate Research Programme\'s (WCRP\'s) Coupled Model Intercomparison Project phase 3 (CMIP3) multi-model dataset': 'nca3-cmip3-r201205', 'the World Climate Research Programme\'s (WCRP\'s) Coupled Model Intercomparison Project phase 3 (CMIP3) multi-model dataset': 'nca3-cmip3-r201205',
...@@ -279,6 +285,10 @@ class Dataset(GcisObject): ...@@ -279,6 +285,10 @@ class Dataset(GcisObject):
self.identifier = self._identifiers[self.name] if self.name in self._identifiers else self.name self.identifier = self._identifiers[self.name] if self.name in self._identifiers else self.name
#Hack to fix a particular kind of bad URL
if self.url and self.url.startswith('ttp://'):
self.url = self.url.replace('ttp://', 'http://')
def __repr__(self): def __repr__(self):
return 'Dataset: {id}: {name}'.format(id=self.identifier, name=self.name) return 'Dataset: {id}: {name}'.format(id=self.identifier, name=self.name)
...@@ -412,8 +422,9 @@ class Organization(Gcisbase): ...@@ -412,8 +422,9 @@ class Organization(Gcisbase):
} }
super(Organization, self).__init__(data, fields=self.gcis_fields, trans=self.translations) super(Organization, self).__init__(data, fields=self.gcis_fields, trans=self.translations)
self.identifier = self._identifiers[self.name] if self.name in self._identifiers else None if not self.identifier:
self.identifier = self._identifiers[self.name] if self.name in self._identifiers else None
def __repr__(self): def __repr__(self):
return 'Organization: {id}: {name}'.format(id=self.identifier, name=self.name) return 'Organization: {id}: {name}'.format(id=self.identifier, name=self.name)
...@@ -449,20 +460,24 @@ class Contributor(Gcisbase): ...@@ -449,20 +460,24 @@ class Contributor(Gcisbase):
'Jeremy Littell': 'scientist', 'Jeremy Littell': 'scientist',
'Emily Cloyd': 'contributing_author', 'Emily Cloyd': 'contributing_author',
'F. Chapin': 'scientist', 'F. Chapin': 'scientist',
' Chapin': 'scientist' ' Chapin': 'scientist',
'Andrew Buddenberg': 'analyst'
} }
self._role = None
super(Contributor, self).__init__(data, fields=self.gcis_fields) super(Contributor, self).__init__(data, fields=self.gcis_fields)
self.person = None person_tree = data.pop('person', None)
self.organization = None org_tree = data.pop('organization', None)
self._role = None
self.person = Person(person_tree) if person_tree else None
self.organization = Organization(org_tree) if org_tree else None
@property @property
def role(self): def role(self):
#Hack hack hack #Hack hack hack
if self._role is None: if self._role is None and self.person is not None:
horrible_key = ' '.join((self.person.first_name, self.person.last_name)) horrible_key = ' '.join((self.person.first_name, self.person.last_name))
self._role = Role(self.people_role_map[horrible_key]) if horrible_key in self.people_role_map else None self._role = Role(self.people_role_map[horrible_key]) if horrible_key in self.people_role_map else None
...@@ -485,3 +500,127 @@ class Role(object): ...@@ -485,3 +500,127 @@ class Role(object):
def __str__(self): def __str__(self):
return self.__repr__() return self.__repr__()
class Parent(Gcisbase):
def __init__(self, data):
self.gcis_fields = ['relationship', 'url', 'publication_type_identifier', 'label', 'activity_uri', 'note']
self.translations = {
'what_type_of_publication_was_the_figure_published_in': 'publication_type_identifier',
'name_title': 'label',
'article_title': 'label',
'book_title': 'label',
'web_page_title': 'label',
'conference_title': 'label',
'title': 'label',
}
self.publication_type_map = {
'report': 'report',
'journal_article': 'article',
'book_section': 'report',
'electronic_article': 'article',
'web_page': 'webpage',
'book': 'book',
'conference_proceedings': 'generic',
}
self.search_hints = {
'report': {
'The State of the Climate 2009 Highlights': 'usgcrp-globclimchhighlights-2009',
'Global Climate Change Impacts in the United States': 'nca2',
'Impacts of Climate Change and Variability on Transportation Systems and Infrastructure: Gulf Study, Phase I.': 'ccsp-sap-4_7-2008',
'Climate and Energy-Water-Land System Interactions': 'pnnl-21185',
'Freshwater Use by U.S. Power Plants Electricity\'s thirst for a Precious Resource': 'ucusa-freshwater-2011',
'New York City Panel on Climate Change Climate Risk Information 2013 Observations, Climate Change Projections and Maps': 'nycpanelonclimch-cri2013',
'Regional Climate Trends and Scenarios for the U.S. National Climate Assessment. Part 2. Climate of the Southeast U.S.': 'noaa-techreport-nesdis-142-2',
'Regional Climate Trends and Scenarios for the U.S. National Climate Assessment. Part 3. Climate of the Midwest U.S.': 'noaa-techreport-nesdis-142-3',
'Reefs at Risk Revisited': ('book', '3788c071-e06a-42c3-b0b9-0396fd494aa3'),
'Climate Change and Pacific Islands: Indicators and Impacts Report for the 2012 Pacific Islands Regional Climate Assessment': 'pirca-climate-change-and-pacific-islands',
'Climate adaptation: Risk, uncertainty and decision-making': 'ukcip-climate-adaptation-risk-uncertainty-and-decision-making',
'Adapting to Impacts of Climate Change. America\'s Climate Choices: Report of the Panel on 43 Adapting to the Impacts of Climate C': ('book', '1e88532d-c40d-47d2-a872-77b2627fbe89'),
'Climate Change 2007: The Physical Science Basis. Contribution of Working Group I to the Fourth Assessment Report of the IPCC': ('book', '92debecd-ca55-46f1-a0c1-734e6b0dc6b1'),
'Snow, Water, Ice and Permafrost in the Arctic (SWIPA): Climate Change and the Cryosphere': ('book', 'e7c9614c-8db8-410f-9fec-0957292554bf'),
'Climate Change 2013: The Physical Science Basis. Contribution of Working Group I to the Fifth Assessment Report of the IPCC': 'ipcc-wg1-ar5-physical-science-basis',
'Regional Climate Trends and Scenarios for the U.S. National Climate Assessment. Part 9. Climate of the Contiguous United States': 'noaa-techreport-nesdis-142-9',
'How to Avoid Dangerous Climate Change. A Target for U.S. Emissions Reductions': 'ucusa-howtoavoid-2007',
'Summary for Decision Makers. Assessment of Climate Change in the Southwest United States': 'swccar-assessment-climate-change-in-southwest-us',
'Climate Variability and Change in Mobile, Alabama: Task 2 Final Report. Impacts of Climate 25 Change and Variability on Transpo': 'fhwa-hep-12-053',
'Effects of Climatic Variability and Change on Forest Ecosystems: A Comprehensive Science Synthesis for the U.S. Forest Sector': 'usfs-gtr-nrs-87',
'Future of America\'s Forests and Rangelands Forest Service. 2010 Resources Planning Act Assessment': 'usfs-gtr-wo-87'
},
'webpage': {
'Toxic Algae Bloom in Lake Erie. October 14, 2011': 'afe12af6-a7d3-4b70-99e5-0f80b67b7047',
'Tribal Energy Program Projects on Tribal Lands': 'abde0ebc-342b-4bb7-b206-016cd3c829c4',
'Atlas of Rural and Small-Town America. Category: County Classifications. Current Map: Rural-urban Continuum Code, 2013': '2cb79b4a-31cf-43ec-a70a-0371626f1407',
'Atlas of Rural and Small-Town America. Category: County Classifications. Current Map: Economic Dependence, 1998-2000': '2cb79b4a-31cf-43ec-a70a-0371626f1407',
'Atlas of Rural and Small-Town America. Category: People.': '2cb79b4a-31cf-43ec-a70a-0371626f1407',
'St. Petersburg Coastal and Marine Science Center': '2f586ef7-91bb-45e5-b463-ee3e358185ba',
'NASA Earth Observatory Natural Hazards': 'c57946b1-f413-491f-b75c-1c08f7594f84',
'Plants of Hawaii': 'a8159919-b01c-442b-afb8-c2e272f81f48',
'Public Roads': '5f3538ab-eb81-4858-b44e-1304b949b288',
'Freight Analysis Framework Data Tabulation Tool': '5fe65558-d010-445b-b4f1-9079224dca6b',
'Ecosystem Services Analysis of Climate Change and Urban Growth in the Upper Santa Cruz Watershed: SCWEPM': 'd4622f7e-aca7-42e6-95da-90579a187c30',
'State and Local Climate Adaptation': '7de6bfc9-55fa-4d12-ae80-486561b3802c',
'Climate Change Response Framework - Northwoods': '267378f7-278b-4201-8ffa-a820f5a694b8',
'NWHI Maps and Publications': 'e6438f11-85f4-4c29-abb5-b09efa3279b2'
},
'article': {
'North American carbon dioxide sources and sinks: magnitude, attribution, and uncertainty': '10.1890/120066',
'Air Quality and Exercise-Related Health Benefits from Reduced Car Travel in the Midwestern United States': '10.1289/ehp.1103440',
'A Shift in Western Tropical Pacific Sea Level Trends during the 1990s': '10.1175/2011JCLI3932.1',
'An update on Earth\'s energy balance in light of the latest global observations': '10.1038/ngeo1580',
'About the Lack of Warming...': ('web_page', 'e2ec2d0f-430c-4032-a309-2514ca1f6572'),
'The Myth of the 1970s Global Cooling Scientific Consensus': '10.1175/2008BAMS2370.1',
'Hurricane Sandy devestates NY/NJ-area passenger rai systems': ('web_page', '135ae7d9-56e3-4dcb-a81c-42a6f1e9b332')
},
'book': {
'Climate Change and Pacific Islands: Indicators and Impacts. Report for the 2012 Pacific Islands Regional Climate Assessment': ('report', 'pirca-climate-change-and-pacific-islands'),
'A focus on climate during the past 100 years in "Climate Variability and Extremes during the Past 100 Years"': '998aa4c2-9f0d-478c-b7bb-19e383c628a9'
},
'generic': {
'Verrazano Narrows Storm Surge Barrier: Against the Deluge: Storm Barriers to Protect New York City, March 31st 2009': '01d188d1-636b-49e6-af43-c1544cee9319'
}
}
self._publication_type_identifier = None
super(Parent, self).__init__(data, fields=self.gcis_fields, trans=self.translations)
#HACK: Set default relationship type
self.relationship = self.relationship if self.relationship else 'prov:wasDerivedFrom'
#HACK to smooth out ambiguous search results
if self.publication_type_identifier in self.search_hints and self.label in \
self.search_hints[self.publication_type_identifier]:
hint = self.search_hints[self.publication_type_identifier][self.label]
if isinstance(hint, tuple):
type, id = hint
self.publication_type_identifier = type
else:
id = hint
type = self.publication_type_identifier
self.url = '/{type}/{id}'.format(type=self.publication_type_identifier, id=id)
@property
def publication_type_identifier(self):
return self._publication_type_identifier
@publication_type_identifier.setter
def publication_type_identifier(self, value):
self._publication_type_identifier = self.publication_type_map[value] \
if value in self.publication_type_map else '**MISSING**' + value
def __repr__(self):
return '{rel}: {type}: {url}'.format(rel=self.relationship, type=self.publication_type_identifier, url=self.url)
def __str__(self):
return self.__repr__()
\ No newline at end of file
...@@ -110,6 +110,9 @@ class GcisClient(object): ...@@ -110,6 +110,9 @@ class GcisClient(object):
self.create_image(image), self.create_image(image),
self.associate_image_with_figure(image.identifier, report_id, figure.identifier) self.associate_image_with_figure(image.identifier, report_id, figure.identifier)
for p in figure.parents:
self.associate_figure_with_parent(report_id, figure.identifier, p)
return resp return resp
@http_resp @http_resp
...@@ -134,6 +137,9 @@ class GcisClient(object): ...@@ -134,6 +137,9 @@ class GcisClient(object):
for c in figure.contributors: for c in figure.contributors:
self.associate_contributor_with_figure(c, report_id, chapter_id, figure.identifier) self.associate_contributor_with_figure(c, report_id, chapter_id, figure.identifier)
for p in figure.parents:
self.associate_figure_with_parent(report_id, figure.identifier, p)
return resp return resp
@http_resp @http_resp
...@@ -534,15 +540,38 @@ class GcisClient(object): ...@@ -534,15 +540,38 @@ class GcisClient(object):
return self.s.post(url, data=json.dumps(data), verify=False) return self.s.post(url, data=json.dumps(data), verify=False)
@http_resp @http_resp
def associate_figure_with_report(self, figure_id, report_id, other_report_id): def associate_figure_with_parent(self, report_id, figure_id, parent):
url = '{b}/report/{rpt}/figure/prov/{fig}'.format(b=self.base_url, rpt=report_id, fig=figure_id) url = '{b}/report/{rpt}/figure/prov/{fig}'.format(b=self.base_url, rpt=report_id, fig=figure_id)
data = { data = {
'parent_uri': '/report/' + other_report_id, 'parent_uri': parent.url,
'parent_rel': 'prov:wasDerivedFrom' 'parent_rel': parent.relationship
} }
return self.s.post(url, data=json.dumps(data), verify=False) try:
self.delete_figure_pub_assoc(report_id, figure_id, parent)
except AssociationException as e:
print e.value
resp = self.s.post(url, data=json.dumps(data), verify=False)
return resp
def delete_figure_pub_assoc(self, report_id, figure_id, parent):
url = '{b}/report/{rpt}/figure/prov/{fig}'.format(b=self.base_url, rpt=report_id, fig=figure_id)
data = {
'delete': {
'parent_uri': parent.url,
'parent_rel': parent.relationship
}
}
resp = self.s.post(url, data=json.dumps(data), verify=False)
if resp.status_code == 200:
return resp
else:
raise AssociationException(
'Parent dissociation failed:\n{url}\n{resp}\n{d}'.format(url=url, resp=resp.text, d=data))
def lookup_publication(self, pub_type, name): def lookup_publication(self, pub_type, name):
url = '{b}/autocomplete'.format(b=self.base_url) url = '{b}/autocomplete'.format(b=self.base_url)
...@@ -550,5 +579,6 @@ class GcisClient(object): ...@@ -550,5 +579,6 @@ class GcisClient(object):
if resp.status_code == 200: if resp.status_code == 200:
return [re.match(r'\[.+\] \{(.+)\} (.*)', r).groups() for r in resp.json()] return [re.match(r'\[.+\] \{(.+)\} (.*)', r).groups() for r in resp.json()]
# return resp.json()
else: else:
raise Exception(resp.text) raise Exception(resp.text)
\ No newline at end of file
...@@ -55,3 +55,20 @@ def realize_contributors(gcis_client, contributors): ...@@ -55,3 +55,20 @@ def realize_contributors(gcis_client, contributors):
if not all(map(lambda c: c.organization.identifier is not None, contributors)): if not all(map(lambda c: c.organization.identifier is not None, contributors)):
print contributors print contributors
def realize_parents(gcis_client, parents):
for parent in parents:
# print parent.publication_type_identifier, parent.label
if parent.url:
print '\t', ' '.join(('Using hint for', parent.publication_type_identifier, parent.label))
continue