#
#
#
#
# date: 2019-08-20
# author: YUUKI OMORI , GIUSEPPE PUGLISI
# python3.6
# Copyright (C) 2019 Giuseppe Puglisi gpuglisi@stanford.edu
#
import reproject
import numpy as np
import astropy.io.fits as fits
[docs]def h2f(hmap,target_header,coord_in='C'):
"""
Returns a target square submap from a projected HEALPIX map, given a WCS header,
using :py:mod:`reproject` package
**Parameters**
- ``hmap`` : {array}
healpix map
- ``target_header``:
header defined from :func:`set_header`
"""
pr,footprint = reproject.reproject_from_healpix(
(hmap, coord_in), target_header, shape_out=(500,500),
order='nearest-neighbor', nested=False)
return pr
[docs]def f2h(flat,target_header,nside,coord_in='C'):
"""
Returns a HEALPIX map projected and the footprint of a flat one , given a WCS header,
using :py:mod:`reproject` package
**Parameters**
- ``flat`` : {2D array}
flat map
- ``target_header``:
header defined from :func:`set_header`
- ``nside``:{int}
nside of output healpix map
"""
pr,footprint = reproject.reproject_to_healpix(
(flat, target_header),coord_system_out='C', nside=nside ,
order='nearest-neighbor', nested=False)
return pr, footprint
[docs]def rd2tp(ra,dec):
"""
Convert ``ra,dec -> theta,phi``
"""
tht = (-dec+90.0)/180.0*np.pi
phi = ra/180.0*np.pi
return tht,phi
[docs]def tp2rd(tht,phi):
"""
Convert ``theta,phi -> ra,dec``
"""
ra = phi/np.pi*180.0
dec = -1*(tht/np.pi*180.0-90.0)
return ra,dec
[docs]def MinMaxRescale(x,a=0,b=1):
"""
Performs a MinMax Rescaling on an array `x` to a generic range :math:`[a,b]`.
"""
xresc = (b-a)*(x- x.min() )/(x.max() - x.min() ) +a
return xresc
[docs]def StandardizeFeatures(x) :
"""
Standardizes an array `x` to have average ``0``, and std. deviation ``1`` .
"""
return (x - x.mean()) /(x.std() )
[docs]def return_intersection(hist_test, hist_true ):
"""
Estimate the intersection between two histograms.
"""
minima = np.minimum(hist_test, hist_true )
intersection = np.true_divide(np.sum(minima), np.sum(hist_true ))
return intersection