Skip to content

Commit

Permalink
Merge pull request #611 from CartoDB/fix-acs-2010-2014
Browse files Browse the repository at this point in the history
Fix acs 2010 2014
  • Loading branch information
Javier Torres committed Jan 16, 2019
2 parents b44dd61 + eb641aa commit fa116a0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,17 @@ uk-census-middle-super-output-areas:
make -- run uk.census.wrapper.CensusMiddleSuperOutputAreas

### us
us-all: us-bls us-acs-2015 us-acs-2016 us-lodes us-spielman us-tiger-2015 us-tiger-2016 us-enviroatlas us-huc us-zillow
us-all: us-bls us-acs-2010 us-acs-2014 us-acs-2015 us-acs-2016 us-lodes us-spielman us-tiger-2015 us-tiger-2016 us-enviroatlas us-huc us-zillow

us-bls:
make -- run us.bls.AllQCEW --maxtimespan 2017Q1

us-acs-2010:
make -- run us.census.acs.ACSAll --year 2010

us-acs-2014:
make -- run us.census.acs.ACSAll --year 2014

us-acs-2015:
make -- run us.census.acs.ACSAll --year 2015

Expand Down
29 changes: 18 additions & 11 deletions tasks/us/census/acs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from tasks.util import grouper
from tasks.us.census.tiger import SumLevel, ShorelineClip, TigerBlocksInterpolation
from tasks.us.census.tiger import (SUMLEVELS, GeoidColumns, GEOID_SUMLEVEL_COLUMN, GEOID_SHORELINECLIPPED_COLUMN)
from tasks.us.census.tiger import YEARS as TIGER_YEARS
from tasks.meta import (current_session, GEOM_REF)
from .acs_columns.columns import QuantileColumns, Columns

Expand Down Expand Up @@ -81,9 +82,9 @@ def requires(self):
'table': Extract(year=self.year,
sample=self.sample,
geography=self.geography),
'tiger': GeoidColumns(year=self.year),
'sumlevel': SumLevel(geography=self.geography, year=self.year),
'shorelineclip': ShorelineClip(geography=self.geography, year=self.year)
'tiger': GeoidColumns(year=self.tiger_year()),
'sumlevel': SumLevel(geography=self.geography, year=self.tiger_year()),
'shorelineclip': ShorelineClip(geography=self.geography, year=self.tiger_year())
}

def version(self):
Expand All @@ -98,8 +99,8 @@ def targets(self):
def columns(self):
input_ = self.input()
columns = OrderedDict({
'geoidsl': input_['tiger'][self.geography + '_{}'.format(self.year) + GEOID_SUMLEVEL_COLUMN],
'geoidsc': input_['tiger'][self.geography + '_{}'.format(self.year) + GEOID_SHORELINECLIPPED_COLUMN]
'geoidsl': input_['tiger'][self.geography + '_{}'.format(self.tiger_year()) + GEOID_SUMLEVEL_COLUMN],
'geoidsc': input_['tiger'][self.geography + '_{}'.format(self.tiger_year()) + GEOID_SHORELINECLIPPED_COLUMN]
})
columns.update(input_['columns'])
return columns
Expand All @@ -109,6 +110,9 @@ def table_timespan(self):
return get_timespan('{start} - {end}'.format(start=int(self.year) - sample + 1,
end=int(self.year)))

def tiger_year(self):
return str(max(int(self.year), min(TIGER_YEARS)))

def populate(self):
connection = current_session()
input_ = self.input()
Expand Down Expand Up @@ -175,14 +179,14 @@ def version(self):
def requires(self):
dependencies = {
'acs': Columns(year=self.year, sample=self.sample, geography=self.geography),
'tiger': GeoidColumns(year=self.year),
'tiger': GeoidColumns(year=self.tiger_year()),
'data': DownloadACS(year=self.year, sample=self.sample),
'sumlevel': SumLevel(geography=self.geography, year=self.year),
'shorelineclip': ShorelineClip(geography=self.geography, year=self.year)
'sumlevel': SumLevel(geography=self.geography, year=self.tiger_year()),
'shorelineclip': ShorelineClip(geography=self.geography, year=self.tiger_year())
}

if self.geography == BLOCK:
dependencies['interpolation'] = TigerBlocksInterpolation(year=self.year)
dependencies['interpolation'] = TigerBlocksInterpolation(year=self.tiger_year())
dependencies['bg_extract'] = Extract(geography=BLOCK_GROUP, sample=self.sample, year=self.year)

return dependencies
Expand All @@ -192,6 +196,9 @@ def table_timespan(self):
return get_timespan('{start} - {end}'.format(start=int(self.year) - sample + 1,
end=int(self.year)))

def tiger_year(self):
return str(max(int(self.year), min(TIGER_YEARS)))

def targets(self):
return {
self.input()['shorelineclip'].obs_table: GEOM_REF,
Expand All @@ -201,8 +208,8 @@ def targets(self):
def columns(self):
input_ = self.input()
cols = OrderedDict([
('geoidsl', input_['tiger'][self.geography + '_{}'.format(self.year) + GEOID_SUMLEVEL_COLUMN]),
('geoidsc', input_['tiger'][self.geography + '_{}'.format(self.year) + GEOID_SHORELINECLIPPED_COLUMN]),
('geoidsl', input_['tiger'][self.geography + '_{}'.format(self.tiger_year()) + GEOID_SUMLEVEL_COLUMN]),
('geoidsc', input_['tiger'][self.geography + '_{}'.format(self.tiger_year()) + GEOID_SHORELINECLIPPED_COLUMN]),
])
for colkey, col in input_['acs'].items():
cols[colkey] = col
Expand Down
1 change: 1 addition & 0 deletions tasks/us/census/tiger.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
GEOID_SUMLEVEL_COLUMN = "_geoidsl"
GEOID_SHORELINECLIPPED_COLUMN = "_geoidsc"
BLOCK = 'block'
YEARS = [2015, 2016]


class TigerSourceTags(TagsTask):
Expand Down
4 changes: 2 additions & 2 deletions tasks/us/zillow.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ def columns(self):
raise Exception('unrecognized geography {}'.format(self.geography))

columns = OrderedDict([
('region_name_sl', input_['geoids']['{}_{}{}'.format(tiger_geo,TIGER_YEAR,GEOID_SUMLEVEL_COLUMN)]),
('region_name_sc', input_['geoids']['{}_{}{}'.format(tiger_geo,TIGER_YEAR,GEOID_SUMLEVEL_COLUMN)]),
('region_name_sl', input_['geoids']['{}_{}{}'.format(tiger_geo, TIGER_YEAR, GEOID_SUMLEVEL_COLUMN)]),
('region_name_sc', input_['geoids']['{}_{}{}'.format(tiger_geo, TIGER_YEAR, GEOID_SHORELINECLIPPED_COLUMN)]),
])
columns.update(input_['metadata'])

Expand Down

0 comments on commit fa116a0

Please sign in to comment.