def modeldesc(request): '''Generates information to complete AR5 table 1, i.e model descriptions ''' #get models to pass to ModelTable table object models = getModels(pubonly=True) #retrieve fields to be tabulated fields = ar5_modeldesc_fields mod_desc = ModelTable(table_title='AR5 Model Description Table', models=models, fields = fields) mod_desc = getModels(pubonly=True) #generate information for ar5 table 1 table1info = modeldesctable(models) # set up my urls ... urls = {} urls['home'] = reverse('cmip5q.explorer.views_ar5.home', args=()) urls['ar5csv'] = reverse('cmip5q.explorer.views_ar5.ar5csv', args=()) urls['ar5bib'] = reverse('cmip5q.explorer.views_ar5.ar5bib', args=()) return render_to_response('explorer/ar5/modeldesc.html', {'table1': table1info, 'urls': urls})
def ar5bib(request): ''' Generates a text file of all references used in ar5 table 1 ''' #get all models models = getModels(pubonly=True) table1info = modeldesctable(models) #iterate through all models and pull out references modelrefs = [] for model in table1info: for refs in [model.maincits, model.aercits, model.atmoscits, model.atmchemcits, model.licecits, model.lsurfcits, model.obgccits, model.oceancits, model.seaicecits]: if not isinstance(refs, str): for ref in refs: if ref[0] == '"' or ref[0] == "'": ref = ref[1:] #check for duplicates before adding if ref + '\n' + '\n' not in modelrefs: modelrefs.append(ref + '\n' + '\n') #sort alphabetically and join up into a full string modelrefs.sort() ar5refs = "".join(modelrefs) response = HttpResponse(ar5refs, mimetype="text/plain") response['Content-Disposition'] = 'attachment; filename=ar5_refs.txt' return response
def create_modeldesc(request): '''Generates information to complete AR5 table 1, i.e model descriptions ''' #get real models models = getModels(pubonly=True) #generate information for ar5 table 1 table1info = modeldesctable(models) # set up my urls ... urls = {} urls['home'] = reverse('cmip5q.explorer.views_ar5.home', args=()) urls['ar5csv'] = reverse('cmip5q.explorer.views_ar5.ar5csv', args=()) urls['ar5bib'] = reverse('cmip5q.explorer.views_ar5.ar5bib', args=()) return render_to_response('explorer/ar5/modeldesc.html', {'table1': table1info, 'urls': urls})
def ar5csv(request): ''' Generates csv representation of ar5 table 1 ''' #get date for csv file title now = datetime.datetime.now() filename = 'ar5csv_modeldesc_%d_%d_%d.csv' % (now.day, now.month, now.year) # Create the HttpResponse object with the appropriate CSV header. response = HttpResponse(mimetype='text/csv') response['Content-Disposition'] = 'attachment; filename=%s' % filename #----- Table 1 (Models) ----- #get real models models = getModels(pubonly=True) #generate information for ar5 table 1 table1info = modeldesctable(models) writer = csv.writer(response) #write column headings writer.writerow(['Model ID| Vintage', 'Institution| Main references', 'Aerosol component name| Aerosol references', 'Atmosphere component name| Atmosphere horizontal grid | Atmosphere grid number of levels| Atmosphere grid top| Atmosphere references', 'Atmos chemistry component name| Atmos chemistry references', 'land ice component name| Land ice references', 'Land surface component name| Land surface references', 'Ocean biogeochem component name| Ocean biogeochem references', 'Ocean component name| Ocean horizontal grid | Ocean number of levels| Ocean top level| Ocean Z coordinate| Ocean top BC | Ocean references', 'Sea ice component name| Sea ice references', ]) #write out each row of information in turn for row in table1info: # first group references into a combined string maincits = [] for cit in row.maincits: maincits.append(cit + '; ') maincits = "".join(maincits).encode("utf-8") if not row.aerimplemented: aercits = 'None' else: aercits = [] for cit in row.aercits: aercits.append(cit + '; ') aercits = "".join(aercits).encode("utf-8") if not row.atmosimplemented: atmoscits = 'None' else: atmoscits = [] for cit in row.atmoscits: atmoscits.append(cit + '; ') atmoscits = "".join(atmoscits).encode("utf-8") if not row.atmchemimplemented: atmchemcits = 'None' else: atmchemcits = [] for cit in row.atmchemcits: atmchemcits.append(cit + '; ') atmchemcits = "".join(atmchemcits).encode("utf-8") if not row.liceimplemented: licecits = 'None' else: licecits=[] for cit in row.licecits: licecits.append(cit+'; ') licecits = "".join(licecits).encode("utf-8") if not row.lsurfimplemented: lsurfcits = 'None' else: lsurfcits=[] for cit in row.lsurfcits: lsurfcits.append(cit+'; ') lsurfcits = "".join(lsurfcits).encode("utf-8") if not row.obgcimplemented: obgccits = 'None' else: obgccits=[] for cit in row.obgccits: obgccits.append(cit+'; ') obgccits = "".join(obgccits).encode("utf-8") if not row.oceanimplemented: oceancits = 'None' else: oceancits=[] for cit in row.oceancits: oceancits.append(cit+'; ') oceancits = "".join(oceancits).encode("utf-8") if not row.seaiceimplemented: seaicecits = 'None' else: seaicecits=[] for cit in row.seaicecits: seaicecits.append(cit+'; ') seaicecits = "".join(seaicecits).encode("utf-8") writer.writerow([row.abbrev+'| '+ str(row.yearReleased), row.centre.name.encode("utf-8")+'| '+ maincits, row.aerabbrev.encode("utf-8")+'| '+aercits, row.atmosabbrev.encode("utf-8")+'| '+row.atmoshorgrid.encode("utf-8")+'| '+row.atmosnumlevels.encode("utf-8")+'| '+row.atmosgridtop.encode("utf-8")+'|'+atmoscits, row.atmchemabbrev.encode("utf-8")+'| '+'| '+atmchemcits, row.liceabbrev.encode("utf-8")+'| '+'| '+licecits, row.lsurfabbrev.encode("utf-8")+'| '+ lsurfcits, row.obgcabbrev.encode("utf-8")+'| '+ obgccits, row.oceanabbrev.encode("utf-8")+'| '+row.oceanhorgrid.encode("utf-8")+'| '+row.oceannumlevels.encode("utf-8")+'| '+row.oceantoplevel.encode("utf-8")+'| '+row.oceanzcoord.encode("utf-8")+'| '+row.oceantopbc.encode("utf-8")+'| '+oceancits, row.seaiceabbrev.encode("utf-8")+'| '+ seaicecits, ]) return response