Load Sample Subset from Extracted Data

[11]:
import fnmatch
import geopandas as gpd
import os
import pandas as pd
from pathlib import Path

from eobox.raster import extraction
from eobox import sampledata

% matplotlib inline
[12]:
dataset = sampledata.get_dataset("s2l1c")

src_vector = dataset["vector_file"]
burn_attribute = "pid"  # should be unique for the polygons and not contain zero
src_raster = fnmatch.filter(dataset["raster_files"], "*B0[2,3,4,8]*")  # 10 m bands
dst_names = ["_".join(Path(src).stem.split("_")[1::]) for src in src_raster]
extraction_dir = Path("s2l1c_ref__s2l1c/s2_l1c/10m")
extraction.extract(src_vector=src_vector,
                   burn_attribute=burn_attribute,
                   src_raster=src_raster,
                   dst_names=dst_names,
                   dst_dir=extraction_dir)
df_extracted = extraction.load_extracted(extraction_dir, "*pid.npy")
display(df_extracted.head())
index_29 = (df_extracted["aux_vector_pid"] == 29)
index_29.sum()
aux_vector_pid
0 17
1 17
2 6
3 6
4 6
[12]:
109
[13]:
display(df_extracted[index_29].head(2))
display(df_extracted[index_29].tail(2))
aux_vector_pid
839 29
840 29
aux_vector_pid
946 29
947 29
[14]:
df_extracted_29 = extraction.load_extracted(extraction_dir, index=index_29)
df_extracted_29.head()
[14]:
aux_coord_y 20170216T102101_B02 20170216T102101_B03 aux_coord_x aux_vector_pid 20170216T102101_B04 20170216T102101_B08
839 5820745.0 1456 1136 341675.0 29 1056 1696
840 5820745.0 1456 1136 341685.0 29 1056 1632
841 5820745.0 1456 1136 341695.0 29 1056 1632
842 5820745.0 1424 1136 341705.0 29 1056 1632
843 5820745.0 1488 1136 341715.0 29 1056 1632
[15]:
df_extracted_29 = extraction.load_extracted(extraction_dir, vars_in_cols=False, index=index_29)
df_extracted_29.head()
[15]:
839 840 841 842 843 844 845 846 847 848 ... 938 939 940 941 942 943 944 945 946 947
aux_coord_y 5820745.0 5820745.0 5820745.0 5820745.0 5820745.0 5820745.0 5820745.0 5820745.0 5820745.0 5820745.0 ... 5820665.0 5820665.0 5820665.0 5820665.0 5820665.0 5820665.0 5820665.0 5820665.0 5820665.0 5820665.0
20170216T102101_B02 1456.0 1456.0 1456.0 1424.0 1488.0 1456.0 1488.0 1488.0 1488.0 1488.0 ... 1424.0 1456.0 1424.0 1424.0 1424.0 1456.0 1456.0 1456.0 1424.0 1392.0
20170216T102101_B03 1136.0 1136.0 1136.0 1136.0 1136.0 1168.0 1168.0 1168.0 1136.0 1136.0 ... 1104.0 1104.0 1104.0 1072.0 1072.0 1104.0 1136.0 1136.0 1104.0 1104.0
aux_coord_x 341675.0 341685.0 341695.0 341705.0 341715.0 341725.0 341735.0 341745.0 341755.0 341765.0 ... 341705.0 341715.0 341725.0 341735.0 341745.0 341755.0 341765.0 341775.0 341785.0 341795.0
aux_vector_pid 29.0 29.0 29.0 29.0 29.0 29.0 29.0 29.0 29.0 29.0 ... 29.0 29.0 29.0 29.0 29.0 29.0 29.0 29.0 29.0 29.0

5 rows × 109 columns