Commit 17420bf3 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

cleanup

parent c80b7f91
Pipeline #24844 canceled with stage
in 2 minutes and 24 seconds
......@@ -3,5 +3,4 @@ coverage
git+https://gitlab.mpcdf.mpg.de/ift/pyHealpix.git
sphinx
sphinx_rtd_theme
#better-apidoc
numpydoc
This diff is collapsed.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# NIFTy4 tutorial\n",
"\n",
"Import the necessary packages:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# some voodoo to make the notebook run properly\n",
"%matplotlib inline\n",
"import nifty4 as ift\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Define a space for our data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"spc = ift.RGSpace(10) # 1D Cartesian space, contains 10 points"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"ask the space about its configuration:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(spc)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, create a Field with Gaussian random numbers, living on that space"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fld = ift.Field.from_random(\"normal\",spc)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ift.plot(fld)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, let's do the same thing in two dimensions:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"spc = ift.RGSpace((10,10))\n",
"fld = ift.Field.from_random(\"normal\",spc)\n",
"ift.plot(fld)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, let's do some basic arithmetics with the field"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"fld += 50\n",
"fld *= -2\n",
"ift.plot(fld)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"... and smooth it."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"smooth = ift.FFTSmoothingOperator(spc,sigma=0.1)\n",
"fld_smooth = smooth(fld)\n",
"ift.plot(fld_smooth)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
" np.random.seed(43)\n",
" # Set up physical constants\n",
" # Total length of interval or volume the field lives on, e.g. in meters\n",
" L = 2.\n",
" # Typical distance over which the field is correlated (in same unit as L)\n",
" correlation_length = 0.1\n",
" # Variance of field in position space sqrt(<|s_x|^2>) (in unit of s)\n",
" field_variance = 2.\n",
" # Smoothing length of response (in same unit as L)\n",
" response_sigma = 0.1\n",
"\n",
" # Define resolution (pixels per dimension)\n",
" N_pixels = 256\n",
"\n",
" # Set up derived constants\n",
" k_0 = 1./correlation_length\n",
" # Note that field_variance**2 = a*k_0/4. for this analytic form of power\n",
" # spectrum\n",
" a = field_variance**2/k_0*4.\n",
" pow_spec = (lambda k: a / (1 + k/k_0) ** 4)\n",
" pixel_width = L/N_pixels\n",
"\n",
" # Set up the geometry\n",
" s_space = ift.RGSpace([N_pixels, N_pixels], distances=pixel_width)\n",
" fft = ift.FFTOperator(s_space)\n",
" h_space = fft.target[0]\n",
" p_space = ift.PowerSpace(h_space)\n",
"\n",
" # Create mock data\n",
"\n",
" Sh = ift.create_power_operator(h_space, power_spectrum=pow_spec)\n",
"\n",
" sp = ift.PS_field(p_space, pow_spec)\n",
" sh = ift.power_synthesize(sp, real_signal=True)\n",
" ss = fft.inverse_times(sh)\n",
"\n",
" R = ift.FFTSmoothingOperator(s_space, sigma=response_sigma)\n",
"\n",
" signal_to_noise = 1\n",
" diag = ift.Field(s_space, ss.var()/signal_to_noise).weight(1)\n",
" N = ift.DiagonalOperator(diag)\n",
" n = ift.Field.from_random(domain=s_space,\n",
" random_type='normal',\n",
" std=ss.std()/np.sqrt(signal_to_noise),\n",
" mean=0)\n",
"\n",
" d = R(ss) + n\n",
"\n",
" # Wiener filter\n",
"\n",
" j = R.adjoint_times(N.inverse_times(d))\n",
" IC = ift.GradientNormController(verbose=True, iteration_limit=500,\n",
" tol_abs_gradnorm=0.1)\n",
" inverter = ift.ConjugateGradient(controller=IC)\n",
" S_inv = fft.adjoint*Sh.inverse*fft\n",
" D = (R.adjoint*N.inverse*R + S_inv).inverse\n",
" # MR FIXME: we can/should provide a preconditioner here as well!\n",
" D = ift.InversionEnabler(D, inverter)\n",
" m = D(j)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ift.plot(m)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ift.plot(d)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ift.plot(ss)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
{% if name %}
{{ name }}
{% for item in range(8 + name|length) -%}={%- endfor %}
{% else %}
{{ fullname }}
{% for item in range(8 + fullname|length) -%}={%- endfor %}
({{ fullname }} module)
{% endif %}
.. currentmodule:: {{ fullname }}
.. automodule:: {{ fullname }}
{% if members -%}
:members: {{ members|join(", ") }}
:undoc-members:
:show-inheritance:
:member-order: bysource
Summary
-------
{% if doc:%}
{{doc}}
{% endif %}
{%- if exceptions %}
Exceptions:
.. autosummary::
:nosignatures:
{% for item in exceptions %}
{{ item }}
{%- endfor %}
{%- endif %}
{%- if classes %}
Classes:
.. autosummary::
:nosignatures:
{% for item in classes %}
{{ item }}
{%- endfor %}
{%- endif %}
{%- if functions %}
Functions:
.. autosummary::
:nosignatures:
{% for item in functions %}
{{ item }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if data %}
Data:
.. autosummary::
:nosignatures:
{% for item in data %}
{{ item }}
{%- endfor %}
{%- endif %}
{% if all_refs %}
``__all__``: {{ all_refs|join(", ") }}
{%- endif %}
{% if members %}
Reference
---------
{%- endif %}
\ No newline at end of file
{% if name %}
{{ name }}
{% for item in range(8 + name|length) -%}={%- endfor %}
({{ fullname }} package)
{% else %}
{{ fullname }}
{% for item in range(8 + fullname|length) -%}={%- endfor %}
({{ fullname }} package)
{% endif %}
.. automodule:: {{ fullname }}
{% if members -%}
:members: {{ members|join(", ") }}
:undoc-members:
:show-inheritance:
{%- endif %}
{% if submodules %}
Submodules:
.. toctree::
:maxdepth: 1
{% for item in submodules %}
{{ fullname }}.{{ item }}
{%- endfor %}
{%- endif -%}
{% if subpackages %}
Subpackages:
.. toctree::
:maxdepth: 1
{% for item in subpackages %}
{{ fullname }}.{{ item }}
{%- endfor %}
{%- endif %}
{% if members or doc %}
Summary
-------
{% if doc:%}
{{doc}}
{% endif %}
{%- if exceptions %}
Exceptions:
.. autosummary::
:nosignatures:
{% for item in exceptions %}
{{ item }}
{%- endfor %}
{%- endif %}
{%- if classes %}
Classes:
.. autosummary::
:nosignatures:
{% for item in classes %}
{{ item }}
{%- endfor %}
{%- endif %}
{%- if functions %}
Functions:
.. autosummary::
:nosignatures:
{% for item in functions %}
{{ item }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if data %}
Data:
.. autosummary::
:nosignatures:
{% for item in data %}
{{ item }}
{%- endfor %}
{%- endif %}
{% if all_refs %}
``__all__``: {{ all_refs|join(", ") }}
{%- endif %}
{% if members %}
Reference
---------
{%- endif %}
\ No newline at end of file
"""
Sample documentation for spaces. (or any other package) This will be displayed under Summary section of module documentation
"""
from .domain import Domain
from .unstructured_domain import UnstructuredDomain
from .structured_domain import StructuredDomain
......
......@@ -16,10 +16,6 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
"""
Sample documentation for DOF space. (or any other module). This will be displayed under Summary section of module documentation
"""
import numpy as np
from .structured_domain import StructuredDomain
......
......@@ -19,6 +19,7 @@
from builtins import object
from ..field import Field
class StatCalculator(object):
def __init__(self):
self._count = 0
......
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