Exemplo n.º 1
0
 def test_pix2coord(self, origin):
     x, y = mkin.coord2pix(self.cx,
                           self.cy,
                           self.cdim,
                           self.imgdim,
                           origin=origin)
     cx, cy = mkin.pix2coord(x, y, self.cdim, self.imgdim, origin=origin)
     cxy = np.r_[cx, cy]
     cxy_gt = np.r_[self.cx, self.cy]
     assert np.all(np.isclose(cxy, cxy_gt, rtol=1e-7, atol=1e-10))
Exemplo n.º 2
0
    def setUp(self):

        self.img = Image.open("moonmap_tiny.png").convert("L")
        imgsize = list(self.img.size)
        self.img = self.img.crop([0, 0, 300, 300])
        self.img = self.img.resize([200, 200])

        # Take top edge of long-lat bounds
        ix = np.array([0, 300])
        iy = np.array([0, 300])
        cdim = [-180, 180, -90, 90]
        llong, llat = mkin.pix2coord(ix, iy, cdim, imgsize, origin="upper")
        self.llbd = np.r_[llong, llat[::-1]]

        self.iglobe = ccrs.Globe(semimajor_axis=1737400,
                                 semiminor_axis=1737400,
                                 ellipse=None)

        self.geoproj = ccrs.Geodetic(globe=self.iglobe)
        self.iproj = ccrs.PlateCarree(globe=self.iglobe)
        self.oproj = ccrs.Orthographic(central_longitude=np.mean(
            self.llbd[:2]),
                                       central_latitude=np.mean(self.llbd[2:]),
                                       globe=self.iglobe)

        xllr = np.array([self.llbd[0], np.mean(self.llbd[:2]), self.llbd[1]])
        yllr = np.array([self.llbd[2], np.mean(self.llbd[2:]), self.llbd[3]])
        xll, yll = np.meshgrid(xllr, yllr)
        xll = xll.ravel()
        yll = yll.ravel()

        # [:,:2] becaus we don't need elevation data
        res = self.iproj.transform_points(x=xll, y=yll,
                                          src_crs=self.geoproj)[:, :2]
        self.iextent = [
            min(res[:, 0]),
            max(res[:, 0]),
            min(res[:, 1]),
            max(res[:, 1])
        ]

        res = self.oproj.transform_points(x=xll, y=yll,
                                          src_crs=self.geoproj)[:, :2]
        self.oextent = [
            min(res[:, 0]),
            max(res[:, 0]),
            min(res[:, 1]),
            max(res[:, 1])
        ]

        self.craters = pd.DataFrame(np.vstack([xllr, yllr]).T,
                                    columns=["Long", "Lat"])
        self.craters["Diameter (km)"] = [10, 10, 10]
Exemplo n.º 3
0
    def test_pix2coord(self):

        for origin in ["lower", "upper"]:
            with self.subTest(origin=origin):
                x, y = mkin.coord2pix(self.cx,
                                      self.cy,
                                      self.cdim,
                                      self.imgdim,
                                      origin=origin)
                cx, cy = mkin.pix2coord(x,
                                        y,
                                        self.cdim,
                                        self.imgdim,
                                        origin=origin)
                cxy = np.r_[cx, cy]
                cxy_gt = np.r_[self.cx, self.cy]
                self.assertTrue(
                    np.all(np.isclose(cxy, cxy_gt, rtol=1e-7, atol=1e-10)))
