<jupyter_start><jupyter_text>Aggregator examplesShows how dfs aggregator functions work<jupyter_code>import numpy as np
import mikeio
from mikeio import aggregator
dfs0 = mikeio.dfs0.Dfs0()
dfs1 = mikeio.dfs1.dfs1()
dfs2 = mikeio.dfs2.dfs2()<jupyter_output><empty_output><jupyter_text>Input data<jupyter_code>dfs2file = r"..\tests\testdata\eq.dfs2"
data2, tt2, names2 = dfs2.read(dfs2file)
print(data2[0].shape)
print(names2)
print(np.nanmean(data2[0][:,0,0]))
print(np.nanmean(data2[0][0,:,0]))
print(np.nanmax(data2[0][:,0,0]))
#
s1, s2, s3 = data2[0].shape
vec=np.reshape(data2[0][:,:,0],s1*s2,1)
print(np.nanmean(vec))
print(np.nanstd(vec))
s1, s2, s3 = data2[0].shape
vec=np.reshape(data2[0][:,:,0],s1*s2,1)<jupyter_output><empty_output><jupyter_text>Example 1make y-average of dfs2 (keeping x-axis)<jupyter_code>dfs1file1 = r"..\tests\testdata\eq_ax_x.dfs1"
aggregator.dfs2todfs1(dfs2file, dfs1file1)
data1, tt1, names1 = dfs1.read(dfs1file1)
print(data1[0].shape)
print(names1)
print(data1[0][0,0])<jupyter_output>(20, 5)
['Item 1']
0.4434114098548889<jupyter_text>Example 2: other axisTake average instead over x-axis<jupyter_code>dfs1file2 = r"..\tests\testdata\eq_ax_y.dfs1"
aggregator.dfs2todfs1(dfs2file, dfs1file2, ax=1)
data1, tt1, names1 = dfs1.read(dfs1file2)
print(data1[0].shape)
print(data1[0][0,0])<jupyter_output>(10, 5)
0.5089341998100281<jupyter_text>Example 3: maxTake max instead over y-axis<jupyter_code>dfs1file3 = r"..\tests\testdata\eq_ax_x_max.dfs1"
aggregator.dfs2todfs1(dfs2file, dfs1file3, ax=0, func=np.nanmax)
data1, tt1, names1 = dfs1.read(dfs1file3)
print(data1[0].shape)
print(data1[0][0,0])<jupyter_output>(20, 5)
0.9117105007171631<jupyter_text>Example 4: aggregate to dfs0Calc mean of each time step<jupyter_code>dfs0fileA = r"..\tests\testdata\eq_mean.dfs0"
aggregator.dfstodfs0(dfs2file, dfs0fileA)
data0, tt0, names0 = dfs0.read(dfs0fileA)
print(data0[0].shape)
print(names0)
print(data0[0][0])<jupyter_output>(1,)
['Item 1']
0.4953838288784027<jupyter_text>Example 5: calc standard deviation pr step<jupyter_code>dfs0fileB = r"..\tests\testdata\eq_std.dfs0"
aggregator.dfstodfs0(dfs2file, dfs0fileB, np.nanstd)
data0, tt0, names0 = dfs0.read(dfs0fileB)
print(data0[0][0])<jupyter_output>0.2997477352619171<jupyter_text>Clean up<jupyter_code>import os
os.remove(dfs1file1)
os.remove(dfs1file2)
os.remove(dfs1file3)
os.remove(dfs0fileA)
os.remove(dfs0fileB)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1617283950617284, 'fraction_numerical': 0.10576131687242799, 'mean_word_length': 8.80241935483871, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '222091', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1170, 'n_words': 147, 'path': 'notebooks/Aggregator.ipynb', 'repo_name': 'maximlt/mikeio', 'size': '2430'}