This is a pretty simple language or a python framework for people who want to keep things simple while also making scientific simulations and calculations.
For now there are very few methods/functions in this framework/language compared to many but, I am continuously developing it. For now it's a bit slow but I am trying to find a soulution so, if any one of you have any suggestion please help me.
This language is compiled down to python at runtime so all valid python is valid MagnetScript statement comprehensively making it a "transpiled" language and it all begins the moment you run your program with "sciencere" and in future I think you would be able to compile it down to python and take python source files with you directly from sciencere.
So in this section I will list a bunch of keywords and statements in this language and more are coming soon
iterate, it's similar to for loop in ther languages and here it is followed by a new variable for loop's local scope, then followed by inside keyword and then followed by an actual already defined variable and for kicks here's a simple example
word="Hello World!"
iterate letter inside word:
echo(letter)
๐ฒ๐ฐ๐ต๐ผ(), pretty much same as print which basically prints out your statement on the console.
๐๐๐ฟ_๐๐น๐ถ๐ฐ๐ฒ(), it takes two arguments the first one being mandatory that is a string to slice while the second one is optional and is a list that contains 3 indexes for slicing your string and by default it will reverse your string and here is an example of it cutting the last character of a string.
print(str_slice('Hello',[None,-1,None]))
๐ฟ๐ฒ๐พ๐๐ถ๐ฟ๐ฒ(), you can use it to import files in your program. It takes two arguments the first one being path to the file and the second optional one being name. Here's a simple example
o=require("_dir_/o.pyclass")
o.userDefinedSum(11, 10)
๐บ๐ด๐_๐ฟ๐ฒ๐พ๐๐ถ๐ฟ๐ฒ(), it takes a single argument that being path to a MagnetScript file and it imports it and here's an example
o=mgs_require("_dir_/o.mags")
o.userDefinedSum(11, 10)
When, this is similar to while in other languages and is simply followed by a condition inside paranthesis then followed by :
and then indexed similar to python and here's an example
x=0
word="Hello"
when(x<len(word)):
echo(word[x])
x+=1
unless, pretty similar to "if not" and should always be followed by a space to be recogonized correctly and here's an example
num=20
unless num>=20:
echo(num, "is less than 20")
else:
echo(num, "is greater than or equal to 20")
function, this is similat to function keyword in many languages and def in python and by using this, you can execute following example
function sum(num1, num2):
num=num1+num2
echo(num)
sum(9, 10)
This is by far the most distinct and important to read feature for this language is that certain words that are specifically reserved for this langugage should be covered with curly and then square brace such as {[unless]}
and here are the list of keywords that should be wrapped in curly square brackets (More ight be added).
function
iterate
inside
when
unless
>|
>:
This shines in it's easy ways to do certain tasks but it doesn't come at too big cost of flexibility because you can just execute python directly if you want to.
๐บ๐ฎ๐ด๐ป๐ฒ๐_๐๐ถ๐บ(), this takes two required arguments first one being sources for example what your magnets are and what are there positions and power and the second one being manupulation where you can manipulate your magnets to rotate and move.
๐ต๐ฒ๐ฎ๐๐บ๐ฎ๐ฝ_๐ถ๐บ๐ฎ๐ด๐ฒ(), this can give you the heatmap of an image by just a single required argument that being image and then there are many optional arguments and here's a list of these argumaents data(boolean) meaning is this image an already read array or just a plain image, cmap(string) default cmap is coolwarm, vmin, vmax, center(float) default is 0.5, robust and figsize(list), title(string) of two integers that determines size of the figure).
๐๐ฎ๐๐ต๐๐ฟ๐ฒ๐ฑ_๐ถ๐บ๐ฎ๐ด๐ฒ(), basically a watershed effect with one required and three optional arguments, required one is image which is quite self explanatory... Optional areguments are data(boolean) meaning that is it an array or just a good ole image, output(boolean) it means that do you want it to be an output image or an output array, figsize(list), title(string) should have two indexes and it determines height and width of the displayed image and you can get what you want in utput by changing outvar parameter.
๐ฏ๐ฟ๐ถ๐ด๐ต๐_๐๐ฐ๐ฎ๐น๐ฒ(), this just makes a bright scale image and you can have other optional parameters such as outer_circle, it maes a dark circle on outside and is False by default, you can give this data or path of an image and yu need to specify it with 'data' parameter, with 'grayscale' you can just set if you want it to be gray or not, with 'dotted_lines' you can set there to be dotted lines if you want to, then there are usual figsiz, cmap, title(string) and output.
๐ฐ๐ผ๐บ๐ฝ๐ฎ๐ฐ๐_๐๐ฒ๐ด๐บ๐ฒ๐ป๐๐ฎ๐๐ถ๐ผ๐ป_๐ถ๐บ๐ฎ๐ด๐ฒ(), this segments the image using different methods avalible by an argument outvar which by defaut outvar='segments_watershed'. The only required argument is image but you can also provide data by using data argument by default data=False, title will be title of output figure by default title='Compact watershed', just figure size of this plot by default figsize=[6,4], then there are options for five different methods this function uses and following are there arguments.
scale=100,
sigma=0.5,
min_size=50,
n_segments=250,
compactness=10,
kernal_siz=3,
max_dist=6,
ratio=0.5,
markers=250
and then finally output, this argument by defult is output=True but changing it to false will output the actual array instead of just plotting out the figure.
๐ฏ๐น๐ฎ๐ฐ๐ธ_๐๐ถ๐บ(), it can generate simulations for blackholes it takes two parameters both are required but these parameters are basic characteristics of blackhole and you need to give those in order for this function to work.
๐ถ๐บ๐ฎ๐ด๐ฒ_๐๐ต๐ผ๐(), this basically takes your image and shows it with required argument image and optional argumets cmap, interpolation, alpha, vmin, vmax, filter_radius, figsize, title.
๐ณ๐ฟ๐ฎ๐บ๐ฒ_๐ฑ๐ฟ๐ฎ๐ด(), frame-drag function of kerr space=time in this function there are seven arguments but only two of them are required first of them being Boyer Lindquist Object(BL_obj) and the second one being Mass(M) and then there are other parameters for example here's a snippet to demonstrate basic functionality
M = 1.989e30 * units.kg
a = 0.3 * units.m
BL_obj = BoyerLindquistDifferential(50e5 * units.km, np.pi / 2 * units.rad, np.pi * units.rad,
0 * units.km / units.s, 0 * units.rad / units.s, 0 * units.rad / units.s,
a)
frame_drag(BL_obj, M)
then there are stepsize and end lambda and defaults are
end_lambda=((1 * units.year).to(units.s)).value/930
OdeMethodKwargs = {"stepsize": ((0.02 * units.min).to(units.s)).value}
and other basic defaults like dot of the given color(dot_color='black'), scatter value(scatter_val=[0,0]) and size, that being default as 2.0 are
scatter_val=[0,0]
dot_color='black'
size=0.2
For now these are the only parameters that are avalible in this function
๐ผ๐ฟ๐ฏ๐ถ๐_๐ฒ๐ฐ๐ฐ๐ฒ๐ฟ_๐๐ถ๐บ(), this function generates a body orbiting another one and it takes two required and three optional arguments, the first required one is Sphere's properties and second required one is Mass. For optinal one's first one is what is ending lamda, second one is stepsize and the last one is Object that I would explain in a bit sorry, if this was a bit confusing but here I have a bit of sample code for you to understand this function better
M = 1.989e30 * units.kg # mass of sun
distance = 147.09e6 * units.km
speed_at_perihelion = 30.29 * units.km / units.s
omega = (units.rad * speed_at_perihelion) / distance
sph_obj = SphericalDifferential(distance, np.pi / 2 * units.rad, np.pi * units.rad,
0 * units.km / units.s, 0 * units.rad / units.s, omega)
orbit_eccer_sim(sph_obj, M)
Running this with sciencere would give you earth's orbit and I hope this let's you under this easily, optional arguments are not used here but on source code defaults are
end_lambda=((1 * units.year).to(units.s)).value
stepsize=((5 * units.min).to(units.s)).value
about that Object argument, honestly the best way to understand it to see the default code here but, I would summarize it a bit by saying you have to define some variables that being bodies with their poperties then link them through a property called 'parent' and then pass last variable(Object) in chain to the function using this argument and here's the default cde for you to easily understand
Sun = Body(name="Sun", mass=M, parent=None)
Object = Body(name="Earth", differential=sph_obj, parent=Sun)
#Pass Object in "orbit_eccer_sim()"
Now, that I have attempted to explain this so, I hope I have explained this well and that's it for this function.
This is based on following libraries
numpy
scipy
magpylib
seaborn
astropy
EinsteinPy
galgebra
skimage
and many functions can't be simplified for example in test.mags there's a really simple way to make basic Schwarzschild spacetime simulation which in my opinion cannot be further simplified but, you can contribute to this project and you might have a better idea.
This is the command line tool to use with MagnetScript to speed up this simulation and calculation programs because it loads all libraries and functions from 'functions.py' but to speed it up you need to not add or remove line from functions import *
because doing otherwise would reload all functions and libraries. This tool is better then GUI interpreter because it won't stop running after execution of every simulation so, all you need to do to know how to use this tool is to type help()
in terminal inside this program to know all currently avalible command and remember that more are indeed coming soon.
โ๏ธSpeeding this up by splitting functions.py in multiple files making a CLI program.
Adding more functions and make further simplifications.
Make Galgebra easier.
Make use of asropy extensively.
Simple setup.py to install all libraries for use.