Tide Controller

HoloOcean worlds support tidal simulation that can be configured either statically within scenario JSON or dynamically at runtime using client commands.

../../_images/tidesinaction.gif

Tide Overview

Tides raise or lower the water level in a HoloOcean world. The water level can be set to a static value, or it can oscillate dynamically in a sinusoidal cycle. The tide can also be changed mid-simulation, either instantaneously or gradually at a maximum rate. Changes to the tide raise or lower the water across the entire world, affecting the water surface, post-processing and all agents.

The tide is configured with one dictionary of settings, the same in the scenario and at runtime:

Setting

Meaning

height

The water level in meters. A tide cycle oscillates around it.

absolute

True (the default) if height is the water level; False if it is a change in meters to add to the current height, for example 1.0 to raise the water a meter.

active

Whether the tide cycle runs.

amplitude

The tide cycle’s amplitude in meters.

period_sec

The time for one full tide cycle, in seconds of simulation time.

max_rate

The fastest the water level may change, in meters per second (see Limiting How Fast the Water Level Changes). Leave it out for no limit.

Settings left out keep their current values. An unknown setting or an invalid value raises a HoloOceanException, and nothing changes.

Note

These older forms still work but are deprecated, and emit a deprecation warning:

  • env.tide(), and the tide controller’s set_tide(), set_tide_cycle() and single-setting setters (set_amplitude, set_period, set_period_sec, set_active, set_max_rate, set_frequency, set_tide_type). Use env.ocean.tide.set_parameters().

  • Assigning env.ocean.tide.amplitude, active or max_rate. Use env.ocean.tide.set_parameters().

  • Reading env.ocean.tide.base_water_level or offset. Use env.ocean.tide.height.

  • A scenario tide given as a number or a [height, absolute] list. Use a dictionary.

  • The period setting (in ticks) and its alias frequency. Use period_sec.

  • The tide_type setting. Only sinusoidal tides exist.

  • The top-level tide and tide_cycle scenario keys. Use ocean.tide; setting the tide both ways is an error.

  • env.tides and env.tide_cycle. Use env.ocean.tide.

Configuring in a Scenario

The tide goes under "tide" in the scenario’s ocean block.

# A static water level of 2.0 meters
config = { "ocean": { "tide": { "height": 2.0 } } }

# A tide cycle of +/- 1.5 m every 120 seconds
config = {
   "ocean": {
      "tide": {
         "active": True,
         "amplitude": 1.5,
         "period_sec": 120,
      }
   }
}

# A tide cycle around a water level of 1.0 m
config = {
   "ocean": {
      "tide": {
         "height": 1.0,
         "active": True,
         "amplitude": 1.5,
         "period_sec": 120,
      }
   }
}

The period stays fixed in seconds: it is converted with the current ticks_per_sec, even if that changes during the run.

Changing the Tide at Runtime

env.ocean.tide.set_parameters() takes the same settings as the scenario. All of the controller’s methods are listed in the Tide API.

env = holoocean.make("...")

# Set the water level to 1.0 meter
env.ocean.tide.set_parameters({"height": 1.0})

# Raise the water level by 1.0 meter from wherever it is now
env.ocean.tide.set_parameters({"height": 1.0, "absolute": False})

# Start a sinusoidal tide cycle
env.ocean.tide.set_parameters({"active": True, "amplitude": 2.5, "period_sec": 60})

# Change only the amplitude of the running cycle
env.ocean.tide.set_parameters({"amplitude": 2.0})

# Read the period in either unit
env.ocean.tide.period_sec      # seconds
env.ocean.tide.period          # ticks

The controller reports its current settings: height is the height last set, with relative changes added, and parameters is a dictionary of all the settings, which set_parameters accepts to restore them. These are the settings, not the water level right now, which moves toward them over time.

env.ocean.tide.height                    # 2.0 after the changes above
saved = env.ocean.tide.parameters
env.ocean.tide.set_parameters(saved)     # restore them later

Limiting How Fast the Water Level Changes

By default every tide change takes effect in a single tick. Setting max_rate (in meters per second) makes the water level move toward each new level gradually instead: a change larger than max_rate times the tick length is spread over several ticks. This applies to static changes and to tide cycles alike, and the water surface, post-processing and agents all move together.

# In the scenario
config = {
   "ocean": {
      "tide": {
         "height": 0.0,
         "max_rate": 0.5,    # Change the water level by at most 0.5 m/s
      }
   }
}

# Or at runtime
env.ocean.tide.set_parameters({"max_rate": 0.5})
env.ocean.tide.set_parameters({"height": 2.0})    # Rises to 2.0 m over 4 seconds of simulation time
env.ocean.tide.set_parameters({"max_rate": None}) # Remove the limit

If a tide cycle changes the water level faster than max_rate (its peak rate is 2π × amplitude / period_sec), a warning is printed, because the cycle would be clipped.

Instantaneous Changes

Pass instant=True to jump to a new level in one tick even when max_rate is set:

env.ocean.tide.set_parameters({"height": 2.0}, instant=True)

An instantaneous change is treated as a reset of the water. Water simulations that keep their own state discard their waves and currents and restart calm at the new level. Floating agents feel the change all at once, so a large jump can push them around. The scenario’s ocean.tide setting is always applied instantaneously, since it’s the starting water level.

Environment Resets and Newly Spawned Agents

env.reset() reloads the level, which puts the water back at its default level, and then reapplies the scenario’s ocean.tide setting. Any tide changes made during the run are discarded and a tide cycle starts again from the beginning of its period. To change the water level without resetting anything else, use env.ocean.tide.set_parameters().

Agents spawned after a tide change, for example with env.add_agent(), start at the current water level.

Note

For more information on the underlying client command, please refer to TideCommand.