コード例 #1
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
コード例 #2
0
    def prepare_dataset_pool(self, recent_years):
        self.cache_dir = os.path.join(self.urbansim_tmp, 'urbansim_cache')
        SimulationState().set_cache_directory(self.cache_dir)

        data = {
            1997: {
                'grid_id': array([1, 2, 3, 4]),
                'is_in_development_type_group_developed': array([0, 0, 0, 0]),
            },
            1998: {
                'grid_id': array([1, 2, 3, 4]),
                'is_in_development_type_group_developed': array([0, 1, 0, 0]),
            },
            1999: {
                'grid_id': array([1, 2, 3, 4]),
                'is_in_development_type_group_developed': array([0, 0, 1, 0])
            },
            2000: {
                'grid_id': array([1, 2, 3, 4]),
                'is_in_development_type_group_developed': array([1, 1, 1, 0])
            },
            2001: {
                'grid_id': array([1, 2, 3, 4]),
                'is_in_development_type_group_developed':
                array([1, 1, 1, 0]) + 1
            }
        }
        self.write_gridcell_data_to_cache(data)

        storage = StorageFactory().get_storage('dict_storage')
        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
コード例 #3
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)
コード例 #4
0
ファイル: SSSai.py プロジェクト: urban-ai/VIBe2UrbanSim
    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)
    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)
コード例 #6
0
 def test_aggregate_unqualified_name(self):
     # test aggregate without the dataset provided for the variable being aggregated
     expr = 'zone.aggregate(my_variable)'
     # to be correct, should be 'zone.aggregate(gridcell.my_variable)'
     storage = StorageFactory().get_storage('dict_storage')
     storage.write_table(table_name='zones',
                         table_data={
                             'zone_id': array([1, 2]),
                         })
     storage.write_table(table_name='gridcells',
                         table_data={
                             'my_variable': array([4, 8, 0.5, 1]),
                             'grid_id': array([1, 2, 3, 4]),
                             'zone_id': array([1, 2, 1, 2]),
                         })
     zone_dataset = Dataset(in_storage=storage,
                            in_table_name='zones',
                            id_name="zone_id",
                            dataset_name='zone')
     gridcell_dataset = Dataset(in_storage=storage,
                                in_table_name='gridcells',
                                id_name="grid_id",
                                dataset_name='gridcell')
     dataset_pool = DatasetPool()
     dataset_pool._add_dataset('gridcell', gridcell_dataset)
     dataset_pool._add_dataset('zone', zone_dataset)
     self.assertRaises(ValueError,
                       zone_dataset.compute_variables, [expr],
                       dataset_pool=dataset_pool)
コード例 #7
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 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
コード例 #9
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]),
                '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)
コード例 #10
0
ファイル: is_young.py プロジェクト: urban-ai/VIBe2UrbanSim
    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)
コード例 #11
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)
    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)
コード例 #13
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)
コード例 #14
0
 def test_aggregate(self):
     # test aggregate with no function specified (so defaults to 'sum')
     storage = StorageFactory().get_storage('dict_storage')
     storage.write_table(table_name='zones',
                         table_data={
                             'zone_id': array([1, 2]),
                         })
     storage.write_table(table_name='gridcells',
                         table_data={
                             'my_variable': array([4, 8, 0.5, 1]),
                             'grid_id': array([1, 2, 3, 4]),
                             'zone_id': array([1, 2, 1, 2]),
                         })
     zone_dataset = Dataset(in_storage=storage,
                            in_table_name='zones',
                            id_name="zone_id",
                            dataset_name='zone')
     gridcell_dataset = Dataset(in_storage=storage,
                                in_table_name='gridcells',
                                id_name="grid_id",
                                dataset_name='gridcell')
     dataset_pool = DatasetPool()
     dataset_pool._add_dataset('gridcell', gridcell_dataset)
     dataset_pool._add_dataset('zone', zone_dataset)
     values = zone_dataset.compute_variables(
         ['zone.aggregate(gridcell.my_variable)'],
         dataset_pool=dataset_pool)
     should_be = array([4.5, 9])
     self.assert_(ma.allclose(values, should_be, rtol=1e-6),
                  "Error in aggregate")
コード例 #15
0
 def test_disaggregate_fully_qualified_variable(self):
     storage = StorageFactory().get_storage('dict_storage')
     storage.write_table(table_name='zones',
                         table_data={
                             'zone_id': array([1, 2, 3, 4]),
                             'id': array([1, 2, 1, 2])
                         })
     # it would be nicer to call this table 'fazzes' but we want to use the existing test variable
     storage.write_table(table_name='test_locations',
                         table_data={
                             'cost': array([4, 8]),
                             'id': array([1, 2])
                         })
     zone_dataset = Dataset(in_storage=storage,
                            in_table_name='zones',
                            id_name="zone_id",
                            dataset_name="zone")
     test_dataset = Dataset(in_storage=storage,
                            in_table_name='test_locations',
                            id_name="id",
                            dataset_name='test_location')
     dataset_pool = DatasetPool()
     dataset_pool._add_dataset('zone', zone_dataset)
     dataset_pool._add_dataset('test_location', test_dataset)
     values = zone_dataset.compute_variables(
         ['zone.disaggregate(opus_core.test_location.cost_times_3)'],
         dataset_pool=dataset_pool)
     should_be = array([12, 24, 12, 24])
     self.assert_(ma.allclose(values, should_be, rtol=1e-6),
                  "Error in test_disaggregate_fully_qualified_variable")
コード例 #16
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)
コード例 #17
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
        ])
コード例 #18
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
コード例 #19
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)
コード例 #20
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)
コード例 #21
0
 def test_aggregate_bad_function(self):
     # the 'function' argument must be a single name -- test this
     expr = "zone.aggregate(2*gridcell.my_variable, function=3+4)"
     storage = StorageFactory().get_storage('dict_storage')
     storage.write_table(table_name='zones',
                         table_data={
                             'zone_id': array([1, 2]),
                         })
     storage.write_table(table_name='gridcells',
                         table_data={
                             'my_variable': array([4, 8, 0.5, 1]),
                             'grid_id': array([1, 2, 3, 4]),
                             'zone_id': array([1, 2, 1, 2]),
                         })
     zone_dataset = Dataset(in_storage=storage,
                            in_table_name='zones',
                            id_name="zone_id",
                            dataset_name='zone')
     gridcell_dataset = Dataset(in_storage=storage,
                                in_table_name='gridcells',
                                id_name="grid_id",
                                dataset_name='gridcell')
     dataset_pool = DatasetPool()
     dataset_pool._add_dataset('gridcell', gridcell_dataset)
     dataset_pool._add_dataset('zone', zone_dataset)
     self.assertRaises(ValueError,
                       zone_dataset.compute_variables, [expr],
                       dataset_pool=dataset_pool)
コード例 #22
0
ファイル: pSSS.py プロジェクト: urban-ai/VIBe2UrbanSim
    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)
コード例 #23
0
 def setUp(self):
     self.storage = StorageFactory().get_storage('dict_storage')
     self.storage.write_table(
         table_name='buildings',
         table_data={
             "building_id":
             arange(1, 31),  # 1 building per building_type and zone
             "zone_id":
             array([
                 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7,
                 7, 8, 8, 8, 9, 9, 9, 10, 10, 10
             ]),
             "building_type_id":
             array(10 * [1, 2, 3]),
             "residential_units":
             array(10 * [200, 0, 0]),
             "commercial_job_spaces":
             array(10 * [0, 100, 0]),
             "industrial_job_spaces":
             array(10 * [0, 0, 100]),
         })
     self.storage.write_table(
         table_name='building_types',
         table_data={
             "building_type_id": array([1, 2, 3]),
             "name": array(["residential", "commercial", "industrial"]),
         })
     self.dataset_pool = DatasetPool(
         package_order=['urbansim_zone', "urbansim"], storage=self.storage)
     self.buildings = self.dataset_pool.get_dataset('building')
     self.building_types = self.dataset_pool.get_dataset('building_type')
コード例 #24
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)
コード例 #25
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)
コード例 #26
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, 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)
コード例 #27
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_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)
コード例 #30
0
    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)