Skip to content

Instantly share code, notes, and snippets.

@taldcroft
Created March 20, 2020 18:14
Show Gist options
  • Save taldcroft/bf5af3788e39946dd6695ebaef1632fc to your computer and use it in GitHub Desktop.
Save taldcroft/bf5af3788e39946dd6695ebaef1632fc to your computer and use it in GitHub Desktop.
Combine cheta logical intervals
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using matplotlib backend: MacOSX\n"
]
}
],
"source": [
"from cheta.utils import logical_intervals\n",
"from kadi.events.query import combine_intervals\n",
"from cxotime import CxoTime\n",
"from astropy.time import Time\n",
"import astropy.units as u\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib\n",
"import operator"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"t = Time('2000:001') + np.arange(1, 1000) * u.s"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"start = t.yday[0]\n",
"stop = t.yday[-1]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"t_sec = t.cxcsec"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"y1 = np.sin(t_sec * 2 * np.pi / 100)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"y2 = np.sin(t_sec * 2 * np.pi / 150)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"intervals0 = logical_intervals(t_sec, y1 > 0.75)\n",
"intervals1 = logical_intervals(t_sec, y2 > 0.75)\n",
"intervals01 = logical_intervals(t_sec, (y1 > 0.75) & (y2 > 0.75))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<i>Table length=3</i>\n",
"<table id=\"table140526522176120\" class=\"table-striped table-bordered table-condensed\">\n",
"<thead><tr><th>datestart</th><th>datestop</th><th>duration</th><th>tstart</th><th>tstop</th></tr></thead>\n",
"<thead><tr><th>str21</th><th>str21</th><th>float64</th><th>float64</th><th>float64</th></tr></thead>\n",
"<tr><td>2000:001:00:04:16.500</td><td>2000:001:00:04:32.500</td><td>16.0</td><td>63072320.684</td><td>63072336.684</td></tr>\n",
"<tr><td>2000:001:00:09:16.500</td><td>2000:001:00:09:32.500</td><td>16.0</td><td>63072620.684</td><td>63072636.684</td></tr>\n",
"<tr><td>2000:001:00:14:16.500</td><td>2000:001:00:14:32.500</td><td>15.9999999925</td><td>63072920.684</td><td>63072936.684</td></tr>\n",
"</table>"
],
"text/plain": [
"<Table length=3>\n",
" datestart datestop ... tstart tstop \n",
" str21 str21 ... float64 float64 \n",
"--------------------- --------------------- ... ------------ ------------\n",
"2000:001:00:04:16.500 2000:001:00:04:32.500 ... 63072320.684 63072336.684\n",
"2000:001:00:09:16.500 2000:001:00:09:32.500 ... 63072620.684 63072636.684\n",
"2000:001:00:14:16.500 2000:001:00:14:32.500 ... 63072920.684 63072936.684"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"intervals01"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"intvls0 = [(intvl['datestart'], intvl['datestop']) for intvl in intervals0]\n",
"intvls1 = [(intvl['datestart'], intvl['datestop']) for intvl in intervals1]"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('2000:001:00:04:16.500', '2000:001:00:04:32.500'),\n",
" ('2000:001:00:09:16.500', '2000:001:00:09:32.500'),\n",
" ('2000:001:00:14:16.500', '2000:001:00:14:32.500')]"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"combine_intervals(operator.and_, intvls0, intvls1, start, stop)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:ska3]",
"language": "python",
"name": "conda-env-ska3-py"
},
"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.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment