You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Possible POC below.
Main issue being that hierarchies can change in patch number or positions or shape in time, thus not all points can be averaged blindly.
It is possible, since time averaging usually is performed over many times but small time intervals, that hierarchies don't change during the averaging time interval. But there is no general guarantee.
The simplest and most expected behavior then is to return a PatchHierarchy with only patches that are constant over the averaging interval.
deftime_avg(hier):
""" return a PatchHierarchy where patch datas are averaged over time. If there is only one time, the hierarchy is returned as is. """nbr_times=len(hier.times())
# no need to average if there is only one timeifnbr_times==1:
returnhier# we first create the returned hierarchy with the same metadata as the input hierarchy# but with the average time and initialized with the first patchlevel# the data of the first time is copied into the new hierarchy# and the averaging is then done.avg_time=hier.times().astype(float).mean()
first_time_lvls=hier.levels(hier.times()[0])
new_levels= {}
forilvl, lvlinfirst_time_lvls.items():
new_levels_patches= []
forpatchinlvl.patches:
pdatas= {}
forpdname, pdinpatch.patch_datas.items():
pdatas[pdname] =FieldData(
pd.layout, pdname, data=pd.dataset[:] /float(nbr_times)
)
new_levels_patches.append(Patch(pdatas, patch.id, attrs=patch.attrs))
new_levels[ilvl] =PatchLevel(ilvl, new_levels_patches)
avg_hier=PatchHierarchy(
new_levels,
hier.domain_box,
refinement_ratio,
time=avg_time,
data_files=hier.data_files,
selection_box=hier.selection_box,
)
fortimeinhier.times():
forilvlinhier.levels(time):
lvl=hier.level(ilvl, time)
avg_lvl=avg_hier.level(ilvl, avg_time)
foravg_patch, patchinzip(avg_lvl, lvl.patches):
foravg_pd, pdinzip(
avg_patch.patch_datas.values(), patch.patch_datas.values()
):
avg_pd.dataset[:] +=pd.dataset[:] /float(nbr_times)
returnavg_hier
The text was updated successfully, but these errors were encountered:
Possible POC below.
Main issue being that hierarchies can change in patch number or positions or shape in time, thus not all points can be averaged blindly.
It is possible, since time averaging usually is performed over many times but small time intervals, that hierarchies don't change during the averaging time interval. But there is no general guarantee.
The simplest and most expected behavior then is to return a PatchHierarchy with only patches that are constant over the averaging interval.
The text was updated successfully, but these errors were encountered: