Commit bb90ecb3 authored by abuddenberg's avatar abuddenberg
Browse files

Merge branch 'surveys'

parents c49bfd2b 21fdef44
......@@ -93,3 +93,27 @@ Let's see about the images:
How about the whole Image?:
print gcis.get_image('69da6d93-4426-4061-a2a1-7b3d01f2dc1c').as_json(indent=4)
Want to find the lineage of a publication?
fig2_1 = gcis.get_figure('nca3', 'ten-indicators-of-a-warming-world')
print fig2_1.parents
Add a parent to a figure directly...
cmip3 = gcis.get_dataset('nca3-cmip3-r201205')
gcis.associate_figure_with_parent('nca3', 'ten-indicators-of-a-warming-world', Parent.from_obj(cmip3))
...or as part of an update
fig2_1.add_parent(Parent.from_obj(cmip3))
gcis.update_figure('nca3', 'our-changing-climate', fig2_1)
**NOTE:** GcisClient will disassociate and then reassociate Parents as part of an update. Adding a new Parent during an
update will cause "Parent dissociation failed" messages to appear--these can be safely ignored.
**ALSO:** Updates do NOT, presently, remove parents you have not included on the Figure object.
Remove a parent from a figure
gcis.delete_figure_parent_assoc('nca3', 'ten-indicators-of-a-warming-world', Parent.from_obj(cmip3))
......@@ -170,4 +170,6 @@ def sort_webform_list(report_id):
if __name__ == '__main__':
main()
print 'The problems script is no longer maintained (and was a bad idea in the first place).'
# Think really hard about uncommenting this, then don't.
# main()
......@@ -420,7 +420,7 @@ def sync(replace=False):
# #Remove existing parents
for p in gcis_fig.parents:
gcis.delete_figure_pub_assoc(report_id, gcis_id, p)
gcis.delete_figure_parent_assoc(report_id, gcis_id, p)
for image in gcis_fig.images:
#TODO: There are better ways to do this. Build File support.
......@@ -445,4 +445,6 @@ def cleanup_after_replace():
print gcis.associate_image_with_figure(image_id, 'nca3', figure_id)
if __name__ == '__main__':
main()
print 'The sync_figures script is no longer maintained and is for reference only.'
# Uncomment at your own risk.
# main()
#!/usr/bin/env python
from gcis_clients import GcisClient, gcis_dev_auth
from gcis_clients.domain import Parent
base_url = 'http://data.globalchange.gov'
......@@ -38,9 +39,17 @@ for image in fig2_7.images:
#How about the whole Image?
print gcis.get_image('69da6d93-4426-4061-a2a1-7b3d01f2dc1c').as_json(indent=4)
#Let's assign some GCMD keywords (The first 4 from the list)
# keyword_ids = [k['identifier'] for k in gcis.get_keyword_listing()[0:4]]
#Want to find the lineage of a publication?
fig2_1 = gcis.get_figure('nca3', 'ten-indicators-of-a-warming-world')
print fig2_1.parents
# for keyword_id in keyword_ids:
# resp = gcis.associate_keyword_with_figure(keyword_id, 'nca3draft', 'observed-us-temperature-change')
# print resp.status_code, resp.text
#Add a parent to a figure directly...
cmip3 = gcis.get_dataset('nca3-cmip3-r201205')
gcis.associate_figure_with_parent('nca3', 'ten-indicators-of-a-warming-world', Parent.from_obj(cmip3))
#...or as part of an update
fig2_1.add_parent(Parent.from_obj(cmip3))
gcis.update_figure('nca3', 'our-changing-climate', fig2_1)
#Remove a parent from a figure
gcis.delete_figure_parent_assoc('nca3', 'ten-indicators-of-a-warming-world', Parent.from_obj(cmip3))
__author__ = 'abuddenberg'
from gcis_clients import GcisClient, SurveyClient, survey_token, gcis_dev_auth, gcis_stage_auth
from gcis_clients.domain import Report, Chapter
from sync_utils import realize_parents, realize_contributors
from collections import OrderedDict
import pickle
import sys
gcis = GcisClient('http://data.gcis-dev-front.joss.ucar.edu', *gcis_dev_auth)
# gcis = GcisClient('https://data-review.globalchange.gov', *gcis_stage_auth)
surveys = SurveyClient('https://healthresources.globalchange.gov', survey_token)
sync_metadata_tree = {
'usgcrp-climate-and-health-assessment-draft': OrderedDict([
('executive-summary', []),
('climate-change-and-human-health', [
('/metadata/figures/3698', 'major_u_s__climate_trends'), #1.1 #climate-change-and-human-health
('/metadata/figures/3632', 'percent_changes_in_the_annual_number_of_extreme_precipitation_events_'), #1.2 #climate-change-and-human-health
('/metadata/figures/3635', 'projected_changes_in_temperature_and_precipitation_by_mid_century'), #1.3 #climate-change-and-human-health
('/metadata/figures/3633', 'projected_changes_in_the_hottest_coldest_and_wettest_driest_day_of_the_year'), #1.4 #climate-change-and-human-health
('/metadata/figures/3757', 'climate_change_and_health'), #1.5 #climate-change-and-human-health
]),
('temperature-related-death-and-illness', [
('/metadata/figures/3811', 'climate_change_and_health__extreme_heat'), #2.1 #temperature-related-death-and-illness
('/metadata/figures/3585', 'heat_related_deaths_during_the_1995_chicago_heat_wave'), #2.2 #temperature-related-death-and-illness
('/metadata/figures/3643', 'projected_net_changes_in_extreme_temperature_related_deaths'), #2.3 #temperature-related-death-and-illness
('/metadata/figures/3653', 'projected_changes_in_deaths_in_u_s__cities_by_season'), #2.4 #temperature-related-death-and-illness
]),
('air-quality-impacts', [
('/metadata/figures/3812', 'climate_change_and_health__outdoor_air_quality'), #3.1 #air-quality-impacts
('/metadata/figures/3647', 'projected_change_in_average_daily_maximum_temperature__seasonal_average_maximum_daily_8_hr_ozone__and_ozone_related_premature_deaths_in_2013'), #3.2 #air-quality-impacts
('/metadata/figures/3649', 'projected_change_in_ozone_related_premature_deaths'), #3.3 #air-quality-impacts
('/metadata/figures/3650', 'ragweed_pollen_season_lengthens'), #3.4 #air-quality-impacts
]),
('vectorborne-diseases', [
('/metadata/figures/3807', 'climate_change_and_health__lyme_disease'), #4.1 #vectorborne-diseases
('/metadata/figures/3659', 'changes_in_lyme_disease_case_report_distribution'), #4.2 #vectorborne-diseases
('/metadata/figures/3658', 'life_cycle_of_blacklegged_ticks__ixodes_scapularis'), #4.3 #vectorborne-diseases
('/metadata/figures/3747', 'lyme_disease_onset_week_modeling_scenarios'), #4.4 #vectorborne-diseases
('/metadata/figures/3674', 'incidence_of_west_nile_neuroinvasive_disease_in_the_united_states'), #4.5 #vectorborne-diseases
('/metadata/figures/3675', 'climate_impacts_on_west_nile_virus_transmission'), #4.6 #vectorborne-diseases
]),
('water-related-illnesses', [
('/metadata/figures/3824', 'climate_change_and_health___vibrio'), #5.1 #water-related-illnesses
('/metadata/figures/3700', 'links_between_climate_change__water_quantity_and_quality__and_human_exposure_to_water_related_illness'), #5.2 #water-related-illnesses #TOO BIG
('/metadata/figures/3671', 'locations_of_livestock_and_projections_of_heavy_precipitation'), #5.3 #water-related-illnesses #TOO BIG
('/metadata/figures/3673', 'potential_routes_of_manure_borne_microbial_contaminants_to_ground_and_surface_water_supplies_'), #5.3 #water-related-illnesses UNUSED?
('/metadata/figures/3709', 'projections_of_vibrio_occurrence_and_abundance_in_chesapeake_bay'), #5.4 #water-related-illnesses
('/metadata/figures/3704', 'changes_in_suitable_coastal_vibrio_habitat_in_alaska'), #5.5 #water-related-illnesses
('/metadata/figures/3734', 'projected_changes_in_caribbean_gambierdiscus_species'), #5.6 #water-related-illnesses
('/metadata/figures/3712', 'projections_of_growth_of_alexandrium_fundyense_in_puget_sound'), #5.7 #water-related-illnesses
]),
('food-safety--nutrition--and-distribution', [
('/metadata/figures/3579', 'farm_to_table'), #6.1 #food-safety--nutrition--and-distribution
## ('/metadata/figures/3600', 'mycotoxin_in_corn'), #6.1 #food-safety--nutrition--and-distribution BOX 1?
('/metadata/figures/3809', 'climate_change_and_health__salmonella'), #6.2 #food-safety--nutrition--and-distribution
('/metadata/figures/3748', 'seasonality_of_human_illnesses_associated_with_foodborne_pathogens'), #6.3 #food-safety--nutrition--and-distribution
('/metadata/figures/3688', 'effects_of_carbon_dioxide_on_protein_and_minerals'), #6.4 #food-safety--nutrition--and-distribution
('/metadata/figures/3597', 'mississippi_river_level_at_st__louis__missouri'), #6.5 #food-safety--nutrition--and-distribution
]),
('extreme-weather', [
('/metadata/figures/3810', 'estimated_deaths_and_billion_dollar_losses_from_extreme_weather_events_in_the_u_s__2004_2013'), #7.1 #extreme-weather #Has Activities
## ('/metadata/figures/3772', 'trends_in_flood_magnitude'), #7.2 #extreme-weather NOT USED
('/metadata/figures/3808', 'climate_change_and_health__flooding'), #7.2 #extreme-weather
('/metadata/figures/3760', 'hurricane_induced_flood_effects_in_eastern_and_central_united_states'), #7.3 #extreme-weather
]),
('mental-health-and-well-being', [
('/metadata/figures/3789', 'climate_change_and_mental_health'), #8.1 #mental-health-and-well-being
('/metadata/figures/3722', 'the_impact_of_climate_change_on_physical__mental__and_community_health'), #8.2 #mental-health-and-well-being
]),
('populations-of-concern', [
('/metadata/figures/3696', 'determinants_of_vulnerability'), #9.1 #populations-of-concern
('/metadata/figures/3694', 'social_determinants_of_health'), #9.2 #populations-of-concern
('/metadata/figures/3758', 'children_at_different_lifestages_experience_unique_vulnerabilities_to_climate_change'), #9.3 #populations-of-concern
('/metadata/figures/3714', 'mapping_social_vulnerability'), #9.4 #populations-of-concern
('/metadata/figures/3717', 'mapping_communities_vulnerable_to_heat_in_georgia'), #9.5 #populations-of-concern
]),
('appendix-1--technical-support-document', [
('/metadata/figures/3623', 'emissions_levels_determine_temperature_rises'), #1.1 #climate-change-and-human-health
('/metadata/figures/3759', 'the_shared_socioeconomic_pathways'), #1.2 #climate-change-and-human-health
('/metadata/figures/3726', 'example_spatial_resolution_of_climate_models'), #1.3 #climate-change-and-human-health
('/metadata/figures/3638', 'sensitivity_analysis_of_differences_in_modeling_approaches'), #1.4 #climate-change-and-human-health
])
])
}
def main():
print gcis.test_login()
# regenerate_image_id_map()
image_id_map = pickle.load(open('image_id_cache.pk1', 'r'))
# create_health_report()
for report_id in sync_metadata_tree:
for chapter_id in sync_metadata_tree[report_id]:
for survey_url, figure_id in sync_metadata_tree[report_id][chapter_id]:
print survey_url, gen_edit_link(survey_url)
figure, datasets = surveys.get_survey(survey_url, do_download=True)
realize_parents(gcis, figure.parents)
realize_contributors(gcis, figure.contributors)
print 'Contributors: ', figure.contributors
print 'Parents: ', figure.parents
for ds in [p for p in figure.parents if p.publication_type_identifier == 'dataset']:
# Assign synthetic activity identifier to for datasets associated with figure
if ds.activity and ds.activity.identifier is None:
ds.activity.identifier = generate_activity_id(figure, ds.publication)
print 'Dataset: ', ds.activity
#Create the figure in GCIS
# print 'Creating figure... ', gcis.create_figure(report_id, chapter_id, figure, skip_images=True)
print 'Updating figure... ', gcis.update_figure(report_id, chapter_id, figure, skip_images=True)
for i in figure.images:
i.identifier = image_id_map[i.identifier]
print '\t', i
realize_parents(gcis, i.parents)
realize_contributors(gcis, i.contributors)
print '\t\tContributors: ', i.contributors
print '\t\tParents: ', i.parents
for ds in [p for p in i.parents if p.publication_type_identifier == 'dataset']:
# Assign synthetic activity identifier to for datasets associated with images
if ds.activity and ds.activity.identifier is None:
ds.activity.identifier = generate_activity_id(i, ds.publication)
print '\t\tDataset: ', ds, ds.activity
#Create image in GCIS
# print 'Creating image... ', gcis.create_image(i, report_id=report_id, figure_id=figure_id)
print 'Updating image... ', gcis.update_image(i)
def gen_edit_link(survey_id):
node_id = survey_id.split('/')[-1]
return 'https://healthresources.globalchange.gov/node/' + node_id
def generate_activity_id(image, dataset):
try:
return '-'.join([image.identifier.split('-')[0], dataset.identifier, '-process'])
except Exception, e:
sys.stderr.write('WARNING: Activity identifier generation failed\n')
def regenerate_image_id_map(existing=None):
from uuid import uuid4
image_id_map = existing if existing else {}
for report_id in sync_metadata_tree:
for chapter_id in sync_metadata_tree[report_id]:
for survey_url, figure_id in sync_metadata_tree[report_id][chapter_id]:
s = surveys.get_survey(survey_url, do_download=False)
for img in s.images:
if img.identifier in image_id_map:
print 'skipping: ', img.identifier
continue
else:
print 'added: ', img.identifier
image_id_map[img.identifier] = str(uuid4())
with open('image_id_cache.pk1', 'wb') as fout:
pickle.dump(image_id_map, fout)
print 'image_id_map regenerated'
def gen_survey_list():
realized_list = []
chapters = [c for c in sync_metadata_tree['usgcrp-climate-and-health-assessment-draft']]
survey_list = surveys.get_list()
for i, survey in enumerate(survey_list):
url = survey['url']
print 'Processing: {b}{url} ({i}/{total})'.format(b=surveys.base_url, url=url, i=i + 1, total=len(survey_list))
s = surveys.get_survey(url)
chp_id = chapters[s.chapter] if s and s.chapter else None
if s:
print s.identifier
print chp_id, s.figure_num, s.title
realized_list.append((chp_id, s.figure_num, s.identifier, s.title, url))
print ''
return realized_list
def create_health_report():
hr = Report({
'identifier': 'usgcrp-climate-and-health-assessment-draft',
'report_type_identifier': 'assessment',
'title': 'Impacts of Climate Change on Human Health in the United States: A Scientific Assessment',
'url': 'http://www.globalchange.gov/health-assessment',
'publication_year': '2015',
'contact_email': 'healthreport@usgcrp.gov'
})
# ['report_identifier', 'identifier', 'number', 'title', 'url']
chapters = [
('executive-summary', None, 'Executive Summary'),
('climate-change-and-human-health', 1, 'Climate Change and Human Health'),
('temperature-related-death-and-illness', 2, 'Temperature-Related Death and Illness'),
('air-quality-impacts', 3, 'Air Quality Impacts'),
('vectorborne-diseases', 4, 'Vectorborne Diseases'),
('water-related-illnesses', 5, 'Climate Impacts on Water-Related Illnesses'),
('food-safety--nutrition--and-distribution', 6, 'Food Safety, Nutrition, and Distribution'),
('extreme-weather', 7, 'Impacts of Extreme Events on Human Health'),
('mental-health-and-well-being', 8, 'Mental Health and Well-Being'),
('populations-of-concern', 9, 'Climate-Health Risk Factors and Populations of Concern'),
('appendix-1--technical-support-document', None, 'Appendix 1: Technical Support Document')
]
print gcis.create_report(hr)
for id, num, title in chapters:
ch = Chapter({
'identifier': id,
'number': num,
'title': title,
'report_identifier': hr.identifier
})
print gcis.create_chapter(hr.identifier, ch)
def create_cmip5_report():
cmip = Report({
'identifier': 'noaa-techreport-nesdis-144',
'report_type_identifier': 'report',
'title': 'Regional Surface Climate Conditions in CMIP3 and CMIP5 for the United States: Differences, Similarities, and Implications for the U.S. National Climate Assessment',
'publication_year': '2015'
})
print gcis.create_report(cmip)
chapters = [
('introduction', 1, 'Introduction'),
('data', 2, 'Data'),
('methods', 3, 'Methods'),
('temperature', 4, 'Temperature'),
('precipitation', 5, 'Precipitation'),
('summary', 6, 'Summary'),
('appendix', None, 'Appendix'),
('references', None, 'References'),
('acknowledgements', None, 'Acknowledgements'),
]
for id, num, title in chapters:
ch = Chapter({
'identifier': id,
'number': num,
'title': title,
'report_identifier': cmip.identifier
})
print gcis.create_chapter(cmip.identifier, ch)
main()
\ No newline at end of file
......@@ -85,6 +85,7 @@ function formsrv_2_figure_metadata_json($image_nid_query = ''){
n.nid,
ci.field_metadata_t1_value as t1,
ci.field_metadata_t2_value as t2,
ci.field_cr_permission_status_value as copyright,
f.filepath
FROM {node} n
JOIN {content_type_chapter_image} ci ON n.nid = ci.nid AND n.vid = ci.vid
......@@ -98,6 +99,7 @@ END;
while($row = $result->fetch_assoc()){
$list[] = array(
'nid' => $row['nid'],
'copyright' => $row['copyright'],
't1' => json_decode($row['t1']),
't2' => json_decode($row['t2']),
'filepath' => $row['filepath']
......
......@@ -71,13 +71,19 @@ class GcisObject(Gcisbase):
super(GcisObject, self).__init__(data, **kwargs)
def add_contributor(self, contributor):
self.contributors.append(contributor)
if isinstance(contributor, Contributor):
self.contributors.append(contributor)
else:
raise TypeError('Expected Contributor, got {t}'.format(t=type(contributor)))
def add_person(self, person):
self.contributors.append(Contributor(person, Organization()))
def add_parent(self, parent):
self.parents.append(parent)
if isinstance(parent, Parent):
self.parents.append(parent)
else:
raise TypeError('Expected Parent, got {t}'.format(t=type(parent)))
class Figure(GcisObject):
......@@ -134,7 +140,7 @@ class Figure(GcisObject):
return super(Figure, self).as_json(omit_fields=omit_fields)
def __str__(self):
string = '{f_id}: Figure {f_num}: {f_name}\n\tImages: {imgs}'.format(
string = '<Figure: id:{f_id} fignum:{f_num} name:{f_name}>\n\t[Images: {imgs}]'.format(
f_id=self.identifier, f_num=self.figure_num, f_name=self.title, imgs=[i.identifier for i in self.images]
)
return string
......@@ -170,7 +176,7 @@ class Report(GcisObject):
return super(Report, self).as_json(omit_fields=omit_fields)
def __repr__(self):
return 'Report: {id}'.format(id=self.identifier)
return '<Report: id:{id}>'.format(id=self.identifier)
def __str__(self):
return self.__repr__()
......@@ -186,7 +192,7 @@ class Chapter(GcisObject):
return super(Chapter, self).as_json(omit_fields=omit_fields)
def __repr__(self):
return 'Chapter: {id}'.format(id=self.identifier)
return '<Chapter: id:{id}>'.format(id=self.identifier)
def __str__(self):
return self.__repr__()
......@@ -203,15 +209,9 @@ class Image(GcisObject):
super(Image, self).__init__(data, fields=self.gcis_fields, trans=trans)
#Hack
self.identifier = self.identifier.replace('/image/', '') if self.identifier else None
self.local_path = local_path
self.remote_path = remote_path
#This does not accurately reflect GCIS' data model
self.datasets = []
@property
def create_dt(self):
return self._create_dt
......@@ -224,81 +224,31 @@ class Image(GcisObject):
self._create_dt = None
def __str__(self):
return 'Image: {id}: {name}'.format(id=self.identifier, name=self.title)
return '<Image: id:{id} name:{name}>'.format(id=self.identifier, name=self.title)
class Dataset(GcisObject):
def __init__(self, data, trans=()):
def __init__(self, data, trans=(), known_ids=None):
self.gcis_fields = ['contributors', 'vertical_extent', 'native_id', 'href', 'references', 'cite_metadata',
'scale', 'publication_year', 'temporal_extent', 'version', 'parents', 'scope', 'type',
'processing_level', 'files', 'data_qualifier', 'access_dt', 'description', 'spatial_ref_sys',
'spatial_res', 'spatial_extent', 'doi', 'name', 'url', 'uri', 'identifier', 'release_dt',
'attributes']
#This desperately needs to get added to the webform
self._identifiers = {
'Global Historical Climatology Network - Daily': 'nca3-ghcn-daily-r201305',
'Global Historical Climatology Network - Monthly': 'nca3-ghcn-monthly-r201305',
'NCDC Merged Land and Ocean Surface Temperature': 'nca3-mlost',
'NOAA Merged Land-Ocean Surface Temperature Analysis (MLOST)': 'nca3-mlost',
'U.S. Climate Divisional Dataset Version 2': 'nca3-cddv2-r1',
'Climate Division Database Version 2': 'nca3-cddv2-r1',
'Eighth degree-CONUS Daily Downscaled Climate Projections by Katharine Hayhoe': 'nca3-cmip3-downscaled-r201304',
'Eighth degree-CONUS Daily Downscaled Climate Projections': 'nca3-cmip3-downscaled-r201304',
'Earth Policy Institute Atmospheric Carbon Dioxide Concentration, 1000-2012': 'nca3-epi-co2-r201307',
'Daily 1/8-degree gridded meteorological data [1 Jan 1949 - 31 Dec 2010]': 'nca3-maurer-r201304',
'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-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',
'World Climate Research Programme\'s (WCRP\'s) Coupled Model Intercomparison Project phase 3 (CMIP3) multi-model dataset': 'nca3-cmip3-r201205',
'World Climate Research Program\'s (WCRP\'s) Coupled Model Intercomparison Project phase 3 (CMIP3) multi-model dataset': 'nca3-cmip3-r201205',
'North American Regional Climate Change Assessment Program dataset': 'nca3-narccap-r201205',
'Gridded Population of the World Version 3 (GPWv3): Population Count Grid': 'nca3-gpwv3-r201211',
'ETCCDI Extremes Indices Archive': 'nca3-etccdi-r201305',
'Historical Climatology Network Monthly (USHCN) Version 2.5': 'nca3-ushcn',
'Annual Maximum Ice Coverage (AMIC)': 'nca3-amic-r201308',
'Global Historical Climatology Network-Daily (GHCN-D) Monthly Summaries: North American subset': 'nca3-ghcnd-monthly-summaries-r201401',
'Global Sea Level From TOPEX & Jason Altimetry': 'nca3-topex-jason-altimetry-r1',
'World Climate Research Program\'s (WCRP\'s) Coupled Model Intercomparison Project phase 5 (CMIP5) multi-model ensemble': 'nca3-cmip5-r1',
'Global CO2 Emissions from Fossil-Fuel Burning, Cement Manufacture, and Gas Flaring: 1751-2009': 'nca3-doe-co2-r201209',
'Proxy-based reconstructions of hemispheric and global surface temperature variations over the past two millennia': 'nca3-mann-recons-r200809',
'EPICA Dome C Ice Core 800KYr Carbon Dioxide Data': 'nca3-epica-ice-core-r20080515',
'Western U.S. Percent Area Moderately to Extremely Dry and Moderately to Extremely Wet': 'nca3-western-us-wet-dry-r2012',
'Total Wildland Fires and Acres (1960-2009)': 'nca3-wildland-fires-r1',
'HadCRUT4': 'nca3-hadcrut4-v4_1_1_0',
'GISS Surface Temperature Analysis (GISTEMP)': 'nca3-gistemp-r2010',
'Solar Constant': 'nca3-solar-constant-r20131003',
#Surely we can do better
'Proxy Data': 'nca3-proxy-data-r1',
'Tide Gauge Data': 'nca3-tide-gauge-data-r1',
'Projected Sea Level Rise': 'nca3-projected-sea-level-rise-r1',
}
'scale', 'publication_year', 'temporal_extent', 'version', 'parents', 'scope', 'type',
'processing_level', 'files', 'data_qualifier', 'access_dt', 'description',
'spatial_ref_sys', 'spatial_res', 'spatial_extent', 'doi', 'name', 'url', 'uri',
'identifier', 'release_dt', 'attributes']
#TODO: This hack has got to go.
self._identifiers = known_ids
#Private attributes for handling date parsing
self._release_dt = None
self._access_dt = None
self._publication_year = None
#These do not accurately reflect GCIS' data model
self.note = None
self.activity = None
super(Dataset, self).__init__(data, fields=self.gcis_fields, trans=trans)
self.identifier = self._identifiers[self.name] if self._identifiers and 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://')
self.identifier = self._identifiers[self.name] if self._identifiers and self.name in self._identifiers else self.identifier
def __repr__(self):
return 'Dataset: {id}: {name}'.format(id=self.identifier, name=self.name)
return '<Dataset: id:{id} name:{name}>'.format(id=self.identifier, name=self.name)
def __str__(self):
return self.__repr__()
......@@ -343,7 +293,7 @@ class Dataset(GcisObject):
@publication_year.setter
def publication_year(self, value):
match = re.search('\d{4}', value) if value else None
match = re.search('\d{4}', str(value)) if value else None
if match:
self._publication_year = match.group()
else:
......@@ -362,7 +312,7 @@ class Activity(GcisObject):
return super(Activity, self).as_json(omit_fields=omit_fields)
def __repr__(self):
return 'Activity: {id}'.format(id=self.identifier)
return '<Activity: id:{id}>'.format(id=self.identifier)
def __str__(self):
return self.__repr__()
......@@ -379,7 +329,7 @@ class Person(Gcisbase):
return super(Person, self).as_json(omit_fields=omit_fields)
def __repr__(self):
return 'Person: {id}: {fn} {ln}'.format(id=self.id, fn=self.first_name, ln=self.last_name)
return '<Person: id:{id} first:{fn} last:{ln}>'.format(id=self.id, fn=self.first_name, ln=self.last_name)
def __str__(self):
return self.__repr__()
......@@ -389,43 +339,10 @@ class Organization(Gcisbase):
def __init__(self, data, trans=()):
self.gcis_fields = ['organization_type_identifier', 'url', 'uri', 'href', 'country_code', 'identifier', 'name']
self._identifiers = {
'NOAA NCDC/CICS-NC': 'cooperative-institute-climate-satellites-nc',
'NCDC/CICS-NC': 'cooperative-institute-climate-satellites-nc',
'NOAA NCDC/CICS NC': 'cooperative-institute-climate-satellites-nc',
'NESDIS/NCDC': 'national-climatic-data-center',
'NCDC': 'national-climatic-data-center',
'U.S. Forest Service': 'us-forest-service',
'NOAA Pacific Marine Environmental Laboratory': 'pacific-marine-environmental-laboratory',
'Jet Propulsion Laboratory': 'jet-propulsion-laboratory',
'HGS Consulting': 'hgs-consulting-llc',
'University of Virginia': 'university-virginia',
'Miami-Dade Dept. of Regulatory and Economic Resources': 'miami-dade-dept-regulatory-economic-resources',
'Nansen Environmental and Remote Sensing Center': 'nansen-environmental-and-remote-sensing-center',
'University of Illinois at Urbana-Champaign': 'university-illinois',
'USGCRP': 'us-global-change-research-program',
'National Park Service': 'national-park-service',
'Institute of the Environment': 'university-arizona',
'USGS': 'us-geological-survey',
'University of Puerto Rico': 'university-puerto-rico',
'University of Alaska': 'university-alaska',
'U.S. Department of Agriculture': 'us-department-agriculture',
'Kiksapa Consulting': 'kiksapa-consulting-llc',
'Centers for Disease Control and Prevention': 'centers-disease-control-and-prevention',
'Pacific Northwest Laboratories': 'pacific-northwest-national-laboratory',
'Susanne Moser Research & Consulting': 'susanne-moser-research-consulting',
'NEMAC': 'national-environmental-modeling-analysis-center',
'LBNL': 'lawrence-berkeley-national-laboratory',
'Texas Tech University': 'texas-tech-university'
}
super(Organization, self).__init__(data, fields=self.gcis_fields, trans=trans)
if not self.identifier:
self.identifier = self._identifiers[self.name] if self.name in self._identifiers else None
def __repr__(self):
return 'Organization: {id}: {name}'.format(id=self.identifier, name=self.name)
return '<Organization: id:{id} name:{name}>'.format(id=self.identifier, name=self.name)
def __str__(self):
return self.__repr__()
......@@ -435,44 +352,6 @@ class Contributor(Gcisbase):
def __init__(self, data):
self.gcis_fields = ['role_type_identifier', 'organization_uri', 'uri', 'href', 'person_uri', 'person_id', 'id']
#Hack
self.people_role_map = {
'Kenneth Kunkel': 'scientist',
'Xungang Yin': 'scientist',
'Nina Bednarsek': 'scientist',
'Henry Schwartz': 'scientist',
'Jessicca Griffin': 'graphic_artist',
'James Youtz': 'scientist',
'Chris Fenimore': 'scientist',
'Deb Misch': 'graphic_artist',
'James Galloway': 'scientist',
'Laura Stevens': 'scientist',
'Nichole Hefty': 'point_of_contact',