Giter VIP home page Giter VIP logo

Comments (3)

christian-oreilly avatar christian-oreilly commented on July 18, 2024

Sorry for not following up on that earlier! It flew under my radar! So... I like the idea of a class if there are some additional things we want this class to manage (i.e., some methods that operates on these attributes, some argument validation to be coded, e.g., through the @property decorator for setters and getters). I would not do it as a class if it is nothing more than the equivalent of a "C structure" (i.e., just a list of attributes) as shown in example 1. For such a case, the Python dictionary works already quite well, plus they allow the use of the ** operator that can be nifty in some case. How familiar are you with the use of the * and ** operators to unpack list and dictionaries (when used in the call of a function) or to allow unspecified positional and keyword arguments (when used in the signatures of a function)? Maybe these can be useful? They often are when working with a larger number of arguments.

That is:

args = ['[binary data here]', 'test.nii.gz']
nv.addVolume(*args)

kwargs = {"data_buffer": '[binary data here]', "name": 'test.nii.gz'}
nv.addVolume(**kwargs)

and

        def addVolume(
            self,
            data_buffer,
            name,
            *args, 
            **kwarg
        ):
                # some code
               
                self.some_other_method_that _requires_the_additional_arguments(*args, **kwargs)

               # some other code

This is quite neat in combination with config files (e.g., json or yaml) which are read as dictionaries that can be passed directly into functions. For a concreate example, you can have a look at these line of codes:

https://github.com/lina-usc/pylossless/blob/14075fc2782d9c5afa67afd897be62f1ccf516fa/pylossless/pipeline.py#L1046-L1060

These lines use the following portion of a YAML config:

https://github.com/lina-usc/pylossless/blob/14075fc2782d9c5afa67afd897be62f1ccf516fa/assets/ll_default_config.yaml#L104-L110

Note that since these arguments are passed to the constructor of the ICA (https://mne.tools/stable/generated/mne.preprocessing.ICA.html), any argument that this constructor accept will work, without me having to define them in my code. Further, the signature of the ICA constructor can change and the users of my code would still be able to use the new arguments available to ICA without me having to change a line of code in my own library.

I am not sure if any of this can be useful for your specific use case; I'll have a better idea when I see what the actual code looks like and how efficient/cumbersome it is.

from ipyniivue.

AnthonyAndroulakis avatar AnthonyAndroulakis commented on July 18, 2024

Thank you. I saw your response earlier but I get to implementing these ideas. I'll write a response once I write some implementations.

from ipyniivue.

christian-oreilly avatar christian-oreilly commented on July 18, 2024

Sure thing, @AnthonyAndroulakis

from ipyniivue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.