Move away from simpleNamespace to class definitions #95
Replies: 4 comments 14 replies
-
Hi @schmidtijoe ! I was excited to read through your proposal. I agree, the flexibility of the I took a look at your fork, and looks like you've refactored all of As an alternative, what if Keen to hear your thoughts, |
Beta Was this translation helpful? Give feedback.
-
Hi @schmidtijoe and @sravan953, I also really like the idea of introducing classes instead of SimpleNamespaces and would be glad helping in the refactoring/restructuring process. However, I definitely agree with @sravan953 that we should ensure compatibility with existing example scripts and thus with all user-defined sequences being used at the moment. Thus, I would in general try to stick to the current naming, which is inspired by the Matlab code and enables easy transitions from Matlab to Python. In my opinion, this should have highest priority. A structure similar to the one @sravan953 suggested should do fine. However, I would suggest to focus on the release of a stable version 1.4 first and start the refactoring afterwards. At this point, I would maybe make sense to introduce some (further) unit tests for the individual functions and methods and make use of GitHub Actions for automatic builds and tests, no?! Maybe we can schedule a zoom meeting to discuss the topic and collect some ideas. What do you think? Best, |
Beta Was this translation helpful? Give feedback.
-
Hi all, I will make a Slack channel so we can coordinate better to figure out when we can meet, would that work? |
Beta Was this translation helpful? Give feedback.
-
Hi all! Apologies for the delayed response, please join me on Slack! |
Beta Was this translation helpful? Give feedback.
-
Hello all,
Intro
I am in the development process of a sequence and loved that this repo is here (since i dislike matlab :D) and got a running version of the sequence up for testing on the scanner pretty quickly. However, i encountered some issues when testing the sequence which i couldn't pinpoint too well initially.
I thought part of what made the following debugging hard for me was the use of all objects as
types.SimpleNamespace()
(SN) since it is not easily trackable (at least with my skillset... , and that was one of the reasons i dislike matlab).Personally, i think python supports okish type checking mechanisms and i think debugging and developing would be much easier when declaring proper objects.
Idea
I started in my own fork to add a class for gradient, rf, adc and timing to give each their own objects and then refactored methods like
make_trapezoid
ormake_sinc_pulse
as individual class members of the object they belong to. I wrote up a quick plot method for each of those classes for quick double checking, which comes in handy when creating objects.What intrigues me most about the approach is that you get a comprehensive overview of all methods and variables connected to an object.
For example, in my process i was concerned whether or not i can set an
adc.phase_offset
parameter. I can find it in themake_adc
method, but after creation, within the code, as the package is now i have no chance of finding out which variables i can set and which parameter SN objects inherit (i guess that is the convenience in using it) if i want to handle my adc object.But i think it would be much more beneficial (besides knowing all the methods of the classes) to actually know which parameters define each object and which of those actually are shipped in a meaningful way to the scanner. Since with the SN way of doing things i can easily define
adc.random_variable
and it will never throw any errors. But i need to follow the object along quite a loong way to find out if therandom_variable
ever is translated into doing something in my actual measurement. I could also by accident setadc.phaseOffset
or whatever typo and it doesnt matter in the process.Surely, from having to go through this debugging process, i know my way around the package better now and especially with a proper python IDE its not too hard to find what actually is written in the .seq for each object. I just think it would make much more sense to not be dependent on sufficiently naming everything. Eg. i could create an object called adc with my RF class and still it is trackable and known throughout the code that it is only an RF object and can only be used for RF things (i know i am being stupidly annoying now).
Misc
Since my use case was quite limited in the methods i needed, i think the refactoring is not that big of a deal for my project. Obviously going into the meat of the code, where .seq is written etc., porting the code might be bigger of a project (i haven't checked yet).
I was wondering if people would think putting the limited time in (i am researcher myself obviously) would be beneficial for the rest of the users.
Also i think proper definition of which variables entirely defines the objects is subject to debate. For example, I was using
trapezoid
andextended_trapezoid
gradients and think a "compressed" waveform is what easily defines both and from where i can generate a gradient-rastered waveform and easily deduce things like thegrad.first
,grad.last
andgrad.shape_dur
etc.. Agrad.amplitude
only makes sense for one of them, hence, i changed it tomax_amplitude
. In principle also a delay could be deduced via a method from the above but also could just get a variable.All in all, i guess it would make debugging straight forward and feature development more consise. I am keen to know what people think.
Beta Was this translation helpful? Give feedback.
All reactions