In [1]:
import os
import numpy as np
import pandas as pd
Note For this to work, you will need the lsst.sims
stack to be installed.
healpy
which is installed with the sims stack, but also available from pip/condalsst.sims
stack.
In [2]:
import opsimsummary as oss
from opsimsummary import Tiling, HealpixTiles
# import snsims
import healpy as hp
In [3]:
%matplotlib inline
import matplotlib.pyplot as plt
noTile = snsims.Tiling()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-9-5f6f8a94508e> in <module>()
----> 1 noTile = snsims.Tiling()
TypeError: Can't instantiate abstract class Tiling with abstract methods __init__, area, pointingSequenceForTile, tileIDSequence, tileIDsForSN
The class snsims.Tiling
is an abstract Base class. Therefore, this cannot be instantiated. It must be subclassed, and the set of methods outlined have to be implemented for this to work.
In [4]:
class NoTile(Tiling):
pass
In [5]:
noTile = NoTile()
"""noTile = NoTile()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-8ddedac7fb97> in <module>()
----> 1 noTile = NoTile()
TypeError: Can't instantiate abstract class NoTile with abstract methods __init__, area, pointingSequenceForTile, positions, tileIDSequence, tileIDsForSN
"""
The above fails because the methods are not implemented. Below is a stupid (ie. not useful) but minimalist class that would work:
In [6]:
class MyTile(Tiling):
def __init__(self):
pass
@property
def tileIDSequence(self):
return np.arange(100)
def tileIDsForSN(self, ra, dec):
x = ra + dec
y = np.remainder(x, 100.)
return np.floor(y)
def area(self, tileID):
return 1.
def pointingSequenceForTile(self, tileID, pointings):
return None
def positions(self):
pass
In [7]:
myTile = MyTile()
Currently there is only concrete tiling class that has been implemented. This is the snsims.HealpixTiles
class.
This shows how to use the HealpixTiles Class
In [8]:
issubclass(HealpixTiles, Tiling)
Out[8]:
In [9]:
help(HealpixTiles)
In [10]:
datadir = os.path.join(oss.__path__[0], 'example_data')
opsimdb = os.path.join(datadir, 'enigma_1189_micro.db')
In [11]:
NSIDE = 4
In [12]:
hpOpSim = oss.HealPixelizedOpSim.fromOpSimDB(opsimdb, NSIDE=NSIDE)
In [13]:
NSIDE
Out[13]:
In [14]:
hpTileshpOpSim = HealpixTiles(healpixelizedOpSim=hpOpSim, nside=NSIDE)
In [15]:
hpTileshpOpSim.pointingSequenceForTile(1, allPointings=None)
In [16]:
phi, theta = hpTileshpOpSim.positions(1, 10000)
In [17]:
mapvals = np.ones(hp.nside2npix(NSIDE)) * hp.UNSEEN
In [18]:
mapvals[1] = 100
In [ ]:
In [19]:
hp.ang2pix(NSIDE, np.radians(theta), np.radians(phi), nest=True)
Out[19]:
In [20]:
theta_c, phi_c = hp.pix2ang(4, 1, nest=True)
In [21]:
hp.mollview(mapvals, nest=True)
hp.projscatter(np.radians(theta), np.radians(phi), **dict(s=0.0002))
hp.projscatter(theta_c, phi_c, **dict(s=8., c='r'))
Out[21]:
In [30]:
%timeit hpTileshpOpSim.pointingSequenceForTile(33, allPointings=None)
In [31]:
preCompMap = os.path.join(oss.__path__[0], 'example_data', 'healpixels_micro.db')
In [33]:
hpTilesMap = HealpixTiles(nside=1, preComputedMap=preCompMap)
In [34]:
hpTilesMap.pointingSequenceForTile(10, allPointings=None)
Out[34]:
In [35]:
%timeit hpOpSim.obsHistIdsForTile(34)
In [36]:
hpTiles = HealpixTiles(healpixelizedOpSim=hpOpSim)
In [37]:
hpTiles.pointingSequenceForTile(34, allPointings=None)
Out[37]:
In [ ]:
In [ ]: