Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

from builtins import object 

import numpy as np 

import healpy as hp 

import os 

from lsst.utils import getPackageDir 

 

 

def ss_split(arr, side='left'): 

""" 

make it possible to run searchsorted easily on 2 dims 

""" 

result = np.searchsorted(arr[1:], arr[0], side=side) 

return result 

 

 

class M5percentiles(object): 

""" 

Take a map of five-sigma limiting depths and convert it to a map of percentiles 

""" 

 

def __init__(self): 

 

# Load up the saved maps 

path = getPackageDir('sims_skybrightness_pre') 

filename = 'data/percentile_m5_maps.npz' 

temp = np.load(os.path.join(path, filename)) 

self.m5_histograms = temp['histograms'].copy().T 

self.histogram_npts = temp['histogram_npts'].copy() 

temp.close() 

self.npix = self.m5_histograms['u'][:, 0].size 

self.nside = hp.npix2nside(self.npix) 

self.nbins = float(self.m5_histograms['u'][0, :].size) 

 

def dark_map(self, filtername='r', nside_out=64): 

"""Return the darkest every healpixel gets 

""" 

result = self.m5_histograms[filtername][:, -1] 

if self.nside != nside_out: 

result = hp.ud_grade(result, nside_out=nside_out) 

return result 

 

def m5map2percentile(self, m5map, filtername='r'): 

""" 

Convert a healpix map to a percentile map 

""" 

orig_mask = np.where(m5map == hp.UNSEEN) 

 

inNside = hp.npix2nside(m5map.size) 

if inNside != self.nside: 

m5map = hp.ud_grade(m5map, nside_out=self.nside, pess=False) 

 

goodPix = np.where(m5map != hp.UNSEEN)[0] 

 

result = np.empty(self.npix, dtype=float) 

result.fill(hp.UNSEEN) 

temp_array = np.column_stack((m5map[goodPix], self.m5_histograms[filtername][goodPix, :])) 

result[goodPix] = np.apply_along_axis(ss_split, 1, temp_array)/self.nbins 

 

# convert the percentiles back to the right nside if needed 

# XXX--I should make a better linear interpolation upgrade function. 

if inNside != self.nside: 

result = hp.ud_grade(result, nside_out=inNside) 

result[orig_mask] = hp.UNSEEN 

return result