forked from microsoft/torchgeo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add plot method and data.py to Esri2020 dataset (microsoft#405)
* add plot method and data.py * typo missed period * forgot data.py * Remove abc, add versionchanged * Update esri2020.py * fixed test and requested changes * Add uncompressed data file * add test coverage Co-authored-by: Caleb Robinson <calebrob6@gmail.com> Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
- Loading branch information
1 parent
373c665
commit 23425bb
Showing
5 changed files
with
126 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import hashlib | ||
import os | ||
import random | ||
import shutil | ||
|
||
import numpy as np | ||
import rasterio | ||
|
||
np.random.seed(0) | ||
random.seed(0) | ||
|
||
SIZE = 64 | ||
|
||
|
||
files = [{"image": "N00E020_agb.tif"}, {"image": "N00E020_agb_err.tif"}] | ||
|
||
|
||
def create_file(path: str, dtype: str, num_channels: int) -> None: | ||
profile = {} | ||
profile["driver"] = "GTiff" | ||
profile["dtype"] = dtype | ||
profile["count"] = num_channels | ||
profile["crs"] = "epsg:4326" | ||
profile["transform"] = rasterio.transform.from_bounds(0, 0, 1, 1, 1, 1) | ||
profile["height"] = SIZE | ||
profile["width"] = SIZE | ||
profile["compress"] = "lzw" | ||
profile["predictor"] = 2 | ||
|
||
Z = np.random.randint( | ||
np.iinfo(profile["dtype"]).max, size=(1, SIZE, SIZE), dtype=profile["dtype"] | ||
) | ||
src = rasterio.open(path, "w", **profile) | ||
src.write(Z) | ||
|
||
|
||
if __name__ == "__main__": | ||
dir = "io-lulc-model-001-v01-composite-v03-supercell-v02-clip-v01" | ||
tif_name = "00A_20200101-20210101.tif" | ||
|
||
if os.path.exists(dir): | ||
shutil.rmtree(dir) | ||
|
||
os.makedirs(dir) | ||
|
||
# Create mask file | ||
create_file(os.path.join(dir, tif_name), dtype="int8", num_channels=1) | ||
|
||
shutil.make_archive(dir, "zip", base_dir=dir) | ||
|
||
# Compute checksums | ||
zipfilename = dir + ".zip" | ||
with open(zipfilename, "rb") as f: | ||
md5 = hashlib.md5(f.read()).hexdigest() | ||
print(f"{zipfilename}: {md5}") |
Binary file modified
BIN
+769 Bytes
(120%)
tests/data/esri2020/io-lulc-model-001-v01-composite-v03-supercell-v02-clip-v01.zip
Binary file not shown.
Binary file modified
BIN
+1.37 KB
(130%)
...2020/io-lulc-model-001-v01-composite-v03-supercell-v02-clip-v01/00A_20200101-20210101.tif
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters