コード例 #1
0
def PlotComparison():
    """Script to compare home-brewed and cartopy plots.
    """

    # Note to self: use scipy.ndimage.imread or
    # Image.open('image.png').convert('LA') if you need
    # to flatten to greyscale

    img = plt.imread("./moonmap_small.png")
    craters = mkin.ReadSalamuniccarCraterCSV()
    mindiam = 100.

    crater_sub = craters.loc[(craters["Name"].notnull())
                             & (craters["Diameter (km)"] > mindiam)]

    cx, cy = coord2pix(crater_sub["Long"].as_matrix(),
                       crater_sub["Lat"].as_matrix(),
                       [img.shape[1], img.shape[0]])

    PlotMoonPic(img, {
        "x": cx,
        "y": cy
    },
                borderless=True,
                savefig="./test_moonpic.png")

    PlotMoonMap(img=img,
                craters=craters,
                mindiam=mindiam,
                projection=ccrs.PlateCarree(central_longitude=0),
                savefig="./test_moonmap.png")
コード例 #2
0
    def setUp(self):
        c1 = mkin.ReadSalamuniccarCraterCSV(filename="./LU78287GT.csv",
                                            sortlat=False)

        def match_end(s):
            if re.match(r" [A-Z]", s[-2:]):
                return True
            return False

        tocut = c1.loc[c1["Name"].notnull(), "Name"].apply(match_end)
        tocut = tocut[tocut].index
        c1.drop(tocut, inplace=True)
        c1.drop(["ID", "Radius (deg)", "D_range", "p", "Name"],
                axis=1,
                inplace=True)
        c1 = c1[c1["Diameter (km)"] > 20]

        c2 = mkin.ReadAlanCraterCSV(filename="./alanalldata.csv",
                                    sortlat=False)
        c2.drop(["Unnamed: 0", "Unnamed: 0.1", "tag"], axis=1, inplace=True)

        self.c = pd.concat([c1, c2], axis=0, ignore_index=True)

        self.c.sort_values(by='Lat', inplace=True)
        self.c.reset_index(inplace=True, drop=True)

        self.co = mkin.ReadCombinedCraterCSV(dropfeatures=True)

        del c1
        del c2
コード例 #3
0
def BigCraters():
    craters = mkin.ReadSalamuniccarCraterCSV(dropfeatures=True)
    big_name_craters = craters[(craters["Name"].notnull()) & \
                                    (craters["Diameter (km)"] > mindiam)].copy()
    mkin.CreatePlateCarreeDataSet("./moonmap_small.png",
                                  big_name_craters,
                                  6,
                                  outprefix="out/out")

    imagelist = sorted(glob.glob("out/out*.png"))
    CheckDataSet(imagelist)
コード例 #4
0
def PlotMoonMap(img="./moonmap_small.png",
                craters=False,
                projection=ccrs.Mollweide(central_longitude=0),
                savefig=False):
    """Cartopy plot of largest named craters (see code comments for references).
    Reads in long/lat for crater centroids.

    Parameters
    ----------
    img : str or ndarray
        Name of file or image file in ndarray form.
    craters : bool or pandas.DataFrame
        LU78287GT craters.  If false, loads from file.
    mindiam : float
        Minimum crater diameter for inclusion in plot
    projection : cartopy.crs projection
        Map projection
    savefig : str or bool
        If true, use as filename.  If False, do not save figure.
    """

    if type(img) == str:
        img = plt.imread(img)

    # Load craters table
    if not type(craters) == pd.core.frame.DataFrame:
        craters = mkin.ReadSalamuniccarCraterCSV()
    #big_name_craters = craters[(craters["Name"].notnull()) &
    #                            (craters["Diameter (km)"] > mindiam)]

    fig = plt.figure()

    # Feeding the projection keyword a ccrs method turns ax into a
    # cartopy.mpl.geoaxes.GeoAxes object, which supports coordinate
    # system transforms.
    ax = fig.add_subplot(1, 1, 1, projection=projection)

    # As noted in the Iris projections and annotations example, transform
    # specifies a non-display coordinate system for the data points.
    ax.imshow(img,
              transform=ccrs.PlateCarree(central_longitude=0),
              extent=[-180, 180, -90, 90],
              origin='upper')

    ax.scatter(craters["Long"],
               craters["Lat"],
               transform=ccrs.PlateCarree(central_longitude=0))

    if savefig:
        fig.savefig(savefig, dpi=200, edgecolor='w')
コード例 #5
0
def ProminentCrater(cratername="Copernicus r"):
    """Checks if one prominent crater is in the right spot
    in split images.

    Parameters
    ----------
    cratername : str
        Crater name.  Try "Copernicus r" or "Tycho r".
    """

    craters = mkin.ReadSalamuniccarCraterCSV()
    tycho = craters[craters['Name'].str.contains(cratername).fillna(
        False)].copy()
    CreateDataSet("./moonmap_small.png", tycho, 4, outprefix="out/octr")

    imagelist = sorted(glob.glob("out/octr*.png"))
    CheckDataSet(imagelist)
コード例 #6
0
ファイル: find_duplicates.py プロジェクト: cczhu/moon-craters
                              ' and Head.'))
    parser.add_argument('--filter_pairs',
                        action='store_true',
                        help=('Leaves only one entry per duplicate pair in'
                              ' output dataframe.'))
    parser.add_argument('--to_xlsx',
                        action='store_true',
                        help='Outputs xlsx instead of csv.')
    args = parser.parse_args()

    ctrs_lroc = mkin.ReadLROCCraterCSV(sortlat=False)
    ctrs_lroc.drop(["tag"], axis=1, inplace=True)
    ctrs_lroc['Dataset'] = 'LROC'

    if args.lroclu:
        ctrs_lu = mkin.ReadSalamuniccarCraterCSV(sortlat=False,
                                                 dropfeatures=False)
        ctrs_lu.drop(["Radius (deg)", "D_range", "p", "Name"],
                     axis=1,
                     inplace=True)
        ctrs_lu = ctrs_lu[ctrs_lu["Diameter (km)"] > 20]
        ctrs_lu['Dataset'] = 'LU'

        craters = pd.concat([ctrs_lroc, ctrs_lu],
                            axis=0,
                            ignore_index=True,
                            copy=True)

    else:
        ctrs_head = mkin.ReadHeadCraterCSV(sortlat=False)
        ctrs_head['Dataset'] = 'Head'