def evaluate(self, x, y, lon0, lat0, a, e, theta): lon, lat = x, y b = a * np.sqrt(1. - e**2) dX = angular_distance(lon0, lat0, lon, lat0) dY = angular_distance(lon0, lat0, lon0, lat) dX = np.where( np.logical_or(np.logical_and(lon - lon0 > 0, lon - lon0 < 180), np.logical_and(lon - lon0 < -180, lon - lon0 > -360)), dX, -dX) dY = np.where(lat > lat0, dY, -dY) phi = theta + 90. cos2_phi = np.power(np.cos(phi * np.pi / 180.), 2) sin2_phi = np.power(np.sin(phi * np.pi / 180.), 2) sin_2phi = np.sin(2. * phi * np.pi / 180.) A = cos2_phi / (2. * b**2) + sin2_phi / (2. * a**2) B = -sin_2phi / (4. * b**2) + sin_2phi / (4. * a**2) C = sin2_phi / (2. * b**2) + cos2_phi / (2. * a**2) E = -A * np.power(dX, 2) + 2. * B * dX * dY - C * np.power(dY, 2) return np.power(180 / np.pi, 2) * 1. / (2 * np.pi * a * b) * np.exp(E)
def evaluate(self, x, y, lon0, lat0, radius): lon, lat = x,y angsep = angular_distance(lon0, lat0, lon, lat) return np.power(180 / np.pi, 2) * 1. / (np.pi * radius ** 2) * (angsep <= radius)
def evaluate(self, x, y, lon0, lat0, radius): lon, lat = x,y angsep = angular_distance(lon0, lat0, lon, lat) return np.power(180 / np.pi, 2) * 1. / (np.pi * radius ** 2) * (angsep <= radius)
def evaluate(self, x, y, lon0, lat0, index, maxr): lon, lat = x, y angsep = angular_distance(lon0, lat0, lon, lat) if self.maxr.value <= 0.05: norm = np.power( 180 / np.pi, -2. - self.index.value ) * np.pi * self.maxr.value**2 * 0.05**self.index.value elif self.index.value == -2.: norm = np.power(0.05 * np.pi / 180., 2. + self.index.value) * np.pi + 2. * np.pi * np.log( self.maxr.value / 0.05) else: norm = np.power( 0.05 * np.pi / 180., 2. + self.index.value) * np.pi + 2. * np.pi * (np.power( self.maxr.value * np.pi / 180., self.index.value + 2.) - np.power(0.05 * np.pi / 180., self.index.value + 2.)) return np.less_equal(angsep, self.maxr.value) * np.power( 180 / np.pi, -1. * index) * np.power( np.add(np.multiply(angsep, np.greater(angsep, 0.05)), np.multiply(0.05, np.less_equal(angsep, 0.05))), index) / norm
def evaluate(self, x, y, lon0, lat0, sigma): lon, lat = x, y angsep = angular_distance(lon0, lat0, lon, lat) return np.power(180 / np.pi, 2) * 1. / (2 * np.pi * sigma**2) * np.exp( -0.5 * np.power(angsep, 2) / sigma**2)
def evaluate(self, x, y, lon0, lat0, sigma): lon, lat = x,y angsep = angular_distance(lon0, lat0, lon, lat) return np.power(180 / np.pi, 2) * 1. / (2 * np.pi * sigma ** 2) * np.exp( -0.5 * np.power(angsep, 2) / sigma ** 2)
def evaluate(self, x, y, lon0, lat0, a, e, theta): b = a * np.sqrt(1. - e**2) # calculate focal points self.lon1, self.lat1, self.lon2, self.lat2 = self.calc_focal_pts(lon0, lat0, a, b, theta) self.focal_pts = True # lon/lat of point in question lon, lat = x, y # sum of geodesic distances to focii (should be <= 2a to be in ellipse) angsep1 = angular_distance(self.lon1, self.lat1, lon, lat) angsep2 = angular_distance(self.lon2, self.lat2, lon, lat) angsep = angsep1 + angsep2 return np.power(180 / np.pi, 2) * 1. / (np.pi * a * b) * (angsep <= 2*a)
def evaluate(self, x, y, lon0, lat0, sigma): lon, lat = x,y angsep = angular_distance(lon0, lat0, lon, lat) s2 = sigma**2 return (180 / np.pi)**2 * 1 / (2.0 * np.pi * s2) * np.exp(-0.5 * angsep**2/s2)
def evaluate(self, x, y, lon0, lat0, radius_inner, radius_outer): lon, lat = x, y angsep = angular_distance(lon0, lat0, lon, lat) return np.power(180 / np.pi, 2) * 1. / ( np.pi * (radius_outer**2 - radius_inner**2)) * ( angsep <= radius_outer) * (angsep > radius_inner)
def evaluate(self, x, y, z, lon0, lat0, rdiff0, rinj, delta, b, piv, piv2): lon, lat = x, y energy = z # energy in kev -> TeV. # NOTE: the use of piv2 is necessary to preserve dimensional correctness: the logarithm can only be taken # of a dimensionless quantity, so there must be a pivot there. e_energy_piv2 = 17. * np.power(energy / piv2, 0.54 + 0.046 * np.log10(energy / piv2)) e_piv_piv2 = 17. * np.power(piv / piv2, 0.54 + 0.046 * np.log10(piv / piv2)) try: rdiff_c = rdiff0 * np.power(e_energy_piv2 / e_piv_piv2, (delta - 1.) / 2.) * \ np.sqrt(b * b / 8. / np.pi * 0.624 + 0.26 * np.power(1. + 0.0107 * e_piv_piv2, -1.5)) / \ np.sqrt(b * b / 8. / np.pi * 0.624 + 0.26 * np.power(1. + 0.0107 * e_energy_piv2, -1.5)) rdiff_i = rdiff0 * rinj * np.power(e_energy_piv2 / e_piv_piv2, delta / 2.) except ValueError: # This happens when using units, because astropy.units fails with the message: # "ValueError: Quantities and Units may only be raised to a scalar power" # Work around the problem with this loop, which is slow but using units is only for testing purposes or # single calls, so it shouldn't matter too much rdiff_c = np.array( list( map(lambda x: (rdiff0 * np.power(e_energy_pivi2 / e_piv_piv2, x) * np .sqrt(b * b / 8. / np.pi * 0.624 + 0.26 * np.power( 1. + 0.0107 * e_piv_piv2, -1.5)) / np.sqrt( b * b / 8. / np.pi * 0.624 + 0.26 * np.power( 1. + 0.0107 * e_energy_piv2, -1.5)), (delta - 1.) / 2.).value))) * rdiff0.unit rdiff_i = np.array( list( map(lambda x: (rdiff0 * rinj * np.power( e_energy_piv2 / e_piv_piv2, x), delta / 2.).value)) ) * rdiff0.unit raise ValueError("") rdiff = np.minimum(rdiff_c, rdiff_i) angsep = angular_distance(lon, lat, lon0, lat0) pi = np.pi rdiffs, angseps = np.meshgrid(rdiff, angsep) return np.power(180.0 / pi, 2) * 1.2154 / (pi * np.sqrt(pi) * rdiffs * (angseps + 0.06 * rdiffs)) * \ np.exp(-np.power(angseps, 2) / rdiffs ** 2)
def evaluate(self, x, y, lon0, lat0, a, e, theta): lon, lat = x, y b = a * np.sqrt(1. - e**2) dX = np.atleast_1d(angular_distance(lon0, lat0, lon, lat0)) dY = np.atleast_1d(angular_distance(lon0, lat0, lon0, lat)) dlon = lon - lon0 if isinstance(dlon, u.Quantity): dlon = (dlon.to(u.degree)).value idx = np.logical_and(np.logical_or(dlon < 0, dlon > 180), np.logical_or(dlon > -180, dlon < -360)) dX[idx] = -dX[idx] idx = lat < lat0 dY[idx] = -dY[idx] if isinstance(theta, u.Quantity): phi = (theta.to(u.degree)).value + 90.0 else: phi = theta + 90. cos2_phi = np.power(np.cos(phi * np.pi / 180.), 2) sin2_phi = np.power(np.sin(phi * np.pi / 180.), 2) sin_2phi = np.sin(2. * phi * np.pi / 180.) A = old_div(cos2_phi, (2. * b**2)) + old_div(sin2_phi, (2. * a**2)) B = old_div(-sin_2phi, (4. * b**2)) + old_div(sin_2phi, (4. * a**2)) C = old_div(sin2_phi, (2. * b**2)) + old_div(cos2_phi, (2. * a**2)) E = -A * np.power(dX, 2) + 2. * B * dX * dY - C * np.power(dY, 2) return np.power(old_div(180, np.pi), 2) * 1. / (2 * np.pi * a * b) * np.exp(E)
def evaluate(self, x, y, lon0, lat0, a, b, theta): # lon/lat of point in question lon, lat = x,y # focal distance f = np.sqrt(a**2 - b**2) # focus 1 coordinate and distance from focus 1 to point lon1 = lon0 - f*np.cos(theta) lat1 = lat0 - f*np.sin(theta) angsep1 = angular_distance(lon1, lat1, lon, lat) # focus 2 coordinate and distance from focus 2 to point lon2 = lon0 + f*np.cos(theta) lat2 = lat0 + f*np.sin(theta) angsep2 = angular_distance(lon2, lat2, lon, lat) # sum of distances to focii (should be <= 2a to be in ellipse) angsep = angsep1 + angsep2 return np.power(180 / np.pi, 2) * 1. / (np.pi * a * b) * (angsep <= 2*a)
def evaluate(self, x, y, lon0, lat0, a, b, theta): # lon/lat of point in question lon, lat = x, y # focal distance f = np.sqrt(a**2 - b**2) # focus 1 coordinate and distance from focus 1 to point lon1 = lon0 - f * np.cos(theta) lat1 = lat0 - f * np.sin(theta) angsep1 = angular_distance(lon1, lat1, lon, lat) # focus 2 coordinate and distance from focus 2 to point lon2 = lon0 + f * np.cos(theta) lat2 = lat0 + f * np.sin(theta) angsep2 = angular_distance(lon2, lat2, lon, lat) # sum of distances to focii (should be <= 2a to be in ellipse) angsep = angsep1 + angsep2 return np.power(180 / np.pi, 2) * 1. / (np.pi * a * b) * (angsep <= 2 * a)
def evaluate(self, x, y, lon0, lat0, index, maxr, minr): lon, lat = x,y angsep = angular_distance(lon0, lat0, lon, lat) if maxr <= minr: norm = np.power(np.pi / 180., 2.+index) * np.pi * maxr**2 * minr**index elif self.index.value == -2.: norm = np.pi * (1.0 + 2. * np.log(maxr / minr) ) else: norm = np.power(minr * np.pi / 180., 2.+index) * np.pi + 2. * np.pi / (2.+index) * (np.power(maxr * np.pi / 180., index+2.) - np.power(minr * np.pi / 180., index+2.)) value = np.less_equal(angsep,maxr) * np.power(np.pi / 180., index) * np.power(np.add(np.multiply(angsep, np.greater(angsep, minr)), np.multiply(minr, np.less_equal(angsep, minr))), index) return value / norm
def evaluate(self, x, y, z, lon0, lat0, rdiff0, delta, b, piv, piv2, incl, elongation): lon, lat = x, y energy = z # energy in kev -> TeV. # NOTE: the use of piv2 is necessary to preserve dimensional correctness: the logarithm can only be taken # of a dimensionless quantity, so there must be a pivot there. e_energy_piv2 = 17. * np.power(energy / piv2, 0.54 + 0.046 * np.log10(energy / piv2)) e_piv_piv2 = 17. * np.power(piv / piv2, 0.54 + 0.046 * np.log10(piv / piv2)) try: rdiff_a = rdiff0 * np.power(e_energy_piv2 / e_piv_piv2, (delta - 1.) / 2.) * \ np.sqrt(b * b / 8. / np.pi * 0.624 + 0.26 * np.power(1. + 0.0107 * e_piv_piv2, -1.5)) / \ np.sqrt(b * b / 8. / np.pi * 0.624 + 0.26 * np.power(1. + 0.0107 * e_energy_piv2, -1.5)) except ValueError: # This happens when using units, because astropy.units fails with the message: # "ValueError: Quantities and Units may only be raised to a scalar power" # Work around the problem with this loop, which is slow but using units is only for testing purposes or # single calls, so it shouldn't matter too much rdiff_a = np.array( map(lambda x: (rdiff0 * np.power(e_energy_pivi2 / e_piv_piv2, x)).value, (delta - 1.) / 2. * np.sqrt(b * b / 8. / np.pi * 0.624 + 0.26 * np.power(1. + 0.0107 * e_piv_piv2, -1.5)) / np.sqrt(b * b / 8. / np.pi * 0.624 + 0.26 * np.power(1. + 0.0107 * e_energy_piv2, -1.5)))) * rdiff0.unit rdiff_b = rdiff_a * elongation pi = np.pi angsep = angular_distance(lon, lat, lon0, lat0) ang = np.arctan2(lat - lat0, (lon - lon0) * np.cos(lat0 * np.pi / 180.)) theta = np.arctan2(np.sin(ang-incl*np.pi/180.)/elongation, np.cos(ang-incl*np.pi/180.)) rdiffs_a, thetas = np.meshgrid(rdiff_a, theta) rdiffs_b, angseps = np.meshgrid(rdiff_b, angsep) rdiffs = np.sqrt(rdiffs_a ** 2 * np.cos(thetas) ** 2 + rdiffs_b ** 2 * np.sin(thetas) ** 2) results = np.power(180.0 / pi, 2) * 1.22 / (pi * np.sqrt(pi) * rdiffs_a * np.sqrt(elongation) * (angseps + 0.06 * rdiffs)) * np.exp(-np.power(angseps, 2) / rdiffs ** 2) return results
def _free_or_fix(self, free, radius, normalization_only): for src_name in self.point_sources: src = self.point_sources[src_name] this_d = angular_distance(self._ra_center, self._dec_center, src.position.ra.value, src.position.dec.value) if this_d <= radius: if normalization_only: src.spectrum.main.shape.K.free = free else: for par in src.spectrum.main.shape.parameters: src.spectrum.main.shape.parameters[par].free = free
def evaluate(self, x, y, z, lon0, lat0, rdiff0, delta, uratio, piv, piv2): lon, lat = x, y energy = z # energy in kev -> TeV. # NOTE: the use of piv2 is necessary to preserve dimensional correctness: the logarithm can only be taken # of a dimensionless quantity, so there must be a pivot there. e_energy_piv2 = 17. * np.power(energy / piv2, 0.54 + 0.046 * np.log10(energy / piv2)) e_piv_piv2 = 17. * np.power(piv / piv2, 0.54 + 0.046 * np.log10(piv / piv2)) try: rdiff = rdiff0 * np.power(e_energy_piv2 / e_piv_piv2, (delta - 1.) / 2.) * \ np.sqrt(1. + uratio * np.power(1. + 0.0107 * e_piv_piv2, -1.5)) / \ np.sqrt(1. + uratio * np.power(1. + 0.0107 * e_energy_piv2, -1.5)) except ValueError: # This happens when using units, because astropy.units fails with the message: # "ValueError: Quantities and Units may only be raised to a scalar power" # Work around the problem with this loop, which is slow but using units is only for testing purposes or # single calls, so it shouldn't matter too much rdiff = np.array( map(lambda x: (rdiff0 * np.power(e_energy_pivi2 / e_piv_piv2, x)).value, (delta - 1.) / 2. * np.sqrt(1. + uratio * np.power(1. + 0.0107 * e_piv_piv2, -1.5)) / np.sqrt(1. + uratio * np.power(1. + 0.0107 * e_energy_piv2, -1.5)))) * rdiff0.unit angsep = angular_distance(lon, lat, lon0, lat0) pi = np.pi rdiffs, angseps = np.meshgrid(rdiff, angsep) return np.power(180.0 / pi, 2) * 1.2154 / (pi * np.sqrt(pi) * rdiffs * (angseps + 0.06 * rdiffs)) * \ np.exp(-np.power(angseps, 2) / rdiffs ** 2)