Skip to content

Commit 68c8679

Browse files
committed
Improved support for datasets with time bands and non-0 center long
1 parent e432e5d commit 68c8679

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ coverage-vizgen uses a YAML dataset configuration file to specify settings for p
6969
* `s3_prefix` - S3 URI to upload MRFs to (if specified)
7070
* `idx_dir` - OnEarth idx directory to move MRF idx files to (if specified)
7171
* `is360` - Convert dataset from 0-360 bounds to -180 - 180 if true
72+
* `center_long` - The center longitude when convert from 0-360 (default: 0)
7273
* `speed_vars` - List of `u` and `v` variables to use for converting to speed
7374

7475
### Example Configurations

bin/vizgen.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import string
2424
import boto3
2525
import zarr
26+
import xarray as xr
2627
from botocore.exceptions import ClientError, NoCredentialsError
2728
from pathlib import Path
2829
from datetime import datetime
@@ -260,6 +261,14 @@ def nc2tiff(input_file, config, process_existing=False, limit=-1, create_cog=Fal
260261
config.reproject = ''
261262

262263
counter += 1
264+
if len(config.time_bands) <= 1:
265+
# check for internal time dimension
266+
dataset = xr.open_dataset(input_file)
267+
time_dimension = dataset['time']
268+
if len(time_dimension.values) > 1:
269+
config.time_bands = [datetime.strptime(str(item)[:-4], '%Y-%m-%dT%H:%M:%S.%f') for item in time_dimension.values]
270+
dataset.close()
271+
print('Using time bands: ' + str(config.time_bands))
263272
for band, time in enumerate(config.time_bands):
264273
if time != '':
265274
bandstring = '_b' + str(band+1)
@@ -296,7 +305,8 @@ def nc2tiff(input_file, config, process_existing=False, limit=-1, create_cog=Fal
296305
output_file_360 = output_file.replace('.tiff', '_360.tiff')
297306
print('Creating GeoTIFF file ' + output_file_360)
298307
gdal_warp = ['gdalwarp', '-t_srs', 'WGS84', '-te', '-180', '-90', '180', '90', output_file,
299-
output_file_360, '-wo', 'SOURCE_EXTRA=1000', '--config', 'CENTER_LONG', '0']
308+
output_file_360, '-wo', 'SOURCE_EXTRA=1000', '--config',
309+
'CENTER_LONG', str(config.center_long)]
300310
print(gdal_warp)
301311
process = subprocess.Popen(gdal_warp, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
302312
process.wait()
@@ -400,12 +410,20 @@ def create_mrf(input_files, config, layer_name, colormap, empty_tile):
400410
else:
401411
raise
402412
date_of_data = date.strftime('%Y%m%d')
403-
print('Detected date: ' + date_of_data)
404413
time_of_data = date.strftime('%H%M%S')
405414
if config.time_bands != [''] and '_b' in filename:
406415
band = int(filename.split('_b')[1].split('_')[0]) - 1
407416
addtime = config.time_bands[band]
408-
time_of_data = (date + timedelta(seconds=addtime)).strftime('%H%M%S')
417+
# determine if sub-daily
418+
if len(config.time_bands) > 1:
419+
if not str(config.time_bands[0]).isnumeric():
420+
date_of_data = config.time_bands[band].strftime('%Y%m%d')
421+
time_of_data = config.time_bands[band].strftime('%H%M%S')
422+
elif config.time_bands[1] - config.time_bands[0] > 366:
423+
time_of_data = (date + timedelta(seconds=addtime)).strftime('%H%M%S')
424+
else:
425+
date_of_data = (date + timedelta(days=addtime-1)).strftime('%Y%m%d')
426+
print('Detected date: ' + date_of_data)
409427
output_dir = config.output_dir + '/' + layer_name + '/' + str(date.year)
410428
if not os.path.exists(output_dir):
411429
os.makedirs(output_dir)

bin/vizingest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def __init__(self, config):
6161
self.s3_prefix = layer_config.get('s3_prefix')
6262
self.idx_dir = layer_config.get('idx_dir')
6363
self.is360 = layer_config.get('is360', False)
64+
self.center_long = layer_config.get('center_long', 0)
6465
self.speed_vars = layer_config.get('speed_vars')
6566

6667
def __str__(self):

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ Rtree==1.0.1
1414
mapbox-vector-tile==2.0.1
1515
urllib3==1.26.16
1616
zarr==2.16.1
17+
xarray==2023.10.1
18+
h5netcdf==1.3.0
19+
netcdf4==1.6.5

version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22

33
# The VIZGEN version to use in the Docker image tag (e.g. coverage/vizgen:{VIZGEN_VERSION}).
4-
export VIZGEN_VERSION=0.6.2
4+
export VIZGEN_VERSION=0.7.0

0 commit comments

Comments
 (0)