def from_array( map_array: np.array, npix: int, theta: float, quantity: str, dir_in: str, map_file: Optional[str] = None, sky_type: str = "array", ) -> Union[SkyArray, SkyHealpix]: """ Initialize class by reading the skymap data from np.ndarray. Args: map_filename: File path with which skymap pd.DataFrame can be loaded. file_dsc: Dictionary pointing to a file via {path, root, extension}. Use when multiple skymaps need to be loaded. """ if sky_type == "array": skymap = SkyArray.from_array(map_array, npix, theta, quantity, dir_in, map_file) elif sky_type == "healpix": skymap = SkyHealpix.from_array(map_array, npix, theta, quantity, dir_in, map_file) return skymap
def from_file( npix: int, theta: float, quantity: str, dir_in: str, map_file: Optional[str] = None, convert_unit: bool = True, sky_type: str = "array", ) -> Union[SkyArray, SkyHealpix]: """ Initialize class by reading the skymap data from pandas hdf5 file or numpy array. The file can be pointed at via map_filename or file_dsc. Args: map_filename: File path with which skymap pd.DataFrame can be loaded. file_dsc: Dictionary pointing to a file via {path, root, extension}. Use when multiple skymaps need to be loaded. sky_type: Indicate what format the sky should have, as it makes different operations are accessible: [healpix, array] """ assert sky_type in [ "array", "healpix", ], "The declared 'sky_type' is not known" assert map_file, SkyMapWarning("There is no file being pointed at") file_extension = map_file.split(".")[-1] if sky_type == "array": if file_extension == "h5": map_df = pd.read_hdf(map_file, key="df") skymap = SkyArray.from_dataframe( map_df, npix, theta, quantity, dir_in, map_file, convert_unit, ) elif file_extension in [ "npy", "fits", ]: # only possible for SkyArray if file_extension == "npy": map_array = np.load(map_file) elif file_extension == "fits": map_array = ConvergenceMap.load(map_file, format="fits").data skymap = SkyArray.from_array(map_array, npix, theta, quantity, dir_in, map_file) elif sky_type == "healpix": skymap = SkyHealpix.from_file(map_file, npix, theta, quantity, dir_in) return skymap
def get_dipole_image(img: Type[SkyArray], cen_pix: tuple, extend_pix: int, extend_deg: float) -> Type[SkyArray]: xlim = np.array([cen_pix[1] - extend_pix, cen_pix[1] + extend_pix]).astype(int) ylim = np.array([cen_pix[0] - extend_pix, cen_pix[0] + extend_pix]).astype(int) img_zoom = SkyArray.from_array( img.crop(xlim, ylim, of="orig", rtn=True), opening_angle=2 * extend_deg, quantity=None, dir_in=None, ) return img_zoom
def simulated_dipole_maps( dipole_index: List[int], dipoles: pd.DataFrame, skymap: Union[str, np.ndarray], extent: float, theta: float = 20., arrow_scale: Optional[float] = None, mlabel: str = "_mtvel_ana", ) -> mpl.figure.Figure: """ Plot sky-data contained in filepaths_map overlayed by halo-data in halos """ fig, axis = plt.subplots( 1, len(dipole_index), figsize=(16, 5), facecolor="w", edgecolor="k", ) # Load Map if isinstance(skymap, str): skyarray = SkyArray.from_file( skymap, opening_angle=theta, quantity="isw_rs", dir_in=None, convert_unit=True, ) if isinstance(skymap, np.ndarray): skyarray = SkyArray.from_array( skymap, opening_angle=theta, quantity="isw_rs", dir_in=None, ) for idx, ax in enumerate(axis.reshape(-1)): dip = dipoles[dipoles["id"] == dipole_index[idx]] zoom = Dipoles.get_dipole_image( skyarray, (dip.theta1_pix.values[0], dip.theta2_pix.values[0]), dip.r200_pix.values[0] * extent, dip.r200_deg.values[0] * extent, ) ax.imshow( zoom.data["orig"] * 1e6, extent=[ dip.theta1_deg.values[0] - dip.r200_deg.values[0]*extent, dip.theta1_deg.values[0] + dip.r200_deg.values[0]*extent, dip.theta2_deg.values[0] - dip.r200_deg.values[0]*extent, dip.theta2_deg.values[0] + dip.r200_deg.values[0]*extent, ], cmap=cm.RdBu_r, origin="lower", zorder=0, ) ax.add_artist( plt.Circle( (dip.theta1_deg.values[0], dip.theta2_deg.values[0]), dip.r200_deg.values[0], fill=False, #alpha=0.5, color="lime", #edgecolor="w", linewidth=1, zorder=1, ) ) ax.quiver( dip.theta1_deg.values[0], dip.theta2_deg.values[0], dip["theta1" + mlabel].values[0], dip["theta2" + mlabel].values[0], facecolor="grey", edgecolor="w", scale=arrow_scale, zorder=2, ) ax.quiver( dip.theta1_deg, dip.theta2_deg, dip.theta1_tv, dip.theta2_tv, linestyle='dotted', linewidth=1, facecolor='none', edgecolor="k", scale=arrow_scale, zorder=2, ) ax.text( dip.theta1_deg.values[0] - dip.r200_deg.values[0]*extent*0.9, dip.theta2_deg.values[0] - dip.r200_deg.values[0]*extent*0.9, "dip.idx = %.2f" % dipole_index[idx], color='black', bbox=dict( facecolor='w', edgecolor='w', alpha=0.8, boxstyle='round,pad=0.5', ), zorder=3, ) ax.set_xlabel(r"$\theta_1 \quad $[deg]") axis[0].set_ylabel(r"$\theta_2 \quad $[deg]") return fig