Conversation
| name_replace = self.name.replace(":", "_") | ||
| files = Path(".").glob(f"{name_replace}*.ovf") | ||
| try: | ||
| name = str(max(files, key=lambda f: int(f.stem[-6:]))) |
There was a problem hiding this comment.
This throws an error when at least 1 file whose name starts with name_replace but doesn't have 6 digits at the end exists in the current directory. This can be alleviated by, e.g.,
name = str(max(filter(lambda f: f.stem[-6:].isnumeric(), files), key=lambda f: int(f.stem[-6:])))
ilateur
left a comment
There was a problem hiding this comment.
It's a bit funny and sad that we now have nice functionality to save and load ovf files... but not npy files. Would it be nice to also have a save_npy() function? Or make it one save() function and decide the type based on the given string (or default if not given)? Or is this useless (just call np.save(field_quantity.eval())) or outside the scope of this pull request?
| name = self.name + ".ovf" | ||
| count = self._ovf_counts.get(self.name, 0) | ||
| name = self.name.replace(":", "_") + f"{count:06d}.ovf" | ||
| self._ovf_counts[self.name] = count + 1 |
There was a problem hiding this comment.
that's pretty clever
Maybe also add an underscore between name and count (+ f"_{count:06d}.ovf")? This is not the mumax3 way though, so what do you think?
| ---------- | ||
| name : str (default="") | ||
| The name of the OVF file. If the name is empty (the default), the name of the FieldQuantity will be used. | ||
| The name of the OVF file. If the name is empty (the default), the name of the FieldQuantity will be used appended with an integer of 6 digits. |
There was a problem hiding this comment.
Maybe if the name is not empty, it should be checked whether it ends with ".ovf" and append it if needed?
| if name == "": | ||
| name = self.name + ".ovf" | ||
| name_replace = self.name.replace(":", "_") | ||
| files = Path(".").glob(f"{name_replace}*.ovf") |
There was a problem hiding this comment.
I'm worried this might be a bit slow when you have saved a lot of files during your simulation. Also having a default behavior for load at all is a bit strange to me 🤔 I would take the simple option and just make name a necessary variable.
There was a problem hiding this comment.
If a situation arises where glob somehow becomes a performance concern, the user can always specify name explicitly, thereby avoiding this entire block of code.
This PR adds
save_ovfandload_ovfmethods toFieldQuantities. This allows users to save and loadFieldQuantitiesvia OVF files.The
save_ovfmethod usespyovfand provides it with all available metadata. However, some metadata appears to be ignored (e.g. simulation time) and some fields are hard-coded in pyovf (e.g. units).pyovfexpects arrays with shape(nz, ny, nx, ncomp), while mumax⁺ uses(ncomp, nz, ny, nx). The save function reorders the axis, while the load function reverses this. To notify users of this reordering, the save function has a warning in the docstring.