def avoidance_cut_old(bore, det_offs, site, name_or_pos, margin): """Cut samples that get too close to the specified object (e.g. "Sun" or "Moon") or celestial position ([ra,dec] in racians). Margin specifies how much to avoid the object by.""" cmargin = np.cos(margin) mjd = utils.ctime2mjd(bore[0]) obj_pos = coordinates.interpol_pos("cel", "hor", name_or_pos, mjd, site) obj_rect = utils.ang2rect(obj_pos, zenith=False) # Only cut if above horizon above_horizon = obj_pos[1] > 0 if np.all(~above_horizon): return sampcut.empty(det_offs.shape[0], bore.shape[1]) cuts = [] for di, off in enumerate(det_offs): det_pos = bore[1:] + off[:, None] #det_rect1 = utils.ang2rect(det_pos, zenith=False) # slow # Not sure defining an ang2rect in array_ops is worth it.. It's ugly, # (angle convention hard coded) and only gives factor 2 on laptop. det_rect = array_ops.ang2rect(np.ascontiguousarray(det_pos.T)).T cdist = np.sum(obj_rect * det_rect, 0) # Cut samples above horizon that are too close bad = (cdist > cmargin) & above_horizon cuts.append(sampcut.from_mask(bad)) res = sampcut.stack(cuts) return res
def earth2sun(pos_earthrel, time, sundist, diff=False): """Compute the apparent displacement pos_sunrel - pos_earthrel for a source with earth-relative pointing given by pos_earthrel[{ra,dec},:] at the given time, and with the given distance from the sun (in AU).""" # Compute the position of the object relative to the earth at each time vec_obj_earthrel = utils.ang2rect(pos_earthrel, zenith=False) vec_earth_sunrel = -ephemeris.ephem_vec("Sun", time) # Get the object earth distance based on the sun distance, using # the law of sines: sin(obj_earth_sun)/obj_sun = sin(sun_obj_earth)/obj_earth. b = np.sum(vec_earth_sunrel**2, 0)**0.5 c = sundist cosC = np.sum(-(vec_obj_earthrel.T * vec_earth_sunrel.T).T, 0) / b sinC = (1 - cosC**2)**0.5 sinB = sinC * b / c sinA = np.sin(np.pi - np.arcsin(sinB) - np.arcsin(sinC)) a = b * sinA / sinB earthdist = a vec_obj_earthrel *= earthdist # Get the relative position vec_obj_sunrel = (vec_obj_earthrel.T + vec_earth_sunrel.T).T # Translate this into an angular position pos_sunrel = utils.rect2ang(vec_obj_sunrel, zenith=False) if not diff: return pos_sunrel # And turn that into a displacement offset = pos_sunrel - pos_earthrel offset[1] = utils.rewind(offset[1]) return offset
def euler_rot(euler_angles, coords, kind="zyz"): coords = np.asarray(coords) co = coords.reshape(2, -1) M = euler_mat(euler_angles, kind) rect = utils.ang2rect(co, False) rect = np.einsum("...ij,j...->i...", M, rect) co = utils.rect2ang(rect, False) return co.reshape(coords.shape)
def ephem_vec(objname, mjd, dt=10): """Computes the earth-relative position vector[{x,y,z},ntime] for the given object. Uses interpolation in steps dt (seconds) to speed things up. Set dt to 0 to disable this. The resulting vector has units of AU.""" # Get low-res [ra,dec,r] sub_time, inds = define_subsamples(mjd, dt=dt / (24. * 3600)) sub_pos = ephem_raw(objname, sub_time) # Convert to low-res [x,y,z] sub_vec = utils.ang2rect(sub_pos[:2], zenith=False) * sub_pos[2] # Interpolate to target resolution full_vec = utils.interpol(sub_vec, inds[None]) return full_vec
def sun2earth(pos_sunrel, time, sundist, diff=False): """Compute the apparent displacement pos_earthrel - pos_sunrel for a source with sun-relative pointing given by pos_sunrel[{ra,dec},:] at the given time, and with the given distance from the sun (in AU).""" # Compute the position of the object relative to the earth at each time vec_obj_sunrel = utils.ang2rect(pos_sunrel, zenith=False) * sundist vec_sun_earthrel = ephemeris.ephem_vec("Sun", time) vec_obj_earthrel = (vec_obj_sunrel.T + vec_sun_earthrel.T).T # Translate this into an angular position pos_earthrel = utils.rect2ang(vec_obj_earthrel, zenith=False) if not diff: return pos_earthrel # And turn that into a displacement offset = pos_earthrel - pos_sunrel offset[1] = utils.rewind(offset[1]) return offset
def avoidance_cut_old(bore, det_offs, site, name_or_pos, margin): """Cut samples that get too close to the specified object (e.g. "Sun" or "Moon") or celestial position ([ra,dec] in racians). Margin specifies how much to avoid the object by.""" cmargin = np.cos(margin) mjd = utils.ctime2mjd(bore[0]) obj_pos = coordinates.interpol_pos("cel","hor",name_or_pos,mjd,site) obj_rect = utils.ang2rect(obj_pos, zenith=False) # Only cut if above horizon above_horizon = obj_pos[1]>0 if np.all(~above_horizon): return sampcut.empty(det_offs.shape[0], bore.shape[1]) cuts = [] for di, off in enumerate(det_offs): det_pos = bore[1:]+off[:,None] #det_rect1 = utils.ang2rect(det_pos, zenith=False) # slow # Not sure defining an ang2rect in array_ops is worth it.. It's ugly, # (angle convention hard coded) and only gives factor 2 on laptop. det_rect = array_ops.ang2rect(np.ascontiguousarray(det_pos.T)).T cdist = np.sum(obj_rect*det_rect,0) # Cut samples above horizon that are too close bad = (cdist > cmargin) & above_horizon cuts.append(sampcut.from_mask(bad)) res = sampcut.stack(cuts) return res