hayden-donnelly
commited on
Commit
•
a7d0de2
1
Parent(s):
09d61a5
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
task_categories:
|
4 |
+
- unconditional-image-generation
|
5 |
+
- image-classification
|
6 |
+
- text-to-image
|
7 |
+
pretty_name: World Heightmaps 360 V1
|
8 |
+
size_categories:
|
9 |
+
- 100K<n<1M
|
10 |
+
---
|
11 |
+
# World Heightmaps 360px
|
12 |
+
This is a dataset of 360x360 Earth heightmaps generated from [SRTM 1 Arc-Second Global](https://huggingface.co/datasets/hayden-donnelly/srtm-1-arc-second-global).
|
13 |
+
Each heightmap is labelled according to its latitude and longitude. There are 573,995 samples.
|
14 |
+
|
15 |
+
## Method
|
16 |
+
1. Convert GeoTIFFs into PNGs with Python and Rasterio.
|
17 |
+
```python
|
18 |
+
import rasterio
|
19 |
+
import matplotlib.pyplot as plt
|
20 |
+
import os
|
21 |
+
|
22 |
+
input_directory = '...'
|
23 |
+
output_directory = '...'
|
24 |
+
file_list = os.listdir(input_directory)
|
25 |
+
|
26 |
+
for i in range(len(file_list)):
|
27 |
+
image = rasterio.open(input_directory + file_list[i])
|
28 |
+
plt.imsave(output_directory + file_list[i][0:-4] + '.png', image.read(1), cmap='gray')
|
29 |
+
```
|
30 |
+
|
31 |
+
2. Split PNGs into 100 patches with Split Image.
|
32 |
+
```python
|
33 |
+
from split_image import split_image
|
34 |
+
import os
|
35 |
+
|
36 |
+
input_directory = '...'
|
37 |
+
output_directory = '...'
|
38 |
+
file_list = os.listdir(input_directory)
|
39 |
+
|
40 |
+
for i in range(len(file_list)):
|
41 |
+
split_image(input_directory + file_list[i], 10, 10, should_square=True, should_cleanup=False, output_dir=output_directory)
|
42 |
+
```
|
43 |
+
|
44 |
+
3. Hand pick a dataset of corrupted and uncorrupted heightmaps then train a discriminator to automatically filter the whole dataset.
|
45 |
+
|
46 |
+
4. Compile images into parquet files.
|
47 |
+
```python
|
48 |
+
import pyarrow as pa
|
49 |
+
import pyarrow.parquet as pq
|
50 |
+
import pandas as pd
|
51 |
+
from PIL import Image
|
52 |
+
import os
|
53 |
+
import io
|
54 |
+
import json
|
55 |
+
|
56 |
+
samples_per_file = 6_000
|
57 |
+
|
58 |
+
root_dir = 'data/datasets/world-heightmaps-360px-png'
|
59 |
+
df = pd.read_csv(os.path.join(root_dir, 'metadata.csv'))
|
60 |
+
df = df.sample(frac=1).reset_index(drop=True)
|
61 |
+
|
62 |
+
def save_table(image_data, table_number):
|
63 |
+
print(f'Entries in table {table_number}: {len(image_data)}')
|
64 |
+
schema = pa.schema(
|
65 |
+
fields=[
|
66 |
+
('heightmap', pa.struct([('bytes', pa.binary()), ('path', pa.string())])),
|
67 |
+
('latitude', pa.string()),
|
68 |
+
('longitude', pa.string())
|
69 |
+
],
|
70 |
+
metadata={
|
71 |
+
b'huggingface': json.dumps({
|
72 |
+
'info': {
|
73 |
+
'features': {
|
74 |
+
'heightmap': {'_type': 'Image'},
|
75 |
+
'latitude': {'_type': 'Value', 'dtype': 'string'},
|
76 |
+
'longitude': {'_type': 'Value', 'dtype': 'string'}
|
77 |
+
}
|
78 |
+
}
|
79 |
+
}).encode('utf-8')
|
80 |
+
}
|
81 |
+
)
|
82 |
+
|
83 |
+
table = pa.Table.from_pylist(image_data, schema=schema)
|
84 |
+
pq.write_table(table, f'data/world-heightmaps-360px-parquet/{str(table_number).zfill(4)}.parquet')
|
85 |
+
|
86 |
+
image_data = []
|
87 |
+
samples_in_current_file = 0
|
88 |
+
current_file_number = 0
|
89 |
+
for i, row in df.iterrows():
|
90 |
+
if samples_in_current_file >= samples_per_file:
|
91 |
+
save_table(image_data, current_file_number)
|
92 |
+
image_data = []
|
93 |
+
samples_in_current_file = 0
|
94 |
+
current_file_number += 1
|
95 |
+
samples_in_current_file += 1
|
96 |
+
image_path = row['file_name']
|
97 |
+
with Image.open(os.path.join(root_dir, image_path)) as image:
|
98 |
+
image_bytes = io.BytesIO()
|
99 |
+
image.save(image_bytes, format='PNG')
|
100 |
+
image_dict = {
|
101 |
+
'heightmap': {
|
102 |
+
'bytes': image_bytes.getvalue(),
|
103 |
+
'path': image_path
|
104 |
+
},
|
105 |
+
'latitude': str(row['latitude']),
|
106 |
+
'longitude': str(row['longitude'])
|
107 |
+
}
|
108 |
+
image_data.append(image_dict)
|
109 |
+
|
110 |
+
save_table(image_data, current_file_number)
|
111 |
+
```
|