<p>I have imported my fits table, hdul0, into python. I'm using astropy.table. I opened it with hdul0 = fits.open('filename').  </p>

<pre><code>hdul0data = Table(hdul0[1].data)
</code></pre>

<p>I have then made a scatter plot of two columns in the table, HDA and OII. I have made a cut-out region on the plot (a short vertical line and then an upwards sloping line from there), and I would like to select the points under that line, like slice them from the original fits table and move the slice into another fits table that I then save. This is what I have done, but it is not working.</p>

<pre><code>x = hdul0data['HDA']
y = hdul0data['OII']
x1 = [2.5, 2.5] #the x values of the vertical line cut 
y1 = [0.0, 2.5] #the y values of the vertical line cut 
x2 = [2.5,16.0] #the x values of the sloping cut 
y2 = [2.5, 16.5] #the y values of the sloping cut  

slopy = np.interp(x, x2, y2)
myslice = np.where((x &gt; 2.5) &amp; (y &lt; slopy))[0]
</code></pre>

<p>The error message I get is <em>"RuntimeWarning: invalid value encountered in greater"</em> (and the same for less). </p>

<p>Can anyone help? How do I slice my table and get the selected points into a new fits file? I think maybe part of the issue is that some of the data points in the HDA and OII columns are NaN, but I don't know how to get rid off it. I read I could use masked, but then I read it might not work with numpy. </p>

<p>EDIT: </p>

<p>Sample values of x and y: </p>

<pre><code>x = [1.0, 6.2, 10.4, NaN, 2.8, NaN, 7.0] 
y = [10.3, NaN, 18.0, 22.9, 2.5, NaN, 31.8] 
</code></pre>

CC BY-SA 4.0
2019-03-21T14:34:38.550Z
I can't reproduce your error. Can you post some sample values of `x` and `y`?
m13op22
CC BY-SA 4.0
2019-03-21T15:08:06.943Z
@HS-nebula added sample values in the main post
Joey
CC BY-SA 4.0
2019-03-21T15:25:49.163Z
What version of Python are you using?
m13op22
CC BY-SA 4.0
2019-03-21T15:59:41.027Z
Are `x` and `y` actually Python lists or `numpy.arrays`?
m13op22
CC BY-SA 4.0
2020-02-25T13:32:42.347Z
I get a different error message `TypeError: '>' not supported between instances of 'list' and 'float'`
usernumber
<python><astropy>
How to "slice" a fits table in astropy?
Joey
# How to "slice" a fits table in astropy?

(Asked by: username_0 on 2019-03-21)

I have imported my fits table, hdul0, into python. I'm using astropy.table. I opened it with hdul0 = fits.open('filename').  
hdul0data = Table(hdul0[1].data)

I have then made a scatter plot of two columns in the table, HDA and OII. I have made a cut-out region on the plot (a short vertical line and then an upwards sloping line from there), and I would like to select the points under that line, like slice them from the original fits table and move the slice into another fits table that I then save. This is what I have done, but it is not working.
x = hdul0data['HDA']
y = hdul0data['OII']
x1 = [2.5, 2.5] #the x values of the vertical line cut 
y1 = [0.0, 2.5] #the y values of the vertical line cut 
x2 = [2.5,16.0] #the x values of the sloping cut 
y2 = [2.5, 16.5] #the y values of the sloping cut  

slopy = np.interp(x, x2, y2)
myslice = np.where((x > 2.5) & (y < slopy))[0]

The error message I get is "RuntimeWarning: invalid value encountered in greater" (and the same for less). 
Can anyone help? How do I slice my table and get the selected points into a new fits file? I think maybe part of the issue is that some of the data points in the HDA and OII columns are NaN, but I don't know how to get rid off it. I read I could use masked, but then I read it might not work with numpy. 
EDIT: 
Sample values of x and y: 
x = [1.0, 6.2, 10.4, NaN, 2.8, NaN, 7.0] 
y = [10.3, NaN, 18.0, 22.9, 2.5, NaN, 31.8]

**Tags:** python, astropy
> **Comments:**
> **username_1**: I can't reproduce your error. Can you post some sample values of `x` and `y`?  
> **username_0**: @HS-nebula added sample values in the main post  
> **username_1**: What version of Python are you using?  
> **username_1**: Are `x` and `y` actually Python lists or `numpy.arrays`?  
> **username_2**: I get a different error message `TypeError: '>' not supported between instances of 'list' and 'float'`  

---

## 0 answers

