Exemplo n.º 1
0
    def test_addition_of_jobs_with_one_characteristics(self):
        dataset_pool = DatasetPool(storage=self.storage, package_order=["washtenaw","urbansim", "opus_core"])
        gridcell_set = dataset_pool.get_dataset('gridcell')
        event_set = self._create_job_addition_event_set_with_characteristics()
        jobs = dataset_pool.get_dataset("job")
        AgentEventModel().run(gridcell_set, event_set, jobs, 2000, dataset_pool)
        number_of_jobs_of_sector_1 = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs_of_sector_1", 
                                                                    dataset_pool=dataset_pool)
        number_of_jobs_of_sector_2 = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs_of_sector_2", 
                                                                    dataset_pool=dataset_pool)
        number_of_jobs_of_sector_4 = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs_of_sector_4", 
                                                                    dataset_pool=dataset_pool)

        # the model should add 2 jobs of sector 1 to gridcell 1, 
        #                      5 jobs of sector 1 to gridcell 5
        self.assert_(ma.allclose(number_of_jobs_of_sector_1, array( [6,4,4,4,9,4,4,4,4,4]))) 
        # other sectors don't change
        self.assert_(ma.allclose(number_of_jobs_of_sector_2, array( 10 * [3]))) 
        self.assert_(ma.allclose(number_of_jobs_of_sector_4, array( 10 * [3]))) 

        AgentEventModel().run(gridcell_set, event_set, jobs, 2001, dataset_pool)
        number_of_jobs_of_sector_1 = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs_of_sector_1", 
                                                                    dataset_pool=dataset_pool)
        number_of_jobs_of_sector_2 = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs_of_sector_2", 
                                                                    dataset_pool=dataset_pool)
        number_of_jobs_of_sector_4 = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs_of_sector_4", 
                                                                    dataset_pool=dataset_pool)
        # the model should add 2 jobs of sector 2 to gridcell 5, 
        #                      1 job of sector 1 to gridcell 1,
        #                      4 jobs of sector 2 to gridcell 2
        #                      70% jobs of sector 2 to gridcell 3
        self.assert_(ma.allclose(number_of_jobs_of_sector_1, array( [7, 4, 4, 4, 9, 4, 4, 4, 4, 4]))) 
        self.assert_(ma.allclose(number_of_jobs_of_sector_2, array( [3, 6, 5, 3, 5, 3, 3, 3, 3, 3]))) 
        # sector 4 does not change
        self.assert_(ma.allclose(number_of_jobs_of_sector_4, array( 10 * [3])))
Exemplo n.º 2
0
    def test_addition_of_households(self):
        dataset_pool = DatasetPool(
            storage=self.storage,
            package_order=["washtenaw", "urbansim", "opus_core"])
        gridcell_set = dataset_pool.get_dataset('gridcell')
        event_set = self._create_household_addition_event_set()
        households = dataset_pool.get_dataset("household")
        AgentEventModel().run(gridcell_set, event_set, households, 2000,
                              dataset_pool)
        number_of_households = gridcell_set.compute_variables(
            "urbansim.gridcell.number_of_households",
            dataset_pool=dataset_pool)
        # the model should add 6 households to gridcell 1,
        self.assert_(
            ma.allclose(number_of_households,
                        array([16, 0, 30, 0, 5, 0, 0, 0, 0, 0])))

        AgentEventModel().run(gridcell_set, event_set, households, 2001,
                              dataset_pool)
        number_of_households = gridcell_set.compute_variables(
            "urbansim.gridcell.number_of_households",
            dataset_pool=dataset_pool)
        # the model should add 50% from gridcell 1 (8) and 25 households to gridcell 3
        self.assert_(
            ma.allclose(number_of_households,
                        array([24, 0, 55, 0, 5, 0, 0, 0, 0, 0])))
    def test_vacancy_rates_calculation(self):

        proposal_data = {
            'proposal_id': array([1]),
            }
        proposal_component_data = {
            'component_id':array([1]),
            }
        storage = StorageFactory().get_storage('dict_storage')
        storage.write_table(table_name = 'development_project_proposals', table_data = proposal_data)
        storage.write_table(table_name = 'development_project_proposal_components', table_data = proposal_component_data)
        dataset_pool = DatasetPool(storage = storage, package_order = ['urbansim_parcel', 'urbansim'])
                       
        proposal_dataset = dataset_pool.get_dataset('development_project_proposal')
        proposal_component_dataset = dataset_pool.get_dataset('development_project_proposal_component')
 
        DPPSM = DevelopmentProjectProposalSamplingModel(proposal_dataset, dataset_pool=dataset_pool, weight_string=None)
        DPPSM.existing_units =   {1:200, 2:200, 3:200, 4:200, 5:200, 6:200}
        DPPSM.demolished_units = {1:100, 2:100, 3:100, 4:50,  5:0,   6:20}
        DPPSM.proposed_units =   {1:50,  2:150, 3:80,  4:100, 5:160, 6:0}
        DPPSM.occupied_units =   {1:180, 2:180, 3:180, 4:180, 5:180, 6:180}
        
        expected = {1:0.0, 2:0.28, 3:0.0, 4:0.28, 5:0.5, 6:0.0}
        actual = {}
        for type in DPPSM.existing_units.keys():
            actual[type] = DPPSM._get_vacancy_rates(type)

        self.assertDictsEqual(actual, expected)
Exemplo n.º 4
0
    def test_vacancy_rates_calculation(self):

        proposal_data = {
            'proposal_id': array([1]),
        }
        proposal_component_data = {
            'component_id': array([1]),
        }
        storage = StorageFactory().get_storage('dict_storage')
        storage.write_table(table_name='development_project_proposals',
                            table_data=proposal_data)
        storage.write_table(
            table_name='development_project_proposal_components',
            table_data=proposal_component_data)
        dataset_pool = DatasetPool(
            storage=storage, package_order=['urbansim_parcel', 'urbansim'])

        proposal_dataset = dataset_pool.get_dataset(
            'development_project_proposal')
        proposal_component_dataset = dataset_pool.get_dataset(
            'development_project_proposal_component')

        DPPSM = DevelopmentProjectProposalSamplingModel(
            proposal_dataset, dataset_pool=dataset_pool, weight_string=None)
        DPPSM.existing_units = {1: 200, 2: 200, 3: 200, 4: 200, 5: 200, 6: 200}
        DPPSM.demolished_units = {1: 100, 2: 100, 3: 100, 4: 50, 5: 0, 6: 20}
        DPPSM.proposed_units = {1: 50, 2: 150, 3: 80, 4: 100, 5: 160, 6: 0}
        DPPSM.occupied_units = {1: 180, 2: 180, 3: 180, 4: 180, 5: 180, 6: 180}

        expected = {1: 0.0, 2: 0.28, 3: 0.0, 4: 0.28, 5: 0.5, 6: 0.0}
        actual = {}
        for type in DPPSM.existing_units.keys():
            actual[type] = DPPSM._get_vacancy_rates(type)

        self.assertDictsEqual(actual, expected)
Exemplo n.º 5
0
    def test_run_model(self):
        dataset_pool = DatasetPool(
            storage=self.storage,
            package_order=['urbansim_parcel', 'urbansim'])
        model = EmploymentEventsModel(dataset_pool=dataset_pool)
        job_set = dataset_pool.get_dataset('job')
        # run 2006
        model.run(dataset_pool.get_dataset('employment_event'),
                  job_set,
                  current_year=2006)
        results = self.get_count_all_sectors_and_areas(job_set)
        expected_results = array(
            [4100, 100, 1000, 5500, 1000, 1000, 1000, 1000, 1000])
        self.assertEqual(ma.allequal(results, expected_results), True)
        # check locations
        buildings = dataset_pool.get_dataset('building')
        jobs_in_sec_1 = buildings.compute_variables(
            ['urbansim_parcel.building.number_of_jobs_of_sector_1'],
            dataset_pool=dataset_pool)
        self.assertEqual(ma.allequal(jobs_in_sec_1, array([4100, 5500, 1000])),
                         True)
        # run 2008
        model.run(dataset_pool.get_dataset('employment_event'),
                  job_set,
                  current_year=2008)
        results = self.get_count_all_sectors_and_areas(job_set)

        expected_results = array(
            [4100, 100, 1000, 5500, 1500, 1000, 1000, 1000, 900])
        self.assertEqual(ma.allequal(results, expected_results), True)
class Tests(opus_unittest.OpusTestCase):
    ACRE = 43560
    def setUp(self):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(
            table_name='development_templates',
            table_data={
                'template_id': array([1,2,3]),
                'building_type_id': array([1, 1, 2]),
                "density_type":  array(['units_per_acre', 'units_per_acre', 'far']),                
                'density':array([0.6, 2.0, 10]),
                'percent_land_overhead':array([0, 10, 20]),
                'land_sqft_min': array([0, 10, 4],dtype=int32) * self.ACRE,
                'land_sqft_max': array([2, 20, 8],dtype=int32) * self.ACRE
            }
        )
        storage.write_table(
            table_name='development_template_components',
            table_data={
                'template_id': array([1,1,2,3,3,3]),
                'component_id': arange(6)+1
            }
        )
        storage.write_table(
            table_name='parcels',
            table_data={
                "parcel_id": array([1,   2,    3]),
                "vacant_land_area": array([1, 50,  200],dtype=int32)* self.ACRE,
            }
        )
        storage.write_table(
            table_name='development_project_proposal_components',
            table_data={
                "proposal_component_id": arange(14)+1,
                "proposal_id":array([1,  1, 2, 3, 3,3, 5,  6, 6,6,   8, 9, 9,9]),
                "template_id":array([1,  1, 2, 3, 3,3, 2,  3, 3,3,   2, 3,3,3]),
                "component_id": array([1,2,3,4,5,6, 3,4,5,6,3,4,5,6])
            }
        )

        self.dataset_pool = DatasetPool(package_order=['urbansim_parcel'],
                                   storage=storage)
        parcels = self.dataset_pool.get_dataset('parcel')
        templates = self.dataset_pool.get_dataset('development_template')
        template_components = self.dataset_pool.get_dataset('development_template_component')
        proposals = create_from_parcel_and_development_template(parcels, templates, 
                                                                dataset_pool=self.dataset_pool, resources=None)
        self.proposal_components = create_from_proposals_and_template_components(proposals, template_components)

    def test_create(self):
        proposals_components = self.dataset_pool.get_dataset("development_project_proposal_component")
        template_ids = self.proposal_components.get_attribute("template_id")
        
        self.assert_(ma.allequal(self.proposal_components.size(), proposals_components.size()))
        self.assert_(self.proposal_components.get_attribute("proposal_id").sum(), proposals_components.get_attribute("proposal_id").sum())
        self.assert_((template_ids==1).sum(), (proposals_components.get_attribute("template_id")==1).sum())
        self.assert_((template_ids==2).sum(), (proposals_components.get_attribute("template_id")==2).sum())
        self.assert_((template_ids==3).sum(), (proposals_components.get_attribute("template_id")==3).sum())
        self.assert_(self.proposal_components.get_attribute("component_id").sum(), proposals_components.get_attribute("component_id").sum())
Exemplo n.º 7
0
    def test_deletion_of_jobs_with_one_characteristics(self):
        dataset_pool = DatasetPool(storage=self.storage, package_order=["psrc_parcel","urbansim", "opus_core"])
        gridcell_set = dataset_pool.get_dataset('gridcell')
        event_set = self._create_job_deletion_event_set_with_characteristics()
        jobs = dataset_pool.get_dataset("job")
        AgentEventModel().run(gridcell_set, event_set, jobs, 2000, dataset_pool=dataset_pool)
        number_of_jobs_of_sector_1 = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs_of_sector_1", 
                                                                    dataset_pool=dataset_pool)
        number_of_jobs_of_sector_2 = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs_of_sector_2", 
                                                                    dataset_pool=dataset_pool)
        number_of_jobs_of_sector_4 = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs_of_sector_4", 
                                                                    dataset_pool=dataset_pool)
        # the model should remove 2 jobs of sector 1 from gridcell 1, 
        #                         5 jobs of sector 1 from gridcell 5
        self.assert_(ma.allclose(number_of_jobs_of_sector_1, array( [2,4,4,4,0,4,4,4,4,4]))) 
        # other sectors don't change
        self.assert_(ma.allclose(number_of_jobs_of_sector_2, array( 10 * [3]))) 
        self.assert_(ma.allclose(number_of_jobs_of_sector_4, array( 10 * [3]))) 

        AgentEventModel().run(gridcell_set, event_set, jobs, 2001, dataset_pool=dataset_pool)
        number_of_jobs_of_sector_1 = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs_of_sector_1", 
                                                                    dataset_pool=dataset_pool)
        number_of_jobs_of_sector_2 = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs_of_sector_2", 
                                                                    dataset_pool=dataset_pool)
        number_of_jobs_of_sector_4 = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs_of_sector_4", 
                                                                    dataset_pool=dataset_pool)
        # the model should remove 2 jobs of sector 2 from gridcell 5, 
        #                         1 job of sector 1 from gridcell 1,
        #                       all jobs of sector 2 from gridcell 2
        #                        70% jobs of sector 2 from gridcell 3
        self.assert_(ma.allclose(number_of_jobs_of_sector_1, array( [1,4,4,4,0,4,4,4,4,4]))) 
        self.assert_(ma.allclose(number_of_jobs_of_sector_2, array( [3, 0, 1, 3, 1, 3, 3, 3, 3, 3]))) 
Exemplo n.º 8
0
    def test_run_model_with_known_buildings(self):
        storage = self.storage
        storage.write_table(
            table_name = 'buildings',
            table_data = {
                  'building_id':    array([1,2,3,4,5,6,7]),
                  'parcel_id':      array([1,1,2,2,2,3,3]),
                  'is_residential': array([0,0,0,1,1,0,0])
                          }
                            )
        
        storage.write_table(
            table_name = 'employment_events',
            table_data = {
           'parcel_id':                     array([2,       2,    -1,     -1,   1]),
           'building_id':                   array([-1,     -1,     6,      7,  -1]),
           'scheduled_year':                array([2006, 2006,   2006,    2006, 2006]),
           'number_of_non_home_based_jobs': array([3500, 500,    -100,     0,   100]),
           'number_of_home_based_jobs':     array([0,     20,       0,    10,    0]),
           'sector_id':                     array([1,     2,       15,     2,    1]),
           'replace_non_home_based_jobs':   array([0,     0,        0,     1,    0])
                          }
                            )
        
        # change in 2006
        ############   
#        parcel/sector       1              2              3
#            1            +100nhb         +3500nhb        --
#            2            =0nhb           +500nhb/+20hb  +10hb
#            15             --             --           -100nhb
       
        dataset_pool = DatasetPool(storage=storage, package_order=['urbansim_parcel', 'urbansim'])
        job_set = JobDataset(in_storage=storage)
        job_set.modify_attribute('building_id', array(6000*[1] + 4000*[3] + 3000*[6]))
        dataset_pool.add_datasets_if_not_included({'job':job_set})
        model = EmploymentEventsModel(dataset_pool=dataset_pool)

        model.run(dataset_pool.get_dataset('employment_event'), job_set, current_year=2006)
        buildings = dataset_pool.get_dataset('building')
        jobs_in_sec_1 = buildings.compute_variables(['urbansim_parcel.building.number_of_jobs_of_sector_1'],
                                                    dataset_pool=dataset_pool)
        jobs_in_sec_2 = buildings.compute_variables(['urbansim_parcel.building.number_of_jobs_of_sector_2'],
                                                    dataset_pool=dataset_pool)
        jobs_in_sec_15 = buildings.compute_variables(['urbansim_parcel.building.number_of_jobs_of_sector_15'],
                                                    dataset_pool=dataset_pool)

        self.assertEqual(jobs_in_sec_1[0:2].sum()==4100, True) # parcel 1
        self.assertEqual(jobs_in_sec_1[2] == 5500, True) # parcel 2 non-residential
        self.assertEqual(jobs_in_sec_1[5:7].sum()==1000, True) # parcel 3
        self.assertEqual(jobs_in_sec_2[0:2].sum()==1000, True) # parcel 1
        self.assertEqual(jobs_in_sec_2[2] == 1500, True) # parcel 2 non-residential
        self.assertEqual(jobs_in_sec_2[3:5].sum() == 20, True) # parcel 2 residential
        self.assertEqual(jobs_in_sec_2[5]==100, True) # parcel 3, building 6
        self.assertEqual(jobs_in_sec_2[6]==10, True) # parcel 3, building 7
        self.assertEqual(jobs_in_sec_15[0:2].sum()==1000, True) # parcel 2 non-residential
        self.assertEqual(jobs_in_sec_15[2] == 1000, True) # parcel 2 residential
        self.assertEqual(jobs_in_sec_15[5]==900, True) # parcel 3, building 6
Exemplo n.º 9
0
 def test_demolition(self):
     demolish_buildings = array([10, 3, 180])
     household_data = {
         'household_id': arange(10)+1,
         'building_id': array([10, 3, 6, 150, 10, 10, -1, 5, 3, 3])
         # demolished         [*   *           *   *         *  *]
         }
     person_data = {
         'person_id':arange(15)+1,
         'household_id': array([1,1,2,3,3,5,4,4,4,6,7,8,9,10,10]),
        # in demolished bldgs  [* * *     *       * *   *  *  *]
         'job_id':       array([5,4,1,2,2,1,3,5,1,5,5,4,3, 3, 1])
        # in demolished bldgs  [  * *     * *   *     * *  *  *]
                    }
     job_data = {
         'job_id': arange(5)+1,
         'building_id': array([180, 145, 10, 180, 179])
     }
     building_data = {
         'building_id': arange(200)+1,
         'parcel_id': arange(200)+1
         }        
     parcel_data = {
         'parcel_id': arange(200)+1,
         'land_use_type_id': array(150*[1]+50*[2]),      
         }
     
     lut_data = {
         'land_use_type_id': array([1,2]),
         'land_use_name': array(['non_vacant', 'vacant'])        
         }
     storage = StorageFactory().get_storage('dict_storage')
     storage.write_table(table_name = 'households', table_data = household_data)
     storage.write_table(table_name = 'buildings', table_data = building_data)
     storage.write_table(table_name = 'jobs', table_data = job_data)
     storage.write_table(table_name = 'persons', table_data = person_data)
     storage.write_table(table_name = 'parcels', table_data = parcel_data)
     storage.write_table(table_name = 'land_use_types', table_data = lut_data)
     dataset_pool = DatasetPool(storage = storage, package_order = ['urbansim_parcel', 'urbansim'])
     
     
     BCM = BuildingConstructionModel()
     BCM.demolish_buildings(demolish_buildings, dataset_pool.get_dataset('building'), dataset_pool)
     JAMM = JoinAttributeModificationModel()
     JAMM.run(dataset_pool.get_dataset('person'), dataset_pool.get_dataset('household'), 
              attribute_to_be_modified='job_id', value=-1, filter='household.building_id <=0')
     JAMM.run(dataset_pool.get_dataset('person'), dataset_pool.get_dataset('job'), 
              attribute_to_be_modified='job_id', value=-1, filter='job.building_id <=0')
     self.assertEqual(all(dataset_pool.get_dataset('household').get_attribute('building_id') ==
                               array([-1, -1, 6, 150, -1, -1, -1, 5, -1, -1])), True)
     self.assertEqual(all(dataset_pool.get_dataset('job').get_attribute('building_id') ==
                               array([-1, 145, -1, -1, 179])), True)
     self.assertEqual(dataset_pool.get_dataset('building').size()==197, True)
     self.assertEqual(all(dataset_pool.get_dataset('person').get_attribute('job_id') == 
                          array([-1,-1,-1,2,2,-1,-1,5,-1,-1,-1,-1,-1,-1,-1])), True)
     self.assertEqual(dataset_pool.get_dataset('parcel')['land_use_type_id'][9], 2)
     self.assertEqual(dataset_pool.get_dataset('parcel')['land_use_type_id'][2], 2)            
Exemplo n.º 10
0
    def prepare_dataset_pool(self, recent_years):
        cache_dir = os.path.join(self.urbansim_tmp, 'urbansim_cache')
        SimulationState().set_cache_directory(cache_dir)

        storage = StorageFactory().get_storage('dict_storage')
        dataset_pool = DatasetPool(package_order=['urbansim'], storage=storage)

        storage.write_table(table_name='gridcells',
                            table_data={
                                'grid_id': array([1, 2, 3, 4]),
                                'industrial_sqft': array([4, 0, 1, 0]),
                            })
        gridcell = dataset_pool.get_dataset('gridcell')
        self._write_dataset_to_cache(gridcell, cache_dir, 1998)
        dataset_pool.remove_all_datasets()

        storage.write_table(table_name='gridcells',
                            table_data={
                                'grid_id': array([1, 2, 3, 4]),
                                'industrial_sqft': array([3, 0, 2, 1]),
                            })
        gridcell = dataset_pool.get_dataset('gridcell')
        self._write_dataset_to_cache(gridcell, cache_dir, 1999)
        dataset_pool.remove_all_datasets()

        storage.write_table(table_name='gridcells',
                            table_data={
                                'grid_id': array([1, 2, 3, 4]),
                                'industrial_sqft': array([3, 0, 3, 1]),
                            })
        gridcell = dataset_pool.get_dataset('gridcell')
        self._write_dataset_to_cache(gridcell, cache_dir, 2000)
        dataset_pool.remove_all_datasets()

        storage.write_table(table_name='urbansim_constants',
                            table_data={
                                'recent_years': array([recent_years]),
                            })

        SimulationState().set_current_time(2001)
        attribute_cache = AttributeCache()
        SessionConfiguration(new_instance=True,
                             package_order=['urbansim'],
                             in_storage=attribute_cache)
        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=attribute_cache)

        # Can't write urbansim_constant, so directly add it to the pool.
        temp_dataset_pool = DatasetPool(package_order=['urbansim'],
                                        storage=storage)
        dataset_pool._add_dataset(
            'urbansim_constant',
            temp_dataset_pool.get_dataset('urbansim_constant'))
        return dataset_pool
Exemplo n.º 11
0
    def test_addition_of_jobs_with_one_characteristics(self):
        dataset_pool = DatasetPool(
            storage=self.storage,
            package_order=["washtenaw", "urbansim", "opus_core"])
        gridcell_set = dataset_pool.get_dataset('gridcell')
        event_set = self._create_job_addition_event_set_with_characteristics()
        jobs = dataset_pool.get_dataset("job")
        AgentEventModel().run(gridcell_set, event_set, jobs, 2000,
                              dataset_pool)
        number_of_jobs_of_sector_1 = gridcell_set.compute_variables(
            "urbansim.gridcell.number_of_jobs_of_sector_1",
            dataset_pool=dataset_pool)
        number_of_jobs_of_sector_2 = gridcell_set.compute_variables(
            "urbansim.gridcell.number_of_jobs_of_sector_2",
            dataset_pool=dataset_pool)
        number_of_jobs_of_sector_4 = gridcell_set.compute_variables(
            "urbansim.gridcell.number_of_jobs_of_sector_4",
            dataset_pool=dataset_pool)

        # the model should add 2 jobs of sector 1 to gridcell 1,
        #                      5 jobs of sector 1 to gridcell 5
        self.assert_(
            ma.allclose(number_of_jobs_of_sector_1,
                        array([6, 4, 4, 4, 9, 4, 4, 4, 4, 4])))
        # other sectors don't change
        self.assert_(ma.allclose(number_of_jobs_of_sector_2, array(10 * [3])))
        self.assert_(ma.allclose(number_of_jobs_of_sector_4, array(10 * [3])))

        AgentEventModel().run(gridcell_set, event_set, jobs, 2001,
                              dataset_pool)
        number_of_jobs_of_sector_1 = gridcell_set.compute_variables(
            "urbansim.gridcell.number_of_jobs_of_sector_1",
            dataset_pool=dataset_pool)
        number_of_jobs_of_sector_2 = gridcell_set.compute_variables(
            "urbansim.gridcell.number_of_jobs_of_sector_2",
            dataset_pool=dataset_pool)
        number_of_jobs_of_sector_4 = gridcell_set.compute_variables(
            "urbansim.gridcell.number_of_jobs_of_sector_4",
            dataset_pool=dataset_pool)
        # the model should add 2 jobs of sector 2 to gridcell 5,
        #                      1 job of sector 1 to gridcell 1,
        #                      4 jobs of sector 2 to gridcell 2
        #                      70% jobs of sector 2 to gridcell 3
        self.assert_(
            ma.allclose(number_of_jobs_of_sector_1,
                        array([7, 4, 4, 4, 9, 4, 4, 4, 4, 4])))
        self.assert_(
            ma.allclose(number_of_jobs_of_sector_2,
                        array([3, 6, 5, 3, 5, 3, 3, 3, 3, 3])))
        # sector 4 does not change
        self.assert_(ma.allclose(number_of_jobs_of_sector_4, array(10 * [3])))
Exemplo n.º 12
0
    def test_deletion_of_jobs(self):
        dataset_pool = DatasetPool(storage=self.storage, package_order=["psrc_parcel","urbansim", "opus_core"])
        gridcell_set = dataset_pool.get_dataset('gridcell')
        event_set = self._create_simple_job_deletion_event_set()
        jobs = dataset_pool.get_dataset("job")
        AgentEventModel().run(gridcell_set, event_set, jobs, 2000, dataset_pool=dataset_pool)
        number_of_jobs = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs", dataset_pool=dataset_pool)
        # the model should remove 5 jobs from gridcell 5 and all jobs from gridcell 10
        self.assert_(ma.allclose(number_of_jobs, array( [10,10,10,10,5,10,10,10,10,0]))) 

        AgentEventModel().run(gridcell_set, event_set, jobs, 2001, dataset_pool=dataset_pool)
        number_of_jobs = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs", dataset_pool=dataset_pool)
        # the model should remove another 3 jobs from gridcell 5
        self.assert_(ma.allclose(number_of_jobs, array( [10,10,10,10,2,10,10,10,10,0])))
Exemplo n.º 13
0
    def test_addition_of_jobs(self):
        dataset_pool = DatasetPool(storage=self.storage, package_order=["washtenaw","urbansim", "opus_core"])
        gridcell_set = dataset_pool.get_dataset('gridcell')
        event_set = self._create_simple_job_addition_event_set()
        jobs = dataset_pool.get_dataset("job")
        AgentEventModel().run(gridcell_set, event_set, jobs, 2000, dataset_pool)
        number_of_jobs = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs", dataset_pool=dataset_pool)
        # the model should add 5 jobs to gridcell 5 and 20 jobs to gridcell 10
        self.assert_(ma.allclose(number_of_jobs, array( [10,10,10,10,15,10,10,10,10,30]))) 

        AgentEventModel().run(gridcell_set, event_set, jobs, 2001, dataset_pool)
        number_of_jobs = gridcell_set.compute_variables("urbansim.gridcell.number_of_jobs", dataset_pool=dataset_pool)
        # the model should add another 3 jobs to gridcell 5
        self.assert_(ma.allclose(number_of_jobs, array( [10,10,10,10,18,10,10,10,10,30])))
