def test_my_inputs(self): storage = StorageFactory().get_storage('dict_storage') parcels_table_name = 'parcels' storage.write_table( table_name=parcels_table_name, table_data={ 'parcel_id': array([1, 2, 3, 4, 5]), 'residential_units': array([1, 1, 3, 2, 3]), 'number_of_surveyed_households': array([2, 1, 3, 0, 5]), 'county': array(['033', '061', '035', '033', '033']) }, ) parcels = ParcelDataset(in_storage=storage, in_table_name=parcels_table_name) values = VariableTestToolbox().compute_variable( self.variable_name, data_dictionary={'parcel': parcels}, dataset='parcel') should_be = array( [1, 0, 0, 0, 3]) #would be a 2-D array if it spanned more than one 'directory' self.assert_(ma.allclose(values, should_be, rtol=1e-05), 'Error in ' + self.variable_name)
def test(self): storage = StorageFactory().get_storage('dict_storage') parcels_table_name = 'parcels' storage.write_table( table_name=parcels_table_name, table_data={'parcel_id': array([1, 2, 3, 4])}, ) parcels = ParcelDataset(in_storage=storage, in_table_name=parcels_table_name) values = VariableTestToolbox().compute_variable( self.variable_name, data_dictionary={ 'parcel': parcels, 'household': { 'parcel_id': array([1, 2, 3, 4, 2, 2]) } }, dataset='parcel') should_be = array([0, 1, 0, 0]) self.assert_(ma.allclose(values, should_be, rtol=1e-20), 'Error in ' + self.variable_name)
def test_my_inputs(self): storage = StorageFactory().get_storage('dict_storage') parcels_table_name = 'parcels' storage.write_table( table_name=parcels_table_name, table_data={ 'parcel_id':array([1,2,3]), 'residential_units':array([1, 2, 5]), }, ) parcels = ParcelDataset(in_storage=storage, in_table_name=parcels_table_name) values = VariableTestToolbox().compute_variable(self.variable_name, \ data_dictionary = { 'parcel':parcels }, dataset = 'parcel' ) should_be = array([False, True, False]) self.assert_(ma.allequal(values, should_be), 'Error in ' + self.variable_name)
def test_my_inputs(self): storage = StorageFactory().get_storage('dict_storage') parcels_table_name = 'parcels' storage.write_table( table_name=parcels_table_name, table_data={ 'parcel_id':array([1,2,3,4,5]), 'grid_id':array([1, 1, 3, 2, 3]) }, ) parcels = ParcelDataset(in_storage=storage, in_table_name=parcels_table_name) values = VariableTestToolbox().compute_variable(self.variable_name, \ data_dictionary = { 'gridcell':{ 'grid_id':array([1, 2, 3]), 'residential_units':array([100, 1000, 1500]) }, 'parcel':parcels }, dataset = 'parcel' ) should_be = array([100.0, 100.0, 1500.0, 1000.0, 1500.0]) self.assert_(ma.allclose(values, should_be, rtol=1e-7), 'Error in ' + self.variable_name)
def test(self): storage = StorageFactory().get_storage('dict_storage') parcels_table_name = 'parcels' storage.write_table( table_name=parcels_table_name, table_data={'parcel_id': array([1, 2, 3, 4])}, ) parcels = ParcelDataset(in_storage=storage, in_table_name=parcels_table_name) sid = number_of_surveyed_households.surveyed_households_starting_id values = VariableTestToolbox().compute_variable(self.variable_name, \ data_dictionary = { 'parcel':parcels, 'household':{ 'parcel_id': array([1, 2, 3, 4, 2, -1]), 'household_id':array([sid+1, 1, sid-5, sid, sid+100, sid+11]) } }, dataset = 'parcel' ) should_be = array([1, 1, 0, 1]) self.assert_(ma.allclose(values, should_be, rtol=1e-20), 'Error in ' + self.variable_name)
def test_my_inputs(self): storage = StorageFactory().get_storage('dict_storage') parcel_table_name = 'parcel' storage.write_table( table_name=parcel_table_name, table_data={ 'parcel_id': array([1, 2, 3, 4]), 'county': array(['033', '031', '021', '033']) }, ) parcels = ParcelDataset(in_storage=storage, in_table_name=parcel_table_name) values = VariableTestToolbox().compute_variable( self.variable_name, \ data_dictionary = { 'household':{ 'parcel_id':array([1, 1, 2, 3, 4]), }, 'parcel':parcels, }, dataset = 'household' ) should_be = array([33, 33, 31, 21, 33]) self.assert_(ma.allclose(values, should_be, rtol=1e-7), 'Error in ' + self.variable_name)
def test_my_inputs(self): storage = StorageFactory().get_storage('dict_storage') parcels_table_name = 'parcels' storage.write_table( table_name=parcels_table_name, table_data={ 'parcel_id': array([1, 2, 3, 4, 5]), 'is_in_city_seattle': array([1, 0, 1, 0, 3]), 'is_single_family_unit': array([1, 0, 0, 1, 3]), }, ) parcels = ParcelDataset(in_storage=storage, in_table_name=parcels_table_name) values = VariableTestToolbox().compute_variable(self.variable_name, data_dictionary={ 'parcel': parcels, }, dataset='parcel') should_be = array([911, 900, 910, 901, 933]) self.assert_(ma.allequal(values, should_be), 'Error in ' + self.variable_name)
def test_my_inputs(self): storage = StorageFactory().get_storage('dict_storage') parcels_table_name = 'parcels' storage.write_table( table_name=parcels_table_name, table_data={ 'parcel_id':array([1,2,3,4,5]), 'residential_units':array([2,0,1,4,7]), 'land_value':array([100,11,20,0,90]), 'improvement_value':array([20,10,17,40,17]), }, ) parcels = ParcelDataset(in_storage=storage, in_table_name=parcels_table_name) values = VariableTestToolbox().compute_variable(self.variable_name, \ data_dictionary = { 'parcel':parcels }, dataset = 'parcel' ) should_be = array([60, 0, 37, 10, 15.28571415]) self.assert_(ma.allclose(values, should_be), 'Error in ' + self.variable_name)
def test_my_inputs(self): storage = StorageFactory().get_storage('dict_storage') edges_table_name = 'edges' storage.write_table( table_name=edges_table_name, table_data={ "source": array([10, 20, 10, 30]), "target": array([2, 3, 3, 1]), "cost": array([12, 1, 15, 17]) }, ) parcels_table_name = 'parcels' storage.write_table( table_name=parcels_table_name, table_data={"parcel_id": array([1, 2, 3])}, ) households_table_name = 'households' storage.write_table( table_name=households_table_name, table_data={ "household_id": array([1, 2, 3, 4]), "parcel_id": array([3, 1, 1, 2]), "work_place_parcel_id": array([10, 30, 30, 20]) }, ) parcels = ParcelDataset(in_storage=storage, in_table_name=parcels_table_name) households = HouseholdDataset(in_storage=storage, in_table_name=households_table_name) household_x_parcels = HouseholdXParcelDataset(dataset1=households, dataset2=parcels) dataset_pool = DatasetPool( package_order=['transit_accessibility', 'psrc', 'urbansim'], storage=storage) values = household_x_parcels.compute_variables( self.variable_name, dataset_pool=dataset_pool) default_value = travel_time_hbw_transit_from_work_to_home.default_value should_be = array([[default_value, 12, 15], [17, default_value, default_value], [17, default_value, default_value], [default_value, default_value, 1]]) self.assert_(ma.allclose(values, should_be, rtol=1e-10), "Error in " + self.variable_name)
def test_my_inputs(self): storage = StorageFactory().get_storage('dict_storage') parcels_table_name = 'parcels' storage.write_table( table_name=parcels_table_name, table_data={ 'parcel_id':array([1,2,3,4,5]), 'grid_id':array([1, 2, 1, 4, 3]) }, ) parcels = ParcelDataset(in_storage=storage, in_table_name=parcels_table_name) city_storage = StorageFactory().get_storage('dict_storage') cities_table_name = 'cities' city_storage.write_table( table_name=cities_table_name, table_data={ 'city_id':array([63000, 56000, 99999]), 'city_name':array(["seattle", "bellevue", "skykomish"]) }, ) cities = CityDataset(in_storage=city_storage, in_table_name=cities_table_name) values = VariableTestToolbox().compute_variable(self.variable_name, data_dictionary = { 'parcel':parcels, 'city':cities, 'gridcell':{ 'grid_id':array([1, 2, 3, 4]), 'city_id':array([63000, 56000, 0, 63000])} }, dataset = 'parcel' ) should_be = array([True, False, True, True, False]) self.assert_(ma.allequal(values, should_be), 'Error in ' + self.variable_name)
def test_my_inputs(self): persons_storage = StorageFactory().get_storage('dict_storage') persons_table_name = 'persons' persons_storage.write_table( table_name=persons_table_name, table_data={ 'person_id': array([1, 2, 3, 4, 5, 6]), 'household_id': array([1, 1, 2, 3, 3, 3]), 'member_id': array([1, 2, 1, 1, 2, 3]), 'worker1': array([1, 0, 0, 0, 0, 1]), 'work_place_parcel_id': array([1, 2, 3, 5, 4, 4]) }, ) persons = PersonDataset(in_storage=persons_storage, in_table_name=persons_table_name) parcels_storage = StorageFactory().get_storage('dict_storage') parcels_table_name = 'parcels' parcels_storage.write_table( table_name=parcels_table_name, table_data={ 'parcel_id': array([1, 2, 3, 4, 5]), 'county': array(['033', '061', '035', '033', '033']) }, ) parcels = ParcelDataset(in_storage=parcels_storage, in_table_name=parcels_table_name) values = VariableTestToolbox().compute_variable(self.variable_name, data_dictionary={ 'person': persons, 'household': { 'household_id': array( [1, 2, 3]) }, 'parcel': parcels }, dataset='household') should_be = array([1, 1, 1]) self.assertEqual(ma.allclose(values, should_be, rtol=1e-7), \ True, msg = "Error in " + self.variable_name)
def test_my_inputs(self): storage = StorageFactory().get_storage('dict_storage') persons_table_name = 'persons' storage.write_table( table_name=persons_table_name, table_data={ 'person_id':array([1, 2, 3, 4, 5]), 'household_id':array([1, 1, 3, 3, 3]), 'member_id':array([1,2,1,2,3]), 'work_place_parcel_id':array([1,1,3,2,4]), }, ) parcels_table_name = 'jobs' storage.write_table( table_name=parcels_table_name, table_data={ 'parcel_id':array([1,2,3,4]), 'county':array(['033','035','033','053']), }, ) persons = PersonDataset(in_storage=storage, in_table_name=persons_table_name) parcels = ParcelDataset(in_storage=storage, in_table_name=parcels_table_name) values = VariableTestToolbox().compute_variable(self.variable_name, \ data_dictionary = { 'parcel':parcels, 'person':persons }, dataset = 'person' ) should_be = array(['033', '033', '033', '035', '053']) for i in range(values.size): self.assert_(values[i] == should_be[i], 'Error in ' + self.variable_name)
def test_my_inputs(self): storage = StorageFactory().get_storage('dict_storage') persons_table_name = 'persons' storage.write_table( table_name=persons_table_name, table_data={ 'person_id':array([1, 2, 3, 4, 5]), 'household_id':array([1, 1, 3, 3, 3]), 'member_id':array([1,2,1,2,3]), 'work_place_parcel_id':array([1,1,3,2,5]) }, ) parcels_table_name = 'jobs' storage.write_table( table_name=parcels_table_name, table_data={ 'parcel_id':array([1,2,3,4]), 'zone_id': array([5,6,7,8]) }, ) persons = PersonDataset(in_storage=storage, in_table_name=persons_table_name) parcels = ParcelDataset(in_storage=storage, in_table_name=parcels_table_name) values = VariableTestToolbox().compute_variable(self.variable_name, data_dictionary = { 'parcel':parcels, 'person':persons }, dataset = 'person' ) should_be = array([5, 5, 7, 6, -1]) self.assert_(ma.allclose(values, should_be, rtol=1e-7), 'Error in ' + self.variable_name)
def test_my_inputs(self): zone_id = array([1, 1, 3, 2]) parcel_id = array([1, 2, 3, 4]) parcel_storage = StorageFactory().get_storage('dict_storage') parcel_table_name = 'parcel' parcel_storage.write_table(table_name=parcel_table_name, table_data={ 'parcel_id': parcel_id, 'zone_id': zone_id }) parcels = ParcelDataset(in_storage=parcel_storage, in_table_name=parcel_table_name) values = VariableTestToolbox().compute_variable(self.variable_name, \ {'household':{ \ 'parcel_id':parcel_id}, \ 'parcel':parcels}, dataset = 'household') should_be = zone_id self.assertEqual(ma.allclose(values, should_be, rtol=1e-7), \ True, msg = 'Error in ' + self.variable_name)