|
23 | 23 | import string |
24 | 24 | import boto3 |
25 | 25 | import zarr |
| 26 | +import xarray as xr |
26 | 27 | from botocore.exceptions import ClientError, NoCredentialsError |
27 | 28 | from pathlib import Path |
28 | 29 | from datetime import datetime |
@@ -260,6 +261,14 @@ def nc2tiff(input_file, config, process_existing=False, limit=-1, create_cog=Fal |
260 | 261 | config.reproject = '' |
261 | 262 |
|
262 | 263 | 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)) |
263 | 272 | for band, time in enumerate(config.time_bands): |
264 | 273 | if time != '': |
265 | 274 | bandstring = '_b' + str(band+1) |
@@ -296,7 +305,8 @@ def nc2tiff(input_file, config, process_existing=False, limit=-1, create_cog=Fal |
296 | 305 | output_file_360 = output_file.replace('.tiff', '_360.tiff') |
297 | 306 | print('Creating GeoTIFF file ' + output_file_360) |
298 | 307 | 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)] |
300 | 310 | print(gdal_warp) |
301 | 311 | process = subprocess.Popen(gdal_warp, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
302 | 312 | process.wait() |
@@ -400,12 +410,20 @@ def create_mrf(input_files, config, layer_name, colormap, empty_tile): |
400 | 410 | else: |
401 | 411 | raise |
402 | 412 | date_of_data = date.strftime('%Y%m%d') |
403 | | - print('Detected date: ' + date_of_data) |
404 | 413 | time_of_data = date.strftime('%H%M%S') |
405 | 414 | if config.time_bands != [''] and '_b' in filename: |
406 | 415 | band = int(filename.split('_b')[1].split('_')[0]) - 1 |
407 | 416 | 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) |
409 | 427 | output_dir = config.output_dir + '/' + layer_name + '/' + str(date.year) |
410 | 428 | if not os.path.exists(output_dir): |
411 | 429 | os.makedirs(output_dir) |
|
0 commit comments