Exemplo n.º 14
0
class AgingModelTest(opus_unittest.OpusTestCase):
    def setUp(self):
        household_data = {
            'household_id': arange(10) + 1,
            'age_of_head': array([20, 23, 22, 21, 31, 41, 43, 52, 62, 73])
        }
        person_data = {
            'person_id': arange(10) + 1,
            'age': array([21, 25, 29, 23, 37, 42, 40, 54, 61, 77])
        }
        storage = StorageFactory().get_storage('dict_storage')
        storage.write_table(table_name='households', table_data=household_data)
        storage.write_table(table_name='persons', table_data=person_data)
        self.dataset_pool = DatasetPool(storage=storage,
                                        package_order=['opus_core'])
        self.households = self.dataset_pool.get_dataset('household')
        self.persons = self.dataset_pool.get_dataset('person')

    def test_aging_model(self):
        # Initialize model
        model = AgingModel()

        # Set up arguments
        datasets_dict = {'household': 'age_of_head', 'person': 'age'}
        num_years = 1

        # Run model
        model.run(datasets_dict, num_years, self.dataset_pool)

        # Check model answers
        self.assertEqual(self.persons.get_attribute('age')[0], 22)
        self.assertEqual(self.persons.get_attribute('age')[1], 26)
        self.assertEqual(self.persons.get_attribute('age')[2], 30)
        self.assertEqual(self.persons.get_attribute('age')[3], 24)
        self.assertEqual(self.persons.get_attribute('age')[4], 38)
        self.assertEqual(self.persons.get_attribute('age')[5], 43)
        self.assertEqual(self.persons.get_attribute('age')[6], 41)
        self.assertEqual(self.persons.get_attribute('age')[7], 55)
        self.assertEqual(self.persons.get_attribute('age')[8], 62)
        self.assertEqual(self.persons.get_attribute('age')[9], 78)
        self.assertEqual(self.households.get_attribute('age_of_head')[0], 21)
        self.assertEqual(self.households.get_attribute('age_of_head')[1], 24)
        self.assertEqual(self.households.get_attribute('age_of_head')[2], 23)
        self.assertEqual(self.households.get_attribute('age_of_head')[3], 22)
        self.assertEqual(self.households.get_attribute('age_of_head')[4], 32)
        self.assertEqual(self.households.get_attribute('age_of_head')[5], 42)
        self.assertEqual(self.households.get_attribute('age_of_head')[6], 44)
        self.assertEqual(self.households.get_attribute('age_of_head')[7], 53)
        self.assertEqual(self.households.get_attribute('age_of_head')[8], 63)
        self.assertEqual(self.households.get_attribute('age_of_head')[9], 74)
Exemplo n.º 15
0
class AgingModelTest(opus_unittest.OpusTestCase):
    def setUp(self):
        household_data = {
            'household_id': arange(10)+1,
            'age_of_head': array([20, 23, 22, 21, 31, 41, 43, 52, 62, 73])
                         }
        person_data = {
            'person_id': arange(10)+1,
            'age': array([21, 25, 29, 23, 37, 42, 40, 54, 61, 77])
                      }
        storage = StorageFactory().get_storage('dict_storage')
        storage.write_table(table_name = 'households', table_data = household_data)
        storage.write_table(table_name = 'persons', table_data = person_data)
        self.dataset_pool = DatasetPool(storage = storage, package_order = ['opus_core'])
        self.households = self.dataset_pool.get_dataset('household')
        self.persons = self.dataset_pool.get_dataset('person')
        
    def test_aging_model(self):
        # Initialize model
        model = AgingModel()
        
        # Set up arguments
        datasets_dict = {'household':'age_of_head','person':'age'}
        num_years = 1
        
        # Run model
        model.run(datasets_dict, num_years, self.dataset_pool)
        
        # Check model answers
        self.assertEqual(self.persons.get_attribute('age')[0], 22)
        self.assertEqual(self.persons.get_attribute('age')[1], 26)
        self.assertEqual(self.persons.get_attribute('age')[2], 30)
        self.assertEqual(self.persons.get_attribute('age')[3], 24)
        self.assertEqual(self.persons.get_attribute('age')[4], 38)
        self.assertEqual(self.persons.get_attribute('age')[5], 43)
        self.assertEqual(self.persons.get_attribute('age')[6], 41)
        self.assertEqual(self.persons.get_attribute('age')[7], 55)
        self.assertEqual(self.persons.get_attribute('age')[8], 62)
        self.assertEqual(self.persons.get_attribute('age')[9], 78)
        self.assertEqual(self.households.get_attribute('age_of_head')[0], 21)
        self.assertEqual(self.households.get_attribute('age_of_head')[1], 24)
        self.assertEqual(self.households.get_attribute('age_of_head')[2], 23)
        self.assertEqual(self.households.get_attribute('age_of_head')[3], 22)
        self.assertEqual(self.households.get_attribute('age_of_head')[4], 32)
        self.assertEqual(self.households.get_attribute('age_of_head')[5], 42)
        self.assertEqual(self.households.get_attribute('age_of_head')[6], 44)
        self.assertEqual(self.households.get_attribute('age_of_head')[7], 53)
        self.assertEqual(self.households.get_attribute('age_of_head')[8], 63)
        self.assertEqual(self.households.get_attribute('age_of_head')[9], 74)
Exemplo n.º 16
0
class Tests(object):
    def setUp(self):
        cache_path = "/workspace/urbansim_cache/asu"
        self.variable_name = opus_path_for_variable_from_module_path(__file__)
        storage = file_flt_storage(cache_path)
        table_names = storage.get_table_names()
        self.dataset_pool = DatasetPool(package_order=['urbansim'],
                                        storage=storage)
        for table_name in table_names:
            dataset = self.dataset_pool.get_dataset(table_name, dataset_arguments={'id_name':[]})
            
    def test_compute(self):
        dataset_name = self.variable_name.split('.')[-2]
        dataset = self.dataset_pool.get_dataset(dataset_name)
        results = dataset.compute_variables(self.variable_name, dataset_pool=self.dataset_pool)
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')        
        
        storage.write_table(
            table_name='zones',
            table_data={
                "zone_id": array([1,2]),
                "trip_mode_bike": array([3,1]),
                "trip_mode_walk": array([5,6]),
                "trip_mode_park_ride": array([3,2]),
                "trip_mode_share_ride2": array([1,8]),
                "trip_mode_drive_alone": array([2,9]),
                "trip_mode_share_ride3": array([8,4]),
                "trip_mode_transit": array([5,5]),
            }
        )
        
        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(self.variable_name, 
                               dataset_pool=dataset_pool)
        values = zone.get_attribute(self.variable_name)
        
        should_be = array([8.0/27.0, 7.0/35.0])
        
        self.assert_(ma.allclose(values, should_be, rtol=1e-7), 
                     msg="Error in " + self.variable_name)
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')        
        
        storage.write_table(
            table_name='zones',
            table_data={
                'zone_id': array([1, 2]),
            }
        )
        storage.write_table(
            table_name='travel_data',
            table_data={
                "from_zone_id": array([1,1,2,2]),
                'to_zone_id': array([1,2,1,2]),
                "am_single_vehicle_to_work_travel_time":array([1.1, 2.2, 3.3, 4.4]),
                "am_pk_period_drive_alone_vehicle_trips":array([1.0, 2.0, 3.0, 4.0]),
            }
        )
        
        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(self.variable_name, 
                               dataset_pool=dataset_pool)
        values = zone.get_attribute(self.variable_name)
        
        should_be = array([(1.1*1.0 +2.2*2.0)/(3.0), 
                           (3.3*3.0 + 4.4*4.0)/(7.0)])
        
        self.assert_(ma.allclose(values, should_be, rtol=1e-7), 
                     msg="Error in " + self.variable_name)
Exemplo n.º 19
0
    def test_safely_divide_two_attributes(self):
        from opus_core.datasets.dataset_pool import DatasetPool
        
        storage = StorageFactory().get_storage('dict_storage')        
        storage.write_table(
            table_name='tests',
            table_data={
                'id': array([1,2,3,4]),
                'numerator': array([1,2,3,0]),
                'denominator': array([2.,0.,2.,0.]),
            }
        )
        
        dataset_pool = DatasetPool(package_order=['opus_core'],
                                   storage=storage)
        test = dataset_pool.get_dataset('test')
        variable = Variable()
        variable.set_dataset(test)

        result = variable.safely_divide_two_attributes('opus_core.test.numerator',
                                                       'opus_core.test.denominator')
        self.assert_(ma.allclose(array([.5, 0, 1.5, 0]), result))
        
        result = variable.safely_divide_two_attributes('opus_core.test.numerator',
                                                       'opus_core.test.denominator', 
                                                        value_for_divide_by_zero=-1.0)
        self.assert_(ma.allclose(array([.5, -1., 1.5, -1.]), result))
    def test_my_input(self):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(table_name='zones',
                            table_data={
                                "zone_id": array([1, 3]),
                                "population": array([10, 1]),
                            })
        storage.write_table(table_name='travel_data',
                            table_data={
                                "from_zone_id":
                                array([3, 3, 1, 1]),
                                "to_zone_id":
                                array([1, 3, 1, 3]),
                                "single_vehicle_to_work_travel_cost":
                                array([1, 2, 3, 4]),
                            })

        dataset_pool = DatasetPool(package_order=['urbansim'], storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(self.variable_name, dataset_pool=dataset_pool)
        values = zone.get_attribute(self.variable_name)

        should_be = array([2.11111, 0.875])

        self.assert_(ma.allclose(values, should_be, rtol=1e-3),
                     msg="Error in " + self.variable_name)
    def test_full_tree(self):
        storage = StorageFactory().get_storage('dict_storage')
        
        storage.write_table(
            table_name='parcels',
            table_data={
                'parcel_id':array([1,2,3,4]),
                'is_in_city_seattle':array([1, 1, 0, 0])
                },
        )
        storage.write_table(
            table_name='households',
            table_data={
                'household_id':array([1,2,3,4,5]),
                'income':array([1000, 300000, 50000, 0, 10550])
                },
        )
        
        dataset_pool = DatasetPool(package_order=['psrc', 'urbansim'],
                                   storage=storage)

        household_x_parcel = dataset_pool.get_dataset('household_x_parcel')
        household_x_parcel.compute_variables(self.variable_name,
                                             dataset_pool=dataset_pool)
        values = household_x_parcel.get_attribute(self.variable_name)
            
        should_be = array([[1000*1, 1000*1, 1000*0, 1000*0], 
                           [300000*1, 300000*1, 300000*0,300000*0 ], 
                           [50000*1, 50000*1, 50000*0,50000*0], 
                           [0, 0, 0, 0], 
                           [10550*1, 10550*1, 10550*0, 10550*0]])
        
        self.assert_(ma.allclose(values, should_be, rtol=1e-3), 
                     msg="Error in " + self.variable_name)
    def test_3(self):
        variable_name = "psrc.gridcell.travel_time_hbw_am_drive_alone_to_3"
        storage = StorageFactory().get_storage("dict_storage")

        storage.write_table(
            table_name="gridcells", table_data={"grid_id": array([1, 2, 3]), "zone_id": array([1, 1, 3])}
        )
        storage.write_table(
            table_name="zones",
            table_data={
                "zone_id": array([1, 2, 3]),
                "travel_time_hbw_am_drive_alone_to_1": array([1.1, 2.2, 3.3]),
                "travel_time_hbw_am_drive_alone_to_3": array([0.1, 0.2, 0.3]),
            },
        )

        dataset_pool = DatasetPool(package_order=["urbansim"], storage=storage)

        gridcell = dataset_pool.get_dataset("gridcell")
        gridcell.compute_variables(variable_name, dataset_pool=dataset_pool)
        values = gridcell.get_attribute(variable_name)

        should_be = array([0.1, 0.1, 0.3])

        self.assert_(ma.allclose(values, should_be, rtol=1e-3), msg="Error in " + variable_name)
Exemplo n.º 23
0
    def test_my_input(self):
        storage = StorageFactory().get_storage('dict_storage')        
        
        storage.write_table(
            table_name='zones',
            table_data={
                'zone_id': array([1, 3]),
            }
        )
        storage.write_table(
            table_name='travel_data',
            table_data={
                "from_zone_id":array([1,3,3,1]),
                "to_zone_id":  array([1,1,3,3]),
                "am_pk_period_drive_alone_vehicle_trips":array([1, 7, 3, 4]),
            }
        )
        
        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(self.variable_name, 
                               dataset_pool=dataset_pool)
        values = zone.get_attribute(self.variable_name)
        
        should_be = array([8, 7])
        
        self.assert_(ma.allequal(values, should_be), 
                     msg="Error in " + self.variable_name)
    def test_my_input(self):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(table_name='zones',
                            table_data={
                                'zone_id': array([1, 3]),
                            })
        storage.write_table(table_name='travel_data',
                            table_data={
                                "from_zone_id":
                                array([1, 3, 3, 1]),
                                "to_zone_id":
                                array([1, 1, 1, 1]),
                                "am_vehicle_miles_traveled":
                                array([1, 7, 3, 4]),
                                "md_vehicle_miles_traveled":
                                array([1, 1, 2, 2]),
                                "pm_ev_ni_vehicle_miles_traveled":
                                array([0, 3, 0, 1]),
                            })

        dataset_pool = DatasetPool(package_order=['urbansim'], storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(self.variable_name, dataset_pool=dataset_pool)
        values = zone.get_attribute(self.variable_name)

        should_be = array([9, 16])

        self.assert_(ma.allequal(values, should_be),
                     msg="Error in " + self.variable_name)
Exemplo n.º 25
0
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')

        building_types_table_name = 'building_types'
        storage.write_table(table_name=building_types_table_name,
                            table_data={
                                'building_type_id': array([1, 2, 3, 4]),
                                'generic_building_type_id': array([2, 3, 1, 1])
                            })

        buildings_table_name = 'buildings'
        storage.write_table(table_name=buildings_table_name,
                            table_data={
                                'building_id': array([1, 2, 3, 4, 5, 6]),
                                'building_type_id': array([2, 1, 2, 4, 3, 3])
                            })
        dataset_pool = DatasetPool(
            package_order=['urbansim_parcel', 'urbansim'], storage=storage)
        buildings = dataset_pool.get_dataset('building')

        values = buildings.compute_variables(self.variable_name,
                                             dataset_pool=dataset_pool)

        should_be = array([True, False, True, False, False, False])

        self.assert_(ma.allequal(values, should_be),
                     'Error in ' + self.variable_name)
Exemplo n.º 26
0
    def test_my_inputs_tree_test(self):
        variable_name = "biocomplexity.land_cover.pcc"
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(table_name='land_covers',
                            table_data={
                                'relative_x': array([1, 2, 1, 2]),
                                'relative_y': array([1, 1, 2, 2]),
                                "lct": array([12, 8, 8, 15])
                            })

        dataset_pool = DatasetPool(package_order=['biocomplexity'],
                                   storage=storage)
        dataset_pool._add_dataset(
            'constant', {
                "FOOTPRINT": array([[0, 1, 0], [1, 1, 1], [0, 1, 0]]),
                "CC": 8,
                "OW": 12
            })

        land_cover = dataset_pool.get_dataset('land_cover')
        land_cover.compute_variables(variable_name, dataset_pool=dataset_pool)
        values = land_cover.get_attribute(variable_name)

        cc_within_fp = array([2, 3, 3, 2])
        ow_within_fp = array([3, 1, 1, 0])
        should_be = cc_within_fp / (5.0 - ow_within_fp)
        should_be = arcsin(sqrt(should_be))

        self.assert_(ma.allclose(values, should_be, rtol=1e-7),
                     msg="Error in " + variable_name)
Exemplo n.º 27
0
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')        
        
        storage.write_table(
            table_name='gridcells',
            table_data={
                'grid_id': array([1, 2, 3]),
                'zone_id': array([1, 1, 3]),
            }
        )
        storage.write_table(
            table_name='zones',
            table_data={
                'zone_id': array([1, 2, 3]),
                "trip_weighted_average_time_hbw_from_home_am_bike": array([4.1, 5.3, 6.2]),
            }
        )
        
        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=storage)

        gridcell = dataset_pool.get_dataset('gridcell')
        gridcell.compute_variables(self.variable_name, 
                                   dataset_pool=dataset_pool)
        values = gridcell.get_attribute(self.variable_name)
        
        should_be = array([4.1, 4.1, 6.2])
        
        self.assert_(ma.allclose(values, should_be, rtol=1e-3), 
                     msg="Error in " + self.variable_name)
Exemplo n.º 28
0
    def get_values(self, number):
        variable_name = "urbansim_parcel.zone.employment_within_%s_minutes_travel_time_hbw_am_walk" % number
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(
            table_name='zones',
            table_data={
                "zone_id":array([1,3]),
                "number_of_jobs":array([10, 1]),
            }
        )
        storage.write_table(
            table_name='travel_data',
            table_data={
                "from_zone_id": array([3,3,1,1]),
                "to_zone_id": array([1,3,1,3]),
                "am_walk_time_in_minutes": array([1.1, 2.2, 3.3, 4.4]),
            }
        )

        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(variable_name,
                               dataset_pool=dataset_pool)
        values = zone.get_attribute(variable_name)
        return values
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')        
        
        storage.write_table(
            table_name='gridcells',
            table_data={
                'grid_id': array([1,2,3]),
                'housing_cost': array([10000, 20000, 100000]),
            }
        )
        storage.write_table(
            table_name='households',
            table_data={
                'household_id': array([1, 2, 3]),
                'income': array([10000, 20000, 500000]),
            }
        )
        
        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=storage)

        household_x_gridcell = dataset_pool.get_dataset('household_x_gridcell')
        household_x_gridcell.compute_variables(self.variable_name, 
                                               dataset_pool=dataset_pool)
        values = household_x_gridcell.get_attribute(self.variable_name)
        
        should_be = array([[0, -1, -9], 
                           [1, 0, -8], 
                           [49, 48, 40]])
        
        self.assert_(ma.allclose(values, should_be, rtol=1e-7), 
                     msg="Error in " + self.variable_name)
Exemplo n.º 30
0
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(table_name='households',
                            table_data={
                                'household_id': array([1, 2, 3, 4]),
                                'age_of_head': array([12, 20, 25, 30]),
                            })

        storage.write_table(table_name='urbansim_constants',
                            table_data={
                                'young_age': array([25]),
                            })

        dataset_pool = DatasetPool(package_order=['urbansim'], storage=storage)

        household = dataset_pool.get_dataset('household')
        household.compute_variables(self.variable_name,
                                    dataset_pool=dataset_pool)
        values = household.get_attribute(self.variable_name)

        should_be = array([1, 1, 1, 0])

        self.assert_(ma.allequal(
            values,
            should_be,
        ),
                     msg="Error in " + self.variable_name)
Exemplo n.º 31
0
    def test_my_inputs( self ):
        storage = StorageFactory().get_storage('dict_storage')        
        
        storage.write_table(
            table_name='households',
            table_data={
                'household_id': array([1, 2, 3, 4]),
                'income': array([50, 100, 200, 300]),
            }
        )
        
        storage.write_table(
            table_name='urbansim_constants',
            table_data={
                "low_income_fraction": array([.25]),
                'mid_income_fraction': array([.25]),
            }
        )
        
        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=storage)

        household = dataset_pool.get_dataset('household')
        household.compute_variables(self.variable_name, 
                                    dataset_pool=dataset_pool)
        values = household.get_attribute(self.variable_name)
        
        should_be = array([0, 0, 0, 1])
        
        self.assert_(ma.allequal(values, should_be,), 
                     msg="Error in " + self.variable_name)
Exemplo n.º 32
0
    def test_my_inputs( self ):
        storage = StorageFactory().get_storage('dict_storage')        
        
        storage.write_table(
            table_name='households',
            table_data={
                'household_id': array([1, 2, 3, 4]),
                'age_of_head': array([12, 20, 25, 30]),
            }
        )
        
        storage.write_table(
            table_name='urbansim_constants',
            table_data={
                'young_age': array([25]),
            }
        )
        
        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=storage)

        household = dataset_pool.get_dataset('household')
        household.compute_variables(self.variable_name, 
                                    dataset_pool=dataset_pool)
        values = household.get_attribute(self.variable_name)
        
        should_be = array( [1,1,1,0] )
        
        self.assert_(ma.allequal(values, should_be,), 
                     msg="Error in " + self.variable_name)
            def test_at_year_2000(self):
                cache_dir = os.path.join(self.temp_dir, 'cache')
                data = {
                    self._id_name: array([1, 2, 3]),
                    'population': array([10, 20, 30]),
                }
                self._write_data_to_year(data, cache_dir, 2000)

                attribute_cache = AttributeCache(cache_directory=cache_dir)
                SimulationState(new_instance=True,
                                base_cache_dir=self.temp_dir)
                SimulationState().set_cache_directory(cache_dir)
                SessionConfiguration(new_instance=True,
                                     in_storage=attribute_cache)

                SimulationState().set_current_time(2000)
                dataset_pool_2000 = DatasetPool(package_order=['urbansim'],
                                                storage=attribute_cache)
                dataset = dataset_pool_2000.get_dataset(self._dataset_name)
                variable_name = '%s.%s.percent_population_difference_from_2000' % (
                    self._package_name, self._dataset_name)
                dataset.compute_variables([variable_name],
                                          dataset_pool=dataset_pool_2000)
                pop_2000 = dataset.get_attribute(variable_name)
                self.assert_(ma.allequal(pop_2000, array([0, 0, 0])))
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(
            table_name='gridcells',
            table_data={
                'grid_id':
                array([1, 2, 3]),
                'percent_high_income_households_within_walking_distance':
                array([50, 10, 20]),
            })
        storage.write_table(table_name='households',
                            table_data={
                                'household_id': array([1, 2, 3, 4]),
                                'is_low_income': array([1, 0, 1, 0]),
                            })
        storage.write_table(table_name='urbansim_constants',
                            table_data={
                                "walking_distance_circle_radius": array([150]),
                                'cell_size': array([150]),
                                'low_income_fraction': array([.25]),
                                'mid_income_fraction': array([.3]),
                            })

        dataset_pool = DatasetPool(package_order=['urbansim'], storage=storage)

        household_x_gridcell = dataset_pool.get_dataset('household_x_gridcell')
        household_x_gridcell.compute_variables(self.variable_name,
                                               dataset_pool=dataset_pool)
        values = household_x_gridcell.get_attribute(self.variable_name)

        should_be = array([[50, 10, 20], [0, 0, 0], [50, 10, 20], [0, 0, 0]])

        self.assert_(ma.allclose(values, should_be, rtol=1e-7),
                     msg="Error in " + self.variable_name)
    def test_full_tree(self):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(
            table_name='parcels',
            table_data={
                'parcel_id': array([1, 2, 3, 4]),
                'is_in_city_seattle': array([1, 1, 0, 0])
            },
        )
        storage.write_table(
            table_name='households',
            table_data={
                'household_id': array([1, 2, 3, 4, 5]),
                'income': array([1000, 300000, 50000, 0, 10550])
            },
        )

        dataset_pool = DatasetPool(package_order=['psrc', 'urbansim'],
                                   storage=storage)

        household_x_parcel = dataset_pool.get_dataset('household_x_parcel')
        household_x_parcel.compute_variables(self.variable_name,
                                             dataset_pool=dataset_pool)
        values = household_x_parcel.get_attribute(self.variable_name)

        should_be = array([[1000 * 1, 1000 * 1, 1000 * 0, 1000 * 0],
                           [300000 * 1, 300000 * 1, 300000 * 0, 300000 * 0],
                           [50000 * 1, 50000 * 1, 50000 * 0, 50000 * 0],
                           [0, 0, 0, 0],
                           [10550 * 1, 10550 * 1, 10550 * 0, 10550 * 0]])

        self.assert_(ma.allclose(values, should_be, rtol=1e-3),
                     msg="Error in " + self.variable_name)
Exemplo n.º 36
0
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(table_name='gridcells',
                            table_data={
                                'grid_id':
                                array([1, 2, 3]),
                                'avg_val_per_unit_residential':
                                array([25, 50, 75]),
                            })
        storage.write_table(table_name='urbansim_constants',
                            table_data={
                                'property_value_to_annual_cost_ratio':
                                array([50]),
                            })

        dataset_pool = DatasetPool(package_order=['urbansim'], storage=storage)

        gridcell = dataset_pool.get_dataset('gridcell')
        gridcell.compute_variables(self.variable_name,
                                   dataset_pool=dataset_pool)
        values = gridcell.get_attribute(self.variable_name)

        should_be = array([25 / 50.0, 1, 75 / 50.0])

        self.assert_(ma.allclose(values, should_be, rtol=1e-7),
                     msg="Error in " + self.variable_name)
Exemplo n.º 37
0
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')        
        
        storage.write_table(
            table_name='zones',
            table_data={
                'zone_id': array([1, 2]),
            }
        )
        storage.write_table(
            table_name='travel_data',
            table_data={
                "from_zone_id": array([1,1,2,2]),
                "to_zone_id":array([1,2,1,2]),
                 "hbw_daily_biking_person_trip_table": array([1.1, 2.2, 3.3, 4.4]),
                 "college_daily_biking_person_trip_table": array([1.0, 2.0, 3.0, 4.0]),
                 "hbnw_daily_biking_person_trip_table": array([2.0, 3.0, 1.0, 0.0]),
                 "nhb_daily_biking_person_trip_table": array([12.8, 4.5, 1.2, 8.0]),
            }
        )
        
        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(self.variable_name, 
                               dataset_pool=dataset_pool)
        values = zone.get_attribute(self.variable_name)
        
        should_be = array([28.6, 24.9])
        
        self.assert_(ma.allclose(values, should_be, rtol=1e-4), 
                     msg="Error in " + self.variable_name)
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')        
        
        storage.write_table(
            table_name='buildings',
            table_data={
                'building_id': arange(50),
                'residential_units': array(5*[0]+10*[20]+5*[15]+10*[50]+15*[3]+5*[45]),
            }
        )
        storage.write_table(
            table_name='jobs',
            table_data={
                'job_id': array([1, 2, 3]),
            }
        )
        
        dataset_pool = DatasetPool(package_order=['urbansim_parcel', 'urbansim'],
                                   storage=storage)        
        job_x_building = dataset_pool.get_dataset('job_x_building', 
                 dataset_arguments={"index2": array([[13, 15, 23, 49],
                                                     [5, 9, 17, 43],
                                                     [17, 18, 40, 47]], dtype="int32")})
        job_x_building.compute_variables(self.variable_name)
        values = job_x_building.get_attribute(self.variable_name)

        # The values are computed using formula from Ben-Akiva book (Chapter of correcting for sampling bias)
        should_be = array([[-11.3207881 , -11.03310603, -12.23707884, -12.13171832],
                           [-15.01597613, -15.01597613, -14.72829406, -13.11885615],
                           [-14.18521949, -14.18521949, -12.57578158, -15.28383178]]) + 11.03310603
        
        self.assert_(ma.allclose(values, should_be, rtol=1e-4), 
                     msg="Error in " + self.variable_name)
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')        
        
        storage.write_table(
            table_name='zones',
            table_data={
                'zone_id': array([1, 2]),
            }
        )
        storage.write_table(
            table_name='travel_data',
            table_data={
                "from_zone_id": array([1,1,2,2]),
                "to_zone_id":array([1,2,1,2]),
                'hbw_daily_drive_to_park_ride_person_trip_table': array([1.1, 2.2, 3.3, 4.4]),
            }
        )
        
        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(self.variable_name, 
                               dataset_pool=dataset_pool)
        values = zone.get_attribute(self.variable_name)
        
        should_be = array([3.3, 7.7])
        
        self.assert_(ma.allclose(values, should_be, rtol=1e-7), 
                     msg="Error in " + self.variable_name)
Exemplo n.º 40
0
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')        
        
        storage.write_table(
            table_name='gridcells',
            table_data={
                'grid_id': array([1,2,3,4]),
                'relative_x': array([1,2,1,2]),
                'relative_y': array([1,1,2,2]),
                'is_development_type_residential': array([1, 1, 1, 0])
            }
        )
        storage.write_table(
            table_name='urbansim_constants',
            table_data={
                "walking_distance_circle_radius": array([150]),
                'cell_size': array([150]),
                "acres": array([105.0]),
            }
        )
        
        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=storage)

        gridcell = dataset_pool.get_dataset('gridcell')
        gridcell.compute_variables(self.variable_name, 
                                   dataset_pool=dataset_pool)
        values = gridcell.get_attribute(self.variable_name)
        
        should_be = array([5, 4, 4, 2])
        
        self.assert_(ma.allclose( values, should_be, rtol=1e-7), 
                     msg = "Error in " + self.variable_name)
Exemplo n.º 41
0
    def test(self):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(table_name='test_agents',
                            table_data={
                                'id': array([1, 2, 3]),
                                'income': array([1, 20, 500]),
                            })
        storage.write_table(table_name='test_locations',
                            table_data={
                                'id': array([1, 2]),
                                'cost': array([1000, 2000]),
                            })

        dataset_pool = DatasetPool(package_order=['opus_core'],
                                   storage=storage)
        test_agent_x_test_location = dataset_pool.get_dataset(
            'test_agent_x_test_location')
        values = test_agent_x_test_location.compute_variables(
            self.variable_name, dataset_pool=dataset_pool)

        should_be = array([[1000, 2000], [20000, 40000], [500000, 1000000]])

        self.assert_(ma.allclose(values, should_be, rtol=1e-20),
                     msg="Error in " + self.variable_name)
Exemplo n.º 42
0
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(table_name='land_covers',
                            table_data={
                                'relative_x': array([1, 2, 1, 2]),
                                'relative_y': array([1, 1, 2, 2]),
                                "lct": array([10, 10, 4, 3])
                            })

        dataset_pool = DatasetPool(package_order=['biocomplexity'],
                                   storage=storage)
        footprint = array([[0, 1, 0], [1, 1, 1], [0, 1, 0]])
        dataset_pool._add_dataset('constant', {
            "FOOTPRINT": footprint,
            'AG': 10,
        })

        gridcell = dataset_pool.get_dataset('land_cover')
        gridcell.compute_variables(self.variable_name,
                                   dataset_pool=dataset_pool)
        values = gridcell.get_attribute(self.variable_name)

        should_be = array([[1, 1], [0, 0]])
        should_be = correlate(ma.filled(should_be.astype(int32), 0),
                              footprint,
                              mode="reflect")
        should_be = less_equal((should_be / 5.0), 400)
        should_be = ln(distance_transform_edt(should_be) +
                       1) / dag.standardization_constant_distance
        should_be = ravel(transpose(should_be))  # flatten by id

        self.assert_(ma.allclose(values, should_be, rtol=1e-7),
                     msg="Error in " + self.variable_name)
Exemplo n.º 43
0
    def test_addition_of_households(self):
        dataset_pool = DatasetPool(storage=self.storage, package_order=["washtenaw","urbansim", "opus_core"])
        gridcell_set = dataset_pool.get_dataset('gridcell')
        event_set = self._create_household_addition_event_set()
        households = dataset_pool.get_dataset("household")
        AgentEventModel().run(gridcell_set, event_set, households, 2000, dataset_pool)
        number_of_households = gridcell_set.compute_variables("urbansim.gridcell.number_of_households", 
                                                              dataset_pool=dataset_pool)
        # the model should add 6 households to gridcell 1, 
        self.assert_(ma.allclose(number_of_households, array( [16,0,30,0,5,0,0,0,0,0]))) 

        AgentEventModel().run(gridcell_set, event_set, households, 2001, dataset_pool)
        number_of_households = gridcell_set.compute_variables("urbansim.gridcell.number_of_households", 
                                                              dataset_pool=dataset_pool)
        # the model should add 50% from gridcell 1 (8) and 25 households to gridcell 3
        self.assert_(ma.allclose(number_of_households, array( [24,0,55,0,5,0,0,0,0,0])))
    def test_with_all_zero_denominator(self):
        storage = StorageFactory().get_storage('dict_storage')        
        
        storage.write_table(
            table_name='zones',
            table_data={
                "zone_id": array([1,2,3,4]),
            }
        )
        storage.write_table(
            table_name='travel_data',
            table_data={
                "from_zone_id":array([1,2,2,3,4]),
                "to_zone_id":array([1,2,1,2,2]),
                "am_single_vehicle_to_work_travel_time":array([1.1, 2.2, 3.3, 4.4, 5.5]),
                "am_pk_period_drive_alone_vehicle_trips":array([0, 0.0, 0.0, 0.0, 0.0]),
            }
        )
        
        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(self.variable_name, 
                               dataset_pool=dataset_pool)
        values = zone.get_attribute(self.variable_name)
        
        should_be = array([0.0, 
                           0.0, 
                           0.0,
                           0.0])
        
        self.assert_(ma.allclose(values, should_be, rtol=1e-7), 
                     msg="Error in " + self.variable_name)
Exemplo n.º 45
0
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(table_name='zones',
                            table_data={
                                "zone_id": array([1, 2]),
                                "trip_mode_bike": array([3, 1]),
                                "trip_mode_walk": array([5, 6]),
                                "trip_mode_park_ride": array([3, 2]),
                                "trip_mode_share_ride2": array([1, 8]),
                                "trip_mode_drive_alone": array([2, 9]),
                                "trip_mode_share_ride3": array([8, 4]),
                                "trip_mode_transit": array([5, 5]),
                            })

        dataset_pool = DatasetPool(package_order=['urbansim'], storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(self.variable_name, dataset_pool=dataset_pool)
        values = zone.get_attribute(self.variable_name)

        should_be = array([5.0 / 27.0, 6.0 / 35.0])

        self.assert_(ma.allclose(values, should_be, rtol=1e-7),
                     msg="Error in " + self.variable_name)
Exemplo n.º 46
0
    def test_my_inputs_convert(self):
        variable_name = "biocomplexity.land_cover.hmai"
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(table_name='land_covers',
                            table_data={
                                'relative_x': array([1, 2, 1, 2]),
                                'relative_y': array([1, 1, 2, 2]),
                                "lct": array([1, 3, 2, 4])
                            })

        dataset_pool = DatasetPool(package_order=['biocomplexity'],
                                   storage=storage)
        dataset_pool._add_dataset(
            'constant', {
                "FOOTPRINT": array([[0, 1, 0], [1, 1, 1], [0, 1, 0]]),
                'HEAVY_MED_URBAN': ['HU', 'MU'],
                'MU': 2,
                'HU': 1,
            })

        land_cover = dataset_pool.get_dataset('land_cover')
        land_cover.compute_variables(variable_name, dataset_pool=dataset_pool)
        values = land_cover.get_attribute(variable_name)

        should_be = arcsin(sqrt(array([0.25, 0, 0.25, 0])))

        self.assert_(ma.allclose(values, should_be, rtol=1e-7),
                     msg="Error in " + variable_name)
Exemplo n.º 47
0
    def test_my_input(self):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(table_name='zones',
                            table_data={
                                "zone_id": array([1, 3]),
                                "number_of_jobs": array([10, 1])
                            })
        storage.write_table(table_name='travel_data',
                            table_data={
                                "from_zone_id": array([3, 3, 1, 1]),
                                "to_zone_id": array([1, 3, 1, 3]),
                                "am_total_transit_time_walk":
                                array([1, 2, 3, 4]),
                            })

        dataset_pool = DatasetPool(package_order=['urbansim'], storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(self.variable_name, dataset_pool=dataset_pool)
        values = zone.get_attribute(self.variable_name)

        should_be = array([1.17361, 10.25])

        self.assert_(ma.allclose(values, should_be, rtol=1e-3),
                     msg="Error in " + self.variable_name)
Exemplo n.º 48
0
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(table_name='zones',
                            table_data={
                                'zone_id': array([1, 2]),
                            })
        storage.write_table(table_name='travel_data',
                            table_data={
                                "from_zone_id":
                                array([1, 1, 2, 2]),
                                "to_zone_id":
                                array([1, 2, 1, 2]),
                                "hbw_daily_biking_person_trip_table":
                                array([1.1, 2.2, 3.3, 4.4]),
                                "college_daily_biking_person_trip_table":
                                array([1.0, 2.0, 3.0, 4.0]),
                                "hbnw_daily_biking_person_trip_table":
                                array([2.0, 3.0, 1.0, 0.0]),
                                "nhb_daily_biking_person_trip_table":
                                array([12.8, 4.5, 1.2, 8.0]),
                            })

        dataset_pool = DatasetPool(package_order=['urbansim'], storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(self.variable_name, dataset_pool=dataset_pool)
        values = zone.get_attribute(self.variable_name)

        should_be = array([28.6, 24.9])

        self.assert_(ma.allclose(values, should_be, rtol=1e-4),
                     msg="Error in " + self.variable_name)
Exemplo n.º 49
0
   def test_my_inputs(self):
       storage = StorageFactory().get_storage('dict_storage')
 
       storage.write_table(
                table_name='buildings',
                table_data={
                   'building_id':      array([1, 2, 3]),
                   }
               )
       storage.write_table(
                table_name='jobs',
                table_data={
                   'job_id':      array([1, 2, 3, 4, 5, 6]),
                   'sector_id':   array([1, 1, 3, 2, 3, 3]),
                   'building_id': array([1, 1, 1, 2, 3, 3])
                   }
               )
       dataset_pool = DatasetPool(package_order=['urbansim_parcel', 'urbansim'], storage=storage)
       buildings = dataset_pool.get_dataset('building')
       
       values = buildings.compute_variables(self.variable_name, dataset_pool=dataset_pool)
       
       should_be = array([1/3., 0, 1])
       
       self.assert_(ma.allequal(values, should_be),
           'Error in ' + self.variable_name)
Exemplo n.º 50
0
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')

        land_use_types_table_name = 'land_use_types'
        storage.write_table(table_name=land_use_types_table_name,
                            table_data={
                                'land_use_type_id':
                                array([0, 2, 3, 4]),
                                'land_use_name':
                                array(
                                    ['foo', 'vacant', 'commercial', 'vacant'])
                            })

        parcel_table_name = 'parcels'
        storage.write_table(table_name=parcel_table_name,
                            table_data={
                                'parcel_id': array([1, 2, 3, 4, 5, 6]),
                                'land_use_type_id': array([2, 0, 2, 4, 3, 3])
                            })
        dataset_pool = DatasetPool(
            package_order=['urbansim_parcel', 'urbansim'], storage=storage)
        parcels = dataset_pool.get_dataset('parcel')

        values = parcels.compute_variables(self.variable_name,
                                           dataset_pool=dataset_pool)

        should_be = array([1, 0, 1, 1, 0, 0])

        self.assert_(ma.allequal(values, should_be),
                     'Error in ' + self.variable_name)
    def test_my_inputs(self):
        storage = StorageFactory().get_storage("dict_storage")

        storage.write_table(
            table_name="gridcells",
            table_data={
                "grid_id": arange(50),
                "residential_units": array(5 * [0] + 10 * [20] + 5 * [15] + 10 * [50] + 15 * [3] + 5 * [45]),
            },
        )
        storage.write_table(table_name="households", table_data={"household_id": array([1, 2, 3])})

        dataset_pool = DatasetPool(package_order=["urbansim"], storage=storage)
        household_x_gridcell = dataset_pool.get_dataset(
            "household_x_gridcell",
            dataset_arguments={"index2": array([[13, 15, 23, 49], [5, 9, 17, 43], [17, 18, 40, 47]], dtype="int32")},
        )
        household_x_gridcell.compute_variables(self.variable_name)
        values = household_x_gridcell.get_attribute(self.variable_name)

        # The values are computed using formula from Ben-Akiva book (Chapter of correcting for sampling bias)
        should_be = (
            array(
                [
                    [-11.3207881, -11.03310603, -12.23707884, -12.13171832],
                    [-15.01597613, -15.01597613, -14.72829406, -13.11885615],
                    [-14.18521949, -14.18521949, -12.57578158, -15.28383178],
                ]
            )
            + 11.03310603
        )

        self.assert_(ma.allclose(values, should_be, rtol=1e-4), msg="Error in " + self.variable_name)
Exemplo n.º 52
0
    def test_my_input(self):
        storage = StorageFactory().get_storage('dict_storage')        
        
        storage.write_table(
            table_name='zones',
            table_data={
                "zone_id": array([1,3]),
                "number_of_jobs": array([10, 1])
            }
        )
        storage.write_table(
            table_name='travel_data',
            table_data={
                "from_zone_id":array([3,3,1,1]),
                "to_zone_id":array([1,3,1,3]),
                "am_total_transit_time_walk":array([1, 2, 3, 4]),
            }
        )
        
        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(self.variable_name, 
                               dataset_pool=dataset_pool)
        values = zone.get_attribute(self.variable_name)
        
        should_be = array([1.17361, 10.25])
        
        self.assert_(ma.allclose(values, should_be, rtol=1e-3), 
                     msg="Error in " + self.variable_name)
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(
            table_name='gridcells',
            table_data={
                'grid_id':
                array([1, 2, 3]),
                'residential_avg_val_per_unit_within_walking_distance':
                array([50, 10, 20]),
            })
        storage.write_table(table_name='households',
                            table_data={
                                'household_id': array([1, 2, 3, 4]),
                                'is_low_income': array([1, 0, 1, 0]),
                            })

        dataset_pool = DatasetPool(package_order=['urbansim'], storage=storage)

        household_x_gridcell = dataset_pool.get_dataset('household_x_gridcell')
        household_x_gridcell.compute_variables(self.variable_name,
                                               dataset_pool=dataset_pool)
        values = household_x_gridcell.get_attribute(self.variable_name)

        should_be = array([[50, 10, 20], [0, 0, 0], [50, 10, 20], [0, 0, 0]])

        self.assert_(ma.allclose(values, should_be, rtol=1e-7),
                     msg="Error in " + self.variable_name)
Exemplo n.º 54
0
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')        
        
        storage.write_table(
            table_name='gridcells',
            table_data={
                'grid_id': array([1, 2, 3]),
                'zone_id': array([1, 1, 3]),
            }
        )
        storage.write_table(
            table_name='zones',
            table_data={
                'zone_id': array([1, 2, 3]),
                "trip_weighted_average_generalized_cost_hbw_to_work_am_drive_alone": array([4.1, 5.3, 6.2]),
            }
        )
        
        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=storage)

        gridcell = dataset_pool.get_dataset('gridcell')
        gridcell.compute_variables(self.variable_name, 
                                   dataset_pool=dataset_pool)
        values = gridcell.get_attribute(self.variable_name)
        
        should_be = array([4.1, 4.1, 6.2])
        
        self.assert_(ma.allclose(values, should_be, rtol=1e-3), 
                     msg="Error in " + self.variable_name)
    def get_values(self, sector, threshold):
        self.variable_name = "urbansim_parcel.zone.sector_%s_employment_within_%s_minutes_travel_time_hbw_am_transit_walk" % (sector, threshold)
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(
            table_name='zones',
            table_data={
                "zone_id":array([1,3]),
                "number_of_jobs_of_sector_2":array([10, 1]),
                "number_of_jobs_of_sector_3":array([7, 2]),
            }
        )
        storage.write_table(
            table_name='travel_data',
            table_data={
                "from_zone_id": array([3,3,1,1]),
                "to_zone_id": array([1,3,1,3]),
                "am_total_transit_time_walk": array([1.1, 2.2, 3.3, 4.4]),
            }
        )

        dataset_pool = DatasetPool(package_order=['urbansim'],
                                   storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(self.variable_name,
                               dataset_pool=dataset_pool)
        values = zone.get_attribute(self.variable_name)
        return values
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')

        building_types_table_name = 'building_types'        
        storage.write_table(
                   table_name=building_types_table_name,
                   table_data={
                    'building_type_id':array([1, 2, 3, 4]), 
                    'generic_building_type_id': array([2,3,1,1])
                    }
                )

        buildings_table_name = 'buildings'        
        storage.write_table(
                 table_name=buildings_table_name,
                 table_data={
                    'building_id':      array([1, 2, 3, 4, 5, 6]),
                    'building_type_id': array([2, 1, 2, 4, 3, 3])
                    }
                )
        dataset_pool = DatasetPool(package_order=['urbansim_parcel', 'urbansim'], storage=storage)
        buildings = dataset_pool.get_dataset('building')
        
        values = buildings.compute_variables(self.variable_name, dataset_pool=dataset_pool)
        
        should_be = array([True, False, True, False, False, False])
        
        self.assert_(ma.allequal(values, should_be),
            'Error in ' + self.variable_name)
Exemplo n.º 57
0
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(table_name='zones',
                            table_data={
                                'zone_id': array([1, 2]),
                            })
        storage.write_table(
            table_name='travel_data',
            table_data={
                "from_zone_id":
                array([1, 1, 2, 2]),
                "to_zone_id":
                array([1, 2, 1, 2]),
                'hbw_daily_drive_to_park_ride_person_trip_table':
                array([1.1, 2.2, 3.3, 4.4]),
            })

        dataset_pool = DatasetPool(package_order=['urbansim'], storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(self.variable_name, dataset_pool=dataset_pool)
        values = zone.get_attribute(self.variable_name)

        should_be = array([3.3, 7.7])

        self.assert_(ma.allclose(values, should_be, rtol=1e-7),
                     msg="Error in " + self.variable_name)
Exemplo n.º 58
0
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(
            table_name='gridcells',
            table_data={
                'grid_id':
                array([1, 2, 3, 4]),
                'relative_x':
                array([1, 2, 1, 2]),
                'relative_y':
                array([1, 1, 2, 2]),
                'number_of_development_type_residential_within_walking_distance':
                array([3, 5, 1, 0])
            })
        storage.write_table(table_name='urbansim_constants',
                            table_data={
                                "walking_distance_circle_radius": array([150]),
                                'cell_size': array([150]),
                                "acres": array([105.0]),
                            })

        dataset_pool = DatasetPool(package_order=['urbansim'], storage=storage)

        gridcell = dataset_pool.get_dataset('gridcell')
        gridcell.compute_variables(self.variable_name,
                                   dataset_pool=dataset_pool)
        values = gridcell.get_attribute(self.variable_name)

        should_be = array([
            3 / 5.0 * 100.0, 5 / 5.0 * 100.0, 1 / 5.0 * 100.0, 0 / 5.0 * 100.0
        ])
    def get_values(self, sector, threshold):
        self.variable_name = "urbansim_parcel.zone.sector_%s_employment_within_%s_minutes_travel_time_hbw_am_drive_alone" % (
            sector, threshold)
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(table_name='zones',
                            table_data={
                                "zone_id": array([1, 3]),
                                "number_of_jobs_of_sector_2": array([10, 1]),
                                "number_of_jobs_of_sector_3": array([7, 2]),
                            })
        storage.write_table(table_name='travel_data',
                            table_data={
                                "from_zone_id":
                                array([3, 3, 1, 1]),
                                "to_zone_id":
                                array([1, 3, 1, 3]),
                                "am_single_vehicle_to_work_travel_time":
                                array([1.1, 2.2, 3.3, 4.4]),
                            })

        dataset_pool = DatasetPool(package_order=['urbansim'], storage=storage)

        zone = dataset_pool.get_dataset('zone')
        zone.compute_variables(self.variable_name, dataset_pool=dataset_pool)
        values = zone.get_attribute(self.variable_name)
        return values