Commit fda2201b authored by Antoine RAVETTA's avatar Antoine RAVETTA

reorganization and work on the Kerr collapse

parent 4b35d04d
......@@ -15,72 +15,20 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"ERROR:root:Internal Python error in the inspect module.\n",
"Below is the traceback from this internal error.\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Traceback (most recent call last):\n",
" File \"/home/antoine/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3325, in run_code\n",
" exec(code_obj, self.user_global_ns, self.user_ns)\n",
" File \"<ipython-input-9-de921bce0e9e>\", line 2, in <module>\n",
" from ..CN_classesCCCN import CrankNicolson\n",
"ValueError: attempted relative import beyond top-level package\n",
"\n",
"During handling of the above exception, another exception occurred:\n",
"\n",
"Traceback (most recent call last):\n",
" File \"/home/antoine/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2039, in showtraceback\n",
" stb = value._render_traceback_()\n",
"AttributeError: 'ValueError' object has no attribute '_render_traceback_'\n",
"\n",
"During handling of the above exception, another exception occurred:\n",
"\n",
"Traceback (most recent call last):\n",
" File \"/home/antoine/anaconda3/lib/python3.7/site-packages/IPython/core/ultratb.py\", line 1101, in get_records\n",
" return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)\n",
" File \"/home/antoine/anaconda3/lib/python3.7/site-packages/IPython/core/ultratb.py\", line 319, in wrapped\n",
" return f(*args, **kwargs)\n",
" File \"/home/antoine/anaconda3/lib/python3.7/site-packages/IPython/core/ultratb.py\", line 353, in _fixed_getinnerframes\n",
" records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))\n",
" File \"/home/antoine/anaconda3/lib/python3.7/inspect.py\", line 1502, in getinnerframes\n",
" frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)\n",
" File \"/home/antoine/anaconda3/lib/python3.7/inspect.py\", line 1460, in getframeinfo\n",
" filename = getsourcefile(frame) or getfile(frame)\n",
" File \"/home/antoine/anaconda3/lib/python3.7/inspect.py\", line 696, in getsourcefile\n",
" if getattr(getmodule(object, filename), '__loader__', None) is not None:\n",
" File \"/home/antoine/anaconda3/lib/python3.7/inspect.py\", line 725, in getmodule\n",
" file = getabsfile(object, _filename)\n",
" File \"/home/antoine/anaconda3/lib/python3.7/inspect.py\", line 709, in getabsfile\n",
" return os.path.normcase(os.path.abspath(_filename))\n",
" File \"/home/antoine/anaconda3/lib/python3.7/posixpath.py\", line 383, in abspath\n",
" cwd = os.getcwd()\n",
"FileNotFoundError: [Errno 2] No such file or directory\n"
]
},
{
"ename": "ValueError",
"evalue": "attempted relative import beyond top-level package",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m"
"diff : 5.570423008216336e-08j\n"
]
}
],
"source": [
"import numpy as np\n",
"from ..CN_classesCCCN import CrankNicolson\n",
"from CCCN import CrankNicolson\n",
"\n",
"lambd = 0.7e-6\n",
"\n",
......@@ -120,7 +68,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"metadata": {},
"outputs": [
{
......@@ -128,9 +76,7 @@
"output_type": "stream",
"text": [
"/home/antoine/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:20: RuntimeWarning: divide by zero encountered in true_divide\n",
"/home/antoine/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:20: RuntimeWarning: invalid value encountered in true_divide\n",
"/home/antoine/Desktop/PHY571/codes/CN_classes/CCCN.py:42: RuntimeWarning: invalid value encountered in multiply\n",
" nu = lambda x: - self.delta_z / 4. / self.delta_r * self.V(x) # minus sign for V convention\n"
"/home/antoine/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:20: RuntimeWarning: invalid value encountered in true_divide\n"
]
}
],
......@@ -152,15 +98,22 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"np.savetxt(\"../CN_cylindric_complex_E.dat\", np.abs(crank.E_matrix))\n",
"np.savetxt(\"../CN_cylindric_complex_r_pts.dat\", crank.r_pts)\n",
"np.savetxt(\"../CN_cylindric_complex_z_pts.dat\", crank.z_pts)"
"np.savetxt(\"../CCCN_E.dat\", np.abs(crank.E_matrix))\n",
"np.savetxt(\"../CCCN_r_pts.dat\", crank.r_pts)\n",
"np.savetxt(\"../CCCN_z_pts.dat\", crank.z_pts)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
......
"""
### Adapted class
Term added with new table dimension:
$$
D_t \dfrac{\partial^2 \mathcal{E}}{\partial t^2}
$$
Matrix similar to TP4 without advection.
3D matrix format:
$$
E(z_i, r_j, t_k)
$$
**Warning**: Non linear term treated with **space half step**. Initial conditions at $z=0$ in **2D**.
Half step $\Delta z/2$ in the scheme.
"""
import numpy as np
import scipy.sparse
import scipy.linalg as la
class CrankNicolsonDisp:
"""A class that solves dE/dz = D1*d2E/dr2 + V(r)*dE/dr + D2*d2E/dt2 + f(E)"""
# Cylindrical grid with rectangular time
def set_grid(self, r_max, n_r, z_min, z_max, n_z, t_min, t_max, n_t):
self.r_max, self.n_r = r_max, n_r
self.z_min, self.z_max, self.n_z = z_min, z_max, n_z
self.t_min, self.t_max, self.n_t = t_min, t_max, n_t
self.r_pts, self.delta_r = np.linspace(0, r_max, n_r, retstep=True, endpoint=False, dtype=complex)
self.z_pts, self.delta_z = np.linspace(z_min, z_max, n_z, retstep=True, endpoint=False, dtype=complex)
self.t_pts, self.delta_t = np.linspace(t_min, t_max, n_t, retstep=True, endpoint=False, dtype=complex)
# Parameters of the scheme
# Dr for diffraction, Dt for dispersion
def set_parameters(self, Dr, Dt, V):
# V has to be vectorised
self.Dr, self.Dt, self.V = Dr, Dt, V
# One solving step for r dependency and t dependency
def solve(self, E_init):
# Coefficient of matrices
sig_r = self.Dr * (self.delta_z) / 2. / self.delta_r**2
sig_t = self.Dt * (self.delta_z) / 2. / self.delta_t**2
nu = lambda x : -self.V(x) * (self.delta_z) / 4. / self.delta_r # minus sign for V convention
# Empty solution matrix (z,r,t)
self.E_matrix = np.zeros([self.n_z, self.n_r, self.n_t], dtype=complex)
# Sparse solver
Ar = self._fillAr_sp(sig_r, nu, self.n_r)
Br = self._fillBr_sp(sig_r, nu, self.n_r)
At = self._fillAt_sp(sig_t, self.n_t) # null advection coefficient
Bt = self._fillBt_sp(sig_t, self.n_t) # null advection coefficient
# Set boundary conditions
# Spatial:
# Dirichlet at infinity
Ar[1,-1] = 1.0
Ar[2,-2] = 0.0
Br[-1,-1] = 0.0
Br[-1,-2] = 0.0
# Neumann at r=0
Ar[0,1] = -2*sig_r
Br[0,1] = 2*sig_r
# Time
# Neumann at t=t_min, t_max
for b in [0,1]:
At[1,-b] = 1.0
At[2*b,1-3*b] = 0.0
Bt[-b,-b] = 0.0
Bt[-b,1-3*b] = 0.0
# Propagate
E = E_init.copy()
E_intermediate = E_init.copy()
for n in range(self.n_z):
# General step initialisation
self.E_matrix[n,:,:] = E
# First half step
# r operator solver for each t
for i in range(self.n_t):
E_intermediate[:,i] = la.solve_banded((1,1), Ar, Br.dot(E[:,i]), \
check_finite=False)
# Second half step
# t operator solver for each r
for i in range(self.n_r):
E[i,:] = la.solve_banded((1,1), At, Bt.dot(E_intermediate[i,:]), \
check_finite=False)
# E has been updated, put into E_matrix at next step
# Deep copy of results for export
# np.savetxt ?
def get_E(self):
return self.E_matrix.copy()
# Diagonal packing for banded r
def _fillAr_sp(self, sig, nu, n):
"""Returns a tridiagonal matrix in compact form ab[1+i-j,j]=a[i,j]"""
A = np.zeros([3,n], dtype=complex) # A has three diagonals and size n
# Superdiagonal
A[0,1:] = -(sig - nu(self.r_pts[:-1]))
# Diagonal
A[1] = 1+2*sig
# Subdiagonal
A[2,:-1] = -(sig + nu(self.r_pts[1:]))
return A
# Diagonal packing for banded t
def _fillAt_sp(self, sig, n):
"""Returns a tridiagonal matrix in compact form ab[1+i-j,j]=a[i,j]"""
_o = np.ones(n, dtype=complex)
A = np.zeros([3,n], dtype=complex) # A has three diagonals and size n
# Superdiagonal
A[0,1:] = -sig
# Diagonal
A[1] = 1+2*sig
# Subdiagonal
A[2,:-1] = -sig
return A
# Sparse tridiagonal storage for r
def _fillBr_sp(self, sig, nu, n):
"""Returns a tridiagonal sparse matrix in csr-form"""
_o = np.ones(n, dtype=complex)
supdiag = (sig - nu(self.r_pts[:-1]))
diag = (1-2*sig)*_o
subdiag = (sig + nu(self.r_pts[1:]))
return scipy.sparse.diags([supdiag, diag, subdiag], [1,0,-1], (n,n), format="csr")
# Sparse tridiagonal storage for t
def _fillBt_sp(self, sig, n):
"""Returns a tridiagonal sparse matrix in csr-form"""
_o = np.ones(n, dtype=complex)
supdiag = sig*_o[:-1]
diag = (1-2*sig)*_o
subdiag = sig*_o[:-1]
return scipy.sparse.diags([supdiag, diag, subdiag], [1,0,-1], (n,n), format="csr")
\ No newline at end of file
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"diff : 5.570423008216336e-08j\n",
"disp : -1e-28j\n"
]
}
],
"source": [
"import numpy as np\n",
"from HSCN import CrankNicolsonDisp\n",
"\n",
"lambd = 0.7e-6\n",
"\n",
"k = 2 * np.pi / lambd\n",
"k_2 = 2e-28\n",
"\n",
"w0 = 1e-3\n",
"tp = 85e-15\n",
"#tp = 1\n",
"Pin = 1\n",
"\n",
"diff_coeff = 1j*1/(2 * k)\n",
"#diff_coeff = 0\n",
"#diff_coeff = 1e-4\n",
"disp_coeff = -1j*k_2/2\n",
"#disp_coeff = 1j * 1e-25\n",
"#disp_coeff = 0\n",
"\n",
"print('diff :', diff_coeff)\n",
"print('disp :', disp_coeff)\n",
"\n",
"\n",
"def potential(r):\n",
" try:\n",
" return diff_coeff / r\n",
" except ZeroDivisionError:\n",
" return 0\n",
"\n",
"\n",
"def gaussian(r, t, r0=0, w0=1, t0=0, tp=1, Pin=1):\n",
" return np.sqrt(2*Pin/(np.pi*w0**2)) * np.exp(-(r-r0)** 2/(w0**2) - (t-t0)** 2/(tp**2))\n",
"\n",
"\n",
"def initial_enveloppe(r_pts, t_pts, w0, tp, Pin):\n",
" return np.array([[gaussian(r_pts[i], t_pts[j], w0=w0, tp=tp, Pin=Pin) for j in range(len(t_pts))] \\\n",
" for i in range(len(r_pts))])"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/antoine/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:27: RuntimeWarning: divide by zero encountered in true_divide\n",
"/home/antoine/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:27: RuntimeWarning: invalid value encountered in true_divide\n"
]
}
],
"source": [
"crank = CrankNicolsonDisp()\n",
"\n",
"crank.set_grid(r_max=1e-2, n_r=100, z_min=0, z_max=10, n_z=100, t_min=-5e-13, t_max=5e-13, n_t=100)\n",
"crank.set_parameters(Dr=diff_coeff, Dt=disp_coeff, V=potential)\n",
"\n",
"crank.solve(initial_enveloppe(crank.r_pts, crank.t_pts, w0, tp, Pin))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"np.save(\"../HSCN_E.npy\", np.abs(crank.E_matrix))\n",
"np.save(\"../HSCN_r_pts.npy\", crank.r_pts)\n",
"np.save(\"../HSCN_z_pts.npy\", crank.z_pts)\n",
"np.save(\"../HSCN_t_pts.npy\", crank.t_pts)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 12,
"metadata": {},
"outputs": [
{
......@@ -31,7 +31,7 @@
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"data_path = '../CN_cylindric_complex_'\n",
"data_path = '../CCCN_'\n",
"\n",
"\n",
"def import_data(path):\n",
......@@ -41,9 +41,9 @@
" return data_array, r_pts, z_pts\n",
"\n",
"\n",
"def plot_data(z_pts, r_pts, E_matrix):\n",
"def plot_data(r_pts, z_pts, E_matrix):\n",
" fig, ax = plt.subplots()\n",
" mesh = ax.pcolormesh(r_pts, z_pts, E_matrix.T)\n",
" mesh = ax.pcolormesh(z_pts, r_pts, E_matrix.T)\n",
" ax.set_xlabel('z')\n",
" ax.set_ylabel('r')\n",
" plt.colorbar(mesh, ax=ax)\n",
......@@ -56,16 +56,16 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f19e1eca1d0>]"
"[<matplotlib.lines.Line2D at 0x7f19e2762160>]"
]
},
"execution_count": 9,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
},
......@@ -88,7 +88,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 14,
"metadata": {},
"outputs": [
{
......
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Imaging of the HSCN values\n",
"\n",
"TODO : find a way to save/load 3D arrays\n",
"\n",
"TODO : make a movie out of it"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"ename": "ValueError",
"evalue": "could not convert string to float: \"\\x93NUMPY\\x01\\x00v\\x00{'descr':\"",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-6-b909b49c3304>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 24\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 25\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 26\u001b[0;31m \u001b[0mdata_ary\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mr_pts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mz_pts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mt_pts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mimport_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata_path\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 27\u001b[0m \u001b[0mplot_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mr_pts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mt_pts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata_ary\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m<ipython-input-6-b909b49c3304>\u001b[0m in \u001b[0;36mimport_data\u001b[0;34m(path)\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mimport_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 10\u001b[0;31m \u001b[0mdata_array\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloadtxt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m'E.npy'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencoding\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'latin1'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 11\u001b[0m \u001b[0mr_pts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m'r_pts.npy'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencoding\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'latin1'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[0mz_pts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m'z_pts.npy'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mencoding\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'latin1'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py\u001b[0m in \u001b[0;36mloadtxt\u001b[0;34m(fname, dtype, comments, delimiter, converters, skiprows, usecols, unpack, ndmin, encoding, max_rows)\u001b[0m\n\u001b[1;32m 1139\u001b[0m \u001b[0;31m# converting the data\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1140\u001b[0m \u001b[0mX\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1141\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mread_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_loadtxt_chunksize\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1142\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mX\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1143\u001b[0m \u001b[0mX\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py\u001b[0m in \u001b[0;36mread_data\u001b[0;34m(chunk_size)\u001b[0m\n\u001b[1;32m 1066\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1067\u001b[0m \u001b[0;31m# Convert each value according to its column and store\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1068\u001b[0;31m \u001b[0mitems\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mconv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mval\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mconv\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mval\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mconverters\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvals\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1069\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1070\u001b[0m \u001b[0;31m# Then pack it according to the dtype's nesting\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py\u001b[0m in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 1066\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1067\u001b[0m \u001b[0;31m# Convert each value according to its column and store\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1068\u001b[0;31m \u001b[0mitems\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mconv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mval\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mconv\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mval\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mconverters\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvals\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1069\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1070\u001b[0m \u001b[0;31m# Then pack it according to the dtype's nesting\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py\u001b[0m in \u001b[0;36mfloatconv\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 773\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m'0x'\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 774\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mfloat\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfromhex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 775\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfloat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 776\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 777\u001b[0m \u001b[0mtyp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mValueError\u001b[0m: could not convert string to float: \"\\x93NUMPY\\x01\\x00v\\x00{'descr':\""
]
}
],
"source": [
"%matplotlib inline\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"data_path = '../HSCN_'\n",
"\n",
"\n",
"def import_data(path):\n",
" data_array = np.loadtxt(path + 'E.npy', encoding='latin1')\n",
" r_pts = np.load(path + 'r_pts.npy', encoding='latin1')\n",
" z_pts = np.load(path + 'z_pts.npy', encoding='latin1')\n",
" t_pts = np.load(path + 't_pts.npy', encoding='latin1')\n",
" return data_array, r_pts, z_pts, t_pts\n",
"\n",
"\n",
"def plot_data(r_pts, t_pts, E_matrix):\n",
" fig, ax = plt.subplots()\n",
" mesh = ax.pcolormesh(t_pts, r_pts, E_matrix[0,:,:].T)\n",
" ax.set_xlabel('t')\n",
" ax.set_ylabel('r')\n",
" plt.colorbar(mesh, ax=ax)\n",
" fig.show()\n",
"\n",
"\n",
"data_ary, r_pts, z_pts, t_pts = import_data(data_path)\n",
"plot_data(r_pts, t_pts, data_ary)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
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