fatmur commited on
Commit
699fff4
·
verified ·
1 Parent(s): ba1d589

Use Python for bucket uploads and downloads

Browse files
Files changed (4) hide show
  1. README.md +27 -27
  2. requirements.txt +1 -0
  3. scripts/sync_bucket.py +49 -0
  4. scripts/upload.sh +0 -19
README.md CHANGED
@@ -7,7 +7,7 @@ license: cc-by-4.0
7
 
8
  The dataset repository holds the label legend and Parquet indexes. The
9
  [Dynamic World bucket](https://huggingface.co/buckets/fatmur/dynamicworld)
10
- holds the original files under `raw/` and prepared rasters under `processed/`.
11
  Resolve each nonempty `label_path`, `image_path` or `scl_path` against
12
  `hf://buckets/fatmur/dynamicworld/processed/`. The current index covers
13
  24,094 prepared labels. The ingestion log, imagery and SCL are published as
@@ -15,41 +15,40 @@ ingestion progresses.
15
 
16
  ## Download
17
 
18
- Install the Hugging Face CLI (`pip install "huggingface_hub>=1.12"`).
19
- Download all Dynamic World source files and prepared rasters into one local
20
- `data/` directory. Fetch the indexes and legend from the dataset repository.
21
 
22
- ```bash
23
- bucket=hf://buckets/fatmur/dynamicworld
24
- hf sync "$bucket/raw" data/raw
25
- hf sync "$bucket/processed" data/processed --include 'label/**' --include 'image/**' --include 'scl/**'
26
- hf download fatmur/dynamicworld --repo-type dataset --include 'processed/*.parquet' --include 'labels.yaml' --local-dir data
27
  ```
28
 
29
- For prepared data only, skip the raw sync. To download only ingested imagery
30
- and SCL when available, use this narrower filter:
31
 
32
- ```bash
33
- hf sync hf://buckets/fatmur/dynamicworld/processed data/processed --include 'image/**' --include 'scl/**'
34
  ```
35
 
36
- For one split, sync the matching raster directories. For on-demand reads,
37
- mount the bucket and resolve the same paths under `/mnt/dynamicworld/processed/`.
 
38
 
39
- ```bash
40
- hf sync hf://buckets/fatmur/dynamicworld/processed data/processed \
41
- --include 'label/val/**' --include 'image/val/**' --include 'scl/val/**'
42
- hf-mount start bucket fatmur/dynamicworld /mnt/dynamicworld
 
43
  ```
44
 
45
  Read the label index immediately after download. Its paths work relative to
46
- the local `data/processed/` directory.
47
 
48
  ```python
49
  from pathlib import Path
50
  import geopandas as gpd
51
 
52
- processed = Path("data/processed")
53
  labels = gpd.read_parquet(processed / "label.parquet")
54
  first_label = processed / labels.label_path.dropna().iloc[0]
55
  ```
@@ -108,7 +107,7 @@ processed/
108
  scripts/
109
  ├── download_labels.py
110
  ├── ingest_scenes.py
111
- └── upload.sh
112
  ```
113
 
114
  1. `eda.ipynb` assigns splits, copies the labels used for training and evaluation
@@ -164,14 +163,15 @@ baseline 04.00, 0 before). Decode with each file's own scale and offset.
164
  Authenticate with `hf auth login` using an account with write access to the
165
  bucket. Preview or run the transfer from the directory containing this README:
166
 
167
- ```bash
168
- bash scripts/upload.sh all --dry-run
169
- bash scripts/upload.sh all
170
  ```
171
 
172
  Use `raw` or `processed` in place of `all` to sync only one part. The processed
173
- upload includes label, image and SCL rasters present locally. Sync adds or
174
- updates files and keeps other bucket contents. After syncing the referenced
 
175
  rasters, publish the current index to the dataset repository:
176
 
177
  ```bash
 
7
 
8
  The dataset repository holds the label legend and Parquet indexes. The
9
  [Dynamic World bucket](https://huggingface.co/buckets/fatmur/dynamicworld)
10
+ holds the original files under `raw/` and the current rasters and Parquet indexes under `processed/`.
11
  Resolve each nonempty `label_path`, `image_path` or `scl_path` against
12
  `hf://buckets/fatmur/dynamicworld/processed/`. The current index covers
13
  24,094 prepared labels. The ingestion log, imagery and SCL are published as
 
15
 
16
  ## Download
17
 
18
+ From the data checkout, install the dependencies with `python -m pip install -r requirements.txt`.
19
+ The Python script downloads both bucket prefixes, including the current
20
+ Parquet indexes, and preserves the paths used by the tables:
21
 
22
+ ```text
23
+ python scripts/sync_bucket.py download all
 
 
 
24
  ```
25
 
26
+ To download just the prepared dataset, use `processed` in place of `all`.
27
+ To download only ingested imagery and SCL as they become available:
28
 
29
+ ```text
30
+ python scripts/sync_bucket.py download processed --include 'image/**' --include 'scl/**'
31
  ```
32
 
33
+ For one split, use `--include 'label/val/**' --include 'image/val/**' --include 'scl/val/**'`.
34
+ The dataset repository also provides `labels.yaml` and versioned Parquet
35
+ indexes. To fetch those files into the same directory:
36
 
37
+ ```python
38
+ from huggingface_hub import snapshot_download
39
+
40
+ snapshot_download("fatmur/dynamicworld", repo_type="dataset", local_dir=".",
41
+ allow_patterns=["labels.yaml", "processed/*.parquet"])
42
  ```
43
 
44
  Read the label index immediately after download. Its paths work relative to
45
+ the local `processed/` directory.
46
 
47
  ```python
48
  from pathlib import Path
49
  import geopandas as gpd
50
 
51
+ processed = Path("processed")
52
  labels = gpd.read_parquet(processed / "label.parquet")
53
  first_label = processed / labels.label_path.dropna().iloc[0]
54
  ```
 
107
  scripts/
108
  ├── download_labels.py
109
  ├── ingest_scenes.py
110
+ └── sync_bucket.py
111
  ```
112
 
113
  1. `eda.ipynb` assigns splits, copies the labels used for training and evaluation
 
163
  Authenticate with `hf auth login` using an account with write access to the
164
  bucket. Preview or run the transfer from the directory containing this README:
165
 
166
+ ```text
167
+ python scripts/sync_bucket.py upload all --dry-run
168
+ python scripts/sync_bucket.py upload all
169
  ```
170
 
171
  Use `raw` or `processed` in place of `all` to sync only one part. The processed
172
+ upload includes the local Parquet indexes and prepared rasters. Sync adds or
173
+ updates files and keeps other bucket contents. Both directions default to the
174
+ data checkout. Use `--data-dir` to select another local directory. After syncing the referenced
175
  rasters, publish the current index to the dataset repository:
176
 
177
  ```bash
requirements.txt CHANGED
@@ -8,3 +8,4 @@ pyyaml
8
  openpyxl
9
  matplotlib
10
  jupyter
 
 
8
  openpyxl
9
  matplotlib
10
  jupyter
11
+ huggingface_hub>=1.12
scripts/sync_bucket.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Upload or download the Dynamic World raw and processed directories."""
2
+
3
+ import argparse
4
+ from pathlib import Path
5
+
6
+ from huggingface_hub import sync_bucket
7
+
8
+ BUCKET = "hf://buckets/fatmur/dynamicworld"
9
+ DATA_DIR = Path(__file__).resolve().parents[1]
10
+
11
+
12
+ def main() -> None:
13
+ parser = argparse.ArgumentParser(description=__doc__)
14
+ parser.add_argument("direction", choices=("upload", "download"))
15
+ parser.add_argument("part", choices=("raw", "processed", "all"))
16
+ parser.add_argument(
17
+ "--data-dir",
18
+ type=Path,
19
+ default=DATA_DIR,
20
+ help="Local parent of raw/ and processed/",
21
+ )
22
+ parser.add_argument(
23
+ "--include",
24
+ action="append",
25
+ help="Glob relative to each selected folder (repeatable)",
26
+ )
27
+ parser.add_argument(
28
+ "--dry-run", action="store_true", help="Print the Hugging Face sync plan"
29
+ )
30
+ args = parser.parse_args()
31
+
32
+ folders = ("raw", "processed") if args.part == "all" else (args.part,)
33
+ for folder in folders:
34
+ local = str(args.data_dir / folder)
35
+ remote = f"{BUCKET}/{folder}"
36
+ source, dest = (
37
+ (local, remote) if args.direction == "upload" else (remote, local)
38
+ )
39
+ sync_bucket(
40
+ source,
41
+ dest,
42
+ include=args.include,
43
+ exclude=["*.partial.*"],
44
+ dry_run=args.dry_run,
45
+ )
46
+
47
+
48
+ if __name__ == "__main__":
49
+ main()
scripts/upload.sh DELETED
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
-
4
- target=${1:-}
5
- if [[ ! $target =~ ^(raw|processed|all)$ || $# -gt 2 || ( $# -eq 2 && $2 != --dry-run ) ]]; then
6
- echo "Usage: bash scripts/upload.sh {raw|processed|all} [--dry-run]" >&2
7
- exit 2
8
- fi
9
- shift
10
- cd "$(dirname "$0")/.."
11
- bucket=hf://buckets/fatmur/dynamicworld
12
-
13
- if [[ $target == raw || $target == all ]]; then
14
- hf sync raw "$bucket/raw" --exclude '*.partial.*' "$@"
15
- fi
16
- if [[ $target == processed || $target == all ]]; then
17
- # Parquet indexes are published in the dataset repository.
18
- hf sync processed "$bucket/processed" --include 'label/**' --include 'image/**' --include 'scl/**' --exclude '*.partial.*' "$@"
19
- fi