@@ -371,7 +371,11 @@ def initialize_forecast_exporter_netcdf(
371
371
shape ,
372
372
metadata ,
373
373
n_ens_members = 1 ,
374
+ datatype = np .float32 ,
374
375
incremental = None ,
376
+ fill_value = None ,
377
+ scale_factor = None ,
378
+ offset = None ,
375
379
** kwargs ,
376
380
):
377
381
"""
@@ -401,12 +405,35 @@ def initialize_forecast_exporter_netcdf(
401
405
n_ens_members: int
402
406
Number of ensemble members in the forecast. This argument is ignored if
403
407
incremental is set to 'member'.
408
+ datatype: np.dtype, optional
409
+ The datatype of the output values. Defaults to np.float32.
404
410
incremental: {None,'timestep','member'}, optional
405
411
Allow incremental writing of datasets into the netCDF files.\n
406
412
The available options are: 'timestep' = write a forecast or a forecast
407
413
ensemble for a given time step; 'member' = write a forecast sequence
408
414
for a given ensemble member. If set to None, incremental writing is
409
415
disabled.
416
+ fill_value: int, optional
417
+ Fill_value for missing data. Defaults to None, which means that the
418
+ standard netCDF4 fill_value is used.
419
+ scale_factor: float, optional
420
+ The scale factor to scale the data as: store_value = scale_factor *
421
+ precipitation_value + offset. Defaults to None. The scale_factor
422
+ can be used to reduce data storage.
423
+ offset: float, optional
424
+ The offset to offset the data as: store_value = scale_factor *
425
+ precipitation_value + offset. Defaults to None.
426
+
427
+ Other Parameters
428
+ ----------------
429
+ institution: str
430
+ The instute, company or community that has created the nowcast.
431
+ Default: the pySTEPS community (https://pysteps.github.io)
432
+ references: str
433
+ Any references to be included in the netCDF file. Defaults to " ".
434
+ comment: str
435
+ Any comments about the data or storage protocol that should be
436
+ included in the netCDF file. Defaults to " ".
410
437
411
438
Returns
412
439
-------
@@ -448,18 +475,25 @@ def initialize_forecast_exporter_netcdf(
448
475
if n_ens_members > 1 :
449
476
n_ens_gt_one = True
450
477
478
+ # Kwargs to be used as description strings in the netCDF
479
+ institution = kwargs .get (
480
+ "institution" , "the pySTEPS community (https://pysteps.github.io)"
481
+ )
482
+ references = kwargs .get ("references" , "" )
483
+ comment = kwargs .get ("comment" , "" )
484
+
451
485
exporter = {}
452
486
453
487
outfn = os .path .join (outpath , outfnprefix + ".nc" )
454
488
ncf = netCDF4 .Dataset (outfn , "w" , format = "NETCDF4" )
455
489
456
490
ncf .Conventions = "CF-1.7"
457
491
ncf .title = "pysteps-generated nowcast"
458
- ncf .institution = "the pySTEPS community (https://pysteps.github.io)"
492
+ ncf .institution = institution
459
493
ncf .source = "pysteps" # TODO(exporters): Add pySTEPS version here
460
494
ncf .history = ""
461
- ncf .references = ""
462
- ncf .comment = ""
495
+ ncf .references = references
496
+ ncf .comment = comment
463
497
464
498
h , w = shape
465
499
@@ -559,14 +593,22 @@ def initialize_forecast_exporter_netcdf(
559
593
if incremental == "member" or n_ens_gt_one :
560
594
var_f = ncf .createVariable (
561
595
var_name ,
562
- np . float32 ,
596
+ datatype = datatype ,
563
597
dimensions = ("ens_number" , "time" , "y" , "x" ),
598
+ compression = "zlib" ,
564
599
zlib = True ,
565
600
complevel = 9 ,
601
+ fill_value = fill_value ,
566
602
)
567
603
else :
568
604
var_f = ncf .createVariable (
569
- var_name , np .float32 , dimensions = ("time" , "y" , "x" ), zlib = True , complevel = 9
605
+ var_name ,
606
+ datatype = datatype ,
607
+ dimensions = ("time" , "y" , "x" ),
608
+ compression = "zlib" ,
609
+ zlib = True ,
610
+ complevel = 9 ,
611
+ fill_value = fill_value ,
570
612
)
571
613
572
614
if var_standard_name is not None :
@@ -576,6 +618,11 @@ def initialize_forecast_exporter_netcdf(
576
618
var_f .units = var_unit
577
619
if grid_mapping_var_name is not None :
578
620
var_f .grid_mapping = grid_mapping_var_name
621
+ # Add gain and offset
622
+ if scale_factor is not None :
623
+ var_f .scale_factor = scale_factor
624
+ if offset is not None :
625
+ var_f .add_offset = offset
579
626
580
627
exporter ["method" ] = "netcdf"
581
628
exporter ["ncfile" ] = ncf
0 commit comments