Drawing

BFIELD module: familiarization

This page is intended to familiarized with the
BFIELD module of the gPemPy suite of codes.

First, make sure you unzipped the gPemPy.zip files somewhere on your computer and that you are working on the same directory (or alternatively, that you add the .py modules to your Python PATH).

Then on a Terminal in your working directory and within a Python 2.7 environment, you should be able to run the BFIELD module functions if healpy is installed on your desktop.

In [1]:
#to produce inline images
%pylab inline

#imports
import BFIELD as bf
import GalaxyBasics as gb
Populating the interactive namespace from numpy and matplotlib

Now, you have all the required tools to build interesting Galactic Magnetic field (GMF) models on the Galaxy. We shall start with some visualization of GMF models presented in the literature.

Convenient functions are implemented in the BFIELD module to visualize the various models in different cross-cut of the Galaxy.
In a friendly user scheme, the GMF models are referred with their names. They are python dictionary where the key is simply the name of the GMF model and the value is another dictionary used to initialize the many parameters and variables of the models. They are structured as follow:

{'GMF_name':{'GMF_parameter_names':GMF_parameters_values}}

First, the GMF model presented in Jaffe et al. (2010, 2013) is a composite model with logarithmic spiral arm patterns and a ring component in the inner Galactic space. This parameterization is not intended to model the very central part of the Galaxy where the field is set to zero.
Below, we first visualize that model in the (x,y)-plane and then in the (x,z)-plane.
The default values of the model parameter (see below) are assumed here. It is therefore not necessary to specify them. Indeed, the visualization functions make use of the dictionary-like approach which set to default values all the parameters that are not otherwise specified.

In [2]:
#the (x,y) cross-cut
bf.plot_galactic_Bfield_xy_slice({'JAFFE':{}})

#the (x,z) cross-cut
bf.plot_galactic_Bfield_xz_slice({'JAFFE':{}})
        JAFFE B field model has been computed with DEFAULT parameter values

    >>> Field amplitude has been computed with a
        0.05 [kpc] grid-spacing

        JAFFE B field model has been computed with DEFAULT parameter values
    >>> Field lines have been computed with a
        0.25 [kpc] grid-spacing using streamplot

        JAFFE B field model has been computed with DEFAULT parameter values

        JAFFE B field model has been computed with DEFAULT parameter values

Above we have not specify anything and just let the python functions work by themselves. Color scales indicate the norm of the three-dimensional magnetic field vectors (so, the amplitude of the field) and the pink lines indicate the Galactic magnetic field lines (projected on the plane of interest). From the streamline arrows on the first plot, we can see that the the magnetic field is either clockwise or counter-clockwise in the (x,y)-plane. As can be seen on the second plot, the field lines of the Jaffe et al. model are parallel to the Galactic plane.

It is possible to change easily the range of the color value with the keyed argument crange=[vmin,vmax]. It is also possible to assess negative amplitude for vectors that are oriented conter-clokwise in the (x,y)-plane thanks to the keyed argument directional=True.

In [3]:
#the (x,y) cross-cut. Same as above but with determined color range
bf.plot_galactic_Bfield_xy_slice({'JAFFE':{}},crange=[-1.5,1.5],directional=True)
        JAFFE B field model has been computed with DEFAULT parameter values

    >>> Field amplitude has been computed with a
        0.05 [kpc] grid-spacing

        JAFFE B field model has been computed with DEFAULT parameter values
    >>> Field lines have been computed with a
        0.25 [kpc] grid-spacing using streamplot

To see the different functionalities of the visualization functions, we invite you to read the documentation accessible from the Terminal through the help() function as:

In [1]:
#help(bf.plot_galactic_Bfield_xy_slice)
#help(bf.plot_galactic_Bfield_xy_slice)
#help(bf.plot_sky_projection)

It is possible to change the resolution of the grid, the position of the Sun and so on.

GMF models

Within the BFIELD modules we tried to implement as many models as possible allowing for a pretty large variety of geometrical configurations for the GMF.
Using the dictionary approach, all the parameter variables are set to their default values. The default initialization can be obtained with the following:

bf.getBFieldDefault('JAFFE')

This allows the user to have an example of a complet initilization of the GMF. Notice that calling the above function without specifying the name of the GMF model will list all the default initializations of all the implemented models. Try:

bf.getBFieldDefault()

This gives you the list of all the implemented models. As we shall see below, this function can also be used to return the dictionary corresponding to the model if the keyed arguments output is set to True. That dictionary can then be used for other purpose.

In [4]:
#BiSymmetricSpiral model
bss = bf.getBFieldDefault('BSS',output=True)
{
	'BSS': {
		'Xi_0': 0.4363323129985824,
		'z_0': 1.0,
		'B_amp_param': 8.0,
		'rho_0': 8.0,
		'B_amp_type': 'cyl',
		'pitch': 0.2007128639793479,
		'B_0': 2.1,
		'coord_format': 'cartesian'
	}
}
In [5]:
bf.plot_galactic_Bfield_xy_slice(bss,directional=True,crange=[-4.,4.])
    >>> Field amplitude has been computed with a
        0.05 [kpc] grid-spacing
    >>> Field lines have been computed with a
        0.25 [kpc] grid-spacing using streamplot

As you can see, the BSS model produces magnetic field that goes inwards or outwards given that the vectors, projected on the (x,y)-plane, point clockwise or counter-clockwise, resp.

Now, given the dirctionary-like approach, you can decide to change some of the parameter values of the model that you are visualizing. For the BSS, we can even decide to change one of the functional form (help(bf.BSS) for more info). Indeed, we can change the amplitude modulation of the field from a cylindrical-radial dependence to a spherical-radial dependence as:

In [6]:
bss['BSS']['B_amp_type'] = 'sph'
bf.plot_galactic_Bfield_xy_slice(bss,directional=True,crange=[-4.,4.])
    >>> Field amplitude has been computed with a
        0.05 [kpc] grid-spacing
    >>> Field lines have been computed with a
        0.25 [kpc] grid-spacing using streamplot

There is no difference in this view (as expected as we are in the plane $z=0$). Now, lets produce the sky-map corresponding to the line of sight integration of the GMF amplitude and compare the two variantes discussed above.

In [7]:
#default: cylindircal dep.
bf.plot_sky_projection({'BSS':{}},crange=[10.,45.])
plt.title(r'Integrated field amplitude -- default')
#spherical dep.
bf.plot_sky_projection({'BSS':{'B_amp_type':'sph'}},crange=[10.,45.])
plt.title(r'Integrated field amplitude -- spherical')
    The Galaxy Template has been built with:
        NSIDE =  64 
        radial_step =  0.2 kpc
        radial_max =  20.0 kpc

    The Galactic space is thus populated by 4915200 points
    distributed spherically around the Sun.
    
    Dot products between basis vectors have been computed

        BSS B field model has been computed with DEFAULT parameter values

    The Galaxy Template has been built with:
        NSIDE =  64 
        radial_step =  0.2 kpc
        radial_max =  20.0 kpc

    The Galactic space is thus populated by 4915200 points
    distributed spherically around the Sun.
    
    Dot products between basis vectors have been computed
Out[7]:
<matplotlib.text.Text at 0x10e4207d0>

Even if the amplitude of the Galactic magnetic field is NOT a direct observable, it is not difficule to guess that these two variantes will produce different observables when combined with some Galactic matter density field.

Notes

In the way we use the functions above, a lot of things are recomputed at each call. For instance, the Galactic template that samples our Galaxy is recomputed each time. For the sky projection, all locations are converted in the observer reference frame and the Galactocentric reference frame. All the dotproducts between basis vectors are re-evaluated in order to project the B field vectors from one to the other reference frame, if required (not here). etc., etc.
This is obviously not optimal even if the computing time is not excessive (few secondes).

It is obviously possible to handle GMF differently and to avoid to reprocess all these quantities each time.

  • The function BFielder() convert any dictionary-like GMF calls to vectorial components in cylindrical coordinates centered on the Galactic centre: $({B}_{\rho},\, {B}_z,\, {B}_{\phi})$. This function requires as an entry the Galactic coordinates at which the GMF has to be evaluates.
  • The functions field_name(XYZ) will return the same results as BFielder(XYZ,'field_name') does except that you do not make use of the dictionary-like approach to handle the field. It runs a little bite faster.

For example, the two vector fields created below are expected to be exactly equivalent.

In [8]:
# creat the Galactic template, ie cartesian coordinates
# centered on the observer, on the Galactic centre and
# the dotproducts between the basic vectors (if useful)
_,XYZ_gal,dotproducts = gb.GalacticTemplate()

bss_1 = bf.BSS(XYZ_gal)

bss_2 = bf.BFielder(XYZ_gal,{'BSS':{}})

diff_12 = np.abs(bss_1 - bss_2)
diff_12.max()
    The Galaxy Template has been built with:
        NSIDE =  64 
        radial_step =  0.2 kpc
        radial_max =  20.0 kpc

    The Galactic space is thus populated by 4915200 points
    distributed spherically around the Sun.
    
    Dot products between basis vectors have been computed

        BSS B field model has been computed with DEFAULT parameter values
Out[8]:
0.0

Notes 2

We strongly invite the interested reader to take note of all the implemented functions available in the BFIELD module. This is

  1. to have an overview of the different possibilities for the GMF structure
  2. to have an overview of the different functions that allows to handle easily the vector field in the context of diffuse emission modelization. Indeed, they are convenient functions that are dedicated to the computation of the various angles and norms required for the modelization of the diffuse polarized Galactic emissions, i.e. the synchrotron emission and the thermal dust emission.
In [9]:
dir(bf)
Out[9]:
['ARM4',
 'ASS',
 'BFielder',
 'BSS',
 'BT',
 'B_Regular',
 'CCR',
 'COMPO',
 'JAFFE',
 'LSA',
 'MLS',
 'OneParamFunc',
 'RING',
 'WMAP',
 '__B0_of_r',
 '__builtins__',
 '__doc__',
 '__file__',
 '__gal2sun_vector',
 '__get_AlphaGamma',
 '__get_AlphaGammaBtrans2',
 '__get_AlphaGammaBtrans2_fromGal',
 '__get_AlphaGamma_fromGal',
 '__get_Btransverse2_fromGal',
 '__get_cylindrical_coord',
 '__name__',
 '__package__',
 'deg2rad',
 'gb',
 'getBFieldDefault',
 'np',
 'pi',
 'plot_galactic_Bfield_xy_slice',
 'plot_galactic_Bfield_xz_slice',
 'plot_sky_projection']
Have fun and try the following
In [ ]:
bf.plot_galactic_Bfield_xz_slice({'COMPO':{'ASS':{'B_0':.7,
                                                  'B_amp_type':'sph'},
                                           'BT':{'B_0':0}}})
In [ ]:
bf.plot_galactic_Bfield_xy_slice({'COMPO':{'ARM4':{'rho_min':5.},
                                           'RING':{'B_0':1.},
                                           'B_sun':0.2
                                          }}
                                 )
In [ ]:
bf.plot_sky_projection({'COMPO':{'ASS':{'B_0':0.7,
                                        'B_amp_type':'sph'},
                                 'BT':{}}})
plt.title(r'Integrated magnetic field amplitude')

Enjoy the BFIELD module and its facilities for GMF model visualization !

Creation date : Jul. 18 2017
@author : V.Pelgrims [pelgrims@lpsc.in2p3.fr] Drawing