def __init__(self, **kwargs):
        districts = self._try_load_district_dataset(**kwargs)
        if districts is not None:
            district_ids = districts.get_id_attribute()
            OD_array = array([[x, y] for x in district_ids
                              for y in district_ids])

            storage = StorageFactory().get_storage('dict_storage')

            storage.write_table(table_name=self.in_table_name_default,
                                table_data={
                                    'commute_id':
                                    OD_array[:, 0] * 1000 + OD_array[:, 1],
                                    'origin_district_id':
                                    OD_array[:, 0],
                                    'destination_district_id':
                                    OD_array[:, 1],
                                })

            UrbansimDataset.__init__(
                self,
                in_storage=storage,
                #in_table_name=self.in_table_name_default,
                #id_name=self.id_name_default,
                #dataset_name=self.dataset_name
            )
        else:
            UrbansimDataset.__init__(self, **kwargs)
Ejemplo n.º 2
0
    def __init__(self, subgroup_definition=[], **kwargs):
        in_storage = kwargs.get('in_storage', None)
        if self.use_cached_table_if_exists and in_storage and in_storage.table_exists(self.in_table_name_default): 
            return UrbansimDataset.__init__(self, **kwargs)

        if subgroup_definition:
            self.subgroup_definition = subgroup_definition
            
        dataset, short_names, subgroup_ids = self.solve_dependencies(**kwargs)
        table_data = {}
            
        table_data[self.id_name_default], unique_index = np_unique( subgroup_ids, return_index=True )
        
        table_data.update([(short_name, dataset[short_name][unique_index]) for short_name in short_names])

        storage = StorageFactory().get_storage('dict_storage')
        storage.write_table(table_name=self.in_table_name_default,
                            table_data=table_data
                            ) 
    
        UrbansimDataset.__init__(self, in_storage=storage, 
                                 #in_table_name=self.in_table_name_default, 
                                 #id_name=self.id_name_default, 
                                 #dataset_name=self.dataset_name
                             )
    def __init__(self, **kwargs):
        districts = self._try_load_district_dataset(**kwargs)
        if districts is not None:
            district_ids = districts.get_id_attribute()
            OD_array = array([[x, y] for x in district_ids for y in district_ids])

            storage = StorageFactory().get_storage("dict_storage")

            storage.write_table(
                table_name=self.in_table_name_default,
                table_data={
                    "commute_id": OD_array[:, 0] * 1000 + OD_array[:, 1],
                    "origin_district_id": OD_array[:, 0],
                    "destination_district_id": OD_array[:, 1],
                },
            )

            UrbansimDataset.__init__(
                self,
                in_storage=storage,
                # in_table_name=self.in_table_name_default,
                # id_name=self.id_name_default,
                # dataset_name=self.dataset_name
            )
        else:
            UrbansimDataset.__init__(self, **kwargs)
Ejemplo n.º 4
0
 def __init__(self, **kwargs):
     UrbansimDataset.__init__(self, **kwargs)
     node_ids = self.get_id_attribute()
     node_d = dict(zip(self.d['nodeids'],range(len(node_ids))))
     node_ids = [node_d[x] for x in node_ids]
     self.node_ids = array(node_ids, dtype="int32")
     global MAXDISTANCE, pya
     self.MAXDISTANCE = MAXDISTANCE
     self.pya = pya
Ejemplo n.º 5
0
    def __init__(self, id_values=id_values, **kwargs):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(table_name=self.in_table_name_default,
                            table_data= {
                                         self.id_name_default: id_values,
                                         }
                            )

        kwargs.update({'in_storage': storage})
        UrbansimDataset.__init__(self, **kwargs)
 def __init__(self,
              resources=None,
              dataset1=None,
              dataset2=None,
              index1=None,
              index2=None,
              **kwargs):
     """ This dataset is an interaction of two datasets (originally, parcel and development template).
         It's similar to InteractionSet, but flattend to 1d, thus regression model can use this dataset without changes
     """
     UrbansimDataset.__init__(self, resources=resources, **kwargs)
     self._set_my_class_attributes(dataset1, dataset2, index1, index2)
