Skip to content

Creating a World

Creating a JUNE World

A key step in using JUNE is creating a "world" - a simulation environment with geographic locations, buildings, and populations. For an example script see example_scripts/create_world_2.py. Here is a summary of how to create a basic world:

Understanding World Creation

A JUNE world consists of: - Geographic areas (super areas, areas, and locations) - Buildings (households, schools, hospitals, etc.) - Population (people with demographic attributes) - Leisure venues (pubs, cinemas, etc.) - Travel networks (commuting patterns)

Example: Creating a Basic World

Here's a step-by-step guide to create a world based on the example script:

  1. Activate your JUNE environment: bash conda activate JUNE

  2. Create a script or modify the example script at example_scripts/create_world.py

  3. Define geographic location: ```python import os import numpy as np from june.geography import Geography

# Define which MSOAs (Middle Layer Super Output Areas) to load # These are UK geographic units file_path = os.path.join(os.path.dirname(file), "london_areas.txt") msoas_to_load = np.loadtxt(file_path, dtype=np.str_)

# Load geography for these areas geography = Geography.from_file({"super_area": msoas_to_load}) ```

  1. Add buildings to the geography: ```python from june.groups import Hospitals, Schools, Companies, CareHomes, Universities

# Add different types of buildings geography.hospitals = Hospitals.for_geography(geography) geography.companies = Companies.for_geography(geography) geography.schools = Schools.for_geography(geography) geography.universities = Universities.for_geography(geography) geography.care_homes = CareHomes.for_geography(geography) ```

  1. Generate the world: ```python from june.world import generate_world_from_geography

# Generate world including households world = generate_world_from_geography(geography, include_households=True) ```

  1. Add leisure activities: ```python from june.groups.leisure import ( Pubs, Cinemas, Groceries, Gyms, generate_leisure_for_config )

# Add different types of leisure venues world.pubs = Pubs.for_geography(geography) world.cinemas = Cinemas.for_geography(geography) world.groceries = Groceries.for_geography(geography) world.gyms = Gyms.for_geography(geography)

# Generate leisure activities leisure = generate_leisure_for_config(world) leisure.distribute_social_venues_to_areas( areas=world.areas, super_areas=world.super_areas ) # Assigns possible social venues to people ```

  1. Add travel networks: ```python from june.groups.travel import Travel

# Initialise commuting patterns travel = Travel() travel.initialise_commute(world) ```

  1. Save the world: python # Save the world to an HDF5 file to load it later world.to_hdf5("my_world.hdf5") print("World created and saved!")

  2. Run your script: bash python create_world.py

This will create a world file (my_world.hdf5) that can be loaded in subsequent simulations.

Common Issues with World Creation

  • Memory usage: Creating large worlds can require significant RAM. Start with a small number of areas first.
  • Missing data: Ensure all necessary data files are available in the expected locations.
  • HDF5 errors: If you encounter errors saving or loading the world, check that h5py is properly installed.
  • Performance: World creation can be time-consuming. The script includes profiling to help identify bottlenecks.

Loading a Saved World

To use your saved world in a simulation:

from june.world import World

# Load the world from the HDF5 file
world = World.from_hdf5("my_world.hdf5")

Example Script

For an example script see example_scripts/create_world_2.py