Daksh17440 commited on
Commit
2cdda79
ยท
verified ยท
1 Parent(s): 6dbd716

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +466 -3
README.md CHANGED
@@ -1,3 +1,466 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ pretty_name: Population
6
+ ---
7
+ # ๐ŸŒ LandScan Global Population Dataset โ€” `pop_2000-23.h5`
8
+
9
+ [![License](https://img.shields.io/badge/License-CC%20BY%204.0-lightgrey.svg)](https://creativecommons.org/licenses/by/4.0/)
10
+ [![Source](https://img.shields.io/badge/Source-Oak%20Ridge%20National%20Laboratory-blue)](https://landscan.ornl.gov/)
11
+ [![Resolution](https://img.shields.io/badge/Resolution-1%20km-green)]()
12
+ [![Years](https://img.shields.io/badge/Years-2000--2023-orange)]()
13
+ [![Format](https://img.shields.io/badge/Format-HDF5-red)]()
14
+
15
+ A production-ready, chunked HDF5 tensor of **LandScan Global** annual population estimates from **2000 to 2023** โ€” packaged for efficient use in deep learning, geospatial analysis, and HPC workflows. No more downloading 24 separate GeoTIFFs.
16
+
17
+ ---
18
+
19
+ ## ๐Ÿ“ฆ Dataset at a Glance
20
+
21
+ | Property | Value |
22
+ |---|---|
23
+ | **Source** | LandScan Global โ€” Oak Ridge National Laboratory (ORNL) |
24
+ | **Years covered** | 2000 โ€“ 2023 (24 time steps) |
25
+ | **Spatial resolution** | ~1 km (30 arc-seconds) |
26
+ | **Spatial extent** | Global (180ยฐWโ€“180ยฐE, 90ยฐSโ€“90ยฐN) |
27
+ | **Master grid** | 21,600 rows ร— 43,200 columns |
28
+ | **CRS** | WGS84 / EPSG:4326 |
29
+ | **Unit** | Ambient population count per pixel |
30
+ | **Data type** | float32 |
31
+ | **Format** | HDF5 (chunked + GZIP compressed) |
32
+ | **Chunk shape** | (1, 256, 256) โ€” time ร— lat ร— lon |
33
+
34
+ > **What is LandScan?**
35
+ > LandScan represents ambient population โ€” the average number of people present in a location over 24 hours โ€” rather than residential census counts. It integrates census data, land cover, roads, slope, and remote sensing to model where people actually are, not just where they live.
36
+
37
+ ---
38
+
39
+ ## ๐Ÿ—‚๏ธ File Structure
40
+
41
+ ```
42
+ pop_2000-23.h5
43
+ โ”‚
44
+ โ”œโ”€โ”€ /population float32 (24, 21600, 43200) โ† main data tensor
45
+ โ”‚ dim[0] โ†’ time 24 annual steps (2000โ€“2023)
46
+ โ”‚ dim[1] โ†’ lat 21,600 latitude rows (90ยฐN โ†’ 90ยฐS)
47
+ โ”‚ dim[2] โ†’ lon 43,200 longitude cols (180ยฐW โ†’ 180ยฐE)
48
+ โ”‚
49
+ โ”œโ”€โ”€ /coords
50
+ โ”‚ โ”œโ”€โ”€ years int32 (24,) [2000, 2001, โ€ฆ, 2023]
51
+ โ”‚ โ”œโ”€โ”€ lat float64 (21600,) centre latitude of each row (ยฐN)
52
+ โ”‚ โ””โ”€โ”€ lon float64 (43200,) centre longitude of each col (ยฐE)
53
+ โ”‚
54
+ โ”œโ”€โ”€ /native_extent
55
+ โ”‚ โ”œโ”€โ”€ years int32 (24,) year index
56
+ โ”‚ โ”œโ”€โ”€ n_rows int32 (24,) native row count per year
57
+ โ”‚ โ””โ”€โ”€ n_cols int32 (24,) native col count per year
58
+ โ”‚
59
+ โ””โ”€โ”€ /stats
60
+ โ”œโ”€โ”€ mean float32 (24,) mean over inhabited pixels
61
+ โ”œโ”€โ”€ std float32 (24,) std over inhabited pixels
62
+ โ”œโ”€โ”€ max float32 (24,) max pixel value per year
63
+ โ”œโ”€โ”€ total_pop float32 (24,) global population sum per year
64
+ โ””โ”€โ”€ nan_fraction float32 (24,) fraction of NaN pixels per year
65
+ ```
66
+
67
+ ### NaN semantics
68
+
69
+ There are two distinct sources of `NaN` in this dataset:
70
+
71
+ | NaN type | Meaning |
72
+ |---|---|
73
+ | Within native extent, flagged as nodata | Ocean, permanent ice, or uninhabited area |
74
+ | Beyond native extent | That LandScan release had a smaller grid (2001โ€“2012 were 20,880 rows) โ€” data simply did not exist |
75
+
76
+ The `/native_extent` group tells you exactly how many rows and columns contained real data for each year, so your code can mask accordingly.
77
+
78
+ ---
79
+
80
+ ## โšก Quickstart โ€” Partial Reads (No Full Download Needed)
81
+
82
+ HuggingFace supports [HTTP range requests](https://huggingface.co/docs/hub/datasets-adding#large-files) on `.h5` files. The HDF5 chunked layout `(1, 256, 256)` means **only the chunks you touch are transferred over the network** โ€” you never need to download the full file.
83
+
84
+ ### Install dependencies
85
+
86
+ ```bash
87
+ pip install h5py numpy fsspec huggingface_hub
88
+ ```
89
+
90
+ ### Open the file remotely
91
+
92
+ ```python
93
+ import h5py
94
+ import numpy as np
95
+ from huggingface_hub import hf_hub_url
96
+
97
+ # Stream directly from HuggingFace โ€” no full download
98
+ url = hf_hub_url(
99
+ repo_id = "Daksh17440/landscan-global-population",
100
+ filename = "pop_2000-23.h5",
101
+ repo_type = "dataset",
102
+ )
103
+
104
+ # ROS3 driver = HTTP range-request backend for HDF5
105
+ f = h5py.File(url, "r", driver="ros3")
106
+
107
+ pop = f["population"] # shape (24, 21600, 43200) โ€” not yet loaded
108
+ lat = f["coords/lat"][:]
109
+ lon = f["coords/lon"][:]
110
+ yrs = f["coords/years"][:] # [2000, 2001, โ€ฆ, 2023]
111
+ ```
112
+
113
+ > **Tip:** Install `hdf5` with ROS3 support: `conda install -c conda-forge h5py` (includes it by default). For pip: `pip install h5py[ros3]`.
114
+
115
+ ---
116
+
117
+ ## ๐Ÿ” Usage Examples
118
+
119
+ ### 1. Read a single year
120
+
121
+ ```python
122
+ # Year 2020 is at index 20 (2020 - 2000 = 20)
123
+ pop_2020 = f["population"][20, :, :] # shape (21600, 43200)
124
+ # Only ~3.4 GB RAM; only touched chunks downloaded over network
125
+ ```
126
+
127
+ ### 2. Look up the index for any year
128
+
129
+ ```python
130
+ years = f["coords/years"][:]
131
+
132
+ def year_idx(y):
133
+ idx = np.where(years == y)[0]
134
+ if len(idx) == 0:
135
+ raise ValueError(f"Year {y} not in dataset")
136
+ return int(idx[0])
137
+
138
+ pop_2015 = f["population"][year_idx(2015), :, :]
139
+ ```
140
+
141
+ ### 3. Spatial crop โ€” bounding box query
142
+
143
+ ```python
144
+ lat = f["coords/lat"][:]
145
+ lon = f["coords/lon"][:]
146
+
147
+ def bbox_slice(lat_min, lat_max, lon_min, lon_max):
148
+ """Return numpy index slices for a lat/lon bounding box."""
149
+ row = np.where((lat >= lat_min) & (lat <= lat_max))[0]
150
+ col = np.where((lon >= lon_min) & (lon <= lon_max))[0]
151
+ return slice(row[0], row[-1]+1), slice(col[0], col[-1]+1)
152
+
153
+ # South Asia: 5โ€“35ยฐN, 65โ€“95ยฐE
154
+ rs, cs = bbox_slice(5, 35, 65, 95)
155
+
156
+ # Single year crop โ€” minimal network transfer
157
+ south_asia_2023 = f["population"][23, rs, cs]
158
+
159
+ # All years crop โ€” full time series for the region
160
+ south_asia_all = f["population"][:, rs, cs] # shape (24, ~3334, ~3334)
161
+ ```
162
+
163
+ ### 4. Time-range + spatial crop together
164
+
165
+ ```python
166
+ # India, 2010โ€“2020
167
+ years = f["coords/years"][:]
168
+ t_mask = np.where((years >= 2010) & (years <= 2020))[0]
169
+ rs, cs = bbox_slice(8, 37, 68, 97)
170
+
171
+ india_decade = f["population"][t_mask[0]:t_mask[-1]+1, rs, cs]
172
+ # shape: (11, H_india, W_india)
173
+ ```
174
+
175
+ ### 5. Country / region centroids โ€” point time series
176
+
177
+ ```python
178
+ # Population at a single point over all years (full time series)
179
+ # New Delhi: 28.6ยฐN, 77.2ยฐE
180
+ lat_idx = int(np.argmin(np.abs(lat - 28.6)))
181
+ lon_idx = int(np.argmin(np.abs(lon - 77.2)))
182
+
183
+ delhi_series = f["population"][:, lat_idx, lon_idx] # shape (24,)
184
+ # Extremely fast โ€” 24 single-pixel reads
185
+ ```
186
+
187
+ ### 6. Global population trend (no pixel reads needed)
188
+
189
+ ```python
190
+ # Pre-computed โ€” instant, no pixel data transferred
191
+ total_pop = f["stats/total_pop"][:]
192
+ years = f["coords/years"][:]
193
+
194
+ for yr, pop in zip(years, total_pop):
195
+ print(f" {yr}: {pop/1e9:.3f} billion")
196
+ ```
197
+
198
+ ### 7. Use with xarray (NetCDF-style labelled arrays)
199
+
200
+ ```python
201
+ import xarray as xr
202
+ import h5py
203
+ import numpy as np
204
+
205
+ with h5py.File("pop_2000-23.h5", "r") as f:
206
+ # Load a region into an xarray DataArray with named coords
207
+ rs, cs = bbox_slice(5, 35, 65, 95)
208
+ data = f["population"][:, rs, cs]
209
+ years = f["coords/years"][:]
210
+ lats = f["coords/lat"][rs]
211
+ lons = f["coords/lon"][cs]
212
+
213
+ da = xr.DataArray(
214
+ data,
215
+ dims = ["time", "lat", "lon"],
216
+ coords = {"time": years, "lat": lats, "lon": lons},
217
+ name = "population",
218
+ attrs = {"units": "persons per pixel", "source": "LandScan Global"}
219
+ )
220
+
221
+ # Now use xarray operations
222
+ annual_mean = da.mean(dim=["lat", "lon"])
223
+ trend = da.sel(time=slice(2010, 2020))
224
+ ```
225
+
226
+ ### 8. PyTorch โ€” lazy streaming Dataset
227
+
228
+ ```python
229
+ import h5py
230
+ import numpy as np
231
+ import torch
232
+ from torch.utils.data import Dataset
233
+
234
+ class LandScanDataset(Dataset):
235
+ """
236
+ Streams spatial patches on demand.
237
+ Never loads the full tensor into RAM.
238
+
239
+ Parameters
240
+ ----------
241
+ h5_path : local path or remote ROS3 URL
242
+ year_range : (start_year, end_year) inclusive, e.g. (2010, 2020)
243
+ bbox : (lat_min, lat_max, lon_min, lon_max) or None for global
244
+ patch_size : spatial size of each returned patch (pixels)
245
+ stride : step between patch centres
246
+ """
247
+ def __init__(self, h5_path, year_range=(2000, 2023),
248
+ bbox=None, patch_size=256, stride=128):
249
+ self.f = h5py.File(h5_path, "r")
250
+ self.pop = self.f["population"]
251
+ years = self.f["coords/years"][:]
252
+ lat = self.f["coords/lat"][:]
253
+ lon = self.f["coords/lon"][:]
254
+
255
+ # Time axis
256
+ t_mask = np.where((years >= year_range[0]) & (years <= year_range[1]))[0]
257
+ self.t0, self.t1 = int(t_mask[0]), int(t_mask[-1]) + 1
258
+ self.T = self.t1 - self.t0
259
+
260
+ # Spatial axis
261
+ if bbox:
262
+ lat_m = np.where((lat >= bbox[0]) & (lat <= bbox[1]))[0]
263
+ lon_m = np.where((lon >= bbox[2]) & (lon <= bbox[3]))[0]
264
+ self.r0, self.r1 = int(lat_m[0]), int(lat_m[-1]) + 1
265
+ self.c0, self.c1 = int(lon_m[0]), int(lon_m[-1]) + 1
266
+ else:
267
+ self.r0, self.r1 = 0, self.pop.shape[1]
268
+ self.c0, self.c1 = 0, self.pop.shape[2]
269
+
270
+ H, W = self.r1 - self.r0, self.c1 - self.c0
271
+ self.ps = patch_size
272
+
273
+ # All valid patch top-left corners
274
+ self.patches = [
275
+ (r, c)
276
+ for r in range(0, H - patch_size, stride)
277
+ for c in range(0, W - patch_size, stride)
278
+ ]
279
+
280
+ def __len__(self):
281
+ return len(self.patches) * self.T
282
+
283
+ def __getitem__(self, idx):
284
+ t_rel = idx % self.T
285
+ p_idx = idx // self.T
286
+ r, c = self.patches[p_idx]
287
+
288
+ t = self.t0 + t_rel
289
+ r_abs, c_abs = self.r0 + r, self.c0 + c
290
+
291
+ patch = self.pop[t, r_abs:r_abs+self.ps, c_abs:c_abs+self.ps]
292
+ patch = patch.astype(np.float32)
293
+
294
+ # Replace NaN with 0 for model input (or use a mask)
295
+ nan_mask = np.isnan(patch)
296
+ patch = np.nan_to_num(patch, nan=0.0)
297
+
298
+ return {
299
+ "population" : torch.from_numpy(patch[None]), # (1, ps, ps)
300
+ "nan_mask" : torch.from_numpy(nan_mask[None]), # (1, ps, ps)
301
+ "year" : torch.tensor(self.t0 + t_rel + 2000 - self.t0),
302
+ }
303
+
304
+ def __del__(self):
305
+ self.f.close()
306
+
307
+
308
+ # โ”€โ”€ Example usage โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
309
+ from torch.utils.data import DataLoader
310
+
311
+ ds = LandScanDataset(
312
+ h5_path = "pop_2000-23.h5",
313
+ year_range = (2015, 2023),
314
+ bbox = (5, 35, 65, 95), # South Asia
315
+ patch_size = 256,
316
+ stride = 128,
317
+ )
318
+ loader = DataLoader(ds, batch_size=8, shuffle=True, num_workers=4)
319
+
320
+ for batch in loader:
321
+ x = batch["population"] # (8, 1, 256, 256)
322
+ mask = batch["nan_mask"] # (8, 1, 256, 256)
323
+ yr = batch["year"]
324
+ break
325
+ ```
326
+
327
+ ### 9. Normalize using pre-computed stats
328
+
329
+ ```python
330
+ with h5py.File("pop_2000-23.h5", "r") as f:
331
+ means = f["stats/mean"][:] # (24,) โ€” per year
332
+ stds = f["stats/std"][:] # (24,)
333
+ years = f["coords/years"][:]
334
+
335
+ # Normalize a patch for year 2018
336
+ t = int(np.where(years == 2018)[0])
337
+ pop_2018_patch = f["population"][t, 5000:5256, 8000:8256]
338
+ normalized = (pop_2018_patch - means[t]) / (stds[t] + 1e-8)
339
+ ```
340
+
341
+ ### 10. HPC / MPI parallel reads
342
+
343
+ ```python
344
+ # h5py supports MPI-IO for multi-node HPC jobs
345
+ # Launch with: mpirun -n 8 python script.py
346
+
347
+ from mpi4py import MPI
348
+ import h5py
349
+ import numpy as np
350
+
351
+ comm = MPI.COMM_WORLD
352
+ rank = comm.Get_rank()
353
+ size = comm.Get_size()
354
+
355
+ with h5py.File("pop_2000-23.h5", "r", driver="mpio", comm=comm) as f:
356
+ T = f["population"].shape[0]
357
+ my_years = np.array_split(np.arange(T), size)[rank]
358
+
359
+ for t in my_years:
360
+ slab = f["population"][t, :, :]
361
+ # Each rank independently processes its years โ€” no contention
362
+ result = slab[~np.isnan(slab)].sum()
363
+ print(f" rank={rank} t={t} total={result/1e9:.3f}B")
364
+ ```
365
+
366
+ ---
367
+
368
+ ## ๐Ÿ—บ๏ธ Native Extent per Year
369
+
370
+ Years 2001โ€“2012 have fewer rows than the master grid because older LandScan releases used a slightly cropped polar extent. Pixels beyond the native extent are `NaN`.
371
+
372
+ ```python
373
+ with h5py.File("pop_2000-23.h5", "r") as f:
374
+ ext_years = f["native_extent/years"][:]
375
+ n_rows = f["native_extent/n_rows"][:]
376
+ n_cols = f["native_extent/n_cols"][:]
377
+
378
+ for yr, h, w in zip(ext_years, n_rows, n_cols):
379
+ flag = " โ† cropped" if h < 21600 else ""
380
+ print(f" {yr}: {h} ร— {w}{flag}")
381
+ ```
382
+
383
+ Expected output:
384
+ ```
385
+ 2000: 21600 ร— 43200
386
+ 2001: 20880 ร— 43200 โ† cropped
387
+ ...
388
+ 2012: 20880 ร— 43200 โ† cropped
389
+ 2013: 21600 ร— 43200
390
+ ...
391
+ 2023: 21600 ร— 43200
392
+ ```
393
+
394
+ ---
395
+
396
+ ## ๐Ÿงฎ Global Population Trend
397
+
398
+ | Year | Global Population |
399
+ |------|------------------|
400
+ | 2000 | ~6.09 billion |
401
+ | 2005 | ~6.45 billion |
402
+ | 2010 | ~6.85 billion |
403
+ | 2015 | ~7.28 billion |
404
+ | 2020 | ~7.79 billion |
405
+ | 2023 | ~8.1 billion |
406
+
407
+ ---
408
+
409
+ ## ๐Ÿ“ Coordinate Reference
410
+
411
+ ```
412
+ Top-left pixel centre : 89.9917ยฐN, 179.9917ยฐW
413
+ Bottom-right pixel centre: 89.9917ยฐS, 179.9917ยฐE
414
+ Pixel size : 0.008333ยฐ (~0.926 km at equator, ~1 km average)
415
+ ```
416
+
417
+ ```python
418
+ # Convert lat/lon to row/col index
419
+ def latlon_to_idx(lat_val, lon_val, lat_arr, lon_arr):
420
+ row = int(np.argmin(np.abs(lat_arr - lat_val)))
421
+ col = int(np.argmin(np.abs(lon_arr - lon_val)))
422
+ return row, col
423
+ ```
424
+
425
+ ---
426
+
427
+ ## โš ๏ธ Known Issues & Limitations
428
+
429
+ - **2001โ€“2012 polar crop**: 720 rows missing at the poles (โ‰ฅ ~83.5ยฐN / โ‰ค ~83.5ยฐS). These are ocean/ice โ€” NaN fill has no impact on population analysis.
430
+ - **NaN โ‰  zero population**: Do not fill NaN with 0 indiscriminately โ€” ocean pixels and missing-extent pixels are both NaN but have different meanings. Use `/native_extent` to distinguish them if needed.
431
+ - **Ambient vs residential**: LandScan is *ambient* population. It differs from census residential counts โ€” commuters, transit zones, and commercial areas inflate daytime values.
432
+ - **Population redistribution, not growth only**: Year-to-year changes reflect both demographic change and model improvements across LandScan releases.
433
+
434
+ ---
435
+
436
+ ## ๐Ÿ“„ Citation
437
+
438
+ If you use this dataset, please cite the original LandScan source:
439
+
440
+ ```bibtex
441
+ @dataset{landscan_global,
442
+ author = {Oak Ridge National Laboratory},
443
+ title = {LandScan Global Population Database},
444
+ year = {2023},
445
+ publisher = {Oak Ridge National Laboratory},
446
+ url = {https://landscan.ornl.gov},
447
+ note = {Annual releases 2000--2023}
448
+ }
449
+ ```
450
+
451
+ ---
452
+
453
+ ## ๐Ÿ”— Links
454
+
455
+ - [LandScan Global โ€” ORNL](https://landscan.ornl.gov)
456
+ - [LandScan Methodology](https://landscan.ornl.gov/landscan-datasets)
457
+ - [HDF5 Chunking Guide](https://docs.h5py.org/en/stable/high/dataset.html#chunked-storage)
458
+ - [h5py ROS3 (remote streaming)](https://docs.h5py.org/en/stable/high/file.html#ros3)
459
+
460
+ ---
461
+
462
+ ## ๐Ÿ“œ License
463
+
464
+ The original LandScan Global data is made available under the [Creative Commons Attribution 4.0 International License (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/).
465
+ Attribution: *UT-Battelle, LLC, Oak Ridge National Laboratory*.
466
+ This HDF5 repackaging does not alter the underlying data.