<<

LiU-ITN-TEK-A14/052 SE

Visualizing : Acquiring and Rendering Data of 's Hans-Christian Helltegen

2014-12-18

Department of Science and Technology Institutionen för teknik och naturvetenskap Linköping University Linköpings universitet nedewS ,gnipökrroN 47 106-ES 47 ,gnipökrroN nedewS 106 47 gnipökrroN LiU-ITN-TEK-A14/052 SE

Visualizing Space Weather: Acquiring and Rendering Data of Earth's Magnetosphere Examensarbete utfört i Datateknik vid Tekniska högskolan vid Linköpings universitet Hans-Christian Helltegen

Handledare Alexander Bock Examinator Anders Ynnerman

Norrköping 2014-12-18 Upphovsrätt

Detta dokument hålls tillgängligt på Internet – eller dess framtida ersättare – under en längre tid från publiceringsdatum under förutsättning att inga extra- ordinära omständigheter uppstår. Tillgång till dokumentet innebär tillstånd för var och en att läsa, ladda ner, skriva ut enstaka kopior för enskilt bruk och att använda det oförändrat för ickekommersiell forskning och för undervisning. Överföring av upphovsrätten vid en senare tidpunkt kan inte upphäva detta tillstånd. All annan användning av dokumentet kräver upphovsmannens medgivande. För att garantera äktheten, säkerheten och tillgängligheten finns det lösningar av teknisk och administrativ art. Upphovsmannens ideella rätt innefattar rätt att bli nämnd som upphovsman i den omfattning som god sed kräver vid användning av dokumentet på ovan beskrivna sätt samt skydd mot att dokumentet ändras eller presenteras i sådan form eller i sådant sammanhang som är kränkande för upphovsmannens litterära eller konstnärliga anseende eller egenart. För ytterligare information om Linköping University Electronic Press se förlagets hemsida http://www.ep.liu.se/

Copyright

The publishers will keep this document online on the Internet - or its possible replacement - for a considerable time from the date of publication barring exceptional circumstances. The online availability of the document implies a permanent permission for anyone to read, to download, to print out single copies for your own use and to use it unchanged for any non-commercial research and educational purpose. Subsequent transfers of copyright cannot revoke this permission. All other uses of the document are conditional on the consent of the copyright owner. The publisher has taken technical and administrative measures to assure authenticity, security and accessibility. According to intellectual property law the author has the right to be mentioned when his/her work is accessed as described above and to be protected against infringement. For additional information about the Linköping University Electronic Press and its procedures for publication and for assurance of document integrity, please refer to its WWW home page: http://www.ep.liu.se/

© Hans-Christian Helltegen Visualizing Space Weather: Acquiring and Rendering Data of Earth’s Magnetosphere Master’s Thesis in Media Technology and Engineering

HANS-CHRISTIAN HELLTEGEN

Department of Science and Technology Media and Information Technology Linkoping¨ University Norrk¨oping, Sweden 2014 Abstract

This thesis aims to describe the work and results of an intership at NASA’s Goddard Space Flight Center and part of the OpenSpace project. The project is a collabora- tion between Link¨oping University in Norrk¨oping, the American Museum of Natural History in New York and the Community Coordinated Modeling Center at NASA out- side Washington D.C. The work done during this intership has been to research and implement visualizations for Earth’s magnetosphere based on data from scientific space weather models. An interface was developed to access and read the data sets into the OpenSpace software, where the data is be rendered using volume ray-casting and field- line tracing. The fieldlines are a major part of this thesis and every step of the way from the seed points to the rendering are presented and discussed. All of these features and functionality have been implemented in the OpenSpace software which will continue to grow towards its goal of being able to interactively visualize space in a multi-screen environment in real time. Acknowledgements

First off I would like to thank my supervisor Alexander Bock and my examinator pro- fessor Anders Ynnerman for entrusting me with this project, I really appreciate it and this have been a great experience! Also thank you Alex for your help with my thesis, your detailed feedback and notes have made the writing so much easier. Thank you Masha for doing everything in your power to help two lost Swedes find a place to live. Your generosity and kindness welcomed us in the best possible way to the US. Thanks to everyone at the CCMC for making me feel part of the gang and always being there to an- swer questions and give feedback. Without your expertise none of this would have been possible. Thank you Michael for putting up with my terrible jokes and trying to do the impossible task of education me about space. Bob, thank you for keeping us up-to-date with the general project and also making sure we’re heading the right direction.

Thank you Jeimy for being an awesome roommate and giving me the latino experience. Thank you Aleksi and Andr´es for showing me D.C. and introducing me to so many fun people. You guys made my trip so much better and really helped me discover one of the best cities I’ve ever been in. Thanks Marina for confirming every single stereotype I had about Russians and taking me to all kinds of cool places. Thanks to all the other D.C. people who made my stay great! I am definitely returning one day and hope to see you all again.

Jonas, thank you for being my partner in science. Having someone to exchange ideas and arrive in the US with was great. Finally thanks to my family and friends for all the encouragement, putting up with me being away and tolerating when I have been bad at keeping in touch.

Hans-Christian, Link¨oping November 2014 Contents

1 Introduction 1 1.1 Context ...... 1 1.2 PurposeandRequirements ...... 1 1.3 ThesisStructure ...... 2

2 Background 3 2.1 OpenSpace ...... 3 2.2 SpaceWeather ...... 3 2.3 CCMC...... 5 2.4 Kameleon...... 5 2.5 BATS-R-US...... 6 2.6 CDF...... 6 2.7 Fieldlines ...... 7 2.8 Lorentz Force ...... 9

3 Method & Implementation 10 3.1 TheData ...... 10 3.2 VolumeRendering ...... 10 3.3 Kameleon Wrapper ...... 11 3.4 FieldlineTracing ...... 12 3.5 Runge-Kutta ...... 14 3.6 MagneticFields...... 15 3.7 SeedPoints ...... 15 3.8 GeometryLines...... 16 3.9 Lorentz Force ...... 17 3.10 Billboards ...... 17

4 Results 19 4.1 VolumeRendering ...... 19 4.2 FieldlineTracing ...... 20 4.3 Fieldline Classification ...... 22

i CONTENTS

4.4 Billboards...... 23 4.5 Lorentz Force Trajectories ...... 26

5 Discussion 27 5.1 Kameleon Wrapper ...... 27 5.2 FieldlineTracing ...... 28 5.3 Billboards...... 28 5.4 SeedPoints ...... 29 5.5 Lorentz Force Trajectories ...... 29

6 Conclusion 30

Bibliography 31

ii 1

Introduction

n this chapter I briefly outline some basic information for the thesis. I explain the I context behind the thesis, i.e. how it came to be, the purpose and requirements of the work, and finally the structure of the thesis.

1.1 Context

This thesis is the result of an internship with the Community Coordinated Modeling Center (CCMC) at NASA’s Goddard Space Flight Center in USA for doing my master’s thesis as a part of the collaborative project OpenSpace. The thesis is written from a computer science perspective due to my background being engineering in media technol- ogy and computer science. The OpenSpace project began in 2012 and I am part of the third round of students sent.

1.2 Purpose and Requirements

The purpose of this thesis and work is to implement visualization schemes for the mag- netosphere while developing the core OpenSpace software. These visualization needs to:

• Run in real time. The visualizations are going to be used for exploration, so interactive speeds are a required.

• Be scientifically correct. NASA researchers are going to use it for their research.

• Be aesthetically pleasing. OpenSpace will be used for space shows at museums so the visual quality needs to be good.

The resulting application also needs to be able to run cross-platform, i.e. on Linux, Mac, and Windows, in stereoscopic 3D and on multi-channel displays, such as planetariums.

1 1.3. THESIS STRUCTURE CHAPTER 1. INTRODUCTION

1.3 Thesis Structure

In chapter 2, I explain the OpenSpace project, Space Weather, and the CCMC with their tools in depth. Then in chapter 3 of my thesis work, an overview of appropriate visualization techniques and the implementation of the selected visualization techniques are explained. In chapter 4 I showcase results from my implemented techniques and discuss how the work progressed. After that the results, techniques, and remarks are discussed in chapter 5. Finally in chapter 6 I give my thoughts on the work as a whole and give some closing words.

2 2

Background

his chapter gives some background to the thesis by explaining the OpenSpace T project and its collaborators. Necessary terms which are used later in the thesis are explain in this chapter.

2.1 OpenSpace

OpenSpace is a collaborative project between Link¨oping University (LiU), the Commu- nity Coordinated Modeling Center (CCMC) at NASA, and the Hayden Planetarium at the American Museum of Natural History (AMNH). The project aims to develop an open source software that will be able to visualize space in real time for both public outreach and scientific use. The visualizations will be generated from NASA data and needs to be scientifically correct whilst also being visually pleasing. This thesis is a part of the third round of students sent from LiU in Sweden to NASA’s Goddard Space Flight Center in Maryland, USA, to do their master’s theses as a part of the OpenSpace project. The two previous students sent were Martin T¨ornros who did a case study on visualizing space weather [1] and Victor Sand who looked into dynamic visualization of space weather using time series [2]. Screenshots of their work can be seen in figures 2.1 and 2.2. This iteration of OpenSpace aims to start developing the code which will be the foundation of the software while exploring new ways of visualizing space weather data.

2.2 Space Weather

Space weather is a phenomenon involving how the and its solar affect Earth, other and spacecraft. The strategic plan from the National Space Weather Program [3] defines space weather as:

“”Space weather” refers to conditions on the sun and in the , magnetosphere, , and thermosphere that can influence the perfor-

3 2.2. SPACE WEATHER CHAPTER 2. BACKGROUND

Figure 2.1: Visualization of a event (in orange) and solar wind (in blue) from Martin T¨ornros’s thesis [1].

mance and reliability of space-borne and ground-based technological systems and can endanger human life or health. Adverse conditions in the space environment can cause disruption of satellite operations, communications, navigation, and electric power distribution grids, leading to a variety of so- cioeconomic losses.”

There are many aspects of space weather that are interesting from a visualizing stand- point. Previous theses in the project were mainly concerned with the solar wind, flares, and coronal mass ejections (CME). This thesis, however, is focussed on visualizing Earth’s magnetic field and the magnetosphere. The magnetosphere and it’s significance in terms of space weather is explained by the National Research Council [4] as:

“Earth is immersed in the escaping ionized outer atmosphere of the Sun. This ”solar wind,” flowing against Earth’s magnetic field, shapes the near- Earth space environment. The magnetic bubble of the ”magnetosphere,” carved out by Earth’s field, shields our upper atmosphere with its ionized region, the ionosphere, from the direct effects of the solar wind.”

4 2.3. CCMC CHAPTER 2. BACKGROUND

Figure 2.2: Picture from Victor Sand’s demo of his thesis work [2] at the Hayden Plane- tarium in New York.

2.3 CCMC

The CCMC is a part of the Heliophysics Science Division at NASA’s Goddard Space Flight Center. From their website:

“The Community Coordinated Modeling Center (CCMC) is a multi-agency partnership. The CCMC provides, to the international research community, access to modern space science simulations. In addition, the CCMC supports the transition to space weather operations of modern space research models.”

Their contribution is supplying space weather data, software for accessing the data, and lending their expertise about space weather visualizing and science.

2.4 Kameleon

A big part of what the CCMC does is providing access to scientific models for space weather research and forecasting. These models are not developed by the CCMC, they are instead converted to output the data in the standardized format CDF (Common Data Format). For this conversion, and also for accessing and interpolating the data,

5 2.5. BATS-R-US CHAPTER 2. BACKGROUND

CCMC has developed a software suite called Kameleon. This software suite gives their users tools to read the output of all the space weather models that Kameleon supports.

2.5 BATS-R-US

The model used for this thesis is the BATS-R-US, which is an acronym for Block- Adaptive-Tree-Solarwind-Roe-Upwind-Scheme. The model was developed by the Center for Space Environment Modeling (CSEM) at the University of Michigan [5] and is a model of Earth’s magnetosphere. The output of the model contains several magneto- spheric variables such as atomic mass density ρ, magnetic field b, and electrical current field j, amongst others. BATS-R-US is defined as an adaptive rectangular grid in the Geocentric Solar Magnetospheric (GSM) coordinate system. As explained by C.T. Rus- sell in his article Geophysical coordinate transformations [6]: GSM has its X-axis from the Earth to the Sun. The Y-axis is defined to be perpendicular to the Earth’s magnetic dipole so that the X-Z plane contains the dipole axis. The positive Z-axis is chosen to be in the same sense as the northern magnetic pole.

2.6 CDF

CDF (Common Data Format) is, as previously mentioned, a data format developed by the Space Physics Data Facility at NASA’s Goddard Space Flight Center [7] and is the format used by Kameleon to store model output. In the CDF file data is stored as either variables or attributes (essentially metadata). Variables are scalars, vectors, or n-dimensional arrays while attributes are entries describing either the global CDF file or a single variable specifically. Part of the CDF distribution package are utility programs, called the CDF toolkit. One of these programs is called CDFedit which allows users to display the contents of a CDF file through a text interface as shown in figure 2.3.

6 2.7. FIELDLINES CHAPTER 2. BACKGROUND

Figure 2.3: CDFedit showing the variable attributes contained in a BATS-R-US output file.

2.7 Fieldlines

Much of this thesis will be centered around visualizing magnetic fields around Earth. These fields are 3-dimensional vector fields which means that each voxel in the data will have a direction and a magnitude. Vector fields are difficult to visulize but a commmonly used method is fieldlines. Fieldlines, as the name implies, are lines which represent an underlaying vector field. These lines can be placed sparsely to visualize the flow of a vector field, which is very hard to comprehend otherwise. An example of fieldlines visualizing a magnetic field is shown in 2.4. The method used for creating fieldlines is called fieldline tracing and is discussed in detail in chapter 3.4.

Fieldlines are important because it allows scientists to see advanced structures within a vector field. In the case of astrophysicists at NASA, they need fieldlines to be able to see features in the magnetic fields surrounding and planets. A concrete example of this is a structure called a magnetic flux tube which are found on the surface of the Sun and around Earth, amongst other places. On the Sun they connect or regions of high magnetic flux that causes (heated gas consisting of separated charged particles) to flow within the flux tube. When a magnetic flux tube on the Sun’s surface is filled with plasma they are called coronal loops, an example of coronal loops is seen in figure 2.5. Around Earth the magnetic flux tubes are always present but are mostly quiet, however they can get filled with plasma by a flux transfer event following the opening of a magnetic portal. This is something which can happen during geo-magnetic storms that also causes phenomena such as the northern lights. These portals open in the interface region where different types of fieldlines meet as seen in figure 2.6.

7 2.7. FIELDLINES CHAPTER 2. BACKGROUND

Figure 2.4: Iron filings showing the magnetic field around a permanent magnet and field- lines in red visualizing the same magnetic field.

Figure 2.5: Coronal loops on the surface of the Sun. Coronal loops are created by plasma flowing within a magnetic flux tube that connect sunspots or areas of high magnetic flux. Earth placed for scale. Image courtesy of NASA.

8 2.8. LORENTZ FORCE CHAPTER 2. BACKGROUND

Figure 2.6: Image showing classified fieldlines near Earth. In the so called X-point (or ”electron diffusion region”) between the blue Magnetosphere lines and the red Solar Wind lines where the green North and yellow South connected lines meet, a magnetic portal may open. When a magnetic portal opens a flux transfer event occurs and a magnetic flux tube is filled with plasma, connecting Earth’s magnetosphere with the Sun’s magnetic field. Image courtesy of NASA.

2.8 Lorentz Force

When visualizing the magnetosphere by tracing fieldlines it is as if imaginary particles are introduced that follow the magnetic field. Tracing the trajectories of real particles (i.e. protons and electrons) and how they move in Earth’s magnetosphere requires a different method that takes more into consideration than just the flow of the magnetic field. For this there is an equation called Lorentz force [8], shown in equation 2.1, which calculates a force F on a particle with the electric charge q and velocity v in the electric field E and magnetic field B.

F = q(E + v × B) (2.1) The traced trajetories of these particles allow scientists and other users to see how charged particles emitted by the Sun behave in Earth’s magnetosphere and can lead to a greater understanding of the interaction between Earth and the Sun.

9 3

Method & Implementation

his part of the thesis will be used for explaining the method, implementation, and T approach taken for the thesis work. The work will be explained in chronological order so the reader can see how the work progressed and the thought process behind it.

3.1 The Data

David Sibeck 112707 13d ful 1 t00002110 n0028227.out.cdf is the data set used for this thesis. The data set is a single time step outputted by the BATS-R-US model for 1 the global magnetosphere. The domain of the model run is x = [−255, 33]Re , y = [−48, 48]Re, and z = [−48, 48]Re and consists of 20323440 blocks with variable val- ues. The rectangular blocks are arranged in varying degrees of spatial levels with the smaller blocks located closer to Earth. The range of the spatial level for a block is ∆ = [0.00625, 4.00000]Re.

3.2 Volume Rendering

The first thesis work done was implementing support for basic volume rendering using OpenGL and GLSL. Volume rendering is the practice of creating 2D images from 3D volumetric data sets and is commonly used in scientific visualization. The volume ren- dering technique chosen in this case was volume ray casting. Volume ray casting is an -based volume rendering technique which means that it iterates over pixels in the resulting image rather than over objects in the scene. This makes it very easy to use in conjunction with shaders on the GPU (which are also run per pixel) and this boosts performance massively compared to if it would have been run on the CPU. The ray casting algorithm by itself is straightforward. For every pixel in the resulting image:

1 1 Re = 6371 km ( mean radius)

10 3.3. KAMELEON WRAPPER CHAPTER 3. METHOD & IMPLEMENTATION

1. Cast a ray from the camera into the volume

2. Sample the volumetric data set along the ray

3. Composite the sampled values for the resulting pixel color

The concept behind volume ray casting can also be seen illustrated in figure 3.1. The ray caster was, as previously mentioned, implemented with OpenGL and GLSL as the class RenderableVolumeGL in OpenSpace. The functionality was implemented in a generic way which would allow any volumetric data set to be rendered and visualized.

Figure 3.1: The volume ray casting concept. Rays are sent from the camera, through the image plane and then into the volume. Each ray is then sampled, the sampled values composited, and the resulting value is used as the pixels color. Illustration from [2].

3.3 Kameleon Wrapper

With the volume rendering capability implemented in OpenSpace, data was now needed for visualization. This meant it was time to start using Kameleon and the CDF-file men- tioned previously. To keep modularity high, an interface and wrapper class, Kameleon- Wrapper, was implemented. The interface provided by Kameleon gives the user func- tionality to get a single attribute or a interpolated variable value at any point within the bounds of the CDF-file. This is great for handling the data and for doing calculations but not the optimal interface for rendering since it is a time-consuming operation.

11 3.4. FIELDLINE TRACING CHAPTER 3. METHOD & IMPLEMENTATION

This meant that the first functionality implemented in the Kameleon wrapper was the ability to generate a uniformly sampled volumetric data set for a given scalar variable and desired data dimensions. To achieve a uniform sampling a simple step size is calculated for each axis as seen in equation 3.1, where xmax and xmin are the actual min and actual max variable attributes for the x variable in the CDF file and OutDimx is the desired x-resolution of the resulting data set. The sampled data set could then easily be used directly by the RenderableVolumeGL class implemented earlier.

(xmax − xmin) Stepx = (3.1) OutDimx

Figure 3.2: Diagram showing the simplified interaction between the RenderableVolumeGL and KameleonWrapper classes, and how Kameleon is used by the KameleonWrapper. The interpolate function is called from KameleonWrapper for every voxel in the resulting data set.

One thing to consider when working with scientific model runs through Kameleon is that there are many different coordinate systems depending on which model and settings are used for the run. For example, the ENLIL model is defined in spherical coordinates {r,θ,ϕ} while the BATS-R-US model is in the cartesian coordinate system GSM as explained in 2.5. These coordinate systems need to be transformed to the standard right-handed coordinate system often used in computer graphics before being used in OpenSpace.

3.4 Fieldline Tracing

After the Kameleon wrapper was implemented and volumetric scalar variables being able to be visualized, it was time to tackle the harder task of visualizing volumetric vector values, also knows as vector fields. One common way of visualizing vector fields is by tracing and drawing fieldlines (as explained in chapter 2.7), which consists of placing an

12 3.4. FIELDLINE TRACING CHAPTER 3. METHOD & IMPLEMENTATION imaginary particle in the field and tracing it’s path following the vector field. This is done by starting at a given point (called a seed point), sampling the vector field, calculating a direction, stepping along the calculated direction and then saving the new point it arrives at. This is then repeated until a stop condition is met. The stop conditions in this case is if the fieldline goes out of the bounds mentioned in section 3.1, inside Earth or if a maximum number of steps have been taken. An illustration of a fieldline tracing is seen in figure 3.3.

Figure 3.3: Illustration showing a fieldline tracing of a vector field. Each black arrow is a cell in a vector field with a direction and magnitude. The red point is the seed point which results in the red-dotted fieldline.

To do the stepping, a numerical method for calculating the direction is needed. The first method used for this was Euler method [9] seen in equation 3.2 where pn is the current point, h is the step size, f~(pn) is the vector field direction at the current point and pn+1 is the new point. The Euler method is a very basic first order method for numerical integration, it was only used during early testing due to it being quick to implement but inaccurate. A first order method means that only one step is taken per point, which means that the local error (error per step) is proportional to the square of the step size. This means that the local error will increase very quickly as seen in figure 3.4.

pn+1 = pn + h · f~(pn) (3.2)

13 3.5. RUNGE-KUTTA CHAPTER 3. METHOD & IMPLEMENTATION

Figure 3.4: Image of an Euler method approximation (in red) of a curve (in blue). For every point An the slope of the curve is used together with a step size to create the next point, An+1. With the Euler method the error always increase for every point, a smaller step size only affects how fast it increases.

3.5 Runge-Kutta

Although the Euler method did produce some interesting results, a better and more accurate method for calculation the direction by numerical integration was needed. The method chosen for this was the 4th order Runge-Kutta method [9][10] as shown in equa- tion 3.3. This method works by calculating four increments k1, k2, k3, k4 and then combining them as a weighted average with the step size h and added to the current point pn to get the next point pn+1. The four increments are the directions sampled h h from the vector field data at the points pn, pn + 2 k1, pn + 2 k2, and pn +hk3 respectively.

h pn+1 = pn + 6 (k1 + 2k2 + 2k3 + k4)

k1 = f~(pn) ~ h k2 = f(pn + 2 k1) (3.3) ~ h k3 = f(pn + 2 k2)

k4 = f~(pn + hk3) The method was implemented in the fieldline tracer function in the KameleonWrapper class. Comparisons between the Euler method and the Runge-Kutta 4th order is seen in figures 4.3 and 4.4, and discussed in section 5.2.

14 3.6. MAGNETIC FIELDS CHAPTER 3. METHOD & IMPLEMENTATION

3.6 Magnetic Fields

The data from the BATS-R-US model describes Earth’s magnetosphere i.e. the magnetic field around Earth that protects us from the Sun. When visualizing magnetic fields, there are certain characteristics and traits that can be useful to highlight and consider. It is known that all magnetic fields are related to the two poles (the north and south pole in this case) and that there are two major types of fieldlines: open and closed. An open fieldline means that one end of the fieldline is attached to a pole and the other end isn’t connected to anything while a closed fieldline is connected to both poles. By keeping track of the end-points while tracing the fieldlines they can easily be classified as either open or closed. Another classification for magnetospheric fieldlines, which was suggested by Dr. Lutz Rastaetter at CCMC, is to classify each fieldline into one of four categories:

• Open south. Only connected to the south pole

• Open north. Only connected to the north pole

• Closed. Connected to both poles

• Solar wind. Not connected to any pole

The classified fieldline is then mapped to a color corresponding to the type. This is the main classification which will be used during this thesis.

3.7 Seed Points

Although the numerical tracing method is important to obtain good results, the most important part when tracing fieldlines are the seed points. The difference between field- lines traced with arbitrary placed and expertly placed seed points can be significant. Often times the fieldlines traced with arbitrary placed seed points can completely miss certain interesting features while the more expertly placed seed points can give the user an entirely different view and understanding of the underlaying vector field. Placing seed points in a calculated and expertly way, however, can be very difficult and have been a problem within scientific visualization for a long time.

Calculating where to put seed points optimally requires knowledge about the data and also the desired features to be visualized. In the case of this thesis and its work, it is known that the data is about the magnetic field around Earth and that there are certain interesting features such as magnetic flux tubes in the so called X-points mentioned in section 2.7 and seen in figure 2.6. Dr. Asher Pembroke at the CCMC at NASA’s Goddard Space Flight Center used this knowledge to create an algorithm for optimally placing seed points to be able to visualize these interesting and otherwise hard to see features.

15 3.8. GEOMETRY LINES CHAPTER 3. METHOD & IMPLEMENTATION

Pembroke’s seed point placing algorithm is an iterative approach which uses the results of previous fieldline traces to determine where to place the seed points for the next iteration. First a small number of initial traces are chosen such that at least three different types of fieldlines are present (out of the 4 types mentioned in 3.6). Then, these traces are sampled with the local resolution in the model and the sampled positions and placed into a 3D Delaunay triangulation [11]. For each of the resulting tetrahedra, it is then identified which of those have 1) more than two topology types among the 4 vertices and 2) are larger than the local resolution times a factor. The centroid of those tetrahedra are then used as the seed points for the next iteration of fieldline traces. The result of this algorithm is seed points which traces fieldlines that goes through the X- points and shows the magnetic flux tube structure. Visualizations using this Pembroke’s algorithm is seen in figure 4.8.

3.8 Geometry Lines

With the lines traced and classified, the only thing remaining is to draw them to the screen as geometry. To render the lines, the data needs to be formatted in a way so that OpenGL can draw them as one GL LINE STRIP per fieldline. The easy but inefficient way of doing it is storing each fieldline as a seperate vertex arrays and drawing them one at a time using glDrawArrays. This will, however, result in one glDrawArrays call per fieldline per frame which is not optimal. A more optimal approach is storing all vertices for all fieldlines in one array, have another array for the starting indicies, a third array for the number of indicies per line, and then using glMultiDrawArrays. This will draw all of the fieldlines with only one OpenGL call per frame which is faster and more efficient. An example of the data structure can be seen in figure 3.5.

Figure 3.5: Illustration showing the data structures needed for OpenGL’s glMultiDrawAr- rays call. The colors red, green, and blue represent three fieldlines and the data associated with them. ”Line start” specifies where in the line point array each fieldline start and ”Line count” is the number of verticies per fieldline. Each element in the line points array contain the vertex position {x, y, z} and color {r, g, b, a}.

16 3.9. LORENTZ FORCE CHAPTER 3. METHOD & IMPLEMENTATION

3.9 Lorentz Force

With the Kameleon wrapper, fieldline tracing, Runge-Kutta, and geometry line rendering implemented, OpenSpace could visualize any vector variable in the CDF file as fieldlines. The variables, however, does not by themselves show how a charged particle would behave if it got close to earth. For this we use the Lorentz Force equation discussed in 2.8 with the initial v0 set to the solar wind velocity sampled at the seed point in the CDF-file.

The equation is solved using the Runge-Kutta-Nystr¨om method [12] with some sim- plifications. The increments k1, k2, k3, k4 are normalized so that only the direction is taken into consideration, i.e. the magnitude is not considered. This means that the numerical value of q and m in F = ma doesn’t have to be considered (since they are constant), only the sign of q which decides if it’s a proton or an electron. The trajecto- ries of these particles will loop around the magnetic fieldlines in a circular motion while drifting in the same direction. The functionality for tracing Lorentz force trajectories was implemented in the KameleonWrapper class.

3.10 Billboards

Although drawing field-lines and Lorentz force trajectories as GL LINE STRIP is effi- cient and correct, it does leave something to be desired when it comes to visual quality. The main issue is that lines in OpenGL are drawn with a certain width which is defined in screen pixels. This means that the depth and perception of a line is lost and the width of a line changes with the resolution of the viewport. A better representation for the lines is to construct triangle geometry around the line which will instead have a width which is relative to the rest of the scene and not the viewport. This can be done during run-time on the GPU by using a geometry shader which will take a segment of a GL LINE STRIP as input and output a number of triangles.

Instead of drawing a high number of triangles around each line to represent a cylinder it is possible to use a method called billboarding. Billboarding means that for each line a textured quad is drawn and aligned towards the camera. This creates the illusion of being 3-dimensional while simply being a 2D image which is significantly more efficient than generating and rendering true 3D geometry using many triangles. A problem with using billboards in this particular case is that there will be overlap and gaps between two adjacent billboards as is illustrated in figure 3.6a. To avoid this problem a chamfer needs to be calculated using information from the adjecent lines. For this there is the GL LINE STRIP ADJACENCY primitive which sends information about current and adjacent vertices to the geometry shader as opposed to using GL LINE STRIP that only sends vertices for the current line segment.

17 3.10. BILLBOARDS CHAPTER 3. METHOD & IMPLEMENTATION

(a) Billboards without adjancency informa- tion. (b) Chamfered billboards.

Figure 3.6: Illustrations showing billboards generated using a geometry shader with orig- inal line and vertices in red and generated geometry in black. Figure 3.6a doesn’t use any information from the adjacenct vertices which causes the resulting billboards to overlap and have gaps. Figure 3.6b illustrates how the billboards look after calculating a chamfer using

the adjacent vertices p0, p3 to calculate the normals Np1 and Np1 using equation 3.4.

Figure 3.6b illustrates how the chamfered billboards are drawn using adjacency infor- mation. The points p1, p2 are part of the current line segment and the points p0, p3 are the two adjacent vertices. In equation 3.4 two vectors u and v are calculated as p2 − p1 and p3 − p1 respectively and are used together with the camera view direction

VC to calculate the normals Np1 and Np1 for the chamfered new vertices while keeping the resulting quad aligned towards the camera.

u = p2 − p1

v = p3 − p1 (3.4) Np1 = VC × u

Np2 = VC × v For texturing the billboard it is possible to simply use a interpolated normal in the fragment shader and use it to calculate a color instead of using an actual texture. This is done in the geometry shader by passing a normal perpendicular to and pointing away from the original line for each new vertex. These normals will then be interpolated to a fragment normal in the fragment shader and the length of the interpolated normal will correspond to how close the fragment is to the original line. This means that the length of the fragment normal can be used to adjust the final fragment color giving the billboard a smooth gradient and adding to the illusion of it being a 3-dimensional tube.

18 4

Results

n this part of the thesis the results of the thesis work is displayed. The figures will I showcase results of the work explained in chapter 3. All figures in this chapter are screen shots taken of an interactive 3D scene rendered by OpenSpace in real time.

4.1 Volume Rendering

Figure 4.1: The scalar variable ρ (atomic mass density) from a BATS-R-US model output file visualized with the volume ray caster. The box for within the ray casting is done had to be scaled in x since the x-axis is roughly three times the size as the y- and z-axis, as mentioned in section 3.1.

19 4.2. FIELDLINE TRACING CHAPTER 4. RESULTS

4.2 Fieldline Tracing

Figure 4.2: Magnetic field-lines traced with 4th order Runge-Kutta scheme visualized with geometry as described in section 3.8. A sphere textured as Earth is placed at the correct position and scale relative to the field-lines.

20 4.2. FIELDLINE TRACING CHAPTER 4. RESULTS

Figure 4.3: Comparison between 4th order Runge-Kutta (RK4) and Euler method. The green line is traced with Euler method with a step size h = 10∆ (∆ is the local resolution of the last sampled block in the model) and the blue line is traced with RK4 and the same step size h. The red line is an oversampled reference traced with RK4 and h = ∆. In the model run used for this visualization ∆ = [0.00625, 4.00000]Re which is the range of the spatial level mentioned in 3.1.

Figure 4.4: Close up of a field-line traced with Euler (green) and one traced with RK4 (red), both with the same step size h = ∆. Even at such a small step size the Euler method misses the vortex which is part of a magnetic flux tube.

21 4.3. FIELDLINE CLASSIFICATION CHAPTER 4. RESULTS

4.3 Fieldline Classification

(a) Seedpoints around Earth

(b) Seedpoints in line through earth

Figure 4.5: Two sets of field-lines colored with the classification described in section 3.6. Figure 4.5a shows seedpoints distributed at uniform distances around Earth and the picture taken from the side. Figure 4.5b shows seedpoints (shown as pink points) placed along a line going through Earth. Notice how some of the lines, especially the blue, turn straight further away from Earth. This is because the magnetic force gets very weak and the lines start to follow the solar wind.

22 4.4. BILLBOARDS CHAPTER 4. RESULTS

4.4 Billboards

Figure 4.6: Classified fieldlines visualized with billboards as described in section 3.10. With the billboards it is now possible to see some depth and perspective when the fieldlines gets further away from the camera.

23 4.4. BILLBOARDS CHAPTER 4. RESULTS

(a) From the front

(b) Inside the magnetosphere

Figure 4.7: Fieldlines traced around Earth and visualized with billboards shown from the front in figure 4.7a and from inside the magnetosphere in figure 4.7b.

24 4.4. BILLBOARDS CHAPTER 4. RESULTS

(a) From the front

(b) Inside

(c) From the side

Figure 4.8: Three angles showing classified fieldlines produced by the seed points created with the iterative seed point placement method developed by Dr. Asher Pembroke at CCMC as can be read in section 3.7. Note the flux tube consisting of fieldlines of all classifications that bundle together in a tube-like structure on the boundary between the different types of fieldlines as dicussed in section 2.7. 25 4.5. LORENTZ FORCE TRAJECTORIES CHAPTER 4. RESULTS

4.5 Lorentz Force Trajectories

Figure 4.9: Lorentz force trajectories visualized with billboards near Earth. Trajectories of positive particles (protons) are shown in pink and negative particles (electrons) in cyan.

26 5

Discussion

his section will be used to discuss the results seen in chapter 4 and how it could T be improved by future work on the OpenSpace project.

5.1 Kameleon Wrapper

The KameleonWrapper-class successfully provides an interface for generating volumetric and line data sets from a CDF-file. This decreases coupling between the Kameleon library and the rest of the OpenSpace code base which allows them to work together without being dependant on each other. However, this means that the name KameleonWrapper is misleading since it doesn’t wrap the functionaliy in Kameleon, i.e. providing the same interface though an abstract layer. Instead it uses the Kameleon functionality to construct a new interface which makes more sense for visualization purposes. The class should be renamed to reflect this.

The KameleonWrapper-class is also starting to become quite big and will only continue to grow as more kinds of data sets and options are implemented. This means that the class should be split into multiple classes to be better prepared for expanding in the future. Also the building of data sets and reading through Kameleon is all made on a single thread. By examining the Kameleon library code further it could be determined if either the functionality is already thread-safe or how much work would be needed to make it thread-safe and then contribute to the Kameleon development in collaboration with the CCMC. This could potentially speed up the processing time for building the datasets and accessing the CDF files.

27 5.2. FIELDLINE TRACING CHAPTER 5. DISCUSSION

5.2 Fieldline Tracing

All figures in sections 4.2 have been traced with the field-line tracer implemented in KameleonWrapper on the magnetic field variables bx,by,bz from a BATS-R-US model run. The figures 4.3 and 4.4 the differences in quality between the Euler method and the 4th order Runge-Kutta for the numerical stepping. In figure 4.3 the green line is traced with Euler method and step size h = 10∆ (∆ is the local resolution of the last sampled block in the model run), the blue line is sampled with RK4 and the same step size h = 10∆, and the red line is a tightly sampled reference traced with RK4 and h = ∆. The possible values for ∆ are the spatial level range mentioned in 3.1. We see that the green line traced with Euler might be reasonably close to the red reference line from a distance but looks very crude up close and might even miss features such as the vortices a magnetic flux tube consists of. As suspected and evident from the blue line, RK4 produces a very good estimate even at higher step sizes. Figure 4.4 shows a close up of two lines both traced with the small step size h = ∆, green line traced with Euler and the red line with RK4. Here we see that even at a small step size the Euler method can completely miss more advanced and interesting structures such as part of a flux tube which the red line correctly traces. The significant increase in quality and correctness naturally comes with a cost in performance. The Euler method is 4 times faster than RK4 since RK4 in essence takes 4 Euler steps for each step. This means Euler can produce decent results for more simple tracings at much higher speeds, which makes it more suitable for real time tracing. Adding support for real time tracing and visualizations in OpenSpace could be an extension to the work presented in this thesis.

The figures 4.5a and 4.5b show two sets of field-lines rendered with the classification described in chapter 3.6. Figure 4.5a is traced with seed points placed uniformly in a cube around earth and picture taken from the −z side and figure 4.5b is traced with seed points in a line along the x-axis going through earth. The classification gives the user a clear distinction between the different types of field-lines and even with arbitrary placed seed points we can see characteristics such as the open field-lines bundling into two separate tube-like structures.

5.3 Billboards

Most of the focus during this thesis work has been on getting scientifically accurate representations, being able to visualize interesting features and proper classification of features. Some work, however, was done purely for the sake of increasing the visual quality. This work was the implementation of visualizing lines as billboards, as described in section 3.10. Figures 4.6 and 4.7 show two sets of fieldlines visualized with billboards. The advantage over using billboards instead of GL LINES is that the width of a line is now relative to the scene, not the viewport which means that some perspective and depth can be seen. The lines also appear smoother and less aliased than before, all of which contributes to higher visual quality. The downsides of using billboards is the natural

28 5.4. SEED POINTS CHAPTER 5. DISCUSSION trade-off between computation time and visual quality but also that the billboards can look crude up close. A possible solution for this would be to have a dynamic level of detail which would set the size of the billboards relative to the distance to the camera. Another way of increasing the visual quality up close is to place two billboards perpendicular to each other at every line segment. This increases the 3-dimensional illusion when up close but does next to nothing when further away and requires twice the geometry compared to using one billboard per line.

5.4 Seed Points

Although arbitrarily placed seed points can give us a good general idea of how the magnetic field around Earth behaves, other more specific features are usually lost. These features are often the more interesting parts and visualizing them is a bit trickier. One of these interesting features is the magnetic flux tube, explained in section 2.7, which is found in the boundary region between the different types of field-lines. The magnetic flux tube is shown in figures 4.8a, 4.8b, and 4.8c. These fieldlines are traced with the seed points created by the method described in section 3.7 and visualized as billboards. Using these specialized seed points helps us understand features which we weren’t able to see before. These seed points, however, are created by a standalone experimental method which isn’t integrated with OpenSpace as of writing. The seed points are stored in a separate file after generating and is then read into OpenSpace at start up and traced. This is not very flexible and if the method will be used further then it should be implemented natively in OpenSpace or as a submodule.

5.5 Lorentz Force Trajectories

The Lorentz force trajectories shown in figure 4.9 have been traced with the method described in 3.9 and the functionality for tracing these trajectories is implemented in the KameleonWrapper. These trajectories show the path of electrons (in cyan) and protons (in pink) emitted from the Sun as they are being affected by the magnetic and current field in Earth’s magnetosphere. The decision to set the initial particle velocity v0 to the sampled solar wind velocity at the seed point caused some discussion with the NASA researchers who thought it was an interesting approach. This visualization can be used to get a sense of how actual charged particles behave when entering Earth’s magnetosphere.

29 6

Conclusion

he results and discussion presented in this thesis show how fieldlines can be used T to visualize Earth’s magnetic field and its interesting features. These results have been implemented in the OpenSpace project which will continue to be developed in the future by new theses works. These future theses will be build upon and be depen- dent on the work presented in this thesis, particularly the KameleonWrapper interface to CCMC’s Kameleon framework to read space weather data and construct data sets. The interface provided in KameleonWrapper together with having the Kameleon frame- work in its own sub module enables OpenSpace to grow and be developed side-by-side with Kameleon without either being directly dependent on each other. This paper also highlights the importance in intelligent seedpoint placement and show how much more interesting information and features can be seen when using an algorithm such as the one presented in section 3.7. The results also show the big difference between the two numerical integration methods Euler and 4th order Runge-Kutta, where Runge-Kutta vastly outperforms Euler albeit being more computationally expensive. The functional- ity to trace and render Lorentz force trajectories for protons and electrons give insight into how actual particles emitted from the Sun behave whilst being in Earth’s magne- tosphere. This is useful for understanding the interaction between the Sun and Earth but also in general between a and its surrounding planets. As the work on this the- sis progressed, NASA scientists at CCMC has continually been part of the process and providing both feedback and knowledge about space weather and the magnetosphere. Often as the development progressed the results were hard to understand correctly and the expertise provided by the CCMC was a great help in understanding the data and results. The Hayden Planetarium at AMNH has also been part of the development and providing suggestions and feedback from their standpoint in wanting to use OpenSpace as a tool for visualizing NASA data and space to the public. The continuation of this col- laboration between the three stakeholders provides the project a very broad perspective and knowledge which is essential for the future growth of OpenSpace.

30 Bibliography

[1] M. T¨ornros, Interactive visualization of space weather data, Master’s thesis, Link¨oping University (jun 2013).

[2] V. Sand, Dynamic visualization of space weather data, Master’s thesis, Link¨oping University (feb 2014).

[3] The National Space Weather Program, Strategic plan, FCM-P30-1995.

[4] Space Weather:A Research Perspective, The National Academies Press, 1997. URL http://www.nap.edu/openbook.php?record_id=12272

[5] CSEM and CRASH team, BATS-R-US and CRASH User Manual, University of Michigan, version 9.10 (oct 2011).

[6] C. T. Russell, Geophysical coordinate transformations, Cosmic Electrodynamics (1971) 184–196.

[7] Space Physics Data Facility, CDF User’s Guide, NASA Goddard Space Flight Cen- ter, version 3.4 (feb 2012).

[8] D. J. Griffiths, Introduction to Electrodynamics (3rd Edition), Benjamin Cum- mings, 1998.

[9] J. C. Butcher, The Numerical Analysis of Ordinary Differential Equations: Runge- Kutta and General Linear Methods, Wiley-Interscience, New York, NY, USA, 1987.

[10] K. I. Joy, Numerical methods for particle tracing in vector fields (mar 2007). URL http://graphics.cs.ucdavis.edu/~joy/ecs277/

[11] P. Maur, Delaunay triangulation in 3d, Tech. Rep. DCSE/TR-2002-02, University of West Bohemia in Pilsen (2002).

[12] I. Mandre, Non-relativistic charged particle motion in the electric and magnetic fields using the runge-kutta-nystr¨om method (sep 2007). URL http://www.mare.ee/indrek/ephi/nystrom.pdf

31