Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • wdata wdata
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 4
    • Issues 4
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • wtools
  • wdatawdata
  • Wiki
    • Examples
  • Python examples

Last edited by Gabriel Wlazłowski Dec 08, 2024
Page history
This is an old version of this page. You can view the most recent version or browse the history.

Python examples

  • Simple plot of 1D data
  • Simple plot of 2D data
  • Cross section of velocity field for quantum vortex

Simple plot of 1D data

The example below demonstrates how to plot 1D data, precisely:

datadim                   1   # dimension of block size: 1=nx, 2=nx*ny, 3=nx*ny*nz

The simple plotting script may look like:

#!/usr/bin/python3

# Before the run:
# Get wdata lib:
#   pip3 install wdata
# (add -U if you want to update)
# For more info see: 
#   https://pypi.org/project/wdata/


import numpy as np
import matplotlib.pyplot as plt
from wdata.io import WData, Var

# I read data directly from dwarf,
# Before running the script I mounted file system:
# sshfs gabrielw@dwarf.if.pw.edu.pl:/home2/ /home/gabrielw/home2-dwarf/

fwtxt="/home/gabrielw/home2-dwarf/scratch/barrus-gw/h1d/lambda006.wtxt"
data = WData.load(fwtxt)

fig, ax = plt.subplots()
ax.plot(data.xyz[0], data.rho_a[-1]) # plot last frame [-1]

ax.set(xlabel='x', ylabel=r'$n_{\uparrow}(x)$')
ax.grid()

fig.savefig("rho_a.png")
plt.show()

The result of this example: rho_a

Simple plot of 2D data

The example below demonstrates how to plot 1D data, precisely:

datadim                   2   # dimension of block size: 1=nx, 2=nx*ny, 3=nx*ny*nz

The simple plotting script may look like:

#!/usr/bin/python3

# Before run:
# Get wata lib:
#   pip3 install wdata
# (add -U if you want to update)
# For more info see: 
#   https://pypi.org/project/wdata/


import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from wdata.io import WData, Var

# I read data directly from dwarf,
# Before running the script I mounted file system:
# sshfs gabrielw@dwarf.if.pw.edu.pl:/home2/ /home/gabrielw/home2-dwarf/

fwtxt="/home/gabrielw/home2-dwarf/archive/ntg/repository/atomicjj/CALC-BCS/td-round5-bcs/td1-bcs-z0.02-V0.6.wtxt"
data = WData.load(fwtxt)

ratio=data.Nxyz[0]/data.Nxyz[1]
scale=2.0
fig, ax = plt.subplots(figsize=(scale*ratio,1.2*scale))

im = ax.imshow(np.transpose(data.rho_a[0]), interpolation='bilinear', extent=[0, data.Nxyz[0], 0, data.Nxyz[1]], aspect='auto')
fig.colorbar(im, ax=ax, orientation="horizontal")

plt.tight_layout()
fig.savefig("rho_a.png")
plt.show()

The result of this example: rho_a

Cross section of velocity field for quantum vortex

#!/usr/bin/python3

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from scipy.interpolate import interp1d
from wdata.io import WData, Var

# This data set contains vortex solution of SLADE functional. 
# It is provided as supplementary material of publication: 
#   todo
fwtxt="/home/gabrielw/Desktop/st-vortex/sv-ddcc05p00-T0p05.wtxt"
data = WData.load(fwtxt)

j_a = data.j_a[-1] # last frame
rho_a = data.rho_a[-1] # last frame

x = data.xyz[0]
sec=int(data.Nxyz[0]/2)
j_a = j_a[0,sec,:]      # extract x component of j_a along y axis for x=Nx/2 (center of box)
rho_a = rho_a[sec,:]    # extract rho_a along y axis for x=Nx/2 (center of box)
vs = np.abs(j_a/rho_a)  # computer velocity (absolute value)

# interpolate data
vs_int = interp1d(x[:,0], vs, kind='quadratic')
newx=np.linspace(-20,20,200)

# flow for ideal vortex
r = np.linspace(3,40,100)    # take range [3-40]
vs_ideal = 0.5 / r           # vs=1/2r (m=hbar=1, and factor 2 accounts for Cooper pairs)

# plot 
fig, ax = plt.subplots()
ax.plot(x, vs, 'bo', markersize=3, label='data') 
ax.plot(newx, vs_int(newx), 'b', linestyle="-") 
ax.plot(r, vs_ideal, color="k", linestyle="--", label=r'$\sim 1/r$') 
ax.plot(r*(-1.0), vs_ideal, color="k", linestyle="--") 

ax.set(xlabel='y', ylabel=r'$v(0,y)$')
ax.set_xlim([-20,20])
ax.grid()
plt.legend(loc='upper right')

fig.savefig("velocity.png")
plt.show()

Output velocity

Clone repository
  • Data types
  • Examples
    • C examples
    • Python examples
  • Tags
  • VisIt plugin compilation
  • Visit integration
  • Home
  • wdata format concept