File size: 2,538 Bytes
0a7933d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#%%
from pathlib import Path
import pandas as pd
import rasterio
from rasterio.warp import transform_bounds

#%%
# IMPORTS
DATA_FOLDER = Path("/home/sabrina/Documents/Tese/05_Dataset/MatchGeo-DEM-v1/data")

REGIONS = {'ATA_MV', 'BRA_SP', 'CHN_WS', 'ESP_EH', 'FIN_LM', 'GER_BN', 'IDN_SV', 'KAZ_AC', 'KSA_WA', 'NAM_HF', 'NZL_KP', 'PHL_TA', 'USA_GC'}

#%%

dict_profile = {
    "region": [],
    "file_size_mb": [],
    "nodata": [],
    "crs": [],
    "dtype": [],
    "resolution":[],
    "width": [],
    "heigth": [],
    "n_tiles": [],
    "tile_size": [],
    "x_min": [],
    "x_max": [],
    "y_min": [],
    "y_max": [],
    "long_min": [],
    "long_max": [],
    "lat_min": [],
    "lat_max": [],
}

#%%
for region in REGIONS:
        
    # Get merged file size
    tif_path = Path(DATA_FOLDER, f"{region}/{region}.tif")
    file_size = tif_path.stat().st_size / (10**6)

    # Get raster profile and bounds
    with rasterio.open(tif_path) as src:
        profile = src.profile
        bounds = src.bounds
        try:
            lonlat_bounds = transform_bounds(src.crs, "EPSG:4326", *bounds)
        except:
            lonlat_bounds = transform_bounds("EPSG:25832", "EPSG:4326", *bounds)
          

    # Get number of tiles
    tile_path = Path(DATA_FOLDER, f"{region}/tiles")
    n_tiles = len(list(tile_path.glob("*.tif")))

    # Get tile size
    tile0 = list(tile_path.glob("*.tif"))[0]
    with rasterio.open(tile0) as src:
        tile_size = src.width

    # Update dictionary
    dict_profile['region'].append(region)
    dict_profile['file_size_mb'].append(file_size)
    dict_profile['nodata'].append(profile.get('nodata'))
    dict_profile['crs'].append(str(profile['crs']))
    dict_profile['dtype'].append(profile['dtype'])
    dict_profile['resolution'].append(profile['transform'][0])
    dict_profile['width'].append(profile['width'])
    dict_profile['heigth'].append(profile['height'])
    dict_profile['n_tiles'].append(n_tiles)
    dict_profile['tile_size'].append(tile_size)
    dict_profile['x_min'].append(bounds.left)
    dict_profile['x_max'].append(bounds.right)
    dict_profile['y_min'].append(bounds.bottom)
    dict_profile['y_max'].append(bounds.top)
    dict_profile['long_min'].append(lonlat_bounds[0])
    dict_profile['long_max'].append(lonlat_bounds[2])
    dict_profile['lat_min'].append(lonlat_bounds[1])
    dict_profile['lat_max'].append(lonlat_bounds[3])

#%%
# Create DataFrame
df = pd.DataFrame(dict_profile)
print(df)
# %%

df.to_csv(Path(DATA_FOLDER, "metadadata.csv"))

# %%