|  | 
| 26 | 26 |    "metadata": {}, | 
| 27 | 27 |    "outputs": [], | 
| 28 | 28 |    "source": [ | 
|  | 29 | +    "from __future__ import annotations\n", | 
|  | 30 | +    "\n", | 
| 29 | 31 |     "import numpy as np\n", | 
| 30 |  | -    "from matplotlib import pyplot as plt\n", | 
| 31 | 32 |     "from IPython.core.pylabtools import figsize\n", | 
| 32 |  | -    "figsize(10,3)\n", | 
|  | 33 | +    "from matplotlib import pyplot as plt\n", | 
|  | 34 | +    "\n", | 
|  | 35 | +    "figsize(10, 3)\n", | 
| 33 | 36 |     "\n", | 
| 34 | 37 |     "try:\n", | 
| 35 |  | -    "    from LC import LightCurve\n", | 
| 36 | 38 |     "    from HOP import Hopject\n", | 
|  | 39 | +    "    from LC import LightCurve\n", | 
| 37 | 40 |     "    from LC_Set import LC_Set\n", | 
| 38 | 41 |     "except ModuleNotFoundError:\n", | 
| 39 |  | -    "    print('If you installed the zipped version from GitHub, you have to delete \"lightcurves.\" in the import statements of the above files')" | 
|  | 42 | +    "    print(\n", | 
|  | 43 | +    "        'If you installed the zipped version from GitHub, you have to delete \"lightcurves.\" in the import statements of the above files'\n", | 
|  | 44 | +    "    )" | 
| 40 | 45 |    ] | 
| 41 | 46 |   }, | 
| 42 | 47 |   { | 
|  | 
| 77 | 82 |     } | 
| 78 | 83 |    ], | 
| 79 | 84 |    "source": [ | 
| 80 |  | -    "time, flux, flux_error = np.load('./lc.npy') #mock lc with gaussian flares\n", | 
| 81 |  | -    "time += 55000 #e.g. MJD\n", | 
|  | 85 | +    "time, flux, flux_error = np.load(\"./lc.npy\")  # mock lc with gaussian flares\n", | 
|  | 86 | +    "time += 55000  # e.g. MJD\n", | 
| 82 | 87 |     "lc = LightCurve(time, flux, flux_error)\n", | 
| 83 | 88 |     "lc.plot_lc()\n", | 
| 84 | 89 |     "plt.legend()" | 
|  | 
| 122 | 127 |     } | 
| 123 | 128 |    ], | 
| 124 | 129 |    "source": [ | 
| 125 |  | -    "block_pbin, block_val, block_val_error, edge_index, edges = lc.get_bblocks(p0_value=0.05)\n", | 
| 126 |  | -    "#for more information on edges and edge_index see Appendix A2\n", | 
|  | 130 | +    "block_pbin, block_val, block_val_error, edge_index, edges = lc.get_bblocks(\n", | 
|  | 131 | +    "    p0_value=0.05\n", | 
|  | 132 | +    ")\n", | 
|  | 133 | +    "# for more information on edges and edge_index see Appendix A2\n", | 
| 127 | 134 |     "lc.plot_bblocks()\n", | 
| 128 | 135 |     "plt.legend()" | 
| 129 | 136 |    ] | 
|  | 
| 173 | 180 |     } | 
| 174 | 181 |    ], | 
| 175 | 182 |    "source": [ | 
| 176 |  | -    "hops_bl = lc.find_hop('baseline')\n", | 
| 177 |  | -    "print('hops_bl is a list of Hopjects with interesting attributes, see HOP.py')\n", | 
|  | 183 | +    "hops_bl = lc.find_hop(\"baseline\")\n", | 
|  | 184 | +    "print(\"hops_bl is a list of Hopjects with interesting attributes, see HOP.py\")\n", | 
| 178 | 185 |     "print(hops_bl)\n", | 
| 179 | 186 |     "\n", | 
| 180 | 187 |     "hop = hops_bl[0]\n", | 
|  | 
| 220 | 227 |     } | 
| 221 | 228 |    ], | 
| 222 | 229 |    "source": [ | 
| 223 |  | -    "hops_half = lc.find_hop('half', lc_edges='add')\n", | 
| 224 |  | -    "#one could add the edges of the light curve as start and end of HOP if there is a peak\n", | 
|  | 230 | +    "hops_half = lc.find_hop(\"half\", lc_edges=\"add\")\n", | 
|  | 231 | +    "# one could add the edges of the light curve as start and end of HOP if there is a peak\n", | 
| 225 | 232 |     "\n", | 
| 226 | 233 |     "hop = hops_half[0]\n", | 
| 227 | 234 |     "print(hop.start_time, hop.peak_time, hop.end_time)\n", | 
|  | 
| 266 | 273 |     } | 
| 267 | 274 |    ], | 
| 268 | 275 |    "source": [ | 
| 269 |  | -    "hops_flip = lc.find_hop('flip', lc_edges='neglect') \n", | 
| 270 |  | -    "#or one could conservatively neglect the edges of the light curve \n", | 
| 271 |  | -    "#because it is uncertain whether there would be more decrease/increase of flux\n", | 
|  | 276 | +    "hops_flip = lc.find_hop(\"flip\", lc_edges=\"neglect\")\n", | 
|  | 277 | +    "# or one could conservatively neglect the edges of the light curve\n", | 
|  | 278 | +    "# because it is uncertain whether there would be more decrease/increase of flux\n", | 
| 272 | 279 |     "\n", | 
| 273 | 280 |     "hop = hops_flip[0]\n", | 
| 274 | 281 |     "print(hop.start_time, hop.peak_time, hop.end_time)\n", | 
|  | 
| 323 | 330 |     } | 
| 324 | 331 |    ], | 
| 325 | 332 |    "source": [ | 
| 326 |  | -    "hops_sharp = lc.find_hop('sharp', lc_edges='neglect') \n", | 
|  | 333 | +    "hops_sharp = lc.find_hop(\"sharp\", lc_edges=\"neglect\")\n", | 
| 327 | 334 |     "\n", | 
| 328 | 335 |     "hop = hops_sharp[0]\n", | 
| 329 | 336 |     "print(hop.start_time, hop.peak_time, hop.end_time)\n", | 
|  | 
| 361 | 368 |     } | 
| 362 | 369 |    ], | 
| 363 | 370 |    "source": [ | 
| 364 |  | -    "lc.plot_all_hop(lc_edges='neglect')" | 
|  | 371 | +    "lc.plot_all_hop(lc_edges=\"neglect\")" | 
| 365 | 372 |    ] | 
| 366 | 373 |   }, | 
| 367 | 374 |   { | 
|  | 
| 400 | 407 |    ], | 
| 401 | 408 |    "source": [ | 
| 402 | 409 |     "hop = hops_flip[3]\n", | 
| 403 |  | -    "print('asymmetry measure: ', hop.asym)\n", | 
|  | 410 | +    "print(\"asymmetry measure: \", hop.asym)\n", | 
| 404 | 411 |     "hop.plot_hop()" | 
| 405 | 412 |    ] | 
| 406 | 413 |   }, | 
|  | 
| 549 | 556 |     } | 
| 550 | 557 |    ], | 
| 551 | 558 |    "source": [ | 
| 552 |  | -    "time = np.arange(0, 2000, 1)        # e.g. daily binning for 12 years = 4380 days of observation\n", | 
| 553 |  | -    "N_b=len(time)         # number of bins\n", | 
|  | 559 | +    "time = np.arange(\n", | 
|  | 560 | +    "    0, 2000, 1\n", | 
|  | 561 | +    ")  # e.g. daily binning for 12 years = 4380 days of observation\n", | 
|  | 562 | +    "N_b = len(time)  # number of bins\n", | 
| 554 | 563 |     "flux = np.ones(N_b)\n", | 
| 555 |  | -    "rel_flux_error = 0.1       # flux error ~ 5% \n", | 
| 556 |  | -    "noise = np.random.normal(0, 0.07, N_b)        # white noise backround with strength \n", | 
|  | 564 | +    "rel_flux_error = 0.1  # flux error ~ 5%\n", | 
|  | 565 | +    "noise = np.random.normal(0, 0.07, N_b)  # white noise backround with strength\n", | 
| 557 | 566 |     "\n", | 
| 558 | 567 |     "# maximum values for gaussian flares\n", | 
| 559 | 568 |     "amp_max = 100\n", | 
| 560 | 569 |     "cen_max = 4380\n", | 
| 561 | 570 |     "wid_max = 40\n", | 
| 562 | 571 |     "\n", | 
|  | 572 | +    "\n", | 
| 563 | 573 |     "def gaussian(x, amp, cen, wid):\n", | 
| 564 | 574 |     "    \"1-d Gaussian: gaussian(x=data, amp, cen, wid)\"\n", | 
| 565 |  | -    "    return (amp / (np.sqrt(2*np.pi) * wid)) * np.exp(-(x-cen)**2 / (2*wid**2))\n", | 
|  | 575 | +    "    return (amp / (np.sqrt(2 * np.pi) * wid)) * np.exp(-((x - cen) ** 2) / (2 * wid**2))\n", | 
|  | 576 | +    "\n", | 
| 566 | 577 |     "\n", | 
| 567 | 578 |     "def rand_gauss(x, amp_max, cen_max, wid_max):\n", | 
| 568 | 579 |     "    \"random 1-d Gaussian\"\n", | 
| 569 | 580 |     "    \"takes maximum values for parameters and multiplies each with uniform random number [0,1) ... 0 aba kee1\"\n", | 
| 570 | 581 |     "    \"https://numpy.org/doc/stable/reference/random/generated/numpy.random.random.html\"\n", | 
| 571 | 582 |     "    amp = np.random.random(1) * amp_max\n", | 
| 572 | 583 |     "    cen = np.random.random(1) * cen_max\n", | 
| 573 |  | -    "    #wid = np.random.random(1) * wid_max\n", | 
| 574 |  | -    "    wid = amp*0.25       # assume that flares are self similar; always same shape\n", | 
| 575 |  | -    "    return(gaussian(x, amp, cen, wid))\n", | 
|  | 584 | +    "    # wid = np.random.random(1) * wid_max\n", | 
|  | 585 | +    "    wid = amp * 0.25  # assume that flares are self similar; always same shape\n", | 
|  | 586 | +    "    return gaussian(x, amp, cen, wid)\n", | 
|  | 587 | +    "\n", | 
| 576 | 588 |     "\n", | 
| 577 | 589 |     "lc_array = np.zeros(10, dtype=object)\n", | 
| 578 | 590 |     "for l in range(10):\n", | 
|  | 
| 584 | 596 |     "    flux_error = flux * rel_flux_error\n", | 
| 585 | 597 |     "    lc = LightCurve(time, flux, flux_error)\n", | 
| 586 | 598 |     "    lc.get_bblocks()\n", | 
| 587 |  | -    "    lc.find_hop('flip')\n", | 
|  | 599 | +    "    lc.find_hop(\"flip\")\n", | 
| 588 | 600 |     "    lc_array[l] = lc\n", | 
| 589 |  | -    "    \n", | 
|  | 601 | +    "\n", | 
| 590 | 602 |     "    plt.figure(l)\n", | 
| 591 | 603 |     "    lc.plot_lc()\n", | 
| 592 | 604 |     "    lc.plot_bblocks()\n", | 
| 593 | 605 |     "    lc.plot_hop()\n", | 
| 594 |  | -    "    plt.xlabel('Time')\n", | 
| 595 |  | -    "    plt.ylabel('Flux')" | 
|  | 606 | +    "    plt.xlabel(\"Time\")\n", | 
|  | 607 | +    "    plt.ylabel(\"Flux\")" | 
| 596 | 608 |    ] | 
| 597 | 609 |   }, | 
| 598 | 610 |   { | 
|  | 
| 633 | 645 |     } | 
| 634 | 646 |    ], | 
| 635 | 647 |    "source": [ | 
| 636 |  | -    "lcs = LC_Set(lc_array, block_min = 2)       #single block flares do not resolve asymmetry\n", | 
|  | 648 | +    "lcs = LC_Set(lc_array, block_min=2)  # single block flares do not resolve asymmetry\n", | 
| 637 | 649 |     "lcs.plot_asym()\n", | 
| 638 | 650 |     "plt.legend()\n", | 
| 639 |  | -    "plt.ylabel('probability density')\n", | 
| 640 |  | -    "plt.xlabel('asymmetry measure')\n", | 
|  | 651 | +    "plt.ylabel(\"probability density\")\n", | 
|  | 652 | +    "plt.xlabel(\"asymmetry measure\")\n", | 
| 641 | 653 |     "# for histogram binning see https://docs.astropy.org/en/stable/api/astropy.visualization.hist.html" | 
| 642 | 654 |    ] | 
| 643 | 655 |   }, | 
|  | 
| 712 | 724 |     } | 
| 713 | 725 |    ], | 
| 714 | 726 |    "source": [ | 
| 715 |  | -    "time, flux, flux_error = np.load('./lc.npy') #mock lc with gaussian flares\n", | 
| 716 |  | -    "time += 55000 #e.g. MJD\n", | 
| 717 |  | -    "fig = plt.figure(0,(10,3))\n", | 
| 718 |  | -    "time_one = np.ones(len(time)) #used for plotting\n", | 
|  | 727 | +    "time, flux, flux_error = np.load(\"./lc.npy\")  # mock lc with gaussian flares\n", | 
|  | 728 | +    "time += 55000  # e.g. MJD\n", | 
|  | 729 | +    "fig = plt.figure(0, (10, 3))\n", | 
|  | 730 | +    "time_one = np.ones(len(time))  # used for plotting\n", | 
| 719 | 731 |     "ax0 = fig.add_subplot(211)\n", | 
| 720 |  | -    "plt.plot(time,time_one,linewidth=0,label='data bin',marker='+',c = 'blue', markersize=10)\n", | 
| 721 |  | -    "plt.axvline(edges[0],color='red',label='edges',linewidth=1)\n", | 
| 722 |  | -    "for i in range(1,len(edges)):\n", | 
| 723 |  | -    "    plt.axvline(edges[i],color='red',linewidth=1)\n", | 
| 724 |  | -    "plt.xlabel('Time/ MJD', fontsize = 14)\n", | 
|  | 732 | +    "plt.plot(\n", | 
|  | 733 | +    "    time, time_one, linewidth=0, label=\"data bin\", marker=\"+\", c=\"blue\", markersize=10\n", | 
|  | 734 | +    ")\n", | 
|  | 735 | +    "plt.axvline(edges[0], color=\"red\", label=\"edges\", linewidth=1)\n", | 
|  | 736 | +    "for i in range(1, len(edges)):\n", | 
|  | 737 | +    "    plt.axvline(edges[i], color=\"red\", linewidth=1)\n", | 
|  | 738 | +    "plt.xlabel(\"Time/ MJD\", fontsize=14)\n", | 
| 725 | 739 |     "plt.yticks([])\n", | 
| 726 | 740 |     "ax0.xaxis.tick_top()\n", | 
| 727 |  | -    "ax0.xaxis.set_label_position('top') \n", | 
|  | 741 | +    "ax0.xaxis.set_label_position(\"top\")\n", | 
| 728 | 742 |     "plt.legend()\n", | 
| 729 | 743 |     "\n", | 
| 730 | 744 |     "ax1 = fig.add_subplot(212)\n", | 
| 731 |  | -    "plt.plot(time_one,linewidth=0,label='data bin',marker='+',c = 'blue', markersize=10)\n", | 
| 732 |  | -    "plt.axvline(edge_index[0],color='green',label='edge_index',linewidth=1)\n", | 
| 733 |  | -    "for i in range(1,len(edge_index)):\n", | 
| 734 |  | -    "    plt.axvline(edge_index[i],color='green',linewidth=1)\n", | 
| 735 |  | -    "plt.xlabel('Time array index', fontsize = 14)\n", | 
|  | 745 | +    "plt.plot(time_one, linewidth=0, label=\"data bin\", marker=\"+\", c=\"blue\", markersize=10)\n", | 
|  | 746 | +    "plt.axvline(edge_index[0], color=\"green\", label=\"edge_index\", linewidth=1)\n", | 
|  | 747 | +    "for i in range(1, len(edge_index)):\n", | 
|  | 748 | +    "    plt.axvline(edge_index[i], color=\"green\", linewidth=1)\n", | 
|  | 749 | +    "plt.xlabel(\"Time array index\", fontsize=14)\n", | 
| 736 | 750 |     "plt.yticks([])\n", | 
| 737 | 751 |     "plt.legend()\n", | 
| 738 | 752 |     "plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0.2, hspace=0)" | 
|  | 
0 commit comments