@@ -1078,8 +1078,7 @@ def load_octree(
10781078 the root oct is not refined, there will be only one entry
10791079 for the root, so the size of the mask will be (n_octs - 1)*8 + 1.
10801080 data : dict
1081- A dictionary of 1D arrays. Note that these must of the size of the
1082- number of "False" values in the ``octree_mask``.
1081+ A dictionary of 1D arrays. See note below for the format.
10831082 bbox : array_like (xdim:zdim, LE:RE), optional
10841083 Size of computational domain in units of length
10851084 sim_time : float, optional
@@ -1115,17 +1114,50 @@ def load_octree(
11151114 Optional string used to assign a name to the dataset. Stream datasets will use
11161115 this value in place of a filename (in image prefixing, etc.)
11171116
1117+ Note
1118+ ----
1119+ Data is a dictionary with keys (type, field_name). ``type`` is typically
1120+ ``gas`` for gas fields and ``io`` for particle fields, but these are not
1121+ strictly enforced.
1122+
1123+ - Field values are 2D arrays of shape (Ncell, 1), with Ncell the number of
1124+ ``False`` values in ``octree_mask``.
1125+ - Particle values are 1D arrays of shape (Npart,), with Npart the number of
1126+ particles
1127+
1128+ Each entry can be:
1129+ 1. A raw numpy array. If it is a known field (e.g., density), it is assumed
1130+ to be in code units. If it is not a known field, it is assumed to be
1131+ dimensionless.
1132+ 2. A tuple (numpy array, unit string). As above, but the type is now
1133+ explicit.
1134+ 3. Instead of a numpy array, a parameter-less function that returns a
1135+ numpy array can be provided. This is useful for cases where the data
1136+ is generated on-the-fly, or to implement a basic form of lazy loading.
1137+ **Note that this is only supported for fields, not particles.**
1138+
11181139 Example
11191140 -------
11201141
11211142 >>> import numpy as np
1122- >>> oct_mask = np.zeros(33) # 5 refined values gives 7 * 4 + 5 octs to mask
1143+ >>> oct_mask = np.zeros(33) # 5 refined values gives 7 * 4 + 5 octs to mask
11231144 ... oct_mask[[0, 5, 7, 16]] = 8
11241145 >>> octree_mask = np.array(oct_mask, dtype=np.uint8)
11251146 >>> quantities = {}
1126- >>> quantities["gas", "density"] = np.random.random((29, 1)) # num of false's
1127- >>> # Quantities can also contain parameter-less callbacks
1128- >>> quantities["gas", "temperature"] = lambda: np.random.random((29, 1)) * 1e4
1147+ ... # Note: there are 29 leaf cells
1148+ ... quantities["gas", "density"] = np.random.random((29, 1))
1149+ ... quantities["gas", "dinosaurs"] = np.random.random((29, 1))
1150+ ... quantities["gas", "turtle_number_density"] = (np.random.random((29, 1)), "1/cm**3")
1151+ ... quantities["gas", "costly_field"] = lambda: np.random.random((29, 1))
1152+ ... quantities["gas", "costly_field_with_units"] = (lambda: np.random.random((29, 1)), "K")
1153+ >>> # Load in 123 particles
1154+ ... quantities["io", "particle_position_x"] = np.random.random(123)
1155+ ... quantities["io", "particle_position_y"] = np.random.random(123)
1156+ ... quantities["io", "particle_position_z"] = np.random.random(123)
1157+ ... # This also works
1158+ ... quantities["io", "particle_position"] = np.random.random((123, 3))
1159+ ... quantities["io", "particle_mass"] = (np.random.random(123), "g")
1160+
11291161 >>> bbox = np.array([[-10.0, 10.0], [-10.0, 10.0], [-10.0, 10.0]])
11301162
11311163 >>> ds = load_octree(
0 commit comments