Brandy Melville (@brandymelvilleusa) • Instagram
seen from United States
seen from United States
seen from United States
seen from Myanmar (Burma)

seen from United States
seen from United Kingdom

seen from Netherlands
seen from United States
seen from China
seen from China
seen from Italy
seen from United States
seen from Russia

seen from Italy

seen from Australia

seen from United Arab Emirates
seen from China
seen from Lithuania
seen from China
seen from T1
Brandy Melville (@brandymelvilleusa) • Instagram
Brandy Melville (@brandymelvilleusa) • Instagram
Getting IGRF into Python
There's this thing called the International Geomagnetic Reference Field (IGRF). It's a mathematical model that approximates the shape of the Earth's magnetic field. For reasons of science, I want to run it on my computer. In this particular case, I want to have it as a Python module. It's not in the standard library, but a couple of intrepid pioneers have created implementations. I'll go through installing python-magnetosphere, because I picked it randomly from the alternatives. It contains more than IGRF, but I'm not going to care about that now. All this will be happening on Linux, because the road to getting it to work on Windows is just too long and winding.
Begin.
Download the python-magnetosphere source. Version 0.1 at the time of writing. (There is also an x64-build for Python 2.5, which may work but probably won't if your linux doesn't run Python 2.5.)
Unpack the source. Revealed is a small source tree with a few bits, including a README and a setup.py. Ideally, we'd run [$ python setup.py install --user]. Of course, this case isn't ideal.
We look at the README file, and find that it refers to a FORTRAN source and a set of IGRF/DGRF data files. Those should be put in the dat/ directory. Those files can be found at ftp://nssdcftp.gsfc.nasa.gov/. If you're located in the source directory, these commands will download them for you: $ mkdir dat $ cd dat $ wget -r -l 1 -nd ftp://nssdcftp.gsfc.nasa.gov/models/geomagnetic/igrf/fortran_code/
And then there's the libf2c dependency. The sources will compile just fine without it, and will not fail until you try to use the python module. On a recent Ubuntu (meaning 12.04) it's sufficient to say [$ sudo apt-get install libf2c2-dev].
Now we can move on to editing the C sources. The files cxformmodule.c and cxformmodule.c both contain the line #include <python2.5/Python.h> and you need to change that to whatever your Python version is. On Ubuntu 12.04 you have to change 2.5 to 2.7 in both files.
And then it turns out we also need a file from the CXFORM library. It's sufficient to download it, unpack it, and copy cxform.h to the magnetosphere directory, you don't have to compile the whole library.
Now the script will build. The install path for the IGRF/DGRF data files is hard-coded into igrf_sub.c and setup.py (none of that pesky PREFIX= stuff here) so if you don't want those installed into /usr/local/lib/ there's more editing to be done. In igrf_sub.c: find the line extern char *trimwhitespace(char *str); char prefix_dp[28] = "/usr/local/lib/igrf/"; strcat(prefix_dp, fspec); o__1.ofnm = trimwhitespace(prefix_dp); change it to for example extern char *trimwhitespace(char *str); char prefix_dp[100] = "/home/asmund/local/lib/igrf/"; strcat(prefix_dp, fspec); o__1.ofnm = trimwhitespace(prefix_dp); (note that I also changed the string length). Then also change setup.py similarly: data_files=[('/usr/lib/igrf', to data_files=[('/home/asmund/local/lib/igrf/', (notice that the path was different in the two files, so the module probably wouldn't have worked anyay.)
Now, finally: $ python setup.py install --user $ cd (leave build directory before testing, otherwise python gets confused)
(...)
IAGA V-MOD Geomagnetic Field Modeling: International Geomagnetic Reference Field IGRF-11
IGRF 1900.0 から最新の IGRF 2010.0 まで掲載。理科年表の数値と微妙に違ってるなぁ