pam.samplers.facility
            FacilitySampler(facilities, zones, activities=None, build_xml=True, fail=True, random_default=True, weight_on=None, max_walk=None, transit_modes=None, expected_euclidean_speeds=None, activity_areas_path=None, seed=None)
#
  Sampler object for facilities.
Note
If a zone id is missing then the sampler will not be able to default to random sample, so will either return None or fail as per the fail flag.
| PARAMETER | DESCRIPTION | 
|---|---|
facilities | 
          
             facilities Geodataframe 
                
                  TYPE:
                      | 
        
zones | 
          
             zones Geodataframe 
                
                  TYPE:
                      | 
        
activities | 
          
             optionally set list of subset of activities to be considered. Defaults to None.  | 
        
build_xml | 
          
             flag to build a facility xml output (for MATSim). Defaults to True. 
                
                  TYPE:
                      | 
        
fail | 
          
             flag hard fail if sample not found. Defaults to True. 
                
                  TYPE:
                      | 
        
random_default | 
          
             flag for defaulting to random sample when activity missing. Defaults to True. 
                
                  TYPE:
                      | 
        
weight_on | 
          
             the column name of the facilities geodataframe which contains facility weights (for sampling). Defaults to None.  | 
        
max_walk | 
          
             maximum walking distnace from a transit stop. Defaults to None.  | 
        
transit_modes | 
          
             a list of PT modes. If not specified, the default list in variables.TRANSIT_MODES is used. Defaults to None.  | 
        
expected_euclidean_speeds | 
          
             a dictionary specifying the euclidean speed of the various modes (m/s). If not specified, the default list in variables.EXPECTED_EUCLIDEAN_SPEEDS is used. Defaults to None.  | 
        
activity_areas_path | 
          
             path to the activity areas shapefile (previously exported throught the FacilitySampler.export_activity_areas method). Defaults to None.  | 
        
seed | 
          
             If given, seed number for reproducible results. Defaults to None.  | 
        
Source code in pam/samplers/facility.py
                
          EXPECTED_EUCLIDEAN_SPEEDS = expected_euclidean_speeds if expected_euclidean_speeds is not None else variables.EXPECTED_EUCLIDEAN_SPEEDS
  
  
      instance-attribute
  
#
  
          TRANSIT_MODES = transit_modes if transit_modes is not None else variables.TRANSIT_MODES
  
  
      instance-attribute
  
#
  
          activities = list(set(facilities.activity))
  
  
      instance-attribute
  
#
  
          activity_areas = self.spatial_join(facilities, zones)
  
  
      instance-attribute
  
#
  
          activity_areas_dict = self.activity_areas_indexing(self.activity_areas)
  
  
      instance-attribute
  
#
  
          build_xml = build_xml
  
  
      instance-attribute
  
#
  
          error_counter = 0
  
  
      instance-attribute
  
#
  
          facilities = {}
  
  
      instance-attribute
  
#
  
          fail = fail
  
  
      instance-attribute
  
#
  
          index_counter = 0
  
  
      instance-attribute
  
#
  
          logger = logging.getLogger(__name__)
  
  
      instance-attribute
  
#
  
          random_default = random_default
  
  
      instance-attribute
  
#
  
          random_sampler = RandomPointSampler(geoms=zones, fail=fail, seed=seed)
  
  
      instance-attribute
  
#
  
          samplers = self.build_facilities_sampler(self.activity_areas_dict, weight_on=weight_on, max_walk=max_walk)
  
  
      instance-attribute
  
#
  
          seed = seed
  
  
      instance-attribute
  
#
  
          activity_areas_indexing(activity_areas)
#
  Convert joined zone-activities gdf to a nested dictionary for faster indexing.
The first index level refers to zones, while the second to activity purposes.
Source code in pam/samplers/facility.py
            
          build_facilities_sampler(activity_areas, weight_on=None, max_walk=None)
#
  Build facility location sampler from osmfs input.
The sampler returns a tuple of (uid, Point). TODO: I do not like having a sjoin and assuming index names here TODO: look to move to more carefully defined input data format for facilities.
| PARAMETER | DESCRIPTION | 
|---|---|
activity_areas | 
          
             
                
                  TYPE:
                      | 
        
weight_on | 
          
             a column (name) of the facilities geodataframe to be used as a sampling weight. Defaults to None.  | 
        
max_walk | 
          
             Defaults to None.  | 
        
| RETURNS | DESCRIPTION | 
|---|---|
              dict
           | 
          
             
                
                  TYPE:
                      | 
        
Source code in pam/samplers/facility.py
            
          export_activity_areas(filepath)
#
  
          load_activity_areas(filepath)
#
  
          sample(location_idx, activity, mode=None, previous_duration=None, previous_loc=None)
#
  Sample a Point from the given location and for the given activity.
| PARAMETER | DESCRIPTION | 
|---|---|
location_idx | 
          
             the zone to sample from 
                
                  TYPE:
                      | 
        
activity | 
          
             activity purpose 
                
                  TYPE:
                      | 
        
mode | 
          
             transport mode used to access facility. Defaults to None.  | 
        
previous_duration | 
          
             the time duration of the arriving leg. Defaults to None.  | 
        
previous_loc | 
          
             the location of the last visited activity. Defaults to None. 
                
                  TYPE:
                      | 
        
| RETURNS | DESCRIPTION | 
|---|---|
              
                  Point
              
           | 
          
             shapely.geometry.Point: Sampled point  | 
        
Source code in pam/samplers/facility.py
            
          sample_facility(location_idx, activity, patience=1000, mode=None, previous_duration=None, previous_loc=None)
#
  Sample a facility id and location. If a location idx is missing, can return a random location.
Source code in pam/samplers/facility.py
            
          spatial_join(facilities, zones)
#
  Spatially join facility and zone data.
Source code in pam/samplers/facility.py
            
          
          write_facilities_xml(path, comment=None, coordinate_reference_system=None)
#
  Source code in pam/samplers/facility.py
            
          euclidean_distance(p1, p2)
#
  
          inf_yielder(candidates, weights=None, transit_distance=None, max_walk=None, transit_modes=None, expected_euclidean_speeds=None, seed=None)
#
  Redirect to the appropriate sampler.
| PARAMETER | DESCRIPTION | 
|---|---|
candidates | 
          
             Tuples contain candidate facilities index values and their geolocation.  | 
        
weights | 
          
             sampling weights (ie facility floorspace). Defaults to None.  | 
        
transit_distance | 
          
             distance of each candidate facility from the closest PT stop. Defaults to None.  | 
        
max_walk | 
          
             maximum walking distance from a PT stop. Defaults to None.  | 
        
transit_modes | 
          
             Possible transit modes. Defaults to None.  | 
        
expected_euclidean_speeds | 
          
             Defaults to None.  | 
        
seed | 
          
             If given, seed number for reproducible results. Defaults to None.  | 
        
| RETURNS | DESCRIPTION | 
|---|---|
              
                  tuple[Any, Point]
              
           | 
          
             tuple[Any, shapely.geometry.Point]: Sampled candidate.  | 
        
Source code in pam/samplers/facility.py
            
          inf_yielder_simple(candidates, seed=None)
#
  Endlessly yield shuffled candidate items.
Source code in pam/samplers/facility.py
            
          inf_yielder_weighted(candidates, weights, transit_distance, max_walk, transit_modes, expected_euclidean_speeds, mode, previous_duration, previous_loc, seed=None)
#
  A more complex sampler, which allows for weighted and rule-based sampling (with replacement).
| PARAMETER | DESCRIPTION | 
|---|---|
candidates | 
          
             Tuples contain candidate facilities index values and their geolocation.  | 
        
weights | 
          
             sampling weights (ie facility floorspace).  | 
        
transit_distance | 
          
             distance of each candidate facility from the closest public transport (PT) stop.  | 
        
max_walk | 
          
             maximum walking distance from a PT stop.  | 
        
transit_modes | 
          
             Possible transit modes.  | 
        
expected_euclidean_speeds | 
          
             | 
        
mode | 
          
             transport mode used to access facility.  | 
        
previous_duration | 
          
             the time duration of the arriving leg.  | 
        
previous_loc | 
          
             the location of the last visited activity. 
                
                  TYPE:
                      | 
        
seed | 
          
             If given, seed number for reproducible results. Defaults to None.  | 
        
| YIELDS | DESCRIPTION | 
|---|---|
              
                  Any
              
           | 
          
             Iterator[tuple[Any, shapely.geometry.Point]]:  |