Creates a new `Scene` or a batch of new scenes inside `parent_directory`. See Also: `Scene.at()`, `Scene.list()`. Args: parent_directory: Directory to hold the new `Scene`. If it doesn't exist, it will be created. shape: Determines numbe
(parent_directory: str,
shape: math.Shape = math.EMPTY_SHAPE,
name='sim',
copy_calling_script=True,
**dimensions)
| 109 | |
| 110 | @staticmethod |
| 111 | def create(parent_directory: str, |
| 112 | shape: math.Shape = math.EMPTY_SHAPE, |
| 113 | name='sim', |
| 114 | copy_calling_script=True, |
| 115 | **dimensions) -> 'Scene': |
| 116 | """ |
| 117 | Creates a new `Scene` or a batch of new scenes inside `parent_directory`. |
| 118 | |
| 119 | See Also: |
| 120 | `Scene.at()`, `Scene.list()`. |
| 121 | |
| 122 | Args: |
| 123 | parent_directory: Directory to hold the new `Scene`. If it doesn't exist, it will be created. |
| 124 | shape: Determines number of scenes to create. Multiple scenes will be represented by a `Scene` with `is_batch=True`. |
| 125 | name: Name of the directory (excluding index). Default is `'sim'`. |
| 126 | copy_calling_script: Whether to copy the Python file that invoked this method into the `src` folder of all created scenes. |
| 127 | See `Scene.copy_calling_script()`. |
| 128 | dimensions: Additional batch dimensions |
| 129 | |
| 130 | Returns: |
| 131 | Single `Scene` object representing the new scene(s). |
| 132 | """ |
| 133 | shape = shape & math.batch(**dimensions) |
| 134 | parent_directory = expanduser(parent_directory) |
| 135 | abs_dir = abspath(parent_directory) |
| 136 | if not isdir(abs_dir): |
| 137 | os.makedirs(abs_dir) |
| 138 | next_id = 0 |
| 139 | else: |
| 140 | indices = [int(f[len(name)+1:]) for f in os.listdir(abs_dir) if f.startswith(f"{name}_")] |
| 141 | next_id = max([-1] + indices) + 1 |
| 142 | ids = unpack_dim(wrap(tuple(range(next_id, next_id + shape.volume))), 'vector', shape) |
| 143 | paths = math.map(lambda id_: join(parent_directory, f"{name}_{id_:06d}"), ids) |
| 144 | scene = Scene(paths) |
| 145 | scene.mkdir() |
| 146 | if copy_calling_script: |
| 147 | try: |
| 148 | scene.copy_calling_script() |
| 149 | except IOError as err: |
| 150 | warnings.warn(f"Failed to copy calling script to scene during Scene.create(): {err}", RuntimeWarning) |
| 151 | return scene |
| 152 | |
| 153 | @staticmethod |
| 154 | def list(parent_directory: str, |