Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/jyhmiinlin/pynufft
12 October 2022, 03:52:55 UTC
  • Code
  • Branches (16)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/codeQL-branch
    • refs/heads/gh-pages
    • refs/heads/master
    • refs/tags/0.3.1.7
    • refs/tags/0.3.1.8
    • refs/tags/2020.0.0
    • refs/tags/2020.1.2
    • refs/tags/2020.2.1
    • refs/tags/2020.2.3
    • refs/tags/2022.2.1
    • refs/tags/2022.2.2
    • refs/tags/2022.2.3
    • refs/tags/2022.2.3rc1
    • refs/tags/v0.3.1.8
    • refs/tags/v2020.0.0
    • refs/tags/v2020.1.2
    No releases to show
  • 6a45d33
  • /
  • example
  • /
  • script_2D.py
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge Iframe embedding
swh:1:cnt:30ddf0901935e0a7784892078c0ed6ec21a8ba1a
origin badgedirectory badge Iframe embedding
swh:1:dir:c0c798aab17971bc32cd88fa2d8891f80ee77cd2
origin badgerevision badge
swh:1:rev:505b5ef808e2d357b192a6ec1c4d5b4c45606cc9
origin badgesnapshot badge
swh:1:snp:a9d01202ad630f8a750d9bf34ca651272e4b534f
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 505b5ef808e2d357b192a6ec1c4d5b4c45606cc9 authored by Jyh-Miin Lin on 14 February 2020, 19:27:23 UTC
commit message
Tip revision: 505b5ef
script_2D.py
import numpy 
import scipy.misc
import matplotlib.pyplot 

from pynufft import NUFFT_cpu







# load k-space points
import pkg_resources
DATA_PATH = pkg_resources.resource_filename('pynufft', './src/data/')
om = numpy.load(DATA_PATH+'om2D.npz')['arr_0']

# om = numpy.random.randn(120000, 2)
print(om)
print('setting non-uniform coordinates...')
matplotlib.pyplot.plot(om[::10,0],om[::10,1],'o')
matplotlib.pyplot.title('non-uniform coordinates')
matplotlib.pyplot.xlabel('axis 0')
matplotlib.pyplot.ylabel('axis 1')
matplotlib.pyplot.show()

NufftObj = NUFFT_cpu()

Nd = (256, 256)  # image size
print('setting image dimension Nd...', Nd)
Kd = (512, 512)  # k-space size
print('setting spectrum dimension Kd...', Kd)
Jd = (6, 6)  # interpolation size
print('setting interpolation size Jd...', Jd)

NufftObj.plan(om, Nd, Kd, Jd)

image = scipy.misc.ascent()
image = scipy.misc.imresize(image, (256,256))
image=image*1.0/numpy.max(image[...])

print('loading image...')

matplotlib.pyplot.imshow(image.real, cmap=matplotlib.cm.gray)
matplotlib.pyplot.show()


y = NufftObj.forward(image)
print('setting non-uniform data')
print('y is an (M,) list',type(y), y.shape)


matplotlib.pyplot.subplot(2,2,1)
image0 = NufftObj.solve(y, solver='cg',maxiter=50)
matplotlib.pyplot.title('Restored image (cg)')
matplotlib.pyplot.imshow(image0.real, cmap=matplotlib.cm.gray, norm=matplotlib.colors.Normalize(vmin=0.0, vmax=1))


matplotlib.pyplot.subplot(2,2,2)
image2 = NufftObj.adjoint(y )
matplotlib.pyplot.imshow(image2.real, cmap=matplotlib.cm.gray, norm=matplotlib.colors.Normalize(vmin=0.0, vmax=5))
matplotlib.pyplot.title('Adjoint transform')


matplotlib.pyplot.subplot(2,2,3)
image3 = NufftObj.solve(y, solver='L1TVOLS',maxiter=50,rho=0.1)
matplotlib.pyplot.title('L1TV OLS')
matplotlib.pyplot.imshow(image3.real, cmap=matplotlib.cm.gray, norm=matplotlib.colors.Normalize(vmin=0.0, vmax=1))

matplotlib.pyplot.subplot(2,2,4)
image4 = NufftObj.solve(y, solver='L1TVLAD',maxiter=50,rho=0.1)
matplotlib.pyplot.title('L1TV LAD')
matplotlib.pyplot.imshow(image4.real, cmap=matplotlib.cm.gray, norm=matplotlib.colors.Normalize(vmin=0.0, vmax=1))
matplotlib.pyplot.show()


shifted_kspectrum = numpy.fft.fftshift(numpy.fft.fftn(numpy.fft.fftshift(image0)))
#     print('getting the k-space spectrum, shape =',shifted_kspectrum.shape)
print('Showing the shifted k-space spectrum')

matplotlib.pyplot.imshow( shifted_kspectrum.real, cmap = matplotlib.cm.gray, norm=matplotlib.colors.Normalize(vmin=-100, vmax=100))
matplotlib.pyplot.title('shifted k-space spectrum')
matplotlib.pyplot.show()


W0 = numpy.ones((NufftObj.st['M'], ))


# W_x = NufftObj.xx2k( NufftObj.adjoint(NufftObj.forward(NufftObj.k2xx(W0))))
# W_y =  NufftObj.xx2k(NufftObj.x2xx(NufftObj.adjoint(NufftObj.k2y(W0))))
W =  NufftObj.xx2k(NufftObj.adjoint(W0))

# W =   NufftObj.y2k(W0)
# matplotlib.pyplot.subplot(1,)
matplotlib.pyplot.imshow(numpy.real((W*W.conj())**0.5))
matplotlib.pyplot.title('Ueckers inverse function (real)')
# matplotlib.pyplot.subplot(1,2,2)
# matplotlib.pyplot.imshow(W.imag)
# matplotlib.pyplot.title('Ueckers inverse function (imaginary)')
matplotlib.pyplot.show()


p0 = NufftObj.adjoint(NufftObj.forward(image))
p1 = NufftObj.k2xx((W.conj()*W)**0.5*NufftObj.xx2k(image))

print('error between Toeplitz and Inverse reconstruction', numpy.linalg.norm( p1 - p0)/ numpy.linalg.norm(p0))


matplotlib.pyplot.subplot(1,3,1)
matplotlib.pyplot.imshow(numpy.real(p0 ))
matplotlib.pyplot.title('Toeplitz')
matplotlib.pyplot.subplot(1,3,2)
matplotlib.pyplot.imshow(numpy.real(p1))
matplotlib.pyplot.title('Ueckers inverse function')
matplotlib.pyplot.subplot(1,3,3)
matplotlib.pyplot.imshow(numpy.abs(p0 - p1)/ numpy.abs(p1))
matplotlib.pyplot.title('Difference')
matplotlib.pyplot.show()

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top