def findindex2Dsphere(azimg, elimg, az, el): """ finds nearest row,column index of projection on 2-D sphere. E.g. an astronomical or auroral camera image inputs: azimg: azimuth of image pixels (deg) elimg: elevation of image pixels (deg) az: azimuth of point you seek to find the index for (deg) el: elevation of point you seek to find the index for (deg) output: row, column of 2-D image closest to az,el brute force method of finding the row,col with the closest az,el using haversine method useful for: azimuth, elevation right ascension, declination latitude, longitude """ az = atleast_1d(az) el = atleast_1d(el) assert azimg.ndim == 2 and elimg.ndim == 2 assert isinstance(az[0], float) and isinstance(el[0], float) adist = anglesep(azimg, elimg, az, el) return unravel_index(adist.argmin(), azimg.shape)
def test_haversine(self): try: assert_allclose(anglesep(35, 23, 84, 20), ha) except ImportError: pass #%% compare with astropy assert_allclose(anglesep_meeus(35, 23, 84, 20), ha)
def line2plane(cam: xarray.Dataset) -> xarray.Dataset: """ previously, you find the row, col pixels along the line from the other camera to magnetic zenith. In this function, you find the indices of the plane passing through that line and both cameras. Inputs: ------- row: row indices of line col: column indices of line nPlane: number of samples (pixels) to take for plane. If the plane is horizontal in the images, it would be approximately the number of x-pixels. If diagonal, it would be about sqrt(2)*Nx. If less, the image is sampled more sparsely, which is in effect recducing the resolution of the image. This parameter is not critical. """ # %% linear regression polycoeff = np.polyfit(cam["cols"], cam["rows"], deg=3, full=False) # %% columns (x) to cut from picture (have to pick either rows or cols, arbitrarily I use cols) # NOT range, NEED dtype= for arange api # %% rows (y) to cut from picture cam["cutrow"] = np.rint(np.polyval(polycoeff, cam["cutcol"])).astype(int) assert (cam["cutrow"] >= 0).all() and ( cam["cutrow"] < cam.y.size ).all(), "impossible least squares fit for 1-D cut\n is your video orientation correct? are you outside the FOV?" # DONT DO THIS: cutrow.clip(0,self.supery,cutrow) # %% angle from magnetic zenith corresponding to those pixels anglesep_deg = anglesep( cam.Bel, cam.Baz, # NEED .values or you'll get 2-D instead of 1-D! cam.el.values[cam.cutrow, cam.cutcol], cam.az.values[cam.cutrow, cam.cutcol], ) if cam.verbose: from maatplotlib.pyplot import figure ax = figure().gca() ax.plot(cam.cutcol, anglesep_deg, label="angle_sep from MZ") ax.plot(cam.cutcol, cam.el.values[cam.cutrow, cam.cutcol], label="elevation angle [deg]") ax.legend() assert anglesep_deg.ndim == 1 if not np.isfinite(anglesep_deg).all(): logging.error(f"did you pick areas outside the {cam.filename} FOV?") # %% assemble angular distances from magnetic zenith--these are used in the tomography algorithm cam["angle_deg"], cam["angleMagzenind"] = sky2beam(anglesep_deg, cam.cutcol.size) return cam
def main(): p = ArgumentParser(description="angular distance between two sky points") p.add_argument("r0", help="right ascension: first point [deg]", type=float) p.add_argument("d0", help="declination: first point [deg]", type=float) p.add_argument("r1", help="right ascension: 2nd point [deg]", type=float) p.add_argument("d1", help="declination: 2nd point [degrees]", type=float) a = p.parse_args() dist_deg = anglesep_meeus(a.r0, a.d0, a.r1, a.d1) dist_deg_astropy = anglesep(a.r0, a.d0, a.r1, a.d1) print(f"{dist_deg:.6f} deg sep") assert dist_deg == approx(dist_deg_astropy)
def main(): p = ArgumentParser(description="angular distance between two sky points") p.add_argument('r0', help='right ascension: first point [deg]', type=float) p.add_argument('d0', help='declination: first point [deg]', type=float) p.add_argument('r1', help='right ascension: 2nd point [deg]', type=float) p.add_argument('d1', help='declination: 2nd point [degrees]', type=float) a = p.parse_args() dist_deg = anglesep_meeus(a.r0, a.d0, a.r1, a.d1) dist_deg_astropy = anglesep(a.r0, a.d0, a.r1, a.d1) print('{:.6f} deg sep'.format(dist_deg)) assert dist_deg == approx(dist_deg_astropy)
def test_anglesep(): pytest.importorskip("astropy") assert pmh.anglesep(35, 23, 84, 20) == approx(ha)
def test_anglesep(): pytest.importorskip('astropy') assert pmh.anglesep(35, 23, 84, 20) == approx(ha)