-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add own data * data.py with cmap * remove .img test data format
- Loading branch information
1 parent
cd125b1
commit c6f77e4
Showing
5 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/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 | ||
|
||
SIZE = 32 | ||
|
||
np.random.seed(0) | ||
random.seed(0) | ||
|
||
|
||
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(size=(SIZE, SIZE), low=0, high=8) | ||
|
||
src = rasterio.open(path, "w", **profile) | ||
for i in range(1, profile["count"] + 1): | ||
src.write(Z, i) | ||
|
||
|
||
directories = ["2020_30m_cdls", "2021_30m_cdls"] | ||
raster_extensions = [[".tif", ".tif.ovr"], [".tif", ".tif.ovr"]] | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
for dir, extensions in zip(directories, raster_extensions): | ||
filename = dir + ".zip" | ||
|
||
# Remove old data | ||
if os.path.isdir(dir): | ||
shutil.rmtree(dir) | ||
|
||
os.makedirs(os.path.join(os.getcwd(), dir)) | ||
|
||
for e in extensions: | ||
create_file( | ||
os.path.join(dir, filename.replace(".zip", e)), | ||
dtype="int8", | ||
num_channels=1, | ||
) | ||
|
||
# Compress data | ||
shutil.make_archive(filename.replace(".zip", ""), "zip", ".", dir) | ||
|
||
# Compute checksums | ||
with open(filename, "rb") as f: | ||
md5 = hashlib.md5(f.read()).hexdigest() | ||
print(f"{filename}: {md5}") | ||
|
||
shutil.rmtree(dir) |
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