{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-05-07T15:32:31.772870Z",
     "start_time": "2025-05-07T15:32:29.860423Z"
    }
   },
   "source": [
    "from matplotlib import pyplot as plt\n",
    "from flandre.utils.RfMat import RfMat\n",
    "import cupy as cp\n",
    "\n",
    "from flandre.beamformer.das import gen_pwi\n",
    "from flandre.beamformer.dist import direct_dist\n",
    "from flandre.utils.Config import DeviceConfig\n",
    "from flandre.utils.Msg import ImageArgMsg\n",
    "from flandre.utils.RfSequence import RfSequence\n",
    "\n",
    "arg = ImageArgMsg(\n",
    "    sender='',\n",
    "    t_end=2900,\n",
    "    t_start=0,\n",
    "    v2=1524,\n",
    "    dct_center=1086,\n",
    "    dct_bandwidth=915,\n",
    "    f_rows=6002,\n",
    "    beta=40,\n",
    "    tgc=0,\n",
    "    g8=80\n",
    ")\n",
    "rff = RfSequence('/run/media/lambda/b86dccdc-f134-464b-a310-6575ee9ae85c/us/baby789,S=(256 6002),M=PWI,U=120')\n",
    "\n",
    "dc = DeviceConfig(v2=1540, rows=5999)\n",
    "pwi, _, la = gen_pwi(direct_dist(dc, p=cp), dc)\n",
    "print(la)\n",
    "\n",
    "data = RfMat.from_rf_frame(rff.frames[1000], device='gpu')\n",
    "data = data.dct_center(arg.dct_center, arg.dct_bandwidth)\n",
    "data = data.call(lambda m: m.astype(cp.int16))\n",
    "data = data.call(pwi)\n",
    "data = data.call(cp.asarray, order='C')\n",
    "data = data.argrelextrema()\n",
    "data = data.conv_guass(b=arg.beta * 0.01)\n",
    "data = data.crop(arg.t_start, arg.t_end)\n",
    "data = data.time_gain_compensation_global((1 - arg.g8 * (1.0 / 128)) ** 2)\n",
    "data = data.rotate90()\n",
    "\n",
    "data.png('/home/lambda/source/scarlet/flandre/@DS/test.png', pre=300)\n",
    "\n",
    "data.cpu().jupyter(figsize=(30, 30), aspect=0.3)\n"
   ],
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/lambda/source/scarlet/flandre/.venv/lib/python3.12/site-packages/cupyx/jit/_interface.py:173: FutureWarning: cupyx.jit.rawkernel is experimental. The interface can change in the future.\n",
      "  cupy._util.experimental('cupyx.jit.rawkernel')\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2974\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 3000x3000 with 1 Axes>"
      ],
      "image/png": "[encoded data, 959580 characters]"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "execution_count": 1
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "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.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
