So this post comes rather late, but I’d still like to talk about what I did in the first week, and a little into the second week. Firstly, thanks to a pull request offered by my GSoC mentor John (@mohawkjohn), I now have rake tasks set up properly in the repository and rake seems to be working.
There are installation instructions in the readme and there are already some sample Kernel files in
the spec folder to try out various routines on. Apart from cloning the repository, one additional thing you will need to do is download the SPICE toolkit. You may want to keep the entire compressed file for later, but you’ll only need the
cspice.a file in the
lib/ subdirectory. After this follow the instructions in the readme and you should be good to go. (Be sure to run
bundle install to install any dependencies that you don’t already have.)
After you’re done compiling and installing, run
rake pry in the gem root directory.
If you remember, almost any useful task involving the SPICE Toolkit is preceded by loading data through kernel files. The relevant routine to do this is called
furnsh_c() , and the most direct way to access it through Ruby is by calling the function
SpiceRub::Native.furnsh. (However, this is not recommended because SpiceRub has a specific Ruby class unifying all the kernel related methods, and also because SPICE maintains its own internal variables for both tracking loaded kernel files and unloading them.)
Below is a crude dependency sequence:
1 2 3 4 5
That’s the basic design of the wrapper, so here are a few simple examples on using the Kernel API.
=> denotes the interpreted output of pry.
First of all, the main KernelPool class is a singleton class, that means it can only be instantiated with the
#instance method and the usual
#new is private.
Any subsequent calls to
#instance will produce the same object.
1 2 3 4 5 6 7 8 9 10 11 12
This is to make sure there is only one KernelPool state being maintained at a time. Now we have a bunch of kernel files in the
spec/data/kernels folder which we’ll use for this example. There is an accessor attribute called
@path which can be used to point to a particular folder.
From here on it’s required that you’re running pry or irb from the gem root folder in order for the paths to match in these examples.
Now let’s load a couple of kernel files, you can type
system("ls", kernel_pool.path) into your console to get a list of all the test kernels available in that folder. The KernelPool object has a
#load method to load kernel files. If the variable path is set, then you only need to enter the file name, otherwise the entire path needs to be provided. An integer denoting the index of the kernel in the pool is returned if the load is successful.
Note that this is the same as providing the full relative path of
spec/data/kernels/naif0011.tls when the
path variable is not set or nil.
Let’s load two more files:-
1 2 3 4 5 6 7 8 9 10 11 12 13
So now if you try to view the
@pool member of
kernel_pool, you’ll find three SpiceKernel objects with
@loaded=true and their respective file paths.
There isn’t much to do with a
SpiceKernel object except unload it, or check its state. Note that you can only load kernel files into a
KernelPool object and unload them via the
You can access the kernel pool by calling the
# operator and using the index that was returned on load:
1 2 3 4 5 6 7 8 9 10 11
So here we unload the first kernel and note that the count drops to 2. If you look up
kernel_pool, you’ll find that the kernel is still present — but its
@loaded variable has been set to false, which means that it has been removed from the CSPICE internal kernel pool.
To unload all kernels simultaneously and delete the kernel pool, use
1 2 3 4 5 6 7 8
And that about wraps up this blog post on basic kernel handling. Since we know how to load data but not use it yet, I’ll cover that and the various kernel types in the next blog post. Thank you for reading.