From 1714269ba8c5ee1ac37678a479267e05e944f418 Mon Sep 17 00:00:00 2001
From: Francisco Jimenez Forteza <francisco.jimenez@condor1.atlas.local>
Date: Sat, 29 May 2021 12:39:45 +0000
Subject: [PATCH] correcting rd_model_wq_m_a

---
 code_new/Sumit/RD_Fits.ipynb | 81 +++++++++++++++++++++++++++++++++---
 code_new/Sumit/rdown.py      | 16 +++----
 2 files changed, 83 insertions(+), 14 deletions(-)

diff --git a/code_new/Sumit/RD_Fits.ipynb b/code_new/Sumit/RD_Fits.ipynb
index d3cdfcf..688ecb7 100644
--- a/code_new/Sumit/RD_Fits.ipynb
+++ b/code_new/Sumit/RD_Fits.ipynb
@@ -65,7 +65,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
+   "execution_count": 2,
    "metadata": {},
    "outputs": [
     {
@@ -73,7 +73,7 @@
      "output_type": "stream",
      "text": [
       "usage: ipykernel_launcher.py [-h] [-c CONFIG_FILE]\n",
-      "ipykernel_launcher.py: error: unrecognized arguments: -f /work/francisco.jimenez/.local/share/jupyter/runtime/kernel-433f529b-f75c-4320-8450-e97305857525.json\n"
+      "ipykernel_launcher.py: error: unrecognized arguments: -f /work/francisco.jimenez/.local/share/jupyter/runtime/kernel-b3311339-24b7-4dfe-a2d4-890fff02f1cb.json\n"
      ]
     }
    ],
@@ -353,9 +353,56 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 12,
    "metadata": {},
-   "outputs": [],
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "(array([0.55578191, 0.54351639, 0.52079511, 0.49045859, 0.45795517,\n",
+       "        0.43991139, 0.43963542]),\n",
+       " array([11.74090006,  3.88312743,  2.29980777,  1.62209641,  1.25654938,\n",
+       "         1.03071732,  0.86348675]))"
+      ]
+     },
+     "execution_count": 12,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "rdown.QNM_spectrum(mf, af)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 13,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "best fit pars from fit:  [1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  0.8 0.9 1. ]\n"
+     ]
+    },
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "/work/francisco.jimenez/sio/git/rdstackingproject/code_new/rdown.py:81: RuntimeWarning: divide by zero encountered in double_scalars\n",
+      "  w_m_a[i] = qnm[0]/mass\n",
+      "/work/francisco.jimenez/sio/git/rdstackingproject/code_new/rdown.py:150: RuntimeWarning: divide by zero encountered in true_divide\n",
+      "  ansatz += (xvars[i]*np.exp(1j*yvars[i]))*np.exp(-self.time/tau_m_a[i]) * (np.cos(w_m_a[i]*self.time)-1j*np.sin(w_m_a[i]*self.time))\n",
+      "/work/francisco.jimenez/sio/git/rdstackingproject/code_new/rdown.py:150: RuntimeWarning: invalid value encountered in true_divide\n",
+      "  ansatz += (xvars[i]*np.exp(1j*yvars[i]))*np.exp(-self.time/tau_m_a[i]) * (np.cos(w_m_a[i]*self.time)-1j*np.sin(w_m_a[i]*self.time))\n",
+      "/work/francisco.jimenez/sio/git/rdstackingproject/code_new/rdown.py:150: RuntimeWarning: invalid value encountered in multiply\n",
+      "  ansatz += (xvars[i]*np.exp(1j*yvars[i]))*np.exp(-self.time/tau_m_a[i]) * (np.cos(w_m_a[i]*self.time)-1j*np.sin(w_m_a[i]*self.time))\n",
+      "/work/francisco.jimenez/venv/lib/python3.7/site-packages/scipy/optimize/_numdiff.py:497: RuntimeWarning: invalid value encountered in subtract\n",
+      "  df = fun(x) - f0\n"
+     ]
+    }
+   ],
    "source": [
     "# Get a first estimate by trying to fit the data.\n",
     "nll = lambda *args: -rdown_pe.log_likelihood(*args)\n",
@@ -393,7 +440,29 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {},
-   "outputs": [],
+   "outputs": [
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "Process ForkPoolWorker-2:\n",
+      "Process ForkPoolWorker-6:\n",
+      "Process ForkPoolWorker-5:\n",
+      "Process ForkPoolWorker-1:\n",
+      "Process ForkPoolWorker-7:\n",
+      "Process ForkPoolWorker-8:\n",
+      "Process ForkPoolWorker-3:\n",
+      "Process ForkPoolWorker-4:\n",
+      "Traceback (most recent call last):\n",
+      "  File \"/work/francisco.jimenez/local/python-3.7.7/lib/python3.7/multiprocessing/process.py\", line 297, in _bootstrap\n",
+      "    self.run()\n",
+      "Traceback (most recent call last):\n",
+      "Traceback (most recent call last):\n",
+      "Traceback (most recent call last):\n",
+      "Traceback (most recent call last):\n"
+     ]
+    }
+   ],
    "source": [
     "mypool = Pool(nbcores)\n",
     "mypool.size = nbcores\n",
@@ -481,7 +550,7 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "w, tau = rdown.QNM_spectrum()\n",
+    "w, tau = rdown.QNM_spectrum(mf, af)\n",
     "pars = w, tau, mf, af, npamps \n",
     "truths = rd_ut.get_truths(model,pars,fitnoise)"
    ]
diff --git a/code_new/Sumit/rdown.py b/code_new/Sumit/rdown.py
index 29367d3..e57eb5d 100644
--- a/code_new/Sumit/rdown.py
+++ b/code_new/Sumit/rdown.py
@@ -59,12 +59,12 @@ class Ringdown_Spectrum:
             self.tau=-1/(np.imag(omegas_new))*self.mf
 
                
-    def QNM_spectrum(self):
+    def QNM_spectrum(self,mass,spin):
         """ It computes the RD frequencies and damping times in NR units.
         """     
-        omegas_new=np.asarray([self.grav_220[i](a=self.af)[0] for i in range (0,self.n+1)])
-        w_m_a = (np.real(omegas_new))/self.mf
-        tau_m_a=-1/(np.imag(omegas_new))*self.mf
+        omegas_new=np.asarray([self.grav_220[i](a=spin)[0] for i in range (0,self.n+1)])
+        w_m_a = (np.real(omegas_new))/mass
+        tau_m_a=-1/(np.imag(omegas_new))*mass
     
         return (w_m_a, tau_m_a)
     
@@ -159,7 +159,7 @@ class Ringdown_Spectrum:
 
         ansatz = 0
         for i in range (0,self.dim):
-            ansatz += (xvars[i]*np.exp(1j*yvars[i]))*np.exp(-self.time/tau[i]) * (np.cos(w[i]*self.time)-1j*np.sin(w[i]*self.time))
+            ansatz += (xvars[i]*np.exp(1j*yvars[i]))*np.exp(-self.time/self.tau[i]) * (np.cos(self.w[i]*self.time)-1j*np.sin(self.w[i]*self.time))
         # -1j to agree with SXS convention
         return ansatz
     
@@ -200,10 +200,10 @@ class Ringdown_Spectrum:
         mass_vars = theta[-2]
         spin_vars = theta[-1]
 
-        w_m_a , tau_m_a = QNM_spectrum()
+        w_m_a , tau_m_a = self.dict_omega[self.qnm_model](mass_vars,spin_vars)
 
         ansatz = 0
-        for i in range (0,dim):
-            ansatz += (xvars[i]*np.exp(1j*yvars[i]))*np.exp(-timesrd_final_tsh/tau_m_a[i]) * (np.cos(w_m_a[i]*timesrd_final_tsh)-1j*np.sin(w_m_a[i]*timesrd_final_tsh))
+        for i in range (0,self.dim):
+            ansatz += (xvars[i]*np.exp(1j*yvars[i]))*np.exp(-self.time/tau_m_a[i]) * (np.cos(w_m_a[i]*self.time)-1j*np.sin(w_m_a[i]*self.time))
         # -1j to agree with SXS convention
         return ansatz
\ No newline at end of file
-- 
GitLab