-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix forced int32 type conversion in RasterDataset (#384)
* fix forced int32 type conversion * add fix for numpy dtypes which are not supported by tensors * delete whitespace * Adding custom data to test the dtype transform * Fixed formatting Co-authored-by: Caleb Robinson <calebrob6@gmail.com>
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
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,42 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import os | ||
|
||
import numpy as np | ||
import rasterio | ||
import rasterio.transform | ||
from torchvision.datasets.utils import calculate_md5 | ||
|
||
|
||
def generate_test_data(fn: str) -> str: | ||
"""Creates test data with uint32 datatype. | ||
Args: | ||
fn (str): Filename to write | ||
Returns: | ||
str: md5 hash of created archive | ||
""" | ||
profile = { | ||
"driver": "GTiff", | ||
"dtype": "uint32", | ||
"count": 1, | ||
"crs": "epsg:4326", | ||
"transform": rasterio.transform.from_bounds(0, 0, 1, 1, 1, 1), | ||
"height": 4, | ||
"width": 4, | ||
"compress": "lzw", | ||
"predictor": 2, | ||
} | ||
|
||
with rasterio.open(fn, "w", **profile) as f: | ||
f.write(np.random.randint(0, 2**32 - 1, size=(1, 4, 4))) | ||
|
||
md5: str = calculate_md5(fn) | ||
return md5 | ||
|
||
|
||
if __name__ == "__main__": | ||
md5_hash = generate_test_data(os.path.join(os.getcwd(), "test0.tif")) | ||
print(md5_hash) |
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