55# granted to it by virtue of its status as an intergovernmental organisation
66# nor does it submit to any jurisdiction.
77
8+ import base64
89import datetime
910import json
1011import logging
@@ -541,6 +542,8 @@ def write_input_fields(
541542 if ignore is None :
542543 ignore = []
543544
545+ fields .save ("input.grib" )
546+
544547 with self .timer ("Writing step 0" ):
545548 for field in fields :
546549 if field .metadata ("shortName" ) in ignore :
@@ -560,18 +563,49 @@ def write_input_fields(
560563 if accumulations_shape is None :
561564 accumulations_shape = accumulations_template .shape
562565
563- for param in accumulations :
564- self .write (
565- np .zeros (accumulations_shape , dtype = np .float32 ),
566- stepType = "accum" ,
567- template = accumulations_template ,
568- param = param ,
569- startStep = 0 ,
570- endStep = 0 ,
571- date = int (self .start_datetime .strftime ("%Y%m%d" )),
572- time = int (self .start_datetime .strftime ("%H%M" )),
573- check = True ,
574- )
566+ if accumulations_template .metadata ("edition" ) == 1 :
567+ for param in accumulations :
568+
569+ self .write (
570+ np .zeros (accumulations_shape , dtype = np .float32 ),
571+ stepType = "accum" ,
572+ template = accumulations_template ,
573+ param = param ,
574+ startStep = 0 ,
575+ endStep = 0 ,
576+ date = int (self .start_datetime .strftime ("%Y%m%d" )),
577+ time = int (self .start_datetime .strftime ("%H%M" )),
578+ check = True ,
579+ )
580+ else :
581+ # # TODO: Remove this when accumulations are supported for GRIB edition 2
582+
583+ template = """
584+ R1JJQv//AAIAAAAAAAAA3AAAABUBAGIAABsBAQfoCRYGAAAAAQAAABECAAEAAQAJBAIwMDAxAAAA
585+ SAMAAA/XoAAAAAAG////////////////////AAAFoAAAAtEAAAAA/////wVdSoAAAAAAMIVdSoAV
586+ cVlwAAPQkAAD0JAAAAAAOgQAAAAIAcEC//8AAAABAAAAAAH//////////////wfoCRYGAAABAAAA
587+ AAECAQAAAAD/AAAAAAAAABUFAA/XoAAAAAAAAIAKAAAAAAAAAAYG/wAAAAUHNzc3N0dSSUL//wAC
588+ AAAAAAAAANwAAAAVAQBiAAAbAQEH6AkWDAAAAAEAAAARAgABAAEACQQBMDAwMQAAAEgDAAAP16AA
589+ AAAABv///////////////////wAABaAAAALRAAAAAP////8FXUqAAAAAADCFXUqAFXFZcAAD0JAA
590+ A9CQAAAAADoEAAAACAHBAv//AAAAAQAAAAAB//////////////8H6AkWDAAAAQAAAAABAgEAAAAA
591+ /wAAAAAAAAAVBQAP16AAAAAAAACACgAAAAAAAAAGBv8AAAAFBzc3Nzc=
592+ """
593+
594+ template = base64 .b64decode (template )
595+ accumulations_template = ekd .from_source ("memory" , template )[0 ]
596+
597+ for param in accumulations :
598+ self .write (
599+ np .zeros (accumulations_shape , dtype = np .float32 ),
600+ stepType = "accum" ,
601+ template = accumulations_template ,
602+ param = param ,
603+ startStep = 0 ,
604+ endStep = 0 ,
605+ date = int (self .start_datetime .strftime ("%Y%m%d" )),
606+ time = int (self .start_datetime .strftime ("%H%M" )),
607+ check = True ,
608+ )
575609
576610
577611def load_model (name , ** kwargs ):
0 commit comments