def makeNode(self, hholds, units, geocode='0'): hhold_hist, unit_hist = table2hists( np.array(hholds), self.schema), table2hists(np.array(units), self.unit_schema, CC.ATTR_HHGQ, units=True) invar = InvariantsMaker.make(schema=CC.SCHEMA_HOUSEHOLD2010, raw=hhold_hist, raw_housing=unit_hist, invariant_names=('tot', 'gqhh_vect')) cons = HHConstraintsCreator( hist_shape=(hhold_hist.shape, unit_hist.shape), invariants=invar, constraint_names=('no_vacant', 'living_alone', 'size2')).calculateConstraints().constraints_dict node = GeounitNode(raw=hhold_hist, raw_housing=unit_hist, invar=invar, cons=cons, geocode_dict={1: 'Stub'}, geocode=geocode) node.syn = node.raw return node
def makeNode(self, persons, geocode='0123456789abcdef'): person_hist, unit_hist = table2hists(np.array(persons), self.schema, housing_varname=CC.ATTR_HHGQ) invar = InvariantsMaker.make(schema=CC.DAS_DHCP_HHGQ, raw=person_hist, raw_housing=unit_hist, invariant_names=('tot', 'gqhh_tot', 'gqhh_vect')) cons = PConstraintsCreator( hist_shape=(person_hist.shape, unit_hist.shape), invariants=invar, constraint_names=( 'hhgq_total_lb', 'hhgq_total_ub', 'nurse_nva_0')).calculateConstraints().constraints_dict node = GeounitNode(raw=person_hist, raw_housing=unit_hist, invar=invar, cons=cons, geocode_dict={ 16: 'Block', 12: 'Block_Group', 11: 'Tract', 5: 'County', 2: 'State', 1: 'US' }, geocode=geocode) node.syn = node.raw return node
def test_wconstraints(): geocode_dict = { 16: 'Block', 12: 'Block_Group', 11: 'Tract', 5: 'County' } histogram, housing_hist = table2hists( np.array( [ # columns: 'hhgq', 'votingage', 'hispanic', 'cenrace', 'unique unitid' (shape 8,2,2,63 + unitUID) # each row is a person [0, 1, 1, 20, 0], [1, 0, 0, 1, 1], [3, 1, 0, 10, 2], [3, 0, 0, 15, 2], [1, 1, 0, 15, 3] ]), SchemaMaker.fromName(CC.SCHEMA_PL94), CC.ATTR_HHGQ) inv_dict = InvariantsMaker.make(schema=CC.SCHEMA_PL94, raw=histogram, raw_housing=housing_hist, invariant_names=("tot", "gqhh_vect", "gqhh_tot", "va")) con_dict = cPL94.ConstraintsCreator(hist_shape=(histogram.shape, housing_hist.shape), invariants=inv_dict, constraint_names=("total",))\ .calculateConstraints().constraints_dict n1 = nodes.GeounitNode(geocode='123456789abcdefg', geocode_dict=geocode_dict, raw=histogram, raw_housing=housing_hist, cons=con_dict, invar=inv_dict) n2 = nodes.GeounitNode(geocode='123456789abcdefg', geocode_dict=geocode_dict, raw=histogram, raw_housing=housing_hist, cons=con_dict, invar=inv_dict) assert n1 == n2
# for adults, have to fill them with 1 minors and 3 adults, leaving 1 adult # hhgq=1: 3 facilities of other types, # for minors, can fill them with the 3 adults, leaving 1 minor, # for adults, have to fill them with 1 minor amd 2 adults, leaving 2 adults # hhgq=3: 3 facilities of other types, # for minors, can fill them with the 3 adults, leaving 1 minor, # for adults, have to fill them with 1 minor amd 2 adults, leaving 2 adults # other hhgq are 0 'hhgq_va_ub': np.array([[1, 1, 0, 1, 0, 0, 0, 0], # minors / nva [1, 2, 0, 2, 0, 0, 0, 0]] # adults / va ).transpose().ravel(), # We have 1 minors total and 4 adults total # hhgq=0: 1 facility # for minors, can fill it with 1 adult, 0 minors needed. # for adults, can fill it with 1 minor, 0 adults needed # hhgq=1: 2 facilities # for minors, can fill them with 2 adults, 0 minors needed. # for adults, can fill them with 1 minor, 1 adult needed # hhgq=3: 2 facilities # for minors, can fill them with 2 adults, 0 minors needed. # for adults, can fill them with 1 minor, 1 adult needed # other hhgq are 0 'hhgq_va_lb': np.array([[0, 0, 0, 0, 0, 0, 0, 0], # minors [0, 1, 0, 1, 0, 0, 0, 0] # adults ]).transpose().ravel(), } for data in [data1, data2, data_1gqtype]: data['hist'] = table2hists(np.array(data['data']), schema, CC.ATTR_HHGQ)
3, 'householder_ub_lhs': 0, 'spousesUnmarriedPartners_ub': 3, 'spousesUnmarriedPartners_ub_lhs': 0, 'people100Plus_ub': 6, 'people100Plus_ub_lhs': 1, 'parents_ub': 6, 'parents_ub_lhs': 0, 'parentInLaws_ub': 6, 'parentInLaws_ub_lhs': 0, } for data in [data1]: data['hist'] = table2hists(np.array(data['data']), schema), table2hists(np.array(data['units']), unit_schema, CC.ATTR_RELGQ, units=True) data_1gqtype = data1 data2 = data1
def convertPL94(d): return table2hists(d, SchemaMaker.fromName(CC.SCHEMA_PL94), CC.ATTR_HHGQ)
'size3_eld3': 0, 'size3_le25_eld3': 1, # Line 1: size=3, couple with child, hhage < 24, presence of 75+ elderly 'size4_le25_eld3': 0, 'age_child_1': 1, # line 3: hhsex male, children < 6, hhage 75+ 'age_child_2': 0, 'age_child_3': 0, 'hh_elderly_eld3': 1, # line 3: hhage 75+, no one over 60 'hh_elderly_2': 0, 'hh_elderly_3': 0, } for data in [data1, data_1gqtype]: # data['hist'] = table2hists(np.array(data['data']), schema, 'hhsex') # NOTE THAT THE 'hhsex' axis is a stub. data['hist'] = table2hists(np.array(data['data']), schema), table2hists(np.array(data['units']), unit_schema, CC.ATTR_HHTYPE_DHCH, units=True) data2 = data_1gqtype
def p_h_data1(self): return table2hists(self.d, SchemaMaker.fromName(self.schema_name)), table2hists(self.units, SchemaMaker.fromName(_unit_schema_dict[self.schema_name]), self.hhgq_attr, units=True)
def p_h_data1(self): return table2hists(self.d, SchemaMaker.fromName(self.schema_name), self.hhgq_attr)