<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Contents
This notebook shows how to use the functionality in the HealpixTree class. This is a useful function to find groups of Healpixels at high resolution which are connected and nearby. In particular this notebook illustrates two useful methods
Step1:  Instantiate the object
Step2:  Find all the healpixels at the resolution one level higher
Step3:  Find all the pixels at NSIDE=256, which are owned by pixelid =1  at NSIDE=1
Step4:  Visusalize this
<ASSISTANT_TASK:>
Python Code:
from mpl_toolkits.basemap import Basemap
import opsimsummary as oss
oss.__VERSION__
from opsimsummary import HealpixTree, pixelsForAng, HealpixTiles
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
import healpy as hp
Explanation: Contents
This notebook shows how to use the functionality in the HealpixTree class. This is a useful function to find groups of Healpixels at high resolution which are connected and nearby. In particular this notebook illustrates two useful methods:
- How to find the descendent pixels of a sequence of pixels at the next higher resolution using pixelsAtNextLevel
- How to find the descendent pixels at a sequence of pixels at resolution res above the resolution using pixelsAtResolutionLevel
End of explanation
htree = HealpixTree(nside=1, nest=True)
Explanation: Instantiate the object
End of explanation
# By default the nside argument to this function is the nside at which htree was instantiated
print(htree.nside)
ipix =  np.array([0, 1])
htree.pixelsAtNextLevel(ipix)
# We can also be specific, and do this for a particular NSIDE
htree.pixelsAtNextLevel(ipix, nside=128)
Explanation: Find all the healpixels at the resolution one level higher
End of explanation
# How many subdivisions required to go to NSIDE =256 ?
desideredNSIDE = 256
res = int(np.log2(desideredNSIDE))
# nsidenew should be the NSIDE at the resolution we want
nsidenew, pixels = htree.pixelsAtResolutionLevel(1, res, 1)
assert nsidenew == desideredNSIDE
Explanation: Find all the pixels at NSIDE=256, which are owned by pixelid =1  at NSIDE=1
End of explanation
n256 = hp.nside2npix(256)
n1 = hp.nside2npix(1)
arr1 = np.ones(n1) * hp.UNSEEN
arr1[1] = 1
arr256 = np.ones(n256) * hp.UNSEEN
arr256[pixels] = -2
hp.mollview(arr1, nest=True)
hp.mollview(arr256, nest=True)
Explanation: Visusalize this
End of explanation
<END_TASK>