<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 minimask mosaic example
Construct a mosaic of squares over the sky
Step1:  Specify the location of the mask file to write
Step2:  Construct a mask using a tile pattern with centers specified by the healpix grid.
Step3:  Load the file as a mask object
Step4:  Plot the mask on a mollweide projection using healpy.
Step5:  Pixelize the mask onto the healpix grid
<ASSISTANT_TASK:>
Python Code:
%matplotlib notebook
import os
import numpy as np
import tempfile
import matplotlib.pyplot as pyplot
import logging
logging.basicConfig(level=logging.INFO)
import minimask.mask as mask
import minimask.healpix_projection as hp
import minimask.io.mosaic as mosaic
Explanation: minimask mosaic example
Construct a mosaic of squares over the sky
End of explanation
filename = "masks/mosaic.txt"
try:
    os.mkdir(os.path.dirname(filename))
except:
    pass
Explanation: Specify the location of the mask file to write
End of explanation
tile = np.array([[[-0.5, -0.5],[0.5, -0.5],[0.5,0.5],[-0.5,0.5]]])*8
grid = hp.HealpixProjector(nside=4)
lon, lat = grid.pix2ang(np.arange(grid.npix))
centers = np.transpose([lon, lat])
mosaic.Mosaic(tile, centers).write(filename)
Explanation: Construct a mask using a tile pattern with centers specified by the healpix grid.
End of explanation
M = mask.Mask(filename)
print "The number of polygons in the mask is {}.".format(len(M))
Explanation: Load the file as a mask object
End of explanation
import healpy
healpy.mollview(title="")
for x,y in M.render(1):
    healpy.projplot(x,y,lonlat=True)
Explanation: Plot the mask on a mollweide projection using healpy.
End of explanation
map = M.pixelize(nside=64, n=10, weight=False)
healpy.mollview(map, title="")
Explanation: Pixelize the mask onto the healpix grid
End of explanation
<END_TASK>