Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ updates:
actions:
patterns:
- "*"

3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,3 @@ jobs:

- name: Test package
run: pytest



3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.11.13"
rev: "v0.12.1"
hooks:
# id: ruff-check would go here if using both
- id: ruff-format
- id: ruff-check
args: ["--fix", "--show-fixes"]

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

This is the lightcurves repository. Check it out: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1OqafFK4FQA_tBwTTnYMG-1D5uhTQ5X0D#scrollTo=european-mechanism) <br>
See here for scientific application of this code:
https://pos.sissa.it/395/868
https://pos.sissa.it/395/868

## LC.py
Initialize a LightCurve object based on time, flux and flux_error.
Initialize a LightCurve object based on time, flux and flux_error.
Study its Bayesian block representation (based on Scargle et al. 2013 https://ui.adsabs.harvard.edu/abs/2013arXiv1304.2818S/abstract ).<br>
Characterize flares (start, peak, end time) with the HOP algorithm (following Meyer et al. 2019 https://ui.adsabs.harvard.edu/abs/2019ApJ...877...39M/abstract ). There are four different methods to define flares (baseline, half, flip, sharp) as illustrated in the Jupyter Notebook.
Characterize flares (start, peak, end time) with the HOP algorithm (following Meyer et al. 2019 https://ui.adsabs.harvard.edu/abs/2019ApJ...877...39M/abstract ). There are four different methods to define flares (baseline, half, flip, sharp) as illustrated in the Jupyter Notebook.

## HOP.py
Initialize a Hopject to consider parameters of an individual flare.
Expand Down
110 changes: 62 additions & 48 deletions illustration_lightcurve.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@
"metadata": {},
"outputs": [],
"source": [
"from __future__ import annotations\n",
"\n",
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"from IPython.core.pylabtools import figsize\n",
"figsize(10,3)\n",
"from matplotlib import pyplot as plt\n",
"\n",
"figsize(10, 3)\n",
"\n",
"try:\n",
" from LC import LightCurve\n",
" from HOP import Hopject\n",
" from LC import LightCurve\n",
" from LC_Set import LC_Set\n",
"except ModuleNotFoundError:\n",
" print('If you installed the zipped version from GitHub, you have to delete \"lightcurves.\" in the import statements of the above files')"
" print(\n",
" 'If you installed the zipped version from GitHub, you have to delete \"lightcurves.\" in the import statements of the above files'\n",
" )"
]
},
{
Expand Down Expand Up @@ -77,8 +82,8 @@
}
],
"source": [
"time, flux, flux_error = np.load('./lc.npy') #mock lc with gaussian flares\n",
"time += 55000 #e.g. MJD\n",
"time, flux, flux_error = np.load(\"./lc.npy\") # mock lc with gaussian flares\n",
"time += 55000 # e.g. MJD\n",
"lc = LightCurve(time, flux, flux_error)\n",
"lc.plot_lc()\n",
"plt.legend()"
Expand Down Expand Up @@ -122,8 +127,10 @@
}
],
"source": [
"block_pbin, block_val, block_val_error, edge_index, edges = lc.get_bblocks(p0_value=0.05)\n",
"#for more information on edges and edge_index see Appendix A2\n",
"block_pbin, block_val, block_val_error, edge_index, edges = lc.get_bblocks(\n",
" p0_value=0.05\n",
")\n",
"# for more information on edges and edge_index see Appendix A2\n",
"lc.plot_bblocks()\n",
"plt.legend()"
]
Expand Down Expand Up @@ -173,8 +180,8 @@
}
],
"source": [
"hops_bl = lc.find_hop('baseline')\n",
"print('hops_bl is a list of Hopjects with interesting attributes, see HOP.py')\n",
"hops_bl = lc.find_hop(\"baseline\")\n",
"print(\"hops_bl is a list of Hopjects with interesting attributes, see HOP.py\")\n",
"print(hops_bl)\n",
"\n",
"hop = hops_bl[0]\n",
Expand Down Expand Up @@ -220,8 +227,8 @@
}
],
"source": [
"hops_half = lc.find_hop('half', lc_edges='add')\n",
"#one could add the edges of the light curve as start and end of HOP if there is a peak\n",
"hops_half = lc.find_hop(\"half\", lc_edges=\"add\")\n",
"# one could add the edges of the light curve as start and end of HOP if there is a peak\n",
"\n",
"hop = hops_half[0]\n",
"print(hop.start_time, hop.peak_time, hop.end_time)\n",
Expand Down Expand Up @@ -266,9 +273,9 @@
}
],
"source": [
"hops_flip = lc.find_hop('flip', lc_edges='neglect') \n",
"#or one could conservatively neglect the edges of the light curve \n",
"#because it is uncertain whether there would be more decrease/increase of flux\n",
"hops_flip = lc.find_hop(\"flip\", lc_edges=\"neglect\")\n",
"# or one could conservatively neglect the edges of the light curve\n",
"# because it is uncertain whether there would be more decrease/increase of flux\n",
"\n",
"hop = hops_flip[0]\n",
"print(hop.start_time, hop.peak_time, hop.end_time)\n",
Expand Down Expand Up @@ -323,7 +330,7 @@
}
],
"source": [
"hops_sharp = lc.find_hop('sharp', lc_edges='neglect') \n",
"hops_sharp = lc.find_hop(\"sharp\", lc_edges=\"neglect\")\n",
"\n",
"hop = hops_sharp[0]\n",
"print(hop.start_time, hop.peak_time, hop.end_time)\n",
Expand Down Expand Up @@ -361,7 +368,7 @@
}
],
"source": [
"lc.plot_all_hop(lc_edges='neglect')"
"lc.plot_all_hop(lc_edges=\"neglect\")"
]
},
{
Expand Down Expand Up @@ -400,7 +407,7 @@
],
"source": [
"hop = hops_flip[3]\n",
"print('asymmetry measure: ', hop.asym)\n",
"print(\"asymmetry measure: \", hop.asym)\n",
"hop.plot_hop()"
]
},
Expand Down Expand Up @@ -549,30 +556,35 @@
}
],
"source": [
"time = np.arange(0, 2000, 1) # e.g. daily binning for 12 years = 4380 days of observation\n",
"N_b=len(time) # number of bins\n",
"time = np.arange(\n",
" 0, 2000, 1\n",
") # e.g. daily binning for 12 years = 4380 days of observation\n",
"N_b = len(time) # number of bins\n",
"flux = np.ones(N_b)\n",
"rel_flux_error = 0.1 # flux error ~ 5% \n",
"noise = np.random.normal(0, 0.07, N_b) # white noise backround with strength \n",
"rel_flux_error = 0.1 # flux error ~ 5%\n",
"noise = np.random.normal(0, 0.07, N_b) # white noise backround with strength\n",
"\n",
"# maximum values for gaussian flares\n",
"amp_max = 100\n",
"cen_max = 4380\n",
"wid_max = 40\n",
"\n",
"\n",
"def gaussian(x, amp, cen, wid):\n",
" \"1-d Gaussian: gaussian(x=data, amp, cen, wid)\"\n",
" return (amp / (np.sqrt(2*np.pi) * wid)) * np.exp(-(x-cen)**2 / (2*wid**2))\n",
" return (amp / (np.sqrt(2 * np.pi) * wid)) * np.exp(-((x - cen) ** 2) / (2 * wid**2))\n",
"\n",
"\n",
"def rand_gauss(x, amp_max, cen_max, wid_max):\n",
" \"random 1-d Gaussian\"\n",
" \"takes maximum values for parameters and multiplies each with uniform random number [0,1) ... 0 aba kee1\"\n",
" \"https://numpy.org/doc/stable/reference/random/generated/numpy.random.random.html\"\n",
" amp = np.random.random(1) * amp_max\n",
" cen = np.random.random(1) * cen_max\n",
" #wid = np.random.random(1) * wid_max\n",
" wid = amp*0.25 # assume that flares are self similar; always same shape\n",
" return(gaussian(x, amp, cen, wid))\n",
" # wid = np.random.random(1) * wid_max\n",
" wid = amp * 0.25 # assume that flares are self similar; always same shape\n",
" return gaussian(x, amp, cen, wid)\n",
"\n",
"\n",
"lc_array = np.zeros(10, dtype=object)\n",
"for l in range(10):\n",
Expand All @@ -584,15 +596,15 @@
" flux_error = flux * rel_flux_error\n",
" lc = LightCurve(time, flux, flux_error)\n",
" lc.get_bblocks()\n",
" lc.find_hop('flip')\n",
" lc.find_hop(\"flip\")\n",
" lc_array[l] = lc\n",
" \n",
"\n",
" plt.figure(l)\n",
" lc.plot_lc()\n",
" lc.plot_bblocks()\n",
" lc.plot_hop()\n",
" plt.xlabel('Time')\n",
" plt.ylabel('Flux')"
" plt.xlabel(\"Time\")\n",
" plt.ylabel(\"Flux\")"
]
},
{
Expand Down Expand Up @@ -633,11 +645,11 @@
}
],
"source": [
"lcs = LC_Set(lc_array, block_min = 2) #single block flares do not resolve asymmetry\n",
"lcs = LC_Set(lc_array, block_min=2) # single block flares do not resolve asymmetry\n",
"lcs.plot_asym()\n",
"plt.legend()\n",
"plt.ylabel('probability density')\n",
"plt.xlabel('asymmetry measure')\n",
"plt.ylabel(\"probability density\")\n",
"plt.xlabel(\"asymmetry measure\")\n",
"# for histogram binning see https://docs.astropy.org/en/stable/api/astropy.visualization.hist.html"
]
},
Expand Down Expand Up @@ -712,27 +724,29 @@
}
],
"source": [
"time, flux, flux_error = np.load('./lc.npy') #mock lc with gaussian flares\n",
"time += 55000 #e.g. MJD\n",
"fig = plt.figure(0,(10,3))\n",
"time_one = np.ones(len(time)) #used for plotting\n",
"time, flux, flux_error = np.load(\"./lc.npy\") # mock lc with gaussian flares\n",
"time += 55000 # e.g. MJD\n",
"fig = plt.figure(0, (10, 3))\n",
"time_one = np.ones(len(time)) # used for plotting\n",
"ax0 = fig.add_subplot(211)\n",
"plt.plot(time,time_one,linewidth=0,label='data bin',marker='+',c = 'blue', markersize=10)\n",
"plt.axvline(edges[0],color='red',label='edges',linewidth=1)\n",
"for i in range(1,len(edges)):\n",
" plt.axvline(edges[i],color='red',linewidth=1)\n",
"plt.xlabel('Time/ MJD', fontsize = 14)\n",
"plt.plot(\n",
" time, time_one, linewidth=0, label=\"data bin\", marker=\"+\", c=\"blue\", markersize=10\n",
")\n",
"plt.axvline(edges[0], color=\"red\", label=\"edges\", linewidth=1)\n",
"for i in range(1, len(edges)):\n",
" plt.axvline(edges[i], color=\"red\", linewidth=1)\n",
"plt.xlabel(\"Time/ MJD\", fontsize=14)\n",
"plt.yticks([])\n",
"ax0.xaxis.tick_top()\n",
"ax0.xaxis.set_label_position('top') \n",
"ax0.xaxis.set_label_position(\"top\")\n",
"plt.legend()\n",
"\n",
"ax1 = fig.add_subplot(212)\n",
"plt.plot(time_one,linewidth=0,label='data bin',marker='+',c = 'blue', markersize=10)\n",
"plt.axvline(edge_index[0],color='green',label='edge_index',linewidth=1)\n",
"for i in range(1,len(edge_index)):\n",
" plt.axvline(edge_index[i],color='green',linewidth=1)\n",
"plt.xlabel('Time array index', fontsize = 14)\n",
"plt.plot(time_one, linewidth=0, label=\"data bin\", marker=\"+\", c=\"blue\", markersize=10)\n",
"plt.axvline(edge_index[0], color=\"green\", label=\"edge_index\", linewidth=1)\n",
"for i in range(1, len(edge_index)):\n",
" plt.axvline(edge_index[i], color=\"green\", linewidth=1)\n",
"plt.xlabel(\"Time array index\", fontsize=14)\n",
"plt.yticks([])\n",
"plt.legend()\n",
"plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0.2, hspace=0)"
Expand Down
7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ classifiers = [

requires-python = ">=3.10"

#list of dependencies.
#list of dependencies.
#do not list imports from standard library like logging or pickle
dependencies = [
"astropy",
Expand Down Expand Up @@ -87,8 +87,3 @@ isort.required-imports = ["from __future__ import annotations"]

[tool.ruff.lint.per-file-ignores]
"tests/**" = ["T20"]





Loading