forked from astropy/astropy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructhelper.py
More file actions
36 lines (23 loc) · 794 Bytes
/
Copy pathstructhelper.py
File metadata and controls
36 lines (23 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np
def _append_field(table, data, dtype=None, position=None):
newdtype = table.dtype.descr
if position is None:
position = len(newdtype)
newdtype.insert(position, dtype)
newtable = np.empty(table.shape, dtype=newdtype)
for field in table.dtype.fields:
newtable[field] = table[field]
newtable[dtype[0]] = data
return newtable
def _drop_fields(table, names):
names = set(names)
newdtype = [(name, table.dtype[name]) for name in table.dtype.names
if name not in names]
newdtype = np.dtype(newdtype)
if newdtype:
newtable = np.empty(table.shape, dtype=newdtype)
else:
return None
for field in newdtype.fields:
newtable[field] = table[field]
return newtable