def load(): masterpath = database.localpath("awash/counties.csv") fipsdb = database.StaticCSVDatabase(masterpath, 'fips') dbs = [] for filepath in glob.glob(database.localpath("groundwater/*.txt")): if os.path.basename(filepath) == 'notes.txt': continue db = database.OrderedVectorDatabase.read_text( filepath, os.path.basename(filepath[:-4]), 2010, fipsdb) if os.path.basename(filepath[:-4]) == 'aquifer_depth': db.set_metainfo( database.UniformMetainfo("Depth to groundwater table", "m")) if os.path.basename(filepath[:-4]) == 'piezohead0': db.set_metainfo(database.UniformMetainfo("piezohead", "m")) if os.path.basename(filepath[:-4]) == 'county_area': db.set_metainfo(database.UniformMetainfo("county area", "m^2")) if os.path.basename(filepath[:-4]) == 'county_elevation': db.set_metainfo(database.UniformMetainfo("county elevation", "m")) if os.path.basename(filepath[:-4]) == 'drawdown0': db.set_metainfo(database.UniformMetainfo("draw down", "m")) if os.path.basename(filepath[:-4]) == 'vector_storativity': db.set_metainfo(database.UniformMetainfo(" ", "None")) dbs.append(db) return database.ConcatenatedDatabase(dbs)
def load(): crime = database.MatrixCSVDatabase( database.localpath('crime/baseline.csv'), 'county', get_varyears=lambda df, var: [2005]) crime.set_metainfo( database.StoredMetainfo.load(database.localpath('crime/fields.fgh'))) return crime
def __init__(self, crop, includeus=True, includecrop=False): self.crop = crop self.includeus = includeus self.includecrop = includecrop data = pd.read_csv(localpath("ers/ers.csv")) self.data = data[data["crop"] == crop] self.link = pd.read_csv(localpath("ers/reglink.csv"))
def load(): get_fips = lambda df: np.array(df['NHGISST']) * 100 + np.array(df[ 'NHGISCTY']) / 10 variable_filter = lambda cols: filter( lambda col: 'NHGIS' in col or 'mean' in col or 'sum' in col or col == 'STATENAM', cols) metainfo = database.StoredMetainfo({ 'NHGISNAM': dict(unit="name"), 'NHGISST': dict(unit="code"), 'NHGISCTY': dict(unit="code"), 'STATENAM': dict(unit="name"), 'solarsum': dict(unit="W"), 'solarmean': dict(unit="W/m^2"), 'windsum': dict(unit="m^3/s"), 'windmean': dict(unit="m/s"), 'windpowerm': dict(unit="W"), 'windpowers': dict(unit="W/m^2") }) db = database.StaticCSVDatabase( database.localpath("energy/repotential.csv"), get_fips, variable_filter) db.set_metainfo(metainfo) return db
def load(): census = database.MatrixCSVDatabase( database.localpath('census/DataSet.csv'), 'fips', get_varyears=lambda df, var: [2000 + int(var[-2:])]) census.set_metainfo(database.FunctionalMetainfo(get_description, get_unit)) return census
def load(): metainfo = database.StoredMetainfo({'NHGISNAM': dict(unit="name"), 'NHGISST': dict(unit="code"), 'NHGISCTY': dict(unit="code"), 'STATENAM': dict(unit="name"), 'bio1_mean': dict(unit='dC'), 'bio2_mean': dict(unit='dC'), 'bio5_mean': dict(unit='dC'), 'bio6_mean': dict(unit='dC'), 'bio7_mean': dict(unit='dC'), 'bio8_mean': dict(unit='dC'), 'bio9_mean': dict(unit='dC'), 'bio10_mean': dict(unit='dC'), 'bio11_mean': dict(unit='dC'), 'bio12_mean': dict(unit='mm'), 'bio13_mean': dict(unit='mm'), 'bio14_mean': dict(unit='mm'), 'bio16_mean': dict(unit='mm'), 'bio17_mean': dict(unit='mm'), 'bio18_mean': dict(unit='mm'), 'bio19_mean': dict(unit='mm')}) get_fips = lambda df: np.array(df['NHGISST']) * 100 + np.array(df['NHGISCTY']) / 10 variable_filter = lambda cols: filter(lambda col: 'NHGIS' in col or '_mean' in col or col == 'STATENAM', cols) current = database.StaticCSVDatabase(database.localpath("climate/bioclims-current.csv"), get_fips, variable_filter) current.set_metainfo(metainfo) dbs = [current] prefixes = ['current'] for filepath in glob.glob(database.localpath("climate/bioclims-2050/*.csv")): db = database.StaticCSVDatabase(filepath, get_fips, variable_filter, year=2050) db.set_metainfo(metainfo) dbs.append(db) prefixes.append(filepath[filepath.rindex('/')+1:filepath.rindex('/')+3]) return database.CombinedDatabase(dbs, prefixes, '.')
def load(): allage = database.StaticCSVDatabase( database.localpath('mortality/cmf-1999-2010.txt'), 'County Code', year=2004, sep='\t') allage.set_metainfo(metainfo.StoredMetainfo(infos)) byage = database.InterlevedCSVDatabase( database.localpath("mortality/cmf-age-1999-2010.txt"), 'County Code', 'Age Group', 2004, sep='\t') byage.set_metainfo(metainfo.StoredMetainfo(infos)) return database.CombinedDatabase([allage, byage], ['all', 'age'], '.')
def load(): metainfo = database.FunctionalMetainfo(get_description, get_unit) x20082012 = database.MatrixCSVDatabase( database.localpath("election/2008-2012.csv"), 'FIPS', database.variable_filtermap(column2variable_2008), get_varyears_2008, get_datarows_2008) x20082012.set_metainfo(metainfo) x20122016 = database.MatrixCSVDatabase( database.localpath( "election/US_County_Level_Presidential_Results_12-16.csv"), 'combined_fips', database.variable_filtermap(column2variable_2016), get_varyears_2016, get_datarows_2016) x20122016.set_metainfo(metainfo) return database.CombinedDatabase([x20082012, x20122016], ['x20082012', 'x20122016'], '.')
def load(): centroid = database.MatrixCSVDatabase( database.localpath("acra/centroids.csv"), 'fips', get_varyears=lambda df, var: [None]) centroid.set_metainfo( database.StoredMetainfo.load(database.localpath("acra/fields.fgh"))) elevation = database.MatrixCSVDatabase( database.localpath("acra/elevation.csv"), 'fips', get_varyears=lambda df, var: [None]) elevation.set_metainfo( database.StoredMetainfo.load(database.localpath("acra/fields.fgh"))) name = database.MatrixCSVDatabase( database.localpath("acra/us-county-names.csv"), 'fips', get_varyears=lambda df, var: [None]) name.set_metainfo( database.StoredMetainfo.load(database.localpath("acra/fields.fgh"))) dbs = [centroid, elevation, name] prefixes = ['centroid', 'elevation', 'name'] return database.CombinedDatabase(dbs, prefixes, '.')
import database import re filepath = database.localpath("USGS/USGS_gw_sw_use.xlsx") def get_description(variable): chunks = variable.split('_') if len(chunks) == 1: return "unknown" source = dict(SW="surface water", GW="groundwater", To="total extractions")[chunks[1]] demand = dict(PS="public supply", PT="thermoelectric generation", DO="domestic use", IR="irrigation", IN="industrial use", MI="mining", LI="livestock", TO="total use")[chunks[0]] return "%s for %s" % (source, demand) def get_unit(variable): if re.match(r"^[A-Z]{2}_[GSWTo]{2}$", variable): return "Mgal/day" elif variable == 'TP_TotPop': return "1e3 people" elif variable == 'YEAR':
def load(): filepath = database.localpath("labor/lab_cty_00_05_sum.csv") db = database.StaticCSVDatabase(filepath, 'fips', year=2002) db.set_metainfo(metainfo.StoredMetainfo.load_csv(database.localpath("labor/info.csv"), 'variable', 'description', 'unit')) return db
def load(): filepath = database.localpath("ccimpacts/county_damage_mapping_data.csv") db = database.StaticCSVDatabase(filepath, 'fips', year=2090) db.set_metainfo(metainfo.StoredMetainfo(metas)) return db