Commit 6630c21f authored by Maude Le Jeune's avatar Maude Le Jeune
Browse files

+ python

parent b48a74d8
lejeune@localhost.localdomain.4210:1275548606
\ No newline at end of file
#
# This file is part of Spherelib.
#
# Spehrelib is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Healpy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Healpy; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# For more information about Healpy, see http://code.google.com/p/healpy
#
"""spherelib blabla
"""
import warnings
try:
ImportWarning
except NameError:
class ImportWarning(Warning):
pass
import map
import spherelib_map
def rien():
return 0
This diff is collapsed.
#include "mask.h"
#include "healpix_base.h"
#include "fastfiller.h"
void regress(double *tabmap, double *tabmask, int npix, int order=1)
{
arr<double> arrmap(tabmap, npix);
arr<double> arrmask(tabmask, npix);
MapExt<double> map(arrmap, RING);
MapExt<double> mask(arrmask, RING);
//Regress(map, mask);
}
void fastfill(double *tabmap, int npix,double eps=1e-6, int niter=-1, int startscale=0 )
{
arr<double> arrmap(tabmap, npix);
MapExt<double> map(arrmap, RING);
MapExt<double> mask;
mask.SetNside(map.Nside(), map.Scheme());
mask.fill(1.0);
fastfiller<double> (map, mask, eps, niter, startscale);
}
void inplace(double *invec, int n)
{
int i;
for (i=0; i<n; i++)
{
invec[i] = 2*invec[i];
}
}
/*
** _spherelib_map.h
**
** Made by Maude Le Jeune
** Login <lejeune@localhost.localdomain>
**
** Started on Tue May 11 15:21:46 2010 Maude Le Jeune
** Last update Tue May 11 15:21:46 2010 Maude Le Jeune
*/
#ifndef _SPHERELIB_MAP_H_
# define _SPHERELIB_MAP_H_
void regress (double *mapreg, double *maskreg, int nreg, int order=1);
void fastfill(double *mapfill, int nfill, double eps=1e-6, int niter=-1, int startscale=0);
//void inplace (double *invec, int n);
#endif /* !_SPHERELIB_MAP_H_ */
%module spherelib_map
%{
#define SWIG_FILE_WITH_INIT
#include "spherelib_map.h"
%}
%include "numpy.i"
%init
%{
import_array();
%}
// map regression
%apply (double* INPLACE_ARRAY1, int DIM1) {(double* mapreg, int nreg1), (double* maskreg, int nreg2)};
%rename (regress) my_regress;
%feature("docstring", "Remove multipole of HEALPix masked map up to order (1 or 2)") my_regress ;
%feature("autodoc",0) my_regress;
%inline %{
void my_regress (double* mapreg, int nreg1, double* maskreg, int nreg2, int order=1){
if (nreg1!=nreg2){
PyErr_Format(PyExc_ValueError, "Arrays of different lengths");
}
regress (mapreg, maskreg, nreg1, order);
}
%}
%ignore regress;
// gap filling
%apply (double* INPLACE_ARRAY1, int DIM1) {(double* mapfill, int nfill)};
%feature("docstring", "Iteratively fills holes in an HEALPix map by putting in null and undef pixels the mean value of its neighbors") my_regress ;
%feature("autodoc",0) fastfill;
%include "spherelib_map.h"
from spherelib import *
from pylab import *
nside = 1
npix = 12*nside*nside
map = ones(npix)
mask = ones(npix)
regress (map, mask, 2)
fastfill (map)
#a = array([1,2,3],'d')
#inplace(a)
APPNAME='spherelib'
VERSION='1.0'
top = '.'
out = 'build'
def set_options(ctx):
ctx.add_option('--omp', action='store', default=False, help='Openmp compilation')
ctx.add_option('--healpix_target', action='store', default='generic_gcc', help='healpix configuration')
ctx.tool_options('compiler_cxx')
ctx.tool_options('python')
def configure(ctx):
print('→ configuring spherelib')
import Options
print('→ omp is ' + str(Options.options.omp))
if Options.options.omp:
Options.options.healpix_target='gcc_omp'
print('→ healpix_target is ' + str(Options.options.healpix_target))
ctx.env['HEALPIX_TARGET'] = str(Options.options.healpix_target)
ctx.env['CXXFLAGS'] = ['-O2']
if Options.options.omp:
ctx.env['CXXFLAGS'].append('-fPIC')
ctx.env['CXXFLAGS'].append('-fopenmp')
ctx.find_program(['swig'], mandatory=True)
ctx.check_tool('g++ python')
ctx.check_tool( 'python' )
ctx.check_python_headers()
ctx.check_tool('swig')
ctx.check_tool('compiler_cxx')
def get_version():
return VERSION
def build_healpix(bld):
print('→ building healpix (this may take a while)')
import os
import Options
target=bld.env["HEALPIX_TARGET"]
compil_result = os.system('cd ../healpix && '
'HEALPIX_TARGET=%s make '%(target))
if compil_result != 0:
raise Exception('Error while compiling healpix_cxx')
def build(bld):
print('→ building spherelib')
build_healpix(bld)
libs = ['cxxsupport', 'cfitsio', 'fftpack', 'gsl', 'gslcblas', 'healpix_cxx']
import Options
if bld.env["HEALPIX_TARGET"]=="gcc_omp":
libs.append('gomp')
target=bld.env["HEALPIX_TARGET"]
cxx_spherelib = bld(
features = ['cxx', 'cshlib'],
source = ['../lib/src/MapExt.cpp', '../lib/src/AlmExt.cpp', '../lib/src/Bin.cpp', '../lib/src/PowSpecExt.cpp', '../lib/src/CovMat.cpp'],
target = 'spherelib',
vnum = get_version(),
includes = ['../lib/src', '../healpix/'+target+'/include'],
defines = ['HEALPIXDATA=\''+bld.root.abspath()+'../healpix/data/\''],
ccflags = bld.env['CXXFLAGS'],
lib = libs,
libpath = ['../healpix/'+target+'lib'],
name = 'spherelib'
)
cxx_spherelib.install_path = '${PREFIX}/lib'
swig_spherelib = bld(
features = 'cxx cshlib pyext',
includes = ['spherelib', '../include', '../lib/src'],
source = ['spherelib/spherelib_map.i','spherelib/spherelib_map.cpp'],
target = '_spherelib_map',
swig_flags = '-c++ -python -Wall',
lib = libs,
libpath = ['../healpix/'+target+'lib'],
uselib_local = 'spherelib')
swig_spherelib.install_path = '${PYTHONDIR}/spherelib'
obj = bld(features = 'py')
obj.find_sources_in_dirs( ['./spherelib', out+'/default/spherelib'], exts=['.py'] )
obj.install_path = '${PYTHONDIR}/spherelib'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment