def geometric_delay(baselines, skypos, altaz=False, dircos=False, hadec=True, units='mks', latitude=None): """ --------------------------------------------------------------------- Estimates the geometric delays matrix for different baselines from different sky positions. Inputs: baselines: x, y, and z components of baseline vectors in a Mx3 numpy array skypos: Nx2 (Alt-Az or HA-Dec) or Nx3 (direction cosines) numpy array of sky positions altaz: [Boolean flag, default=False] If True, skypos is in Alt-Az coordinates system hadec: [Boolean flag, default=True] If True, skypos is in HA-Dec coordinates system dircos: [Boolean flag, default=False] If True, skypos is in direction cosines coordinates system units: Units of baselines. Default='mks'. Alternative is 'cgs'. latitude: Latitude of the observatory. Required if hadec is True. Outputs: geometric delays [NxM numpy array] Geometric delay for every combination of baselines and skypos. --------------------------------------------------------------------- """ try: baselines, skypos except NameError: raise NameError('baselines and/or skypos not defined in geometric_delay().') if (altaz)+(dircos)+(hadec) != 1: raise ValueError('One and only one of altaz, dircos, hadec must be set to True.') if hadec and (latitude is None): raise ValueError('Latitude must be specified when skypos is in HA-Dec format.') try: units except NameError: print('No units provided. Assuming MKS units.') units = 'mks' if (units != 'mks') and (units != 'cgs'): print('Units should be specified to be one of MKS or CGS. Default=MKS') print('Proceeding with MKS units.') units = 'mks' if not isinstance(baselines, NP.ndarray): raise TypeError('baselines should be a Nx3 numpy array in geometric_delay().') if len(baselines.shape) == 1: baselines = baselines.reshape(1,-1) if baselines.shape[1] == 1: baselines = NP.hstack(baselines, NP.zeros((baselines.size,2))) elif baselines.shape[1] == 2: baselines = NP.hstack(baselines, NP.zeros((baselines.size,1))) elif baselines.shape[1] > 3: baselines = baselines[:,:3] if altaz or hadec: if len(skypos.shape) < 2: if skypos.size != 2: raise ValueError('Sky position in altitude-azimuth or HA-Dec should consist of 2 elements.') else: skypos = skypos.reshape(1,-1) elif len(skypos.shape) > 2: raise ValueError('Sky positions should be a Nx2 numpy array if using altitude-azimuth of HA-Dec.') else: if skypos.shape[1] != 2: raise ValueError('Sky positions should be a Nx2 numpy array if using altitude-azimuth of HA-Dec.') if altaz: dc = GEOM.altaz2dircos(skypos, 'degrees') else: dc = GEOM.altaz2dircos(GEOM.hadec2altaz(skypos, latitude, 'degrees'), 'degrees') else: if len(skypos.shape) < 2: if skypos.size != 3: raise ValueError('Sky position in direction cosines should consist of 3 elements.') else: skypos = skypos.reshape(1,-1) elif len(skypos.shape) > 2: raise ValueError('Sky positions should be a Nx3 numpy array if using direction cosines.') else: if skypos.shape[1] != 3: raise ValueError('Sky positions should be a Nx3 numpy array if using direction cosines.') dc = skypos # Set the speed of light in MKS or CGS units if units == 'mks': c = FCNST.c elif units == 'cgs': c = FCNST.c * 1e2 # geometric_delays = delay_envelope(baselines, dc, units)[:,:,-1] geometric_delays = NP.dot(dc, baselines.T)/c return geometric_delays
def geometric_delay(baselines, skypos, altaz=False, dircos=False, hadec=True, units='mks', latitude=None): """ --------------------------------------------------------------------- Estimates the geometric delays matrix for different baselines from different sky positions. Inputs: baselines: x, y, and z components of baseline vectors in a Mx3 numpy array skypos: Nx2 (Alt-Az or HA-Dec) or Nx3 (direction cosines) numpy array of sky positions altaz: [Boolean flag, default=False] If True, skypos is in Alt-Az coordinates system hadec: [Boolean flag, default=True] If True, skypos is in HA-Dec coordinates system dircos: [Boolean flag, default=False] If True, skypos is in direction cosines coordinates system units: Units of baselines. Default='mks'. Alternative is 'cgs'. latitude: Latitude of the observatory. Required if hadec is True. Outputs: geometric delays [NxM numpy array] Geometric delay for every combination of baselines and skypos. --------------------------------------------------------------------- """ try: baselines, skypos except NameError: raise NameError( 'baselines and/or skypos not defined in geometric_delay().') if (altaz) + (dircos) + (hadec) != 1: raise ValueError( 'One and only one of altaz, dircos, hadec must be set to True.') if hadec and (latitude is None): raise ValueError( 'Latitude must be specified when skypos is in HA-Dec format.') try: units except NameError: print 'No units provided. Assuming MKS units.' units = 'mks' if (units != 'mks') and (units != 'cgs'): print 'Units should be specified to be one of MKS or CGS. Default=MKS' print 'Proceeding with MKS units.' units = 'mks' if not isinstance(baselines, NP.ndarray): raise TypeError( 'baselines should be a Nx3 numpy array in geometric_delay().') if len(baselines.shape) == 1: baselines = baselines.reshape(1, -1) if baselines.shape[1] == 1: baselines = NP.hstack(baselines, NP.zeros((baselines.size, 2))) elif baselines.shape[1] == 2: baselines = NP.hstack(baselines, NP.zeros((baselines.size, 1))) elif baselines.shape[1] > 3: baselines = baselines[:, :3] if altaz or hadec: if len(skypos.shape) < 2: if skypos.size != 2: raise ValueError( 'Sky position in altitude-azimuth or HA-Dec should consist of 2 elements.' ) else: skypos = skypos.reshape(1, -1) elif len(skypos.shape) > 2: raise ValueError( 'Sky positions should be a Nx2 numpy array if using altitude-azimuth of HA-Dec.' ) else: if skypos.shape[1] != 2: raise ValueError( 'Sky positions should be a Nx2 numpy array if using altitude-azimuth of HA-Dec.' ) if altaz: dc = GEOM.altaz2dircos(skypos, 'degrees') else: dc = GEOM.altaz2dircos( GEOM.hadec2altaz(skypos, latitude, 'degrees'), 'degrees') else: if len(skypos.shape) < 2: if skypos.size != 3: raise ValueError( 'Sky position in direction cosines should consist of 3 elements.' ) else: skypos = skypos.reshape(1, -1) elif len(skypos.shape) > 2: raise ValueError( 'Sky positions should be a Nx3 numpy array if using direction cosines.' ) else: if skypos.shape[1] != 3: raise ValueError( 'Sky positions should be a Nx3 numpy array if using direction cosines.' ) dc = skypos # Set the speed of light in MKS or CGS units if units == 'mks': c = FCNST.c elif units == 'cgs': c = FCNST.c * 1e2 # geometric_delays = delay_envelope(baselines, dc, units)[:,:,-1] geometric_delays = NP.dot(dc, baselines.T) / c return geometric_delays
def test_hadec2altaz(): hadec = NP.asarray([[30.0, 0.0], [-90.0, 0.0]]).reshape(-1,2) latitude = 0.0 expected_altaz = NP.asarray([[60.0, 270.0], [0.0, 90.0]]).reshape(-1,2) altaz = GEOM.hadec2altaz(hadec, latitude, units='degrees') NP.testing.assert_allclose(altaz, expected_altaz, atol=1e-12)
def test_hadec2altaz(): hadec = NP.asarray([[30.0, 0.0], [-90.0, 0.0]]).reshape(-1, 2) latitude = 0.0 expected_altaz = NP.asarray([[60.0, 270.0], [0.0, 90.0]]).reshape(-1, 2) altaz = GEOM.hadec2altaz(hadec, latitude, units='degrees') NP.testing.assert_allclose(altaz, expected_altaz, atol=1e-12)