def MWA_Tile_advanced(za, az, freq=100.0e6, delays=None, zenithnorm=True, power=True, jones=False): """ Use the new MWA tile model from mwa_tile.py that includes mutual coupling and the simulated dipole response. Returns the XX and YY response to an unpolarised source. if jones=True, will return the Jones matrix instead delays should be a numpy array of size (2,16), although a (16,) list or a (16,) array will also be accepted """ if isinstance(delays,list): delays=numpy.array(delays) if delays.shape == (16,): try: delays=numpy.repeat(numpy.reshape(delays,(1,16)),2,axis=0) except: logger.error('Unable to convert delays (shape=%s) to (2,16)' % (delays.shape)) return None assert delays.shape == (2,16), "Delays %s have unexpected shape %s" % (delays,delays.shape) logger.setLevel(logging.DEBUG) d = mwa_tile.Dipole(type='lookup') logger.debug("Delays: "+str(delays)) tile = mwa_tile.ApertureArray(dipoles=[d]*16) # tile of identical dipoles j = tile.getResponse(az,za,freq,delays=delays) if jones: return j vis = mwa_tile.makeUnpolInstrumentalResponse(j,j) if not power: return (numpy.sqrt(vis[:,:,0,0].real),numpy.sqrt(vis[:,:,1,1].real)) else: return (vis[:,:,0,0].real,vis[:,:,1,1].real)
def local_beam(za, az, freq, delays=None, zenithnorm=True, power=True, jones=False, interp=True, pixels_per_deg=5, amps=None): '''Code pulled from mwapy that generates the MWA beam response - removes unecessary extra code from mwapy/pb - delays is a 2x16 array, with the first 16 delays for the XX, second 16 for the YY pol. values match what you find in the metafits file - amps are the amplitudes of each individual dipole, again in a 2x16, with XX first then YY''' tile = beam_full_EE.ApertureArray(MWAPY_H5PATH, freq) mybeam = beam_full_EE.Beam(tile, delays, amps) if interp: j = mybeam.get_interp_response(az, za, pixels_per_deg) else: j = mybeam.get_response(az, za) if zenithnorm == True: j = tile.apply_zenith_norm_Jones(j) #Normalise #Use swapaxis to place jones matrices in last 2 dimensions #insead of first 2 dims. if len(j.shape) == 4: j = swapaxes(swapaxes(j, 0, 2), 1, 3) elif len(j.shape) == 3: #1-D j = swapaxes(swapaxes(j, 1, 2), 0, 1) else: #single value pass if jones: return j #Use mwa_tile makeUnpolInstrumentalResponse because we have swapped axes vis = mwa_tile.makeUnpolInstrumentalResponse(j, j) if not power: return (sqrt(vis[:, :, 0, 0].real), sqrt(vis[:, :, 1, 1].real)) else: return (vis[:, :, 0, 0].real, vis[:, :, 1, 1].real)
def local_beam(za, az, freq, delays=None, zenithnorm=True, power=True, jones=False, interp=True, pixels_per_deg=5, amps=None): '''Code pulled my mwapy that generates the MWA beam response - removes unecessary extra code from mwapy/pb''' tile = beam_full_EE.ApertureArray(MWAPY_H5PATH, freq) mybeam = beam_full_EE.Beam(tile, delays, amps) if interp: j = mybeam.get_interp_response(az, za, pixels_per_deg) else: j = mybeam.get_response(az, za) if zenithnorm == True: j = tile.apply_zenith_norm_Jones(j) #Normalise #Use swapaxis to place jones matrices in last 2 dimensions #insead of first 2 dims. if len(j.shape) == 4: j = swapaxes(swapaxes(j, 0, 2), 1, 3) elif len(j.shape) == 3: #1-D j = swapaxes(swapaxes(j, 1, 2), 0, 1) else: #single value pass if jones: return j #Use mwa_tile makeUnpolInstrumentalResponse because we have swapped axes vis = mwa_tile.makeUnpolInstrumentalResponse(j, j) if not power: return (sqrt(vis[:, :, 0, 0].real), sqrt(vis[:, :, 1, 1].real)) else: return (vis[:, :, 0, 0].real, vis[:, :, 1, 1].real)
def MWA_Tile_full_EE(za, az, freq, delays=None, zenithnorm=True, power=True, jones=False, interp=True, pixels_per_deg=5): """ Use the new MWA tile model from beam_full_EE.py that includes mutual coupling and the simulated dipole response. Returns the XX and YY response to an unpolarised source. if jones=True, will return the Jones matrix instead of the XX,YY response. In this case, the power flag will be ignored. If interp=False, the pixels_per_deg will be ignored delays should be a numpy array of size (2,16), although a (16,) list or a (16,) array will also be accepted az - azimuth angles (radians), north through east. za - zenith angles (radian) """ # Convert za and az into 2D numpy arrays, because the Advanced and FullEE models require that format. if type(za) is list: za = numpy.array(za) if type(az) is list: az = numpy.array(az) if (isinstance(za, float)) and (isinstance( az, float)): # Convert float to 2D array za = numpy.array([[za]]) az = numpy.array([[az]]) dtype = 'float' elif (isinstance(za, numpy.ndarray)) and (isinstance(az, numpy.ndarray)): if (len(za.shape) == 1) and (len(az.shape) == 1): # 1D array, convert to 2D array za = za[None, :] az = az[None, :] dtype = '1D' elif (len(za.shape) == 2) and (len(az.shape) == 2): dtype = '2D' else: dtype = 'bad' else: dtype = 'bad' if dtype == 'bad': logger.error( 'ERROR - az/za data types must be the same, and either floats or 1 or 2 dimensional arrays' ) return None tile = beam_full_EE.get_AA_Cached(target_freq_Hz=freq) mybeam = beam_full_EE.Beam( tile, delays, amps=numpy.ones([2, 16]) ) # calling with amplitudes=1 every time - otherwise they get overwritten !!! if interp: j = mybeam.get_interp_response(az, za, pixels_per_deg) else: j = mybeam.get_response(az, za) if zenithnorm: j = tile.apply_zenith_norm_Jones(j) # Normalise # TODO: do frequency interpolation here (with 2nd adjacent beam) # Use swapaxis to place jones matrices in last 2 dimensions # insead of first 2 dims. if len(j.shape) == 4: j = numpy.swapaxes(numpy.swapaxes(j, 0, 2), 1, 3) elif len(j.shape) == 3: # 1-D j = numpy.swapaxes(numpy.swapaxes(j, 1, 2), 0, 1) else: # single value pass if jones: if dtype == 'float': return j[0][0] elif dtype == '1D': return j[0] else: return j # Use mwa_tile makeUnpolInstrumentalResponse because we have swapped axes vis = mwa_tile.makeUnpolInstrumentalResponse(j, j) if not power: xx, yy = (numpy.sqrt(vis[:, :, 0, 0].real), numpy.sqrt(vis[:, :, 1, 1].real)) else: xx, yy = (vis[:, :, 0, 0].real, vis[:, :, 1, 1].real) if dtype == 'float': return xx[0][0], yy[0][0] elif dtype == '1D': return xx[0], yy[0] else: return xx, yy
def MWA_Tile_advanced(za, az, freq=100.0e6, delays=None, zenithnorm=None, power=True, jones=False): """ Use the new MWA tile model from mwa_tile.py that includes mutual coupling and the simulated dipole response. Returns the XX and YY response to an unpolarised source. if jones=True, will return the Jones matrix instead delays should be a numpy array of size (2,16), although a (16,) list or a (16,) array will also be accepted """ if isinstance(delays, list): delays = numpy.array(delays) # Convert za and az into 2D numpy arrays, because the Advanced and FullEE models require that format. if type(za) is list: za = numpy.array(za) if type(az) is list: az = numpy.array(az) if (isinstance(za, float)) and (isinstance( az, float)): # Convert float to 2D array za = numpy.array([[za]]) az = numpy.array([[az]]) dtype = 'float' elif (isinstance(za, numpy.ndarray)) and (isinstance(az, numpy.ndarray)): if (len(za.shape) == 1) and (len(az.shape) == 1): # 1D array, convert to 2D array za = za[None, :] az = az[None, :] dtype = '1D' elif (len(za.shape) == 2) and (len(az.shape) == 2): dtype = '2D' else: dtype = 'bad' else: dtype = 'bad' if dtype == 'bad': logger.error( 'ERROR - az/za data types must be the same, and either floats or 1 or 2 dimensional arrays' ) return None if zenithnorm: logger.warning( 'ERROR: MWA_Tile_advanced does not use the zenithnorm parameter.') if delays.shape == (16, ): try: delays = numpy.repeat(numpy.reshape(delays, (1, 16)), 2, axis=0) except Exception: logger.error('Unable to convert delays (shape=%s) to (2,16)' % (delays.shape)) return None assert delays.shape == ( 2, 16), "Delays %s have unexpected shape %s" % (delays, delays.shape) logger.debug("Delays: " + str(delays)) tile = mwa_tile.get_AA_Cached() # tile of identical dipoles j = tile.getResponse(az, za, freq, delays=delays) if jones: if dtype == 'float': return j[0][0] elif dtype == '1D': return j[0] else: return j vis = mwa_tile.makeUnpolInstrumentalResponse(j, j) if not power: xx, yy = (numpy.sqrt(vis[:, :, 0, 0].real), numpy.sqrt(vis[:, :, 1, 1].real)) else: xx, yy = (vis[:, :, 0, 0].real, vis[:, :, 1, 1].real) if dtype == 'float': return xx[0][0], yy[0][0] elif dtype == '1D': return xx[0], yy[0] else: return xx, yy