Ejemplo n.º 7
0
    def __init__(self, id_values=None, fazset=None, **kwargs):

        UrbansimDataset.__init__(self, **kwargs)

        if id_values <> None:
            self._add_id_attribute(data=id_values, name=self.get_id_name()[0])
        elif fazset <> None:
            if (self.get_id_name()[0] not in fazset.get_attribute_names()) and \
                (self.get_id_name()[0] not in fazset.get_primary_attribute_names()):
                raise StandardError, "Given FazDataset does not contain " + self.get_id_name()[0]
            large_area_ids = fazset.get_attribute(self.get_id_name()[0])
            unique_ids = unique(large_area_ids[large_area_ids >=0])
            self._add_id_attribute(data=unique_ids, name=self.get_id_name()[0])
        self._create_id_mapping_array()
Ejemplo n.º 8
0
    def __init__(self, id_values=None, gridcellset=None, **kwargs):

        UrbansimDataset.__init__(self, **kwargs)

        if id_values <> None:
            self._add_id_attribute(data=id_values, name=self.get_id_name()[0])
        elif gridcellset <> None:
            if (self.get_id_name()[0] not in gridcellset.get_attribute_names()) and \
                (self.get_id_name()[0] not in gridcellset.get_primary_attribute_names()):
                raise StandardError, "Given gridcellset does not contain " + self.get_id_name()[0]
            large_area_ids = gridcellset.get_attribute(self.get_id_name()[0])
            idx = large_area_ids >=0
            unique_ids = unique(large_area_ids[idx])
            self._add_id_attribute(data=unique_ids, name=self.get_id_name()[0])
        self._create_id_mapping_array()
Ejemplo n.º 9
0
    def __init__(self, id_values=1, **kwargs):
        storage = StorageFactory().get_storage('dict_storage')

        storage.write_table(table_name='regions',
            table_data={
                self.id_name_default:array([id_values])
                }
            )

        resources = Resources({
            'in_storage':storage,
            'in_table_name':'regions'
            })

        UrbansimDataset.__init__(self, resources=resources, **kwargs)
Ejemplo n.º 10
0
    def test_my_inputs(self):
        storage = StorageFactory().get_storage('dict_storage')

        landuse_filter_table_name = 'landuse_filter'
        storage.write_table(
                table_name=landuse_filter_table_name,
                table_data={
                    'id':array([1,2,3,4]),
                    'from_development_type_id':array([1,1,3,5]),
                    'to_development_type_id':array([4,6,2,2])
                    },
            )

        landuse_filter = Dataset(
            id_name='id',
            in_storage=storage,
            in_table_name = landuse_filter_table_name
            )

        values = VariableTestToolbox().compute_variable(self.variable_name,
            data_dictionary = {
                'gridcell':{
                    'development_type_id':array([1,2,5])
                    },
                'development_filter':landuse_filter
                },
            dataset = 'gridcell'
            )

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

        self.assert_(ma.allequal(values, should_be),
            'Error in ' + self.variable_name)
    def _compute_if_needed(self, name, dataset_pool, resources=None, quiet=False, version=None):
        """ Compute variable given by the argument 'name' only if this variable
        has not been computed before.
        Check first if this variable belongs to dataset1 or dataset2.
        dataset_pool holds available datasets.
        """
        if not isinstance(name, VariableName):
            variable_name = VariableName(name)
        else:
            variable_name = name
        short_name = variable_name.get_alias()

        dataset_name = variable_name.get_dataset_name()
        if dataset_name == self.get_dataset_name():
            new_version = UrbansimDataset._compute_if_needed(self, variable_name, dataset_pool, resources, quiet=quiet, version=version)
        else:
            if dataset_name == self.dataset1.get_dataset_name():
                owner_dataset = self.dataset1
#                index = self.get_2d_index_of_dataset1()
            elif dataset_name == self.dataset2.get_dataset_name():
                owner_dataset = self.dataset2
#                index = self.get_2d_index()
            else:
                self._raise_error(StandardError, "Cannot find variable '%s'\nin either dataset or in the interaction set." %
                                variable_name.get_expression())
            owner_dataset.compute_variables([variable_name], dataset_pool, resources=resources, quiet=True)
            new_version =  self.compute_variables_return_versions_and_final_value("%s = %s.disaggregate(%s.%s)" % \
                                   ( short_name, self.get_dataset_name(), owner_dataset.get_dataset_name(), short_name ),
                                   dataset_pool=dataset_pool, resources=resources, quiet=quiet )[0]
        return new_version
Ejemplo n.º 12
0
    def __init__(self, id_values=None, zoneset=None, **kwargs):

        UrbansimDataset.__init__(self, **kwargs)

        self.same_age_table = None
        self.same_sector_table = None

        if id_values <> None:
            self._add_id_attribute(data=id_values, name=self.get_id_name()[0])
        elif zoneset <> None:
            if (self.get_id_name()[0] not in zoneset.get_known_attribute_names()):
                raise StandardError, "Given ZoneDataset does not contain " + self.get_id_name()[0]
            fazids = zoneset.get_attribute(self.get_id_name()[0])
            unique_ids = unique(fazids[fazids >=0])
            self._add_id_attribute(data=unique_ids, name=self.get_id_name()[0])
        self._create_id_mapping_array()
Ejemplo n.º 13
0
    def __init__(self, id_values=None, fazset=None, **kwargs):

        UrbansimDataset.__init__(self, **kwargs)

        self.same_age_table = None
        self.same_sector_table = None

        if id_values <> None:
            self._add_id_attribute(data=id_values, name=self.get_id_name()[0])
        elif fazset <> None:
            if (self.get_id_name()[0] not in fazset.get_attribute_names()) and \
                (self.get_id_name()[0] not in fazset.get_primary_attribute_names()):
                raise StandardError, "Given FazDataset does not contain " + self.get_id_name()[0]
            fazdistricts = fazset.get_attribute(self.get_id_name()[0])
            unique_ids = unique(fazdistricts[fazdistricts >=0])
            self._add_id_attribute(data=unique_ids, name=self.get_id_name()[0])
Ejemplo n.º 14
0
    def __init__(self, id_values=None, fazset=None, **kwargs):

        UrbansimDataset.__init__(self, **kwargs)

        self.same_age_table = None
        self.same_sector_table = None

        if id_values <> None:
            self._add_id_attribute(data=id_values, name=self.get_id_name()[0])
        elif fazset <> None:
            if (self.get_id_name()[0] not in fazset.get_attribute_names()) and \
                (self.get_id_name()[0] not in fazset.get_primary_attribute_names()):
                raise StandardError, "Given FazDataset does not contain " + self.get_id_name(
                )[0]
            fazdistricts = fazset.get_attribute(self.get_id_name()[0])
            unique_ids = unique(fazdistricts[fazdistricts >= 0])
            self._add_id_attribute(data=unique_ids, name=self.get_id_name()[0])
Ejemplo n.º 15
0
    def __init__(self, id_values=None, zoneset=None, **kwargs):

        UrbansimDataset.__init__(self, **kwargs)

        self.same_age_table = None
        self.same_sector_table = None

        if id_values <> None:
            self._add_id_attribute(data=id_values, name=self.get_id_name()[0])
        elif zoneset <> None:
            if (self.get_id_name()[0]
                    not in zoneset.get_known_attribute_names()):
                raise StandardError, "Given ZoneDataset does not contain " + self.get_id_name(
                )[0]
            fazids = zoneset.get_attribute(self.get_id_name()[0])
            unique_ids = unique(fazids[fazids >= 0])
            self._add_id_attribute(data=unique_ids, name=self.get_id_name()[0])
        self._create_id_mapping_array()
    def __init__(self, submarket_definition=[], **kwargs):
        if submarket_definition:
            self.submarket_definition = submarket_definition
            
        dataset, short_names, submarket_ids = self.solve_dependencies(**kwargs)
        table_data = {}
            
        table_data['submarket_id'], unique_index = unique( submarket_ids, return_index=True )
        
        table_data.update([(short_name, dataset[short_name][unique_index]) for short_name in short_names])

        storage = StorageFactory().get_storage('dict_storage')        
        storage.write_table(table_name=self.in_table_name_default,
                            table_data=table_data
                            ) 
    
        UrbansimDataset.__init__(self, in_storage=storage, 
                                 #in_table_name=self.in_table_name_default, 
                                 #id_name=self.id_name_default, 
                                 #dataset_name=self.dataset_name
                             )
Ejemplo n.º 17
0
 def __init__(self, **kwargs):
     fazes, sectors = self._try_load_datasets(**kwargs)
     if fazes is not None:
         faz_id = fazes.get_id_attribute()
         sector_id = sectors.get_id_attribute()
         combine_array = array( [[x, y]  for x in faz_id for y in sector_id] )
         storage = StorageFactory().get_storage('dict_storage')        
         storage.write_table(table_name=self.in_table_name_default,
                             table_data={
                                         'dummy_id'   :combine_array[:, 0] * 100 + combine_array[:,1],
                                         'faz_id'     :combine_array[:, 0],
                                         'sector_id'  :combine_array[:, 1],
                                         }
                             ) 
     
         UrbansimDataset.__init__(self, in_storage=storage, 
                                  #in_table_name=self.in_table_name_default, 
                                  #id_name=self.id_name_default, 
                                  #dataset_name=self.dataset_name
                              )
     else:
         UrbansimDataset.__init__(self, **kwargs)
Ejemplo n.º 18
0
 def __init__(self, **kwargs):
     fazes, sectors = self._try_load_datasets(**kwargs)
     if fazes is not None:
         faz_id = fazes.get_id_attribute()
         sector_id = sectors.get_id_attribute()
         combine_array = array( [[x, y]  for x in faz_id for y in sector_id] )
         storage = StorageFactory().get_storage('dict_storage')        
         storage.write_table(table_name=self.in_table_name_default,
                             table_data={
                                         'dummy_id'   :combine_array[:, 0] * 100 + combine_array[:,1],
                                         'faz_id'     :combine_array[:, 0],
                                         'sector_id'  :combine_array[:, 1],
                                         }
                             ) 
     
         UrbansimDataset.__init__(self, in_storage=storage, 
                                  #in_table_name=self.in_table_name_default, 
                                  #id_name=self.id_name_default, 
                                  #dataset_name=self.dataset_name
                              )
     else:
         UrbansimDataset.__init__(self, **kwargs)
Ejemplo n.º 19
0
    def __init__(self, submarket_definition=[], **kwargs):
        if submarket_definition:
            self.submarket_definition = submarket_definition

        dataset, short_names, submarket_ids = self.solve_dependencies(**kwargs)
        table_data = {}

        table_data['submarket_id'], unique_index = unique(submarket_ids,
                                                          return_index=True)

        table_data.update([(short_name, dataset[short_name][unique_index])
                           for short_name in short_names])

        storage = StorageFactory().get_storage('dict_storage')
        storage.write_table(table_name=self.in_table_name_default,
                            table_data=table_data)

        UrbansimDataset.__init__(
            self,
            in_storage=storage,
            #in_table_name=self.in_table_name_default,
            #id_name=self.id_name_default,
            #dataset_name=self.dataset_name
        )
    def _compute_if_needed(self,
                           name,
                           dataset_pool,
                           resources=None,
                           quiet=False,
                           version=None):
        """ Compute variable given by the argument 'name' only if this variable
        has not been computed before.
        Check first if this variable belongs to dataset1 or dataset2.
        dataset_pool holds available datasets.
        """
        if not isinstance(name, VariableName):
            variable_name = VariableName(name)
        else:
            variable_name = name
        short_name = variable_name.get_alias()

        dataset_name = variable_name.get_dataset_name()
        if dataset_name == self.get_dataset_name():
            new_version = UrbansimDataset._compute_if_needed(self,
                                                             variable_name,
                                                             dataset_pool,
                                                             resources,
                                                             quiet=quiet,
                                                             version=version)
        else:
            if dataset_name == self.dataset1.get_dataset_name():
                owner_dataset = self.dataset1
#                index = self.get_2d_index_of_dataset1()
            elif dataset_name == self.dataset2.get_dataset_name():
                owner_dataset = self.dataset2


#                index = self.get_2d_index()
            else:
                self._raise_error(
                    StandardError,
                    "Cannot find variable '%s'\nin either dataset or in the interaction set."
                    % variable_name.get_expression())
            owner_dataset.compute_variables([variable_name],
                                            dataset_pool,
                                            resources=resources,
                                            quiet=True)
            new_version =  self.compute_variables_return_versions_and_final_value("%s = %s.disaggregate(%s.%s)" % \
                                   ( short_name, self.get_dataset_name(), owner_dataset.get_dataset_name(), short_name ),
                                   dataset_pool=dataset_pool, resources=resources, quiet=quiet )[0]
        return new_version
 def __init__(self, **kwargs):
     UrbansimDataset.__init__(self, **kwargs)
 def __init__(self, resources=None, dataset1=None, dataset2=None, index1=None, index2=None, **kwargs):
     """ This dataset is an interaction of two datasets (originally, parcel and development template).
         It's similar to InteractionSet, but flattend to 1d, thus regression model can use this dataset without changes
     """
     UrbansimDataset.__init__(self, resources=resources, **kwargs)
     self._set_my_class_attributes(dataset1, dataset2, index1, index2)
Ejemplo n.º 23
0
    def __init__(self, *args, **kwargs):

        UrbansimDataset.__init__(self, *args, **kwargs)
        self.development_capacity = None
 def get_2d_attribute(self, attribute):
     return UrbansimDataset.get_2d_attribute(self, attribute=attribute)
Ejemplo n.º 25
0
 def __init__(self, *args, **kwargs):
     UrbansimDataset.__init__(self, *args, **kwargs)
     self.mask = None
 def __init__(self, *args, **kwargs):
     UrbansimDataset.__init__(self, *args, **kwargs)               
     
     self.low_income_level = -1
     self.mid_income_level = -1
Ejemplo n.º 27
0
 def __init__(self, *args, **kwargs):
     UrbansimDataset.__init__(self, *args, **kwargs)               
Ejemplo n.º 28
0
 def __init__(self, what='', resources=None, **kwargs):
     # what is a legacy argument that is not used any more
     UrbansimDataset.__init__(self, resources, **kwargs)
     self.independent_variables = []
Ejemplo n.º 29
0
    def __init__(self, *args, **kwargs):

        UrbansimDataset.__init__(self, *args, **kwargs)
        self.development_capacity = None
Ejemplo n.º 30
0
 def __init__(self, id_values=None, **kwargs):
     UrbansimDataset.__init__(self, **kwargs)
     self.development_constraints = None
Ejemplo n.º 31
0
 def __init__(self, **kwargs):
     UrbansimDataset.__init__(self, **kwargs)
     if 'data_link' not in self.get_known_attribute_names():
         raise StandardError, 'Attribute "data_link" must be included in TravelDataLinkDataset'
     path_to_h5 = self.get_attribute('data_link')
     self.skim_dataset = TravelDataH5SkimDataset(path_to_h5[0])
Ejemplo n.º 32
0
 def get_2d_attribute(self, attribute):
     return UrbansimDataset.get_2d_attribute(self, attribute=attribute)
 def __init__(self, *args, **kwargs):
     UrbansimDataset.__init__(self, *args, **kwargs)
     self.mask = None
Ejemplo n.º 34
0
 def flatten_by_id(self, two_d_array):
     return UrbansimDataset.flatten_by_id(self, two_d_array)
 def flatten_by_id(self, two_d_array):
     return UrbansimDataset.flatten_by_id(self, two_d_array)
Ejemplo n.º 36
0
 def __init__(self, id_values=None, **kwargs):
     UrbansimDataset.__init__(self, **kwargs)
Ejemplo n.º 37
0
 def __init__(self, id_values=None, **kwargs):
     UrbansimDataset.__init__(self, **kwargs)
Ejemplo n.º 38
0
 def __init__(self, what='', resources=None, **kwargs):
     # what is a legacy argument that is not used any more
     UrbansimDataset.__init__(self, resources, **kwargs)
     self.independent_variables = []
Ejemplo n.º 39
0
 def _update_id_mapping(self):
     UrbansimDataset._update_id_mapping(self)
     self._create_id_mapping_array()
Ejemplo n.º 40
0
    def __init__(self, *args, **kwargs):
        UrbansimDataset.__init__(self, *args, **kwargs)

        self.low_income_level = -1
        self.mid_income_level = -1