Quacken8 / MagneticDisconnectSimulator

Python simulator of disconnection of solar magnetic field from its roots inpsired by Schüssler and Rempel (2018)
1 stars 0 forks source link

`dataStructure.py` suggestions #6

Closed mejroslav closed 1 year ago

mejroslav commented 1 year ago

https://github.com/Quacken8/MagneticDisconnectSimulator/blob/faef3bd8e65fb5808206e7455553f4014a215acd/dataStructure.py#L164-L174

Maybe you can create a new function?

def saveToFile(filename, ... , data):
   header = f"temperature [{something}], rows index depth, columns index time"
   np.savetxt(filename, data.T, header=header, delimiter=",") 
mejroslav commented 1 year ago

https://github.com/Quacken8/MagneticDisconnectSimulator/blob/faef3bd8e65fb5808206e7455553f4014a215acd/dataStructure.py#L44-L60

Maybe you can simplify the attribute setting using **kwargs argument? I think something like this should work:

class MyClass:
    def __init__(self, **kwargs):
        for key, value in kwargs.items():
            setattr(self, key, value)

# Example usage
my_instance = MyClass(temperature=25, density=1.2, pressure=100)
Quacken8 commented 1 year ago

https://github.com/Quacken8/MagneticDisconnectSimulator/blob/faef3bd8e65fb5808206e7455553f4014a215acd/dataStructure.py#L164-L174

Maybe you can create a new function?

Yes, a function for the saving will surely help readibility. Will do!

Quacken8 commented 1 year ago

https://github.com/Quacken8/MagneticDisconnectSimulator/blob/faef3bd8e65fb5808206e7455553f4014a215acd/dataStructure.py#L44-L60

Maybe you can simplify the attribute setting using **kwargs argument? I think something like this should work:

class MyClass:
    def __init__(self, **kwargs):
        for key, value in kwargs.items():
            setattr(self, key, value)

# Example usage
my_instance = MyClass(temperature=25, density=1.2, pressure=100)

I'm not super sure about this one, becuase it is necessary that all the variables are given to the constructor. I'd still have to check for all of the keys having values, but I guess it would shorten the code a bit...