From ca6649023c5bbc970a8f3af6a2b377a585f9ce94 Mon Sep 17 00:00:00 2001 From: Jan Caron <j.caron@fz-juelich.de> Date: Mon, 13 May 2013 15:53:48 +0200 Subject: [PATCH] Changed cython folder to numcore subfolder Changed setup.py Implemented assertion to check if jacobi matrix is the same --- desktop.ini | 2 +- pyramid/magdata.py | 54 ++++++++++++++++++++ pyramid/numcore/__init__.py | 0 pyramid/{cython => numcore}/c1.pyx | 0 pyramid/{cython => numcore}/c2.pyx | 0 pyramid/{cython => numcore}/c3.pyx | 0 pyramid/{cython => numcore}/hello.pyx | 0 pyramid/{cython => numcore}/initpyximport.py | 0 pyramid/{cython => numcore}/setup.py | 13 ++++- pyramid/phasemap.py | 8 +-- scripts/create_random_distribution.py | 35 +++++++++++++ setup.py | 4 +- 12 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 pyramid/magdata.py create mode 100644 pyramid/numcore/__init__.py rename pyramid/{cython => numcore}/c1.pyx (100%) rename pyramid/{cython => numcore}/c2.pyx (100%) rename pyramid/{cython => numcore}/c3.pyx (100%) rename pyramid/{cython => numcore}/hello.pyx (100%) rename pyramid/{cython => numcore}/initpyximport.py (100%) rename pyramid/{cython => numcore}/setup.py (54%) create mode 100644 scripts/create_random_distribution.py diff --git a/desktop.ini b/desktop.ini index 2d10ec1..85ecbcf 100644 --- a/desktop.ini +++ b/desktop.ini @@ -1,5 +1,5 @@ [.ShellClassInfo] -IconResource=C:\Users\Jan\Daten\FZ-Jülich\PYRAMID\pyramid.ico,0 +IconResource=C:\Users\Jan\PhD Thesis\Pyramid\icon.ico,0 [ViewState] Mode= Vid= diff --git a/pyramid/magdata.py b/pyramid/magdata.py new file mode 100644 index 0000000..3d91b8d --- /dev/null +++ b/pyramid/magdata.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +"""Load magnetization data from LLG files.""" + + +import numpy as np + + +class MagData: + + '''An object storing magnetization data loaded from a LLG-file.''' + + def __init__(self, x_mag, y_mag, z_mag, res): # TODO: electrostatic component! + '''Load magnetization in LLG-file format. + Arguments: + filename - the name of the file where the data are stored + Returns: + None + + ''' + assert np.shape(x_mag) == np.shape(y_mag) == np.shape(z_mag), 'Dimensions do not match!' + + self.res = res + self.dim = np.shape(x_mag) + + + + + + scale = 1.0E-9 / 1.0E-2 #from cm to nm + data = np.genfromtxt(filename, skip_header=2) + x_dim, y_dim, z_dim = np.genfromtxt(filename, dtype=int, + skip_header=1, + skip_footer=len(data[:, 0])) + res = (data[1, 0] - data[0, 0]) / scale + x_len, y_len, z_len = [data[-1, i]/scale+res/2 for i in range(3)] + x_mag, y_mag, z_mag = [data[:, i].reshape(z_dim, y_dim, x_dim) + for i in range(3,6)] + #Reshape in Python and Igor is different, + #Python fills rows first, Igor columns! + self.filename = filename + self.res = res + self.dim = (z_dim, y_dim, x_dim) + self.length = (z_len, y_len, x_len) + self.magnitude = (z_mag, y_mag, x_mag) + + def __str__(self): + '''Return the filename of the loaded file. + Arguments: + None + Returns: + the name of the loaded file as a string + + ''' + return self.filename \ No newline at end of file diff --git a/pyramid/numcore/__init__.py b/pyramid/numcore/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyramid/cython/c1.pyx b/pyramid/numcore/c1.pyx similarity index 100% rename from pyramid/cython/c1.pyx rename to pyramid/numcore/c1.pyx diff --git a/pyramid/cython/c2.pyx b/pyramid/numcore/c2.pyx similarity index 100% rename from pyramid/cython/c2.pyx rename to pyramid/numcore/c2.pyx diff --git a/pyramid/cython/c3.pyx b/pyramid/numcore/c3.pyx similarity index 100% rename from pyramid/cython/c3.pyx rename to pyramid/numcore/c3.pyx diff --git a/pyramid/cython/hello.pyx b/pyramid/numcore/hello.pyx similarity index 100% rename from pyramid/cython/hello.pyx rename to pyramid/numcore/hello.pyx diff --git a/pyramid/cython/initpyximport.py b/pyramid/numcore/initpyximport.py similarity index 100% rename from pyramid/cython/initpyximport.py rename to pyramid/numcore/initpyximport.py diff --git a/pyramid/cython/setup.py b/pyramid/numcore/setup.py similarity index 54% rename from pyramid/cython/setup.py rename to pyramid/numcore/setup.py index b49dc9f..b31924c 100644 --- a/pyramid/cython/setup.py +++ b/pyramid/numcore/setup.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Created on Fri May 03 10:27:04 2013 @@ -8,8 +7,18 @@ Created on Fri May 03 10:27:04 2013 #call with: python setup.py build_ext --inplace --compiler=mingw32 import glob +import numpy from distutils.core import setup +from distutils.extension import Extension from Cython.Build import cythonize +from Cython.Distutils import build_ext + +#setup( +# cmdclass = {'build_ext': build_ext}, +# ext_modules = [Extension("multiply", +# sources=["multiply.pyx", "c_multiply.c"], +# include_dirs=[numpy.get_include()])], +#) setup( name = 'Pyramex', @@ -18,4 +27,4 @@ setup( author = 'Jan Caron', author_email = 'j.caron@fz-juelich.de', ext_modules = cythonize(glob.glob('*.pyx')) -) \ No newline at end of file +) diff --git a/pyramid/phasemap.py b/pyramid/phasemap.py index e828560..60c639d 100644 --- a/pyramid/phasemap.py +++ b/pyramid/phasemap.py @@ -129,7 +129,8 @@ def real_space(mag_data, method, b_0=1, jacobi=None): phase = np.zeros((y_dim, x_dim)) # TODO: only iterate over pixels that have a magn. > threshold (first >0) - jacobi_fd = jacobi.copy() + if jacobi is not None: + jacobi_fd = jacobi.copy() h = 0.0001 for j in range(y_dim): @@ -146,8 +147,9 @@ def real_space(mag_data, method, b_0=1, jacobi=None): - jacobi_diff = jacobi_fd - jacobi - assert (np.abs(jacobi_diff) < 1.0E-8).all(), 'jacobi matrix is not the same' + if jacobi is not None: + jacobi_diff = jacobi_fd - jacobi + assert (np.abs(jacobi_diff) < 1.0E-8).all(), 'jacobi matrix is not the same' return phase diff --git a/scripts/create_random_distribution.py b/scripts/create_random_distribution.py new file mode 100644 index 0000000..1ac5c6b --- /dev/null +++ b/scripts/create_random_distribution.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon May 13 13:05:40 2013 + +@author: Jan +""" + +import random +import numpy as np +import matplotlib.pyplot as plt +import pyramid.magcreator as mc +import time +import pdb, traceback, sys +from numpy import pi + + +def phase_from_mag(): + + count = 10 + dim = (128, 128) + + random.seed(42) + + for i in range(count): + + x = random.rand + + +if __name__ == "__main__": + try: + phase_from_mag() + except: + type, value, tb = sys.exc_info() + traceback.print_exc() + pdb.post_mortem(tb) \ No newline at end of file diff --git a/setup.py b/setup.py index 27d813f..9b340f6 100644 --- a/setup.py +++ b/setup.py @@ -18,8 +18,6 @@ setup( description = 'PYthon based Reconstruction Algorithm for MagnetIc Distributions', author = 'Jan Caron', author_email = 'j.caron@fz-juelich.de', - package_dir = {'': 'src'}, packages = ['pyramid'], - ext_package = ['pyramex'] - ext_modules = cythonize(glob.glob(os.path.join('pyramex','*.pyx'))) + ext_modules = cythonize(glob.glob(os.path.join('pyramid','numcore','*.pyx'))) ) -- GitLab