Skip to content
Snippets Groups Projects

[meshlib] add append method to mesh series

Open joergbuchwald requested to merge joergbuchwald/ogstools:append into main
3 unresolved threads

Allows to append mesh series.

  1. Feature description was added to the changelog
  2. Tests covering your feature were added?
  3. Any new feature or behaviour change was documented?
  4. API-breaking changes documented here

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
108 108 )
109 109 return new_ms
110 110
111 @classmethod
112 def merge(
113 cls, mesh_series1: MeshSeries, mesh_series2: MeshSeries
114 ) -> MeshSeries:
115 "Merge two Mesh Series while keeping all timevalues"
116 ms_list = list(mesh_series1) + list(mesh_series2)
117 ms_timevalues = np.append(
118 mesh_series1.timevalues, mesh_series2.timevalues, axis=0
119 )
120 ms_timevalues, ms_list = zip(
121 *sorted(zip(ms_timevalues, ms_list, strict=False)), strict=False
  • I'm confused about the strict=False. In from_data there is strict=True, so if the length of timevalues and meshes doesn't match it fails anyway, thus we also use strict=True here and fail early. The line is clever but a but confusing with the double zip. Is the sorting necessary? I wonder what a practical use case would be, where you want to join two meshseries and their timevalues are intersecting?

  • I think it is not possible that both lengths disagree. The strinct keyword was added automatically, which is why it is set to False. I can set it to True.

    Some words on the context. I first wanted to have only an append function, but discussed with @TobiasMeisel that merge might be more general and would make sense in the case of different time discretiztions/outputs. During implementation, I realized that both features needed to have different implementations (because of the sorting for merge and the offset for append), which is why there are 2 methods now. However, I'm not completely convinced of this use case.

  • That would be good. I don't really see any usecase here even after giving it some thought.

    And regarding the extend method: would it make sense, to make the offset a function argument, which the user provides? i.e. ms1.extend(ms2, offset=ms1.timevalues[-1]) But if this would be done in 99% of the use cases anyway, then I see that we can automate it. Was just some food for thought.

  • Please register or sign in to reply
  • Florian Zill
    Florian Zill @FZill started a thread on the diff
  • 108 108 )
    109 109 return new_ms
    110 110
    111 @classmethod
    112 def merge(
    113 cls, mesh_series1: MeshSeries, mesh_series2: MeshSeries
    114 ) -> MeshSeries:
    115 "Merge two Mesh Series while keeping all timevalues"
    116 ms_list = list(mesh_series1) + list(mesh_series2)
    117 ms_timevalues = np.append(
    118 mesh_series1.timevalues, mesh_series2.timevalues, axis=0
    119 )
    120 ms_timevalues, ms_list = zip(
    121 *sorted(zip(ms_timevalues, ms_list, strict=False)), strict=False
    122 )
    123 return cls.from_data(ms_list, np.array(ms_timevalues))
  • Florian Zill
    Florian Zill @FZill started a thread on the diff
  • 131 ) -> MeshSeries:
    132 "Extends mesh_series1 with mesh_series2 removing redundant entries"
    133 ms1_list = list(mesh_series1)
    134 ms2_list = list(mesh_series2)
    135 ms1_timevalues = mesh_series1.timevalues
    136 ms2_timevalues = mesh_series2.timevalues
    137 offset = 0.0
    138 if ms2_timevalues[0] < ms1_timevalues[-1]:
    139 offset = ms1_timevalues[-1]
    140 if ms2_timevalues[0] == 0.0:
    141 ms1_timevalues = ms1_timevalues[:-1]
    142 ms1_list = ms1_list[:-1]
    143 elif np.abs(ms2_timevalues[0] - ms1_timevalues[-1]) < epsilon:
    144 ms1_timevalues = ms1_timevalues[:-1]
    145 ms1_list = ms1_list[:-1]
    146 ms2_timevalues = ms2_timevalues + offset
    • Comment on lines +137 to +146
      Suggested change
      138 if ms2_timevalues[0] < ms1_timevalues[-1]:
      139 offset = ms1_timevalues[-1]
      140 if ms2_timevalues[0] == 0.0:
      141 ms1_timevalues = ms1_timevalues[:-1]
      142 ms1_list = ms1_list[:-1]
      143 elif np.abs(ms2_timevalues[0] - ms1_timevalues[-1]) < epsilon:
      144 ms1_timevalues = ms1_timevalues[:-1]
      145 ms1_list = ms1_list[:-1]
      146 ms2_timevalues = ms2_timevalues + offset
      138 delta = ms2_timevalues[0] - ms1_timevalues[-1]
      139 offset = 0.0 if delta >= 0 else ms1_timevalues[-1]
      140 if ((delta < 0) and (ms2_timevalues[0] == 0.0)) or (np.abs(delta) < epsilon):
      141 ms1_timevalues = ms1_timevalues[:-1]
      142 ms1_list = ms1_list[:-1]
      143 ms2_timevalues = ms2_timevalues + offset
    • Please register or sign in to reply
  • Nice Feature!

  • Please register or sign in to reply
    Loading