Skip to content
Snippets Groups Projects
Commit 51b39c56 authored by Jan Caron's avatar Jan Caron
Browse files

Updated to work with Python 3!

GUIs now import .ui-files directly.
parent d2eef42e
No related branches found
No related tags found
No related merge requests found
Showing
with 40 additions and 1742 deletions
......@@ -13,3 +13,4 @@ files*
build*
Pyramid.egg-info*
logfile.log
.idea*
Pyramid
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/pyramid" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="Python 2.7.11 (C:\Anaconda2\python.exe)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="HyperSpy" />
<orderEntry type="module" module-name="Jutil" />
<orderEntry type="module" module-name="Publications" />
<orderEntry type="module" module-name="Script-Vault" />
</component>
<component name="ReSTService">
<option name="workdir" value="$MODULE_DIR$" />
<option name="DOC_DIR" value="$MODULE_DIR$" />
</component>
<component name="TestRunnerService">
<option name="projectConfiguration" value="Nosetests" />
<option name="PROJECT_TEST_RUNNER" value="Nosetests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
</XML>
</value>
</option>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (1)" />
</component>
</project>
\ No newline at end of file
<component name="ProjectDictionaryState">
<dictionary name="Jan" />
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="LongLine" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="*.c" level="WARNING" enabled="false" />
</inspection_tool>
<inspection_tool class="PyArgumentListInspection" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="gui" level="WARNING" enabled="false" />
</inspection_tool>
<inspection_tool class="PyAttributeOutsideInitInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PyBroadExceptionInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PyCallByClassInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<scope name="gui" level="WEAK WARNING" enabled="false" />
</inspection_tool>
<inspection_tool class="PyClassicStyleClassInspection" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="gui" level="WARNING" enabled="false" />
</inspection_tool>
<inspection_tool class="PyCompatibilityInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ourVersions">
<value>
<list size="1">
<item index="0" class="java.lang.String" itemvalue="3.5" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="PyMandatoryEncodingInspection" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="PyMissingOrEmptyDocstringInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<scope name="gui" level="WEAK WARNING" enabled="false" />
</inspection_tool>
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="gui" level="WARNING" enabled="false">
<option name="ignoredPackages">
<value>
<list size="0" />
</value>
</option>
</scope>
<scope name="scripts" level="WARNING" enabled="true">
<option name="ignoredPackages">
<value>
<list size="2">
<item index="0" class="java.lang.String" itemvalue="pylab" />
<item index="1" class="java.lang.String" itemvalue="tqdm" />
</list>
</value>
</option>
</scope>
<option name="ignoredPackages">
<value>
<list size="1">
<item index="0" class="java.lang.String" itemvalue="hyperspy" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<scope name="__init__" level="WEAK WARNING" enabled="true">
<option name="ignoredErrors">
<list>
<option value="E402" />
</list>
</option>
</scope>
<option name="ignoredErrors">
<list>
<option value="W503" />
</list>
</option>
</inspection_tool>
<inspection_tool class="PyPep8NamingInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PyShadowingNamesInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PyTypeCheckerInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<scope name="__init__" level="WARNING" enabled="false" />
<option name="ignoredIdentifiers">
<list>
<option value="multiprocessing" />
<option value="hyperspy.api" />
</list>
</option>
</inspection_tool>
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="true" />
<option name="processLiterals" value="true" />
<option name="processComments" value="true" />
</inspection_tool>
<inspection_tool class="TodoComment" enabled="false" level="INFO" enabled_by_default="false" />
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Project Default" />
<option name="USE_PROJECT_PROFILE" value="true" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7.11 (C:\Anaconda2\python.exe)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/../HyperSpy/.idea/HyperSpy.iml" filepath="$PROJECT_DIR$/../HyperSpy/.idea/HyperSpy.iml" />
<module fileurl="file://$PROJECT_DIR$/../Jutil/.idea/Jutil.iml" filepath="$PROJECT_DIR$/../Jutil/.idea/Jutil.iml" />
<module fileurl="file://$PROJECT_DIR$/../Publications/.idea/Publications.iml" filepath="$PROJECT_DIR$/../Publications/.idea/Publications.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/Pyramid.iml" filepath="$PROJECT_DIR$/.idea/Pyramid.iml" />
<module fileurl="file://$PROJECT_DIR$/../Script-Vault/.idea/Script-Vault.iml" filepath="$PROJECT_DIR$/../Script-Vault/.idea/Script-Vault.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<component name="DependencyValidationManager">
<scope name="*.c" pattern="file[Pyramid]:pyramid/numcore/*.c" />
</component>
\ No newline at end of file
<component name="DependencyValidationManager">
<scope name="__init__" pattern="file[Pyramid]:pyramid/__init__.py" />
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="hg4idea" />
<mapping directory="$PROJECT_DIR$/../Jutil" vcs="hg4idea" />
<mapping directory="$PROJECT_DIR$/../Publications" vcs="hg4idea" />
<mapping directory="$PROJECT_DIR$/../Script-Vault" vcs="hg4idea" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
......@@ -48,13 +48,6 @@ numcore
"""
import logging
_log = logging.getLogger(__name__)
try: # Try importing HyperSpy (here because otherwise API Errors might occur):
import hyperspy.api
except ImportError:
_log.error('Could not load hyperspy package!')
from . import analytic
from . import magcreator
from . import reconstruction
......@@ -92,6 +85,8 @@ from .config import *
from .version import version as __version__
from .version import hg_revision as __hg_revision__
import logging
_log = logging.getLogger(__name__)
_log.info("Starting Pyramid V{} HG{}".format(__version__, __hg_revision__))
del logging
......
......@@ -83,7 +83,7 @@ class DirectionalColormap(colors.LinearSegmentedColormap):
def __init__(self, inverted=False):
self._log.debug('Calling __create_directional_colormap')
cdict = self.CDICT_INV if inverted else self.CDICT
super(DirectionalColormap, self).__init__('directional_colormap', cdict, N=256)
super().__init__('directional_colormap', cdict, N=256)
self._log.debug('Created ' + str(self))
@classmethod
......@@ -250,5 +250,5 @@ class TransparentColormap(colors.LinearSegmentedColormap):
blue = [(0., 0., b), (1., b, 1.)]
alpha = [(0., 0., alpha_range[0]), (1., alpha_range[1], 1.)]
cdict = {'red': red, 'green': green, 'blue': blue, 'alpha': alpha}
super(TransparentColormap, self).__init__('transparent_colormap', cdict, N=256)
super().__init__('transparent_colormap', cdict, N=256)
self._log.debug('Created ' + str(self))
......@@ -11,10 +11,8 @@ FFT operations.
"""
try:
import cPickle as pickle
except ImportError:
import pickle
import pickle
import logging
import os
......@@ -22,28 +20,19 @@ import numpy as np
from pyramid.config import NTHREADS
# pyFFTW depends on this
# try:
# from collections import Counter
# except ImportError:
# from collections_python27 import Counter
# import collections
#
# collections.Counter = Counter
_log = logging.getLogger(__name__)
try:
import pyfftw
BACKEND = 'fftw'
except ImportError:
pyfftw = None
BACKEND = 'numpy'
print("pyFFTW module not found. Using numpy implementation.")
_log.info('pyFFTW module not found. Using numpy implementation.')
__all__ = ['PLANS', 'FLOAT', 'COMPLEX', 'dump_wisdom', 'load_wisdom', # analysis:ignore
'zeros', 'empty', 'configure_backend',
'fftn', 'ifftn', 'rfftn', 'irfftn', 'rfftn_adj', 'irfftn_adj']
_log = logging.getLogger(__name__)
class FFTWCache(object):
......@@ -384,6 +373,12 @@ def configure_backend(backend):
# On import:
ifftn = None
fftn = None
rfftn = None
irfftn = None
rfftn_adj = None
irfftn_adj = None
if pyfftw is not None:
configure_backend('fftw')
else:
......
......@@ -6,19 +6,18 @@
from __future__ import division
from scipy.ndimage.interpolation import zoom
from pyramid import fft
from pyramid.colormap import DirectionalColormap
import abc
import logging
import os
from abc import ABCMeta, abstractmethod
from numbers import Number
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.ticker import MaxNLocator
from scipy.ndimage.interpolation import zoom
from pyramid import fft
from pyramid.colormap import DirectionalColormap
_log = logging.getLogger(__name__)
try: # Try importing HyperSpy:
......@@ -30,7 +29,7 @@ except ImportError:
__all__ = ['VectorData', 'ScalarData']
class FieldData(object):
class FieldData(object, metaclass=abc.ABCMeta):
"""Class for storing field data.
Abstract base class for the representatio of magnetic or electric fields (see subclasses).
......@@ -50,7 +49,6 @@ class FieldData(object):
"""
__metaclass__ = ABCMeta
_log = logging.getLogger(__name__ + '.FieldData')
@property
......@@ -231,7 +229,7 @@ class FieldData(object):
mlab.orientation_axes()
return plot
@abstractmethod
@abc.abstractmethod
def scale_down(self, n):
"""Scale down the field distribution by averaging over two pixels along each axis.
......@@ -252,7 +250,7 @@ class FieldData(object):
"""
pass
@abstractmethod
@abc.abstractmethod
def scale_up(self, n, order):
"""Scale up the field distribution using spline interpolation of the requested order.
......@@ -275,7 +273,7 @@ class FieldData(object):
"""
pass
@abstractmethod
@abc.abstractmethod
def get_vector(self, mask):
"""Returns the field as a vector, specified by a mask.
......@@ -292,7 +290,7 @@ class FieldData(object):
"""
pass
@abstractmethod
@abc.abstractmethod
def set_vector(self, vector, mask):
"""Set the field of the masked pixels to the values specified by `vector`.
......@@ -310,7 +308,7 @@ class FieldData(object):
"""
pass
@abstractmethod
@abc.abstractmethod
def to_signal(self):
"""Convert :class:`~.FieldData` data into a HyperSpy signal.
......@@ -326,7 +324,7 @@ class FieldData(object):
"""
pass
@abstractmethod
@abc.abstractmethod
def save_to_hdf5(self, filename, *args, **kwargs):
"""Save field data in a file with HyperSpys HDF5-format.
......@@ -365,11 +363,6 @@ class VectorData(FieldData):
"""
_log = logging.getLogger(__name__ + '.VectorData')
def __init__(self, a, field):
self._log.debug('Calling __init__')
super(VectorData, self).__init__(a, field)
self._log.debug('Created ' + str(self))
def scale_down(self, n=1):
"""Scale down the field distribution by averaging over two pixels along each axis.
......@@ -389,7 +382,7 @@ class VectorData(FieldData):
"""
self._log.debug('Calling scale_down')
assert n > 0 and isinstance(n, (int, long)), 'n must be a positive integer!'
assert n > 0 and isinstance(n, int), 'n must be a positive integer!'
self.a *= 2 ** n
for t in range(n):
# Pad if necessary:
......@@ -422,8 +415,8 @@ class VectorData(FieldData):
Acts in place and changes dimensions and grid spacing accordingly.
"""
self._log.debug('Calling scale_up')
assert n > 0 and isinstance(n, (int, long)), 'n must be a positive integer!'
assert 5 > order >= 0 and isinstance(order, (int, long)), \
assert n > 0 and isinstance(n, int), 'n must be a positive integer!'
assert 5 > order >= 0 and isinstance(order, int), \
'order must be a positive integer between 0 and 5!'
self.a /= 2 ** n
self.field = np.array((zoom(self.field[0], zoom=2 ** n, order=order),
......@@ -1056,11 +1049,6 @@ class ScalarData(FieldData):
"""
_log = logging.getLogger(__name__ + '.ScalarData')
def __init__(self, a, field):
self._log.debug('Calling __init__')
super(ScalarData, self).__init__(a, field)
self._log.debug('Created ' + str(self))
def scale_down(self, n=1):
"""Scale down the field distribution by averaging over two pixels along each axis.
......@@ -1080,7 +1068,7 @@ class ScalarData(FieldData):
"""
self._log.debug('Calling scale_down')
assert n > 0 and isinstance(n, (int, long)), 'n must be a positive integer!'
assert n > 0 and isinstance(n, int), 'n must be a positive integer!'
self.a *= 2 ** n
for t in range(n):
# Pad if necessary:
......@@ -1112,8 +1100,8 @@ class ScalarData(FieldData):
Acts in place and changes dimensions and grid spacing accordingly.
"""
self._log.debug('Calling scale_up')
assert n > 0 and isinstance(n, (int, long)), 'n must be a positive integer!'
assert 5 > order >= 0 and isinstance(order, (int, long)), \
assert n > 0 and isinstance(n, int), 'n must be a positive integer!'
assert 5 > order >= 0 and isinstance(order, int), \
'order must be a positive integer between 0 and 5!'
self.a /= 2 ** n
self.field = zoom(self.field, zoom=2 ** n, order=order)
......
......@@ -5,7 +5,7 @@
"""This module provides the :class:`~.ForwardModel` class which represents a strategy to map a
threedimensional magnetization distribution onto a two-dimensional phase map."""
from __future__ import division, print_function
from __future__ import division
import logging
import multiprocessing as mp
......@@ -188,7 +188,7 @@ class DistributedForwardModel(ForwardModel):
def __init__(self, data_set, ramp_order=None, nprocs=1):
# Evoke super constructor to set up the normal ForwardModel:
super(DistributedForwardModel, self).__init__(data_set, ramp_order)
super().__init__(data_set, ramp_order)
# Initialize multirocessing specific stuff:
self.nprocs = nprocs
img_per_proc = np.ceil(self.data_set.count / self.nprocs).astype(np.int)
......
......@@ -5,8 +5,6 @@
"""This module provides the :class:`~.Kernel` class, representing the phase contribution of one
single magnetized pixel."""
from __future__ import print_function
import logging
import numpy as np
......@@ -89,6 +87,10 @@ class Kernel(object):
self.slice_mag = (slice(0, dim_uv[0]), # Magnetization is padded on the far end!
slice(0, dim_uv[1])) # (Phase cutout is shifted as listed above)
# Calculate kernel (single pixel phase):
# [M_0] = [PHI_0 / µ_0] = Tm² / N/A² = N/Am * A²/N = A/m
# --> This is the magnetization, not the magnetic moment (A/m * m³ = Am²)!
# [b_0] = [µ_0] * [M_0] = A/m * N/A² = N/Am = T
# [coeff] = [b_0 * a² / (2*PHI_0)] = T * m² / Tm² = 1 --> without unit (phase)!
coeff = b_0 * a ** 2 / (2 * PHI_0) # Minus is gone because of negative z-direction
v_dim, u_dim = dim_uv
u = np.linspace(-(u_dim - 1), u_dim - 1, num=2 * u_dim - 1)
......@@ -141,7 +143,7 @@ class Kernel(object):
None
"""
self._log.debug('Calling print_info')
self._log.debug('Calling log_info')
print('Shape of the FOV :', self.dim_uv)
print('Shape of the Kernel:', self.dim_kern)
print('Zero-padded shape :', self.dim_pad)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment