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

Export of animations #43

Closed
ghost opened this issue Jun 9, 2021 · 4 comments
Closed

Export of animations #43

ghost opened this issue Jun 9, 2021 · 4 comments
Labels
fixed Fix for issue has been released.

Comments

@ghost
Copy link

ghost commented Jun 9, 2021

Hi,

Currently, exporting animations specifying the filename is not working, mainly because animation don't use "filename" as a property, but different ones depending on the file type used.

I made a little workaround for my case. I'm exporting not animations but image sequences so i can load them later, so i modified very naively the export function so it can treat my accordingly. Here is the code so it can work as an inspiration hahaha

def export(self, node=None, file=None, anim = False):

    if node is None:
        for node in self/'exports':
            logger.info(f'Running export node "{node.name()}".')
            node.run()
            logger.info('Finished running export.')
    else:
        if isinstance(node, str):
            if '/' in node:
                node = self/node
            else:
                node = self/'exports'/node
        if not node.exists():
            error = f'Node "{node}" does not exist in model tree.'
            logger.error(error)
            raise ValueError(error)
        if file and anim:
            node.property('imagefilename', str(file))
        else:
            node.property('filename', str(file))
        logger.info(f'Running export node "{node.name()}".')
        node.run()
        logger.info('Finished running export.')

other filenames used by animation are "giffilename", "avifilename", "flashfilename", so there must by a way to tell the function which to use.

Cheers!

@john-hen
Copy link
Collaborator

john-hen commented Jun 9, 2021

Thanks for reporting this. I will file this as a bug since, technically, the export() method does not work as one might think if the export node defines an animation and a file argument is passed.

Though another way to achieve the same outcome should be to set the property "imagefilename" (or whichever property name may apply) of a given export node and then just run the node. (I have not tested this, I'm basing this on your description.)

I will look into supporting animations in Model.export(). I am generally reluctant to introduce new arguments (such as anim here), but that's just to keep the API as clean as possible. Maybe the choice of the property name can just depend on the file extension. It's not entirely clear to me yet if that's possible. Like, it should be possible for .gif, .avi, and .flv, but not sure what file would be for the image sequence that you exported.

@john-hen john-hen added the bug Something isn't working. label Jun 9, 2021
@max3-2
Copy link
Contributor

max3-2 commented Jun 10, 2021

I took a fairly quick look and I think this could get complicated - one of those cases where the COMSOL API is just very ambiguous. I use the demo model and added a quick Animation export using the GUI. Then:

(m/'exports/data').properties() has

filename

(m/'exports/image').properties() has

bmpfilename,
epsfilename,
giffilename,
gltffilename,
jpegfilename,
pngfilename,
tifffilename,

and lastly (m/'exports/Animation 1').properties() has

avifilename,
flashfilename,
giffilename,
imagefilename,
webmfilename

In a first step, we could distinguish the nodes for image and animation data via the implemented type, e.g.

In [20]: (m/'exports/image').type()
Out[20]: 'Image'

In [21]: (m/'exports/data').type()
Out[21]: 'Data'

In [22]: (m/'exports/Animation 1').type()
Out[22]: 'Animation'

Using this and the supplied suffix, we could run a check if the suffix is valid for the type of export and if yes, set the right filename. For Data exports, I would leave that completely free since the possibilities are endless there.
Going this way obviously has the risk that many more exceptions will occur with other node types and the code will increase in complexity. Another way would be simply catching the exception with a hint to the user that in the case of those sepcial exports one has to set the right property himself.

@john-hen john-hen added feature Proposal for a new feature. and removed bug Something isn't working. labels Oct 7, 2021
@john-hen john-hen changed the title Export not working with animations Support export of animations Oct 7, 2021
@john-hen john-hen changed the title Support export of animations Export of animations Oct 7, 2021
@john-hen
Copy link
Collaborator

john-hen commented Oct 7, 2021

As Max points out, this could get complicated. So I changed the status from "bug" to "feature request" and will add a note to the docs that animations aren't supported.

It could also be not that complicated. Maybe it's enough to look at the Java code Comsol generates when we add the animation. Might be a good first issue for someone. It would also require a test to come along with it though.

john-hen added a commit that referenced this issue Feb 21, 2022
Animations can now be exported via `Model.export()`, just like images
and data files. The animation type is deduced from the file ending
as either a GIF, Flash, AVI, or WebM encoded movie, or a PNG image
sequence. This covers all animation types supported by Comsol 5.6.

Much like in #66, we no longer allow specifying nodes via a string
such as `'export/image'`. This was never documented anyway and may lead
to problems with node names that actually contain a forward slash
(which would be escaped as `//`). The node must be given as either a
string such as `'image'` or a reference like `model/'exports'/'image'`.
@john-hen
Copy link
Collaborator

john-hen commented Feb 21, 2022

Fixed in MPh 1.1.3, released today.

@john-hen john-hen added fixed Fix for issue has been released. and removed feature Proposal for a new feature. labels Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed Fix for issue has been released.
Projects
None yet
Development

No branches or pull requests

2 participants