|
| 1 | +.. _user-guide-cli: |
| 2 | + |
| 3 | +Command-line interface |
| 4 | +======================== |
| 5 | + |
| 6 | +Zarr-Python provides a command-line interface that enables: |
| 7 | + |
| 8 | +- migration of Zarr v2 metadata to v3 |
| 9 | +- removal of v2 or v3 metadata |
| 10 | + |
| 11 | +To see available commands run the following in a terminal: |
| 12 | + |
| 13 | +.. code-block:: bash |
| 14 | +
|
| 15 | + $ zarr --help |
| 16 | +
|
| 17 | +or to get help on individual commands: |
| 18 | + |
| 19 | +.. code-block:: bash |
| 20 | +
|
| 21 | + $ zarr migrate --help |
| 22 | +
|
| 23 | + $ zarr remove-metadata --help |
| 24 | +
|
| 25 | +
|
| 26 | +Migrate metadata from v2 to v3 |
| 27 | +------------------------------ |
| 28 | + |
| 29 | +Migrate to a separate location |
| 30 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 31 | + |
| 32 | +To migrate a Zarr array/group's metadata from v2 to v3 run: |
| 33 | + |
| 34 | +.. code-block:: bash |
| 35 | +
|
| 36 | + $ zarr migrate v3 path/to/input.zarr path/to/output.zarr |
| 37 | +
|
| 38 | +This will write new ``zarr.json`` files to ``output.zarr``, leaving ``input.zarr`` un-touched. |
| 39 | +Note - this will migrate the entire Zarr hierarchy, so if ``input.zarr`` contains multiple groups/arrays, |
| 40 | +new ``zarr.json`` will be made for all of them. |
| 41 | + |
| 42 | +Migrate in-place |
| 43 | +~~~~~~~~~~~~~~~~ |
| 44 | + |
| 45 | +If you'd prefer to migrate the metadata in-place run: |
| 46 | + |
| 47 | +.. code-block:: bash |
| 48 | +
|
| 49 | + $ zarr migrate v3 path/to/input.zarr |
| 50 | +
|
| 51 | +This will write new ``zarr.json`` files to ``input.zarr``, leaving the existing v2 metadata un-touched. |
| 52 | + |
| 53 | +To open the array/group using the new metadata use: |
| 54 | + |
| 55 | +.. code-block:: python |
| 56 | +
|
| 57 | + >>> import zarr |
| 58 | + >>> zarr_with_v3_metadata = zarr.open('path/to/input.zarr', zarr_format=3) |
| 59 | +
|
| 60 | +Once you are happy with the conversion, you can run the following to remove the old v2 metadata: |
| 61 | + |
| 62 | +.. code-block:: bash |
| 63 | +
|
| 64 | + $ zarr remove-metadata v2 path/to/input.zarr |
| 65 | +
|
| 66 | +Note there is also a shortcut to migrate and remove v2 metadata in one step: |
| 67 | + |
| 68 | +.. code-block:: bash |
| 69 | +
|
| 70 | + $ zarr migrate v3 path/to/input.zarr --remove-v2-metadata |
| 71 | +
|
| 72 | +
|
| 73 | +Remove metadata |
| 74 | +---------------- |
| 75 | + |
| 76 | +Remove v2 metadata using: |
| 77 | + |
| 78 | +.. code-block:: bash |
| 79 | +
|
| 80 | + $ zarr remove-metadata v2 path/to/input.zarr |
| 81 | +
|
| 82 | +or v3 with: |
| 83 | + |
| 84 | +.. code-block:: bash |
| 85 | +
|
| 86 | + $ zarr remove-metadata v3 path/to/input.zarr |
| 87 | +
|
| 88 | +By default, this will only allow removal of metadata if a valid alternative exists. For example, you can't |
| 89 | +remove v2 metadata unless v3 metadata exists at that location. |
| 90 | + |
| 91 | +To override this behaviour use ``--force``: |
| 92 | + |
| 93 | +.. code-block:: bash |
| 94 | +
|
| 95 | + $ zarr remove-metadata v3 path/to/input.zarr --force |
| 96 | +
|
| 97 | +
|
| 98 | +Dry run |
| 99 | +-------- |
| 100 | +All commands provide a ``--dry-run`` option that will log changes that would be made on a real run, without creating |
| 101 | +or modifying any files. |
| 102 | + |
| 103 | +.. code-block:: bash |
| 104 | +
|
| 105 | + $ zarr migrate v3 path/to/input.zarr --dry-run |
| 106 | +
|
| 107 | + Dry run enabled - no new files will be created or changed. Log of files that would be created on a real run: |
| 108 | + Saving metadata to path/to/input.zarr/zarr.json |
| 109 | +
|
| 110 | +
|
| 111 | +Verbose |
| 112 | +-------- |
| 113 | +You can also add ``--verbose`` **before** any command, to see a full log of its actions: |
| 114 | + |
| 115 | +.. code-block:: bash |
| 116 | +
|
| 117 | + $ zarr --verbose migrate v3 path/to/input.zarr |
| 118 | +
|
| 119 | + $ zarr --verbose remove-metadata v2 path/to/input.zarr |
| 120 | +
|
| 121 | +
|
| 122 | +Equivalent functions |
| 123 | +-------------------- |
| 124 | +All features of the command-line interface are also available via functions under |
| 125 | +:mod:`zarr.metadata`. |
| 126 | + |
| 127 | + |
0 commit comments