{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Copyright (C) 2024 Richard Stiskalek\n",
    "# This program is free software; you can redistribute it and/or modify it\n",
    "# under the terms of the GNU General Public License as published by the\n",
    "# Free Software Foundation; either version 3 of the License, or (at your\n",
    "# option) any later version.\n",
    "#\n",
    "# This program is distributed in the hope that it will be useful, but\n",
    "# WITHOUT ANY WARRANTY; without even the implied warranty of\n",
    "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General\n",
    "# Public License for more details.\n",
    "#\n",
    "# You should have received a copy of the GNU General Public License along\n",
    "# with this program; if not, write to the Free Software Foundation, Inc.,\n",
    "# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from tqdm import trange\n",
    "from joblib import dump\n",
    "from h5py import File\n",
    "\n",
    "import csiborgtools\n",
    "\n",
    "%matplotlib inline\n",
    "%load_ext autoreload\n",
    "%autoreload 2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "fpath = \"/mnt/extraspace/rstiskalek/catalogs/PV_compilation.hdf5\"\n",
    "\n",
    "with File(fpath, 'r') as f:\n",
    "    RA_2MTF = f[\"2MTF/RA\"][...]\n",
    "    DEC_2MTF = f[\"2MTF/DEC\"][...]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saving to  /mnt/extraspace/rstiskalek/csiborg_postprocessing/flow_mock/Carrick2MTFmock_seed0.hdf5\n"
     ]
    }
   ],
   "source": [
    "!rm /mnt/extraspace/rstiskalek/csiborg_postprocessing/flow_mock/*\n",
    "\n",
    "\n",
    "reader = csiborgtools.read.Carrick2015Field()\n",
    "velocity = reader.velocity_field()\n",
    "boxsize = csiborgtools.simname2boxsize(\"Carrick2015\")\n",
    "\n",
    "mean_mag = 10.31\n",
    "std_mag = 0.83\n",
    "\n",
    "kmax = 1\n",
    "seed = 53\n",
    "\n",
    "for k in trange(kmax):\n",
    "    mock, truths = csiborgtools.flow.mock_Carrick2MTF(\n",
    "        velocity, boxsize, RA_2MTF, DEC_2MTF,\n",
    "        mean_mag=mean_mag, std_mag=std_mag,\n",
    "        seed=seed, verbose=True)\n",
    "    seed += 1\n",
    "\n",
    "    fname = f\"/mnt/extraspace/rstiskalek/csiborg_postprocessing/flow_mock/Carrick2MTFmock_seed{k}.hdf5\"  # noqa\n",
    "    print(\"Saving to \", fname)\n",
    "    with File(fname, 'w') as f:\n",
    "        for key in mock.keys():\n",
    "            f.create_dataset(key, data=mock[key])\n",
    "\n",
    "    fname_truths = fname.replace(\".hdf5\", \"_truths.pkl\")\n",
    "    dump(truths, fname_truths)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 11940 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure()\n",
    "plt.hist(mock[\"DEC\"], bins=\"auto\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "venv_csiborg",
   "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.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