Exemplo n.º 4
0
def ProjectionSpeedTest():
    """Sample speed test; modify to heart's content!"""

    imgname = "out/out_01_01.png"
    cdim = [-180, 180, -90, 90]
    csvname = "out/out_01_01.csv"
    imgdim = np.array([4292, 2145])
    resolutions = np.array([32, 64, 128, 256, 512, 1024])
    np.random.shuffle(resolutions)
    resolutions = np.r_[np.array([32]), resolutions]

    # Obtain long/lat bounds
    pos = np.array([0, 0])
    size = np.array([429, 214])
    ix = np.array([pos[0], pos[0] + size[0]])
    iy = np.array([pos[1], pos[1] + size[1]])

    # Using origin="upper" means our latitude coordinates are reversed
    llong, llat = mkin.pix2coord(ix, iy, cdim, imgdim, origin="upper")
    llbd = np.r_[llong, llat[::-1]]

    oname = "out/DELETELATER.png"

    imgloadtime = np.mean(
        timeit.repeat('img = Image.open(imgname).convert("L")',
                      repeat=10,
                      number=1,
                      setup="from __main__ import Image, imgname"))
    raw_image = Image.open(imgname).convert("L")

    restimes = np.zeros(resolutions.size)
    for i, resolution in enumerate(resolutions):
        img = raw_image.resize([
            resolutions[i],
            int(
                np.round(resolutions[i] * raw_image.size[1] /
                         raw_image.size[0]))
        ])
        ct = timeit.repeat("MakePCOTransform(img, oname, llbd, csvname)", \
                setup="from __main__ import MakePCOTransform, img, oname, llbd, csvname", \
                number=1, repeat=10)
        restimes[i] = np.mean(ct)

    return imgloadtime, zip(resolutions, restimes)
Exemplo n.º 5
0
    def setup(self):
        self.img = Image.open(
            'LunarLROLrocKaguya_1180mperpix_downsamp.png').convert("L")
        self.craters = mkin.ReadLROCHeadCombinedCraterCSV(
            filelroc="../LROCCraters.csv",
            filehead="../HeadCraters.csv",
            sortlat=True)
        self.rawlen_range = [256, 512]
        self.npseed = 1337

        np.random.seed(self.npseed)

        rawlen_min = np.log10(self.rawlen_range[0])
        rawlen_max = np.log10(self.rawlen_range[1])

        rawlen = int(10**np.random.uniform(rawlen_min, rawlen_max))
        xc = np.random.randint(0, self.img.size[0] - rawlen)
        yc = np.random.randint(0, self.img.size[1] - rawlen)
        box = np.array([xc, yc, xc + rawlen, yc + rawlen], dtype='int32')
        # THIS WILL BECOME WRONG!
        assert np.all(box == np.array([860, 1256, 1166, 1562]))

        # Take top edge of long-lat bounds.
        ix = np.array([0, 300])
        iy = np.array([0, 300])
        cdim = [-180, 180, -60, 60]
        llong, llat = mkin.pix2coord(ix, iy, cdim, imgsize, origin="upper")
        self.llbd = np.r_[llong, llat[::-1]]

        self.iglobe = ccrs.Globe(semimajor_axis=1737400,
                                 semiminor_axis=1737400,
                                 ellipse=None)

        self.geoproj = ccrs.Geodetic(globe=self.iglobe)
        self.iproj = ccrs.PlateCarree(globe=self.iglobe)
        self.oproj = ccrs.Orthographic(central_longitude=np.mean(
            self.llbd[:2]),
                                       central_latitude=np.mean(self.llbd[2:]),
                                       globe=self.iglobe)

        xllr = np.array([self.llbd[0], np.mean(self.llbd[:2]), self.llbd[1]])
        yllr = np.array([self.llbd[2], np.mean(self.llbd[2:]), self.llbd[3]])
        xll, yll = np.meshgrid(xllr, yllr)
        xll = xll.ravel()
        yll = yll.ravel()

        # [:,:2] becaus we don't need elevation data
        res = self.iproj.transform_points(x=xll, y=yll,
                                          src_crs=self.geoproj)[:, :2]
        self.iextent = [
            min(res[:, 0]),
            max(res[:, 0]),
            min(res[:, 1]),
            max(res[:, 1])
        ]

        res = self.oproj.transform_points(x=xll, y=yll,
                                          src_crs=self.geoproj)[:, :2]
        self.oextent = [
            min(res[:, 0]),
            max(res[:, 0]),
            min(res[:, 1]),
            max(res[:, 1])
        ]

        self.craters = pd.DataFrame(np.vstack([xllr, yllr]).T,
                                    columns=["Long", "Lat"])
        self.craters["Diameter (km)"] = [10, 10, 10]