Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding seasonet dataset + tests + doc #1466

Merged
merged 17 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/api/datasets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ Seasonal Contrast

.. autoclass:: SeasonalContrastS2

SeasoNet
^^^^^^^^

.. autoclass:: SeasoNet

SEN12MS
^^^^^^^

Expand Down
1 change: 1 addition & 0 deletions docs/api/non_geo_datasets.csv
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Dataset,Task,Source,# Samples,# Classes,Size (px),Resolution (m),Bands
`ReforesTree`_,"OD, R",Aerial,100,6,"4,000x4,000",0.02,RGB
`RESISC45`_,C,Google Earth,"31,500",45,256x256,0.2--30,RGB
`Seasonal Contrast`_,T,Sentinel-2,100K--1M,-,264x264,10,MSI
`SeasoNet`_,S,Sentinel-2,"1,759,830",33,120x120,10,MSI
`SEN12MS`_,S,"Sentinel-1/2, MODIS","180,662",33,256x256,10,"SAR, MSI"
`SKIPP'D`_,R,"Fish-eye","363,375",-,64x64,-,RGB
`So2Sat`_,C,Sentinel-1/2,"400,673",17,32x32,10,"SAR, MSI"
Expand Down
141 changes: 141 additions & 0 deletions tests/data/seasonet/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/env python3

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import hashlib
import os
import shutil

import numpy as np
import rasterio
from rasterio.crs import CRS
from rasterio.transform import Affine

np.random.seed(0)

meta = {
"driver": "GTiff",
"nodata": None,
"crs": CRS.from_epsg(32632),
"transform": Affine(10.0, 0.0, 664800.0, 0.0, -10.0, 5342400.0),
"compress": "zstd",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to confirm that the original SeasoNet files are also compressed with ZSTD

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they are

}
bands = ["10m_RGB", "10m_IR", "20m", "60m", "labels"]
count = {"10m_RGB": 3, "10m_IR": 1, "20m": 6, "60m": 2, "labels": 1}
dtype = {
"10m_RGB": np.uint16,
"10m_IR": np.uint16,
"20m": np.uint16,
"60m": np.uint16,
"labels": np.uint8,
}
size = {"10m_RGB": 120, "10m_IR": 120, "20m": 60, "60m": 20, "labels": 120}
start = {"10m_RGB": 0, "10m_IR": 0, "20m": 0, "60m": 0, "labels": 1}
stop = {
"10m_RGB": np.iinfo(np.uint16).max,
"10m_IR": np.iinfo(np.uint16).max,
"20m": np.iinfo(np.uint16).max,
"60m": np.iinfo(np.uint16).max,
"labels": 34,
}

meta_lines = [
"Index,Season,Grid,Latitude,Longitude,Satellite,Year,Month,Day,"
"Hour,Minute,Second,Clouds,Snow,Classes,SLRAUM,RTYP3,KTYP4,Path\n"
]
seasons = ["spring", "summer", "fall", "winter", "snow"]
grids = [1, 2]
name_comps = [
["32UME", "2018", "04", "18", "T", "10", "40", "21", "53", "928425", "7", "503876"],
["32TMT", "2019", "02", "14", "T", "10", "31", "29", "47", "793488", "7", "808487"],
]
index = 0
for season in seasons:
# Remove old data
if os.path.exists(season):
shutil.rmtree(season)

archive = f"{season}.zip"

# Remove old data
if os.path.exists(archive):
os.remove(archive)

for grid, comp in zip(grids, name_comps):
file_name = f"{comp[0]}_{''.join(comp[1:8])}_{'_'.join(comp[8:])}"
dir = os.path.join(season, f"grid{grid}", file_name)
os.makedirs(dir)

# Random images
for band in bands:
meta["count"] = count[band]
meta["dtype"] = dtype[band]
meta["width"] = meta["height"] = size[band]
with rasterio.open(
os.path.join(dir, f"{file_name}_{band}.tif"), "w", **meta
) as f:
for j in range(1, count[band] + 1):
data = np.random.randint(
start[band], stop[band], size=(size[band], size[band])
).astype(dtype[band])
f.write(data, j)

# Generate meta.csv lines
meta_entries = [
index,
season.capitalize(),
grid,
f"{comp[8]}.{comp[9]}",
f"{comp[10]}.{comp[11]}",
"A",
comp[1],
comp[2],
comp[3],
comp[5],
comp[6],
comp[7],
0.0,
0.0,
"'2,3,12,15,17'",
1,
1,
1,
dir,
]
meta_lines.append(",".join(map(str, meta_entries)) + "\n")
index += 1

# Create archives
shutil.make_archive(season, "zip", ".", season)

# Compute checksums
with open(archive, "rb") as f:
md5 = hashlib.md5(f.read()).hexdigest()
print(f"{season}: {repr(md5)}")

# Write meta.csv
with open("meta.csv", "w") as f:
f.writelines(meta_lines)

# Compute checksums
with open("meta.csv", "rb") as f:
md5 = hashlib.md5(f.read()).hexdigest()
print(f"meta.csv: {repr(md5)}")

os.makedirs("splits", exist_ok=True)

for split in ["train", "val", "test"]:
filename = f"{split}.csv"

# Create file list
with open(os.path.join("splits", filename), "w") as f:
for i in range(index):
f.write(str(i) + "\n")

shutil.make_archive("splits", "zip", ".", "splits")

# Compute checksums
with open("splits.zip", "rb") as f:
md5 = hashlib.md5(f.read()).hexdigest()
print(f"splits: {repr(md5)}")
Binary file added tests/data/seasonet/fall.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions tests/data/seasonet/meta.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Index,Season,Grid,Latitude,Longitude,Satellite,Year,Month,Day,Hour,Minute,Second,Clouds,Snow,Classes,SLRAUM,RTYP3,KTYP4,Path
0,Spring,1,53.928425,7.503876,A,2018,04,18,10,40,21,0.0,0.0,"2,3,12,15,17",1,1,1,spring/grid1/32UME_20180418T104021_53_928425_7_503876
1,Spring,2,47.793488,7.808487,A,2019,02,14,10,31,29,0.0,0.0,"2,3,12,15,17",1,1,1,spring/grid2/32TMT_20190214T103129_47_793488_7_808487
2,Summer,1,53.928425,7.503876,A,2018,04,18,10,40,21,0.0,0.0,"2,3,12,15,17",1,1,1,summer/grid1/32UME_20180418T104021_53_928425_7_503876
3,Summer,2,47.793488,7.808487,A,2019,02,14,10,31,29,0.0,0.0,"2,3,12,15,17",1,1,1,summer/grid2/32TMT_20190214T103129_47_793488_7_808487
4,Fall,1,53.928425,7.503876,A,2018,04,18,10,40,21,0.0,0.0,"2,3,12,15,17",1,1,1,fall/grid1/32UME_20180418T104021_53_928425_7_503876
5,Fall,2,47.793488,7.808487,A,2019,02,14,10,31,29,0.0,0.0,"2,3,12,15,17",1,1,1,fall/grid2/32TMT_20190214T103129_47_793488_7_808487
6,Winter,1,53.928425,7.503876,A,2018,04,18,10,40,21,0.0,0.0,"2,3,12,15,17",1,1,1,winter/grid1/32UME_20180418T104021_53_928425_7_503876
7,Winter,2,47.793488,7.808487,A,2019,02,14,10,31,29,0.0,0.0,"2,3,12,15,17",1,1,1,winter/grid2/32TMT_20190214T103129_47_793488_7_808487
8,Snow,1,53.928425,7.503876,A,2018,04,18,10,40,21,0.0,0.0,"2,3,12,15,17",1,1,1,snow/grid1/32UME_20180418T104021_53_928425_7_503876
9,Snow,2,47.793488,7.808487,A,2019,02,14,10,31,29,0.0,0.0,"2,3,12,15,17",1,1,1,snow/grid2/32TMT_20190214T103129_47_793488_7_808487
Binary file added tests/data/seasonet/snow.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/data/seasonet/splits.zip
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/data/seasonet/splits/test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
0
1
2
3
4
5
6
7
8
9
10 changes: 10 additions & 0 deletions tests/data/seasonet/splits/train.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
0
1
2
3
4
5
6
7
8
9
10 changes: 10 additions & 0 deletions tests/data/seasonet/splits/val.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
0
1
2
3
4
5
6
7
8
9
Binary file added tests/data/seasonet/spring.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/data/seasonet/summer.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/data/seasonet/winter.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading