From 082b8536f6d08c7e721f941988e3999d6b3d5d7b Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Fri, 27 Sep 2024 12:58:43 +0200 Subject: [PATCH] Return timestamp --- tests/data/satlas/data.py | 9 +++++++++ tests/data/satlas/landsat.tar | Bin 71680 -> 71680 bytes tests/data/satlas/metadata.tar | Bin 10240 -> 10240 bytes tests/data/satlas/metadata/image_times.json | 1 + tests/data/satlas/naip.tar | Bin 20480 -> 20480 bytes tests/data/satlas/sentinel1.tar | Bin 20480 -> 20480 bytes tests/data/satlas/sentinel2.tar | Bin 51200 -> 51200 bytes tests/data/satlas/static.tar | Bin 10240 -> 10240 bytes tests/datasets/test_satlas.py | 1 + torchgeo/datasets/satlas.py | 15 +++++++++++++-- 10 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/data/satlas/metadata/image_times.json diff --git a/tests/data/satlas/data.py b/tests/data/satlas/data.py index 3891ae44c8..1661f6e425 100755 --- a/tests/data/satlas/data.py +++ b/tests/data/satlas/data.py @@ -36,6 +36,12 @@ [7149, 3246, 'S2A_MSIL1C_20220309T032601_N0400_R018_T48RYR_20220309T060235'], [1234, 5678, 'S2A_MSIL1C_20220309T032601_N0400_R018_T48RYR_20220309T060235'], ] +times = { + '2022-03': '2022-03-01T00:00:00+00:00', + 'm_3808245_se_17_1_20110801': '2011-08-01T12:00:00+00:00', + '2022-01': '2022-01-01T00:00:00+00:00', + 'S2A_MSIL1C_20220309T032601_N0400_R018_T48RYR_20220309T060235': '2022-03-09T06:02:35+00:00', +} FILENAME_HIERARCHY = dict[str, 'FILENAME_HIERARCHY'] | list[str] filenames: FILENAME_HIERARCHY = { @@ -97,6 +103,9 @@ def create_directory(directory: str, hierarchy: FILENAME_HIERARCHY) -> None: with open(os.path.join('metadata', 'good_images_lowres_all.json'), 'w') as f: json.dump(good_images, f) + with open(os.path.join('metadata', 'image_times.json'), 'w') as f: + json.dump(times, f) + for path in os.listdir('.'): if os.path.isdir(path): shutil.make_archive(path, 'tar', '.', path) diff --git a/tests/data/satlas/landsat.tar b/tests/data/satlas/landsat.tar index 9daeeca7fbb88a98bb16b28e7af08b94297597ad..f21ba5980d5d1068f2e0922305914039b87f890f 100644 GIT binary patch delta 1203 zcmZ|Oy)r{V6bJC!k&OvA!Hi+X7^27Q_wH$xynvD!wURc4B#jhSr{o2$Ny7^$ump<|DLaIQSTP@qP4srg)oBeaxj)#IXBvBzhze);#P)>ifT$_jWWrM zsdeb}((K77+sR3Uw6-ds4GeAO^BxI0c`QoWjuBTOX*DP9@_PV``JjfAm{Ca(vx<8} z++K=wS<*oW`uiPNZyIhNHNEDjzc$Fi4=pzk;9&wOEyI%jS;j$oMBEXEj;m>k84nxo zG=&UFlT??r5qE~6^Ir45Kgj&VI9OwN1TRv^ku)trCyBen(6EvQV4|_zq);Gf7F5*9 zTMXSzrvZa_1Vswv|7pOeF4vK`2Mj%ib>sk(enfRWrAQ%3lZ`9~P24kv#+AA>qtTVU wq%hR=+MAhLWKc9($E1lDQ1Sw1 zG`xV4g41MQ9P0tT`Pa2qHhX2WTv%C@0BGzkTEn!EbK|YfTXx;e-Rfvb2(7tlFb;zA zMwi_z&z_F6&34}LNE>darf?gynV$wJ#w18FMY-EakPbm>?L0yPqzMQpgzY#9kwZXx zDPq2*{r=3uV3=M=i=x5k6*VHTEctn|GV?lOfyq-lfE3a%(Ls-;chE$sp=&LZQcSlW46%qeF>LDbhp|g7U-2-7|$=>U~+}FQjm< qDGYsmgkP&l)W${^@=l^ZY1M1<@Y#j?OrW4Xn{gFQ@ry#=KkL7?L?0^v diff --git a/tests/data/satlas/metadata.tar b/tests/data/satlas/metadata.tar index 5cc99eccca5681835e8668712caf0f3b61afc0ca..da55bab052a7f8c57119e458b38cc6ae843539c7 100644 GIT binary patch delta 481 zcmZn&Xb9NA%fxSDY;109q-ShkWNvI?!nIjZmR8bG`RmGF#xm+hIa8FL*Qjjz@HDE9_ zF*7%XJJ-a_&;V-rWJcEi>eWg{21Z7@2F6NO3NWUwfnkV&ffX2OgGr^yc06*fU=@aj zx&{^?6^2GADs*7l4G|^*m13H7g2zD)*)Gcv12ZcFBP(N5s9m+26`3R$C$Y7W88D`n V#?XKfLJDWaYLKX#+IOA8aO&534D7$=GK3YZ$085o!_7#Nxv zo0u>t7)%yqOxesR&clkV1E>e8Lk^b?`BqLedrSWaYLJsxG{qP0x%dD8WkK{njf$QbS%T@>e-nOhn`onwMahv|PQ06`5y`Tzg` diff --git a/tests/data/satlas/sentinel1.tar b/tests/data/satlas/sentinel1.tar index dd01963ca3b396d2cfbd01c56acee4962cd8c087..75585130401baafc42bfaeb3952cd3efad016137 100644 GIT binary patch delta 209 zcmZozz}T>WaRaXizlpK2xv`O+v4MfPrKJhi=0LM2jFZHA1xyXh3=B*d3=B<7&5Rfn z3?>UQrfg;u=V3+GVPI(v)ggyVhdd8Ak`7CA3nQow9b_FqyKvZHVQB<&l?g5#rvIe? D(;qMc delta 209 zcmZozz}T>WaRaXizp;slsfDGUnSr5^k&!Xi=0LM2jFZHA1&oZ$%?-^M3=B<7%}p2- z3?>UQrfg;u=V3+CVQ6S>0o5UgONTrUH@Wtp1FFLWmk!ha FQUL2%Fi8La diff --git a/tests/data/satlas/sentinel2.tar b/tests/data/satlas/sentinel2.tar index 9de07b96c8498b7a0f89ac73b71ca2f1b285fc23..aa3122a90c859c385a9ea54ed3f019ca77218de4 100644 GIT binary patch delta 764 zcmZ|NJ5B>J5P;!qB3lBMM}eS&M507!JY#$979@(~0x5$;O$luZ9u1Mg&_M?mK-vRw zlu)f7T6};{zh}nF^=P>s{p=p@YodnmfBEhSul5+rI$XjAah5GgDjbZ`Ms4#ZKQ z%FdX?2YB?_pFN%q#?!&q#?BTJg_us*0iX|Svr+%2dKuR3?qnN4#B&bTK#*7wl~8EbO(}YgicWJRUFo=~H+2k7 zX>L~9vywUge=T&x=2{mSB-h2V5h0<#yjHiDC3Lk=1GanIWDsF_4Ly@N;%y1tEz~Fp s>M`$gh+Qok5;2+~pG#(9U(BP1=n3N_fnEV4BXe^@GX?`gQv*{|1_gu3 Nf{ZDf83q4~0RW??4l@7% diff --git a/tests/datasets/test_satlas.py b/tests/datasets/test_satlas.py index 428fc262f0..7c10f55bd7 100644 --- a/tests/datasets/test_satlas.py +++ b/tests/datasets/test_satlas.py @@ -37,6 +37,7 @@ def test_getitem(self, dataset: SatlasPretrain, index: int) -> None: assert isinstance(x, dict) for image in dataset.images: assert isinstance(x[f'image_{image}'], Tensor) + assert isinstance(x[f'time_{image}'], Tensor) for label in dataset.labels: assert isinstance(x[f'mask_{label}'], Tensor) diff --git a/torchgeo/datasets/satlas.py b/torchgeo/datasets/satlas.py index 7aa1aaaabc..f52a7fef98 100644 --- a/torchgeo/datasets/satlas.py +++ b/torchgeo/datasets/satlas.py @@ -538,6 +538,7 @@ def __init__( root: Path = 'data', split: str = 'train_lowres', good_images: str = 'good_images_lowres_all', + image_times: str = 'image_times', images: Iterable[str] = ('sentinel1', 'sentinel2', 'landsat'), labels: Iterable[str] = ('land_cover',), transforms: Callable[[dict[str, Tensor]], dict[str, Tensor]] | None = None, @@ -550,6 +551,7 @@ def __init__( root: Root directory where dataset can be found. split: Metadata split to load. good_images: Metadata mapping between col/row and directory. + image_times: Metadata mapping between directory and ISO time. images: List of image products. labels: List of label products. transforms: A function/transform that takes input sample and its target as @@ -572,10 +574,17 @@ def __init__( self._verify() - self.split = pd.read_json(os.path.join(root, 'metadata', f'{split}.json')) + # Read metadata files + self.split = pd.read_json( + os.path.join(root, 'metadata', f'{split}.json'), typ='frame' + ) self.good_images = pd.read_json( - os.path.join(root, 'metadata', f'{good_images}.json') + os.path.join(root, 'metadata', f'{good_images}.json'), typ='frame' + ) + self.image_times = pd.read_json( + os.path.join(root, 'metadata', f'{image_times}.json'), typ='series' ) + self.split.columns = ['col', 'row'] self.good_images.columns = ['col', 'row', 'directory'] self.good_images = self.good_images.groupby(['col', 'row']) @@ -646,6 +655,8 @@ def _load_image( # Choose a random timestamp idx = torch.randint(len(good_directories), (1,)) directory = good_directories[idx] + time = self.image_times[directory].timestamp() + sample[f'time_{image}'] = torch.tensor(time) # Load all bands channels = []