Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generic.concat keep average #739

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

generic.concat keep average #739

wants to merge 4 commits into from

Conversation

daniel-caichac-DHI
Copy link
Collaborator

@daniel-caichac-DHI daniel-caichac-DHI commented Nov 1, 2024

I got it semi working, but not yet.
I need help with mikeCore I think.
I basically managed to create a concatenated file, but the overlap is not being written properly, and after the overlap, I think the second file is being written but with a messed up index.

temp_dfs.Close()

# Calculate average
averaged_data = (existing_data + current_data) / 2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is calculating the average as soon as the dfs2's overlap

averaged_data = (existing_data + current_data) / 2

# Write averaged data
dfs_o.WriteItemTimeStepNext(0, averaged_data)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this line is wrong, since it is 'appending' at the end.
I tried with WriteItemTimeStep but could not make it work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryan-kipawa Is this something that you would like to dig into?

Comment on lines +595 to +598
dfs_o.Flush()
temp_dfs = DfsFileFactory.DfsGenericOpen(
str(outfilename)
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also kind of crazy. It crashes and complains that it cannot open outfilename, but if I do dfs_o.Flush() again after it crashed, then it works.
its almost like I need to add a try/except and flush twice to make it run

Copy link
Collaborator Author

@daniel-caichac-DHI daniel-caichac-DHI Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

I will make a new failing test on Monday, I have some data I know the expected output

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I already uploaded a failing unit test

@@ -552,6 +552,82 @@ def concat(
) # get end time from current file
dfs_i.Close()

if keep == "average":
if i == 0:
# For first file, write all timesteps normally
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to calculate the timestep where the overlap occurs, calcuate the average, write that and then the rest, instead of writing the entire contents and then trying to overwrite?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I would suggest an algorithm like this (file1 starts before file2):

  • open file1
  • write file1 timesteps until start of file file2
  • open file2
  • write overlapping steps by with alpha*data1 + (1-alpha)*data2 until end of file1
  • close file1
  • write rest of file2
  • close file2

using the alpha notation above it will be super simple to later add a keep="linear" that linear mixes the two in the overlapping period.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't shoot the messenger, I chat'gpted this solution due to my lack of mikecore competences

@jsmariegaard jsmariegaard changed the title generic_average generic.concat keep average Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants