import sys sys.path.append("../lib") import os, csv import numpy as np from netCDF4 import Dataset import readbio units_clevel = "deg. C change" units_pfrac = "percent change" bios = [1, 2, 4, 5, 6, 12, 13, 14] units = [units_clevel] * 2 + [units_pfrac] + [units_clevel] * 2 + [units_pfrac] * 3 latitudes = readbio.latitudes() longitudes = readbio.longitudes() with open("tropics.csv", "w") as fp: writer = csv.writer(fp) writer.writerow(["biovar", "baseline", "median"] + ["gcm" + str(ii) for ii in range(1, 18)]) for ii in range(len(bios)): bio = bios[ii] print bio baseline = readbio.baseline(bio) bioconfig = baseline.get_config() gcm_grids = readbio.futures(bio, bioconfig)
rootgrp = Dataset("bio-" + str(bio) + ".nc4", 'w', format="NETCDF4") lat = rootgrp.createDimension('lat', readbio.latcount) lon = rootgrp.createDimension('lon', readbio.loncount) latitudes = rootgrp.createVariable("latitude","f4",("lat",)) latitudes.units = "degrees North" longitudes = rootgrp.createVariable("longitude","f4",("lon",)) longitudes.units = "degrees East" medians = rootgrp.createVariable("change", "f4", ("lat", "lon")) medians.units = units[ii] confs = rootgrp.createVariable("confidence", "f4", ("lat", "lon")) confs.units = "percent" latitudes[:] = readbio.latitudes() longitudes[:] = readbio.longitudes() medians[:, :] = readbio.zeromap() confs[:, :] = readbio.zeromap() for rr in range(len(latitudes)): print rr for cc in range(len(longitudes)): values = readbio.values(gcm_grids, latitudes[rr], longitudes[cc]) baseval = baseline.getll_raw(latitudes[rr], longitudes[cc]) if units[ii] == units_clevel: values = (values - baseval) / 10.0 else: values = 100.0 * (values / float(baseval) - 1)