def pupilCoordsFromPixelCoords(self,
                                   xPix,
                                   yPix,
                                   chipName,
                                   obs_metadata,
                                   includeDistortion=True):
        """
        Convert pixel coordinates into pupil coordinates

        Parameters
        ----------
        xPix is the x pixel coordinate of the point.
        Can be either a float or a numpy array.
        Defined in the Camera team system (not the DM system).

        yPix is the y pixel coordinate of the point.
        Can be either a float or a numpy array.
        Defined in the Camera team system (not the DM system).

        chipName is the name of the chip(s) on which the pixel coordinates
        are defined.  This can be a list (in which case there should be one chip name
        for each (xPix, yPix) coordinate pair), or a single value (in which case, all
        of the (xPix, yPix) points will be reckoned on that chip).

        obs_metadata is an ObservationMetaData characterizing the telescope
        pointing.

        includeDistortion is a boolean.  If True (default), then this method will
        expect the true pixel coordinates with optical distortion included.  If False, this
        method will expect TAN_PIXEL coordinates, which are the pixel coordinates with
        estimated optical distortion removed.  See the documentation in afw.cameraGeom for more
        details.

        Returns
        -------
        a 2-D numpy array in which the first row is the x pupil coordinate
        and the second row is the y pupil coordinate (both in radians)
        """
        dm_xPix = yPix
        if isinstance(chipName, list) or isinstance(chipName, np.ndarray):
            dm_yPix = np.zeros(len(xPix))
            for ix, (det_name, xx) in enumerate(zip(chipName, xPix)):
                came_center_pix = self.getCenterPixel(det_name)
                dm_yPix[ix] = 2.0 * cam_center_pix.getX() - xPix[ix]
        else:
            cam_center_pix = self.getCenterPixel(chipName)
            dm_yPix = 2.0 * cam_center_pix.getX() - xPix
        return coordUtils.pupilCoordsFromPixelCoordsLSST(
            dm_xPix,
            dm_yPix,
            chipName,
            band=obs_metadata.bandpass,
            includeDistortion=includeDistortion)
xpix = []
ypix = []
chip = []
for det in lsst_camera():
    if det.getType()!=SCIENCE:
        continue
    for xx, yy in zip(xpix_mesh, ypix_mesh):
        xpix.append(xx)
        ypix.append(yy)
        chip.append(det.getName())

xpix = np.array(xpix)
ypix = np.array(ypix)
chip = np.array(chip)
xp, yp = pupilCoordsFromPixelCoordsLSST(xpix, ypix, chipName=chip, band='r')
ra, dec = raDecFromPupilCoords(xp, yp, obs_metadata=obs_root,
                               includeRefraction=False)

out_dir = 'ratio_test/catalogs'

sed_candidates = os.listdir(galaxy_dir)

sed_names = rng.choice(sed_candidates, size=len(ra), replace=True)
redshift_vals = rng.random_sample(len(sed_names))*2.0

for i_filter in range(6):
    obs = ObservationMetaData(pointingRA=obs_root.pointingRA,
                              pointingDec=obs_root.pointingDec,
                              rotSkyPos=obs_root.rotSkyPos,
                              mjd=obs_root.mjd,
    def test_dmPixFromCameraPix(self):
        """
        Test that the method to return DM pixel coordinates from
        Camera Team pixel coordinates works.
        """
        camera = lsst_camera()
        camera_wrapper = LSSTCameraWrapper()
        obs = ObservationMetaData(bandpassName='u')

        npts = 100
        rng = np.random.RandomState(1824)
        dm_x_pix_list = rng.random_sample(npts) * 4000.0
        dm_y_pix_list = rng.random_sample(npts) * 4000.0
        name_list = []
        for det in camera:
            name_list.append(det.getName())
        chip_name_list = rng.choice(name_list, size=npts)

        (xPup_list,
         yPup_list) = pupilCoordsFromPixelCoordsLSST(dm_x_pix_list,
                                                     dm_y_pix_list,
                                                     chipName=chip_name_list,
                                                     band=obs.bandpass)

        (cam_x_pix_list,
         cam_y_pix_list) = camera_wrapper.pixelCoordsFromPupilCoords(
             xPup_list, yPup_list, chip_name_list, obs)

        (dm_x_test, dm_y_test) = camera_wrapper.dmPixFromCameraPix(
            cam_x_pix_list, cam_y_pix_list, chip_name_list)

        np.testing.assert_array_almost_equal(dm_x_test,
                                             dm_x_pix_list,
                                             decimal=4)
        np.testing.assert_array_almost_equal(dm_y_test,
                                             dm_y_pix_list,
                                             decimal=4)

        # test transformations made one at a time
        for ii in range(len(cam_x_pix_list)):
            dm_x, dm_y = camera_wrapper.dmPixFromCameraPix(
                cam_x_pix_list[ii], cam_y_pix_list[ii], chip_name_list[ii])

            self.assertAlmostEqual(dm_x_pix_list[ii], dm_x, 4)
            self.assertAlmostEqual(dm_y_pix_list[ii], dm_y, 4)

        # test case where an array of points is on a single chip
        chip_name = chip_name_list[10]

        (xPup_list,
         yPup_list) = pupilCoordsFromPixelCoordsLSST(dm_x_pix_list,
                                                     dm_y_pix_list,
                                                     chipName=chip_name,
                                                     band=obs.bandpass)

        (cam_x_pix_list,
         cam_y_pix_list) = camera_wrapper.pixelCoordsFromPupilCoords(
             xPup_list, yPup_list, chip_name, obs)

        (dm_x_test, dm_y_test) = camera_wrapper.dmPixFromCameraPix(
            cam_x_pix_list, cam_y_pix_list, chip_name)

        np.testing.assert_array_almost_equal(dm_x_test,
                                             dm_x_pix_list,
                                             decimal=4)
        np.testing.assert_array_almost_equal(dm_y_test,
                                             dm_y_pix_list,
                                             decimal=4)

        del camera
        del camera_wrapper
        del lsst_camera._lsst_camera
        plt.ylabel('catsim_flux/phosim_flux')
        plt.ylim(0.8, 1.2)

        plt.tight_layout()

        fig_name = os.path.join(args.fig_dir, '%s_flux_plot.png' % filter_name)
        plt.savefig(fig_name)
        plt.close()

    for i_filter in range(5):
        filter_name = 'ugrizy'[i_filter]
        filter_1 = filter_name
        filter_2 = 'ugrizy'[i_filter + 1]
        xpup, ypup = pupilCoordsFromPixelCoordsLSST(
            xpix_dict[filter_name],
            ypix_dict[filter_name],
            chipName=chip_name_dict[filter_name],
            band=filter_name)

        xmm, ymm = focalPlaneCoordsFromPupilCoordsLSST(xpup,
                                                       ypup,
                                                       band=filter_name)

        phosim_color = 2.5 * np.log10(
            phosim_flux_dict[filter_1] / phosim_flux_dict[filter_2])
        catsim_color = 2.5 * np.log10(
            catsim_flux_dict[filter_1] / catsim_flux_dict[filter_2])
        dcolor = catsim_color - phosim_color

        dmm = 1.0
        xmm_grid = np.arange(xmm.min(), xmm.max() + dmm, dmm)