Beispiel #1
0
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, '.')
Beispiel #2
0
    def get_database(self):
        if not self.loaded:
            return None

        if self.loaded and len(self.loaded) == 1:
            return self.loaded.values()[0]

        return database.CombinedDatabase(self.loaded.values(),
                                         self.loaded.keys(), '.')
Beispiel #3
0
def load():
    dbs = []
    prefixes = []

    metainfo = database.StoredMetainfo({
        'FIPS': dict(unit="name"),
        'Alfalfa': dict(unit="acre"),
        'Otherhay': dict(unit="acre"),
        'Barley': dict(unit="acre"),
        'Barley.Winter': dict(unit="acre"),
        'Maize': dict(unit="acre"),
        'Sorghum': dict(unit="acre"),
        'Soybean': dict(unit="acre"),
        'Wheat': dict(unit="acre"),
        'Wheat.Winter': dict(unit="acre"),
        'fips': dict(unit="name"),
        'known': dict(unit="acre"),
        'total': dict(unit="acre"),
        'barley': dict(unit="acre"),
        'corn': dict(unit="acre"),
        'sorghum': dict(unit="acre"),
        'soybeans': dict(unit="acre"),
        'wheat': dict(unit="acre"),
        'hay': dict(unit="acre")
    })

    db = database.StaticCSVDatabase(os.path.join(pathhere,
                                                 "irrigatedareas.csv"),
                                    'FIPS',
                                    year=2010)
    db.set_metainfo(metainfo)
    dbs.append(db)
    prefixes.append('irrigatedareas')

    db = database.StaticCSVDatabase(os.path.join(pathhere, "rainfedareas.csv"),
                                    'FIPS',
                                    year=2010)
    db.set_metainfo(metainfo)
    dbs.append(db)
    prefixes.append('rainfedareas')

    db = database.StaticCSVDatabase(os.path.join(pathhere, "knownareas.csv"),
                                    'fips',
                                    year=2010)
    db.set_metainfo(metainfo)
    dbs.append(db)
    prefixes.append('knownareas')

    db = database.StaticCSVDatabase(os.path.join(pathhere, "totalareas.csv"),
                                    'FIPS',
                                    year=2010)
    db.set_metainfo(metainfo)
    dbs.append(db)
    prefixes.append('totalareas')

    return database.CombinedDatabase(dbs, prefixes, '.')
Beispiel #4
0
def load():
    dbs = []
    prefixes = []

    fielddb = fields.load()
    dbs.append(fielddb)
    prefixes.append("field")

    weatherdb = weather.load()
    dbs.append(weatherdb)
    prefixes.append("weather")

    areadb = areas.load()
    dbs.append(areadb)
    prefixes.append("area")

    return database.CombinedDatabase(dbs, prefixes, '.')
Beispiel #5
0
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, '.')
Beispiel #6
0
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'], '.')
Beispiel #7
0
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'], '.')
Beispiel #8
0
def load():
    dbs = []
    prefixes = []

    master = database.MatrixCSVDatabase(masterpath, 'FIPS')
    master.set_metainfo(
        database.FunctionalMetainfo(master_get_description, master_get_unit))

    dbs.append(master)
    prefixes.append('agmaster')

    for filename in glob.glob(os.path.join(pathhere, "allyears/*.csv")):
        filename = os.path.basename(filename)
        areamatch = re.match(r'([a-z]+)_area_([a-z]+)_in_acre\.csv', filename)
        if areamatch:
            crop = areamatch.group(1)
            measured = areamatch.group(2)

            db = MatrixDatabase(os.path.join(pathhere, "allyears", filename),
                                crop, 'acre', 'AREA_%s' % measured.upper())
            dbs.append(db)
            prefixes.append('%s-area' % crop)
            continue

        prodmatch = re.match(r'([a-z]+)_production_in_([a-z]+)\.csv', filename)
        if prodmatch:
            crop = prodmatch.group(1)
            unit = prodmatch.group(2)

            db = MatrixDatabase(os.path.join(pathhere, "allyears", filename),
                                crop, unit, 'PRODUCTION')
            dbs.append(db)
            prefixes.append('%s-production' % crop)
            continue

        usdamatch = re.match(r'([a-z]+)-([a-z]+)-([a-z]+)\.csv', filename)
        if usdamatch:
            crop = usdamatch.group(1)
            isirr = usdamatch.group(2)
            report = usdamatch.group(3)

            db = USDADatabase(os.path.join(pathhere, "allyears", filename),
                              crop, isirr, report)
            dbs.append(db)
            prefixes.append('%s-%s-%s' % (crop, isirr, report))
            continue

        usda2007match = re.match(r'([a-z]+)-total-([a-z]+)-2007\.csv',
                                 filename)
        if usda2007match:
            crop = usda2007match.group(1)
            isirr = 'total'
            report = usda2007match.group(2)

            db = USDADatabase(os.path.join(pathhere, "allyears", filename),
                              crop, isirr, report)
            dbs.append(db)
            prefixes.append('%s-%s-%s' % (crop, isirr, report))
            continue

    return database.CombinedDatabase(dbs, prefixes, '.')