Skip to content

Commit 926b947

Browse files
committed
Improving speed if inputting multiple coordinates or pixels
1 parent cda6b12 commit 926b947

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

util/pixfunc.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def coord2pix(lon, lat=None, coord='C', res='F'):
4242
elif res == 'B':
4343
res = 9
4444

45-
4645
#I believe this is the relevant code from coorconv.pro that I need to follow
4746
#uvec = cconv(input*1.,-1) #convert to unit vector
4847
#uvec = skyconv(uvec, inco=in_coord, outco='E') #convert to ecliptic
@@ -58,25 +57,13 @@ def coord2pix(lon, lat=None, coord='C', res='F'):
5857
coord = 'geocentrictrueecliptic'
5958

6059
if lat is not None:
61-
if npts > 1:
62-
c = []
63-
for lon_tmp, lat_tmp in zip(lon, lat):
64-
c_tmp = SkyCoord(lon_tmp, lat_tmp, unit='deg', equinox='J2000', frame=coord)
65-
c.append(c_tmp)
66-
else:
67-
c = SkyCoord(lon, lat, unit='deg', equinox='J2000', frame=coord)
60+
c = SkyCoord(lon, lat, unit='deg', equinox='J2000', frame=coord)
6861
else:
6962
c = lon
7063

71-
if npts == 1:
72-
c = c.geocentrictrueecliptic #check to see if this is the right ecliptic
73-
c = c.cartesian
74-
else:
75-
c2 = []
76-
for i in range(npts):
77-
c2.append(c[i].geocentrictrueecliptic)
78-
c2[i] = c2[i].cartesian
79-
c = c2
64+
c = c.geocentrictrueecliptic #check to see if this is the right ecliptic
65+
c = c.cartesian
66+
8067
output = _uv2pix(c, res=res)
8168

8269
if npts == 1:
@@ -1096,7 +1083,7 @@ def _rastr(pixel, res=6, face=False, sixpack=False, data=-1, bad_pixval=0.0):
10961083

10971084
return raster, x_out, y_out
10981085

1099-
def _pix2dat(pixel, x_in=None, y_in=None, raster=None):
1086+
def _pix2dat(raster, pixel=None, x_in=None, y_in=None):
11001087
'''This function creates a data array given either a list of
11011088
pixels or a set of x and y raster coordinates and a raster
11021089
image (sky cube or face). The skycube can be in either unfolded
@@ -1126,7 +1113,7 @@ def _pix2dat(pixel, x_in=None, y_in=None, raster=None):
11261113
raise ValueError("Improper image size")
11271114

11281115
#Determine number of pixels / get column and row numbers if pixel entry
1129-
if pixel.size != 0:
1116+
if pixel is not None:
11301117
num_pix = pixel.size
11311118

11321119
if input_l == input_h:

0 commit comments

Comments
 (0)