Spaces:
Running on L4
Running on L4
grid reuse
Browse files- helpers/ReadVIIRSNTL.py +7 -7
helpers/ReadVIIRSNTL.py
CHANGED
|
@@ -28,19 +28,16 @@ from PIL import Image
|
|
| 28 |
import rasterio as rio
|
| 29 |
from huggingface_hub import hf_hub_download
|
| 30 |
|
| 31 |
-
from .grid import *
|
| 32 |
-
|
| 33 |
# ==============================================================================
|
| 34 |
# 3. Dataset configuration & remote index (lazy)
|
| 35 |
# ==============================================================================
|
| 36 |
REPO_ID = "Major-TOM/Core-VIIRS-Nighttime-Light"
|
| 37 |
REPO_BASE = f"https://huggingface.co/datasets/{REPO_ID}/resolve/main"
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
#
|
| 42 |
-
#
|
| 43 |
-
# user has even asked for a VIIRS tile.
|
| 44 |
_viirs_df = None
|
| 45 |
|
| 46 |
def _get_viirs_df():
|
|
@@ -96,6 +93,9 @@ def cell_to_viirs(cell, year, return_centre=False, return_gridcell=False, return
|
|
| 96 |
is not in the index or the read fails.
|
| 97 |
"""
|
| 98 |
row, col = cell.split('_')
|
|
|
|
|
|
|
|
|
|
| 99 |
lats, lons = mt_grid.rowcol2latlon([row], [col])
|
| 100 |
|
| 101 |
try:
|
|
|
|
| 28 |
import rasterio as rio
|
| 29 |
from huggingface_hub import hf_hub_download
|
| 30 |
|
|
|
|
|
|
|
| 31 |
# ==============================================================================
|
| 32 |
# 3. Dataset configuration & remote index (lazy)
|
| 33 |
# ==============================================================================
|
| 34 |
REPO_ID = "Major-TOM/Core-VIIRS-Nighttime-Light"
|
| 35 |
REPO_BASE = f"https://huggingface.co/datasets/{REPO_ID}/resolve/main"
|
| 36 |
|
| 37 |
+
# Both the index and the Major TOM grid object are loaded lazily so this
|
| 38 |
+
# module's import has zero side effects. The grid is a ~1 GB GeoDataFrame
|
| 39 |
+
# instantiated by Grid.__init__; we borrow the instance ReadAlphaEarth
|
| 40 |
+
# already created in the Space rather than building a third copy.
|
|
|
|
| 41 |
_viirs_df = None
|
| 42 |
|
| 43 |
def _get_viirs_df():
|
|
|
|
| 93 |
is not in the index or the read fails.
|
| 94 |
"""
|
| 95 |
row, col = cell.split('_')
|
| 96 |
+
# Reuse the Grid instance ReadAlphaEarth already built — avoids
|
| 97 |
+
# allocating a second multi-GB GeoDataFrame.
|
| 98 |
+
from .ReadAlphaEarth import mt_grid
|
| 99 |
lats, lons = mt_grid.rowcol2latlon([row], [col])
|
| 100 |
|
| 101 |
try:
|