@@ -417,10 +417,7 @@ def concat(
417
417
if keep == "last" :
418
418
if i < (len (infilenames ) - 1 ):
419
419
dfs_n = DfsFileFactory .DfsGenericOpen (str (infilenames [i + 1 ]))
420
- nf = dfs_n .FileInfo .TimeAxis .StartDateTime
421
- next_start_time = datetime (
422
- nf .year , nf .month , nf .day , nf .hour , nf .minute , nf .second
423
- )
420
+ next_start_time = dfs_n .FileInfo .TimeAxis .StartDateTime
424
421
dfs_n .Close ()
425
422
426
423
for timestep in range (n_time_steps ):
@@ -478,6 +475,58 @@ def concat(
478
475
) # get end time from current file
479
476
dfs_i .Close ()
480
477
478
+ elif keep == "average" :
479
+ ALPHA = 0.5 # averaging factor
480
+ last_file = i == (len (infilenames ) - 1 )
481
+ overlapping_with_next = False # lets first asume no overlap
482
+
483
+ # Find the start time of next file
484
+ if not last_file :
485
+ dfs_n = DfsFileFactory .DfsGenericOpen (str (infilenames [i + 1 ]))
486
+ next_start_time = dfs_n .FileInfo .TimeAxis .StartDateTime
487
+ else :
488
+ next_start_time = datetime .max # end of time ...
489
+
490
+ if i == 0 :
491
+ timestep_n = 0 # have not read anything before
492
+
493
+ # lets start where we left off (if last file overlapped)
494
+ timestep = timestep_n
495
+ while timestep < n_time_steps :
496
+ current_time = start_time + timedelta (seconds = timestep * dt )
497
+ if current_time >= next_start_time : # false if last file
498
+ overlapping_with_next = True
499
+ break
500
+ for item in range (n_items ):
501
+ itemdata = dfs_i .ReadItemTimeStep (item + 1 , timestep )
502
+ d = itemdata .Data
503
+ darray = d .astype (np .float32 )
504
+ dfs_o .WriteItemTimeStepNext (0 , darray )
505
+
506
+ timestep += 1
507
+
508
+ timestep_n = 0 # have not read anything from next file yet
509
+
510
+ if not overlapping_with_next :
511
+ dfs_n .Close ()
512
+ continue # next file
513
+
514
+ # Otherwhise read overlapping part
515
+ while timestep < n_time_steps :
516
+ for item in range (n_items ):
517
+ itemdata_i = dfs_i .ReadItemTimeStep (item + 1 , timestep )
518
+ itemdata_n = dfs_n .ReadItemTimeStep (item + 1 , timestep_n )
519
+ d_i = itemdata_i .Data
520
+ d_n = itemdata_n .Data
521
+ d_av = d_i * ALPHA + d_n * (1 - ALPHA )
522
+ darray = d_av .astype (np .float32 )
523
+ dfs_o .WriteItemTimeStepNext (0 , (darray ))
524
+ timestep += 1
525
+ timestep_n += 1
526
+
527
+ # Close next file before opening it again
528
+ dfs_n .Close ()
529
+
481
530
dfs_o .Close ()
482
531
483
532
0 commit comments