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

Added support for syncing Parents

parent 848d62da
......@@ -2,7 +2,7 @@
__author__ = 'abuddenberg'
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
webform = WebformClient('http://resources.assessment.globalchange.gov', webform_token)
......@@ -14,102 +14,104 @@ sync_metadata_tree = {
#Reports
'nca3': OrderedDict([
#Chapter 2
# ('our-changing-climate', [
# # (webform_url, gcis_id)
# ('/metadata/figures/3074', 'ten-indicators-of-a-warming-world'), # 2.1
# ('/metadata/figures/3293', 'observed-increase-in-frostfree-season-length'), # 2.10
# ('/metadata/figures/3294', 'projected-changes-in-frostfree-season-length'), # 2.11
# ('/metadata/figures/2677', 'observed-us-precipitation-change'), # 2.12
# ('/metadata/figures/3298', 'observed-us-trend-in-heavy-precipitation'), # 2.16
# ('/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/3170', 'global-temperature-and-carbon-dioxide'), # 2.2
# ('/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/3067', 'ice-cover-in-the-great-lakes'), # 2.27
# ('/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/2523', 'shells-dissolve-in-acidified-ocean-water'), # 2.31
# ('/metadata/figures/3175', 'observed-us-temperature-change'), # 2.7
#
# ]),
# #Chapter 3
# ('water-resources', [
# ('/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', [
# ('/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', [
('our-changing-climate', [
# (webform_url, gcis_id)
('/metadata/figures/3074', 'ten-indicators-of-a-warming-world'), # 2.1
('/metadata/figures/3293', 'observed-increase-in-frostfree-season-length'), # 2.10
('/metadata/figures/3294', 'projected-changes-in-frostfree-season-length'), # 2.11
('/metadata/figures/2677', 'observed-us-precipitation-change'), # 2.12
('/metadata/figures/3298', 'observed-us-trend-in-heavy-precipitation'), # 2.16
('/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/3170', 'global-temperature-and-carbon-dioxide'), # 2.2
('/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/3067', 'ice-cover-in-the-great-lakes'), # 2.27
('/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/2523', 'shells-dissolve-in-acidified-ocean-water'), # 2.31
('/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', [
('/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', [
('/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', [
# ('/metadata/figures/3088', 'possible-future-flood-depths-in-mobile-al-with-rising-sea-level'), # 5.1
# ('/metadata/figures/2905', 'gulf-coast-transportation-hubs-at-risk'), # 5.3
# ('/metadata/figures/3568', 'hurricane-sandy-causes-flooding-in-new-york-city-subway-stations'), # 5.4
# ('/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', [
# ('/metadata/figures/2691', 'projected-changes-in-key-climate-variables-affecting-agricultural-productivity'), # 6.5
# ('/metadata/figures/2872', 'drainage-tiles'), # 6.8
# ]),
# #Chapter 7
# ('forests', [
# ('/metadata/figures/2887', 'forest-ecosystem-disturbances'), # 7.1
# ('/metadata/figures/2977', 'effectiveness-of-forest-management-in-reducing-wildfire-risk'), # 7.2
# ('/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
# ('/metadata/figures/3574', 'biological-responses-to-climate-change'), # 8.4
# ]),
# #Chapter 9
# ('human-health', [
# ('/metadata/figures/3162', 'projected-climate-change-worsens-asthma'), # 9.1
# ('/metadata/figures/2896', 'heavy-downpours-disease'), # 9.7
# ('/metadata/figures/2897', 'harmful-bloom-of-algae'), # 9.8
# ]),
# #Chapter 10
# ('water-energy-land-use', [
# ('/metadata/figures/2601', 'energy-water-land-and-climate-interactions'), # 10.1
# ('/metadata/figures/2917', 'the-columbia-river-basin-land-use-and-land-cover'), # 10.10
# ('/metadata/figures/2410', 'coasttocoast-100degree-days-in-2011'), # 10.2
# ('/metadata/figures/3158', 'projected-landuse-intensity-in-2030'), # 10.6
# ('/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
# ('/metadata/figures/3090', 'new-york-city-and-sea-level-rise'), # 11.3
# ]),
# #Chapter 12
# ('tribal-indigenous-native-lands-resources', [
# ('/metadata/figures/3131', 'indigenous-populations-extend-beyond-reservation-lands'), # 12.1
# ('/metadata/figures/2594', 'many-tribes-many-climate-change-initiatives'), # 12.2
# ('/metadata/figures/2909', 'sand-dune-expansion'), # 12.3
# ('/metadata/figures/2911', 'arctic-marine-food-web'), # 12.5
# ]),
# #Chapter 13
# ('land-use-land-cover-change', [
# ('/metadata/figures/2902', 'building-loss-by-fires-at-california-wildlandurban-interfaces'), # 13.4
# ]),
# #Chapter 14
# ('rural', [
# ('/metadata/figures/2662', 'rural-counties'), # 14.1
# ('/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
# ]),
('/metadata/figures/3568', 'hurricane-sandy-causes-flooding-in-new-york-city-subway-stations'), # 5.4
('/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', [
('/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
('/metadata/figures/2872', 'drainage-tiles'), # 6.8
]),
#Chapter 7
('forests', [
('/metadata/figures/2887', 'forest-ecosystem-disturbances'), # 7.1
('/metadata/figures/2977', 'effectiveness-of-forest-management-in-reducing-wildfire-risk'), # 7.2
('/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
('/metadata/figures/3574', 'biological-responses-to-climate-change'), # 8.4
]),
#Chapter 9
('human-health', [
('/metadata/figures/3162', 'projected-climate-change-worsens-asthma'), # 9.1
('/metadata/figures/2896', 'heavy-downpours-disease'), # 9.7
('/metadata/figures/2897', 'harmful-bloom-of-algae'), # 9.8
]),
#Chapter 10
('water-energy-land-use', [
('/metadata/figures/2601', 'energy-water-land-and-climate-interactions'), # 10.1
('/metadata/figures/2917', 'the-columbia-river-basin-land-use-and-land-cover'), # 10.10
('/metadata/figures/2410', 'coasttocoast-100degree-days-in-2011'), # 10.2
('/metadata/figures/3158', 'projected-landuse-intensity-in-2030'), # 10.6
('/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
('/metadata/figures/3090', 'new-york-city-and-sea-level-rise'), # 11.3
]),
#Chapter 12
('tribal-indigenous-native-lands-resources', [
('/metadata/figures/3131', 'indigenous-populations-extend-beyond-reservation-lands'), # 12.1
('/metadata/figures/2594', 'many-tribes-many-climate-change-initiatives'), # 12.2
('/metadata/figures/2909', 'sand-dune-expansion'), # 12.3
('/metadata/figures/2911', 'arctic-marine-food-web'), # 12.5
]),
#Chapter 13
('land-use-land-cover-change', [
('/metadata/figures/2902', 'building-loss-by-fires-at-california-wildlandurban-interfaces'), # 13.4
]),
#Chapter 14
('rural', [
('/metadata/figures/2662', 'rural-counties'), # 14.1
('/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
('biogeochemical-cycles', [
('/metadata/figures/2874', 'major-north-american-carbon-dioxide-sources-and-sinks'), # 15.1
......@@ -198,7 +200,7 @@ sync_metadata_tree = {
('/metadata/figures/2865', 'northwoods-climate-change-response-framework'), # 28.6
]),
#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/3138', 'warming-trend-and-effects-of-el-nino-la-nina'), # 33.14
('/metadata/figures/2798', 'detection-and-attribution-as-forensics'), # 33.16
......@@ -219,7 +221,7 @@ sync_metadata_tree = {
('/metadata/figures/2796', 'development-of-observing-capabilities'), # 33.7
]),
#Chapter 34: FAQ/CAQ
('appendix-climate-science-faqs', [
('appendix-faqs', [
('/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/3091', 'published-climate-change-research-papers'), # 34.18
......@@ -237,18 +239,7 @@ sync_metadata_tree = {
def main():
print gcis.test_login()
# sync_dataset_metadata(gcis, webform.get_aggregated_datasets())
# 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')
sync(replace=False)
def sync(replace=False):
......@@ -264,6 +255,7 @@ def sync(replace=False):
#Merge data from both systems into one object...
gcis_fig = gcis.get_figure(report_id, gcis_id, chapter_id=chapter_id)
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
realize_contributors(gcis, figure_obj.contributors)
......
......@@ -61,6 +61,9 @@ class GcisObject(Gcisbase):
contrib_list = data.pop('contributors', None)
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)
def add_contributor(self, contributor):
......@@ -69,6 +72,9 @@ class GcisObject(Gcisbase):
def add_person(self, person):
self.contributors.append(Contributor(person, Organization()))
def add_parent(self, parent):
self.parents.append(parent)
class Figure(GcisObject):
def __init__(self, data):
......@@ -245,7 +251,7 @@ class Dataset(GcisObject):
'NCEP/NCAR Reanalysis': 'nca3-ncep-ncar-r1',
'NCDC Global Surface Temperature Anomalies': 'nca3-ncdc-gst-anomalies-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',
'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',
......@@ -279,6 +285,10 @@ class Dataset(GcisObject):
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):
return 'Dataset: {id}: {name}'.format(id=self.identifier, name=self.name)
......@@ -413,6 +423,7 @@ class Organization(Gcisbase):
super(Organization, self).__init__(data, fields=self.gcis_fields, trans=self.translations)
if not self.identifier:
self.identifier = self._identifiers[self.name] if self.name in self._identifiers else None
def __repr__(self):
......@@ -449,20 +460,24 @@ class Contributor(Gcisbase):
'Jeremy Littell': 'scientist',
'Emily Cloyd': 'contributing_author',
'F. Chapin': 'scientist',
' Chapin': 'scientist'
' Chapin': 'scientist',
'Andrew Buddenberg': 'analyst'
}
self._role = None
super(Contributor, self).__init__(data, fields=self.gcis_fields)
self.person = None
self.organization = None
self._role = None
person_tree = data.pop('person', None)
org_tree = data.pop('organization', None)
self.person = Person(person_tree) if person_tree else None
self.organization = Organization(org_tree) if org_tree else None
@property
def role(self):
#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))
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):
def __str__(self):
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):
self.create_image(image),
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
@http_resp
......@@ -134,6 +137,9 @@ class GcisClient(object):
for c in figure.contributors:
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
@http_resp
......@@ -534,15 +540,38 @@ class GcisClient(object):
return self.s.post(url, data=json.dumps(data), verify=False)
@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)
data = {
'parent_uri': '/report/' + other_report_id,
'parent_rel': 'prov:wasDerivedFrom'
'parent_uri': parent.url,
'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):
url = '{b}/autocomplete'.format(b=self.base_url)
......@@ -550,5 +579,6 @@ class GcisClient(object):
if resp.status_code == 200:
return [re.match(r'\[.+\] \{(.+)\} (.*)', r).groups() for r in resp.json()]
# return resp.json()
else:
raise Exception(resp.text)
\ No newline at end of file
......@@ -55,3 +55,20 @@ def realize_contributors(gcis_client, contributors):
if not all(map(lambda c: c.organization.identifier is not None, 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
parent_matches = gcis_client.lookup_publication(parent.publication_type_identifier, parent.label)
if len(parent_matches) == 1:
parent.url = '/{type}/{id}'.format(type=parent.publication_type_identifier, id=parent_matches[0][0])
elif len(parent_matches) == 0:
print '\t', ' '.join(('No ID found for', parent.publication_type_identifier, parent.label))
else:
print '\t', ' '.join(('Ambiguous results for', parent.publication_type_identifier, parent.label))
print '\t\t', parent_matches
\ No newline at end of file
......@@ -6,8 +6,9 @@ from os.path import join
import getpass
import requests
from dateutil.parser import parse
from copy import deepcopy
from domain import Figure, Image, Dataset, Activity, Contributor, Person, Organization
from domain import Figure, Image, Dataset, Activity, Contributor, Person, Organization, Parent
def sanitized(pattern):
......@@ -87,6 +88,11 @@ class WebformClient:
if 'list_the_creator_of_the_figure' in figure_json:
f.add_contributor(parse_creators(figure_json['list_the_creator_of_the_figure']))
#Add provenance information (wasDerivedFrom parent)
if 'what_type_of_source_provided_this_figure' in figure_json and figure_json[
'what_type_of_source_provided_this_figure'] == 'published_source':
f.add_parent(Parent(deepcopy(f.original)))
if 'images' in webform_json[webform_nid]:
for img_idx, image in enumerate(webform_json[webform_nid]['images']):
image_obj = Image(image, local_path=self.get_local_image_path(image),
......@@ -192,4 +198,5 @@ class WebformClient:
dataset_map[dataset.identifier].merge(dataset)
dataset_map[dataset.identifier].activity.merge(dataset.activity)
# print webform_url, dataset.identifier
return dataset_map.values()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment