Skip to content

Commit

Permalink
Added tests for beams, obs, time utilities. Fixed polar plot error.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlewis9 committed Sep 10, 2020
1 parent 59938c1 commit 02512b2
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 33 deletions.
24 changes: 9 additions & 15 deletions ECHO/beams.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ def plot_efield(self, *args, **kwargs):
plot_utils.plot_efield(self.beam,*args, **kwargs)
return
def plot_efield_interp(self, *args, **kwargs):
assert (self.beam!=None),"No efield beam found."
plot_utils.plot_efield_interp(self.beam,*args, **kwargs)
return
def plot_power(self):
assert (self.power!=None),"No power beam found."
assert (self.power_beam!=None),"No power beam found."
plot_utils.plot_power(self.power)

return
def plot_power_interp(self):
if self.power == None:
if self.power_beam == None:
print('No existing power beam.')
else:
plot_utils.plot_power_interp(self.power)
Expand All @@ -80,11 +81,11 @@ def plot_escatter_interp(self):
plot_utils.plot_hp_escatter_interp(self.beam)
return
def plot_powscatter(self):
assert (self.power!=None),"No power beam found."
assert (self.power_beam!=None),"No power beam found."
plot_utils.plot_healpix_powscatter(self.power)
return
def plot_powscatter_interp(self):
assert (self.power!=None),"No power beam found."
assert (self.power_beam!=None),"No power beam found."
plot_utils.plot_hp_powscatter_interp(self.power)
return

Expand All @@ -102,18 +103,17 @@ def make_hpx_beam(self, data_array, lat=None, lon=None):
targetLon=lon

hpx_beam,hpx_rms,hpx_counts = plot_utils.grid_to_healpix(
data_array[1:,1],
data_array[1:,2],
data_array[1:,3],
data_array[1:,5],
data_array[1:,1], #lats
data_array[1:,2], #lons
data_array[1:,3], #alts
data_array[1:,5], #data
lat0 = targetLat, #self.refined_array[0,1],
lon0 = targetLon, #self.refined_array[0,2],
nside = 8
)
self.hpx_beam = hpx_beam
self.hpx_rms = hpx_rms
self.hpx_counts = hpx_counts
self.power = hpx_beam
return hpx_beam, hpx_rms, hpx_counts

def write_beam(self, beam, rms, counts, prefix):
Expand All @@ -131,12 +131,6 @@ def write_beam(self, beam, rms, counts, prefix):

return

def diffrence_beams():
'''Take the difference of healpix beams, plot. Requires multiple beams.
'''
pass

def _valid_beamtype(self, beam_type):
valid_beamtype = ['healpy', 'efield','power']
assert (beam_type in valid_beamtype), "Invalid beamtype! Please select 'healpy', 'efield', or 'power'"
Expand Down
9 changes: 2 additions & 7 deletions ECHO/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,6 @@ def write_beam(self,prefix):

return

def diffrence_beams():
'''Take the difference of healpix beams, plot. Requires multiple beams.
'''
pass

def plot_mollview(self, *args, **kwargs):
'''Plot a mollview of the beam using
Expand Down Expand Up @@ -370,14 +364,15 @@ def plot_polar(self,altitude, *args, **kwargs):
'''Plot polar diagrams of the received beam.
Args:
altitude: angle from zenith in degrees
*args: Variable length argument list.
**kwargs: Arbitrary keyword arguments.
'''
radPhi=np.pi
az=np.linspace(0, 2*radPhi,360)
alt=np.zeros_like(az)
alt[:]=altitude*np.pi/2
alt[:]=altitude*np.pi/180

M = np.ma.array(self.hpx_beam,fill_value=hp.UNSEEN)
M = np.ma.masked_where(hp.UNSEEN==M,M)
Expand Down
25 changes: 14 additions & 11 deletions ECHO/read_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def flag_angles(angletimes,angles,sigma=2):
yawmask = np.abs(yawcos-mean_yawcos)/std_yawcos>sigma
badyaw_indices = np.where(yawmask)[0]
return yawmask,angletimes[badyaw_indices]

def apply_flagtimes(datatimes,flagtimes,dt):
#generate a mask for postimes (astropy.time.Time)
#given a list of times which are bad (astropy.time.Time)
Expand All @@ -380,10 +381,11 @@ def flag_waypoints(postimes,waypoint_times):
return np.zeros(len(postimes))

def mission_endpoint_flagging(pos_data,wpt_data):
"""Read in position and waypoint array, flag all waypoints
"""Read in position and waypoint array, flag mission endpoints and return valid mission data.
Args:
ulog (int): the ulog to be converted.
pos_data: the ulog to be converted.
wpt_data:
Returns:
flagged_array: array of flagged data.
Expand Down Expand Up @@ -828,15 +830,16 @@ def read_CST_puv(CST_txtfile, beam_type, frequency, telescope_name, feed_name, f
'''
Reads in a ASCII formatted CST export file and returns a beam model using pyuvbeam.
CST_txtfile: CST export file
beam_type (str): efield or power
frequency (list, Hz): our reference frequency
telescope_name (str): The instrument name
feed_name (str): The name of the feed
feed_version (str): The version of the feed
model_name (str): Name for the model
model_version (str): version of the model
feed_pol (str): polarization of the feed ('x','y','xx','yy')
Inputs:
CST_txtfile: CST export file
beam_type (str): efield or power
frequency (list, Hz): our reference frequency
telescope_name (str): The instrument name
feed_name (str): The name of the feed
feed_version (str): The version of the feed
model_name (str): Name for the model
model_version (str): version of the model
feed_pol (str): polarization of the feed ('x','y','xx','yy')
'''
beam = UVBeam()
beam.read_cst_beam(CST_txtfile, beam_type=beam_type, frequency=frequency,
Expand Down
41 changes: 41 additions & 0 deletions tests/utils/test_beams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest

import ECHO
import numpy as np
from scipy.interpolate import interp1d


'''
Tests to make:
*create simple test beams
*test that plots won't work on incorrect types (efield, hpx, power, etc)
*test
Beams use pyuvdata and/or healpy
'''

def test_createBeam():
#test that beams can't be made with invalid beam types
with pytest.raises(AssertionError):
testbeam=ECHO.Beam(beam_type='hpx')

#make a beam with each valid beam_type
testbeam=ECHO.Beam(beam_type='healpy')
testbeam=ECHO.Beam(beam_type='efield')
testbeam=ECHO.Beam(beam_type='power')

return

def test_beamplots():
testbeam = ECHO.Beam(beam_type='healpy') #has no beams yet, plotting should fail
with pytest.raises(AssertionError):
testbeam.plot_efield()
testbeam.plot_efield_interp()
testbeam.plot_power()
testbeam.plot_power_interp()
testbeam.plot_escatter()
testbeam.plot_escatter_interp()
testbeam.plot_powscatter()
testbeam.plot_powscatter_interp()

return
33 changes: 33 additions & 0 deletions tests/utils/test_obs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest

import ECHO
import numpy as np
from scipy.interpolate import interp1d


'''
Tests to make:
*test that object initializes properly
Beams use pyuvdata and/or healpy
'''
lat, lon = (33.448376, -112.074036)
frequency = 75.00
description = "This is an observation object."

def test_createObs():
#test that observations are created properly
testobs = ECHO.Observation(lat, lon, frequency, description)
assert (testobs.lat == lat), "Latitude not correct."
assert (testobs.lon == lon), "Longitude not correct."
assert (testobs.ref_frequency == frequency), "Frequency not correct."
assert (testobs.description == description), "Description not correct."
return

def test_sortieList():
#test that the sortie list increments properly
testobs = ECHO.Observation(lat, lon, frequency, description)
testobs.addSortie(tlog='tlog_file', ulog='ulog_file', data='rx_data_file')
assert (len(testobs.sortie_list)==1)
assert (testobs.num_sorties ==1)
return
29 changes: 29 additions & 0 deletions tests/utils/test_time_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest

import ECHO
import numpy as np
from scipy.interpolate import interp1d


'''
Tests to make:
'''

def test_findpeak():
f = np.linspace(50, 100, 51, endpoint=True)
x = np.array([ 8.45090674, 10.04123532, 11.519111 , 11.31353706, 10.93862423,
10.14809911, 10.56714626, 9.35886578, 8.95918093, 7.81729457,
4.37170954, 7.56457857, 8.78697872, 12.04254699, 7.90141348,
9.28847377, 9.65893591, 5.47728162, 11.4554848 , 5.68049579,
10.05662662, 13.03766057, 9.50115484, 7.63408106, 11.65752125,
9.99689695, 9.83531587, 9.11961106, 8.2682244 , 11.24434912,
12.93292398, 9.79594562, 8.22141003, 8.68508538, 8.50393763,
10.83899931, 12.2772833 , 15.7622897 , 14.55045571, 9.2609078 ,
9.0943069 , 7.27017967, 12.93086491, 11.28801567, 7.95531201,
11.79401846, 9.71806665, 8.5215067 , 9.26962276, 13.13287041,
10.83630832])
maxfreq, peak, peakrms = ECHO.time_utils.find_peak(f, x,fmin=50, fmax=100)
assert(maxfreq[0] == 87.), "Incorrect frequency."
assert(peak == 15.7622897), "Incorrect peak value."
return

0 comments on commit 02512b2

Please sign in to comment.