Beispiel #1
0
def execWithValues(conn, sql, values):
    try:
        cur = conn.cursor()
        cur.execute(sql, values)
        conn.commit()
    except Exception, ex:
        exUtil.printTagMessage(ex, exceptionTag, sql)
Beispiel #2
0
def execSQL(sql):
    try:
        conn = getMySQLConn()
        cur = conn.cursor()
        cur.execute(sql)
        conn.commit()
    except Exception, ex:
        exUtil.printTagMessage(ex, exceptionTag, sql)
Beispiel #3
0
    def fitsToDatabase(self, strategy):
        strategy.preHandle()

        filePaths = util.listDirFiles(strategy.dirPath, ".fits")
        for filePath in filePaths:
            try:
                fitsInfo = astroUtil.getFitsInfo(filePath)
                strategy.handle(fitsInfo)
            except Exception, ex:
                exUtil.printTagMessage(ex, "Fits handle error", filePath)
Beispiel #4
0
def getList(sql):
    res = []
    try:
        conn = getMySQLConn()
        cur = conn.cursor()
        data = cur.fetchmany(cur.execute(sql))

        for item in data:
            res.append(item[0])
    except Exception, ex:
        exUtil.printTagMessage(ex, exceptionTag, sql)
Beispiel #5
0
def plot(sql_distinct, sql_select_coordinate, sql_select_coordinate_count, tag, onlyShowAll=False):
    mainClassList = getMainClassList(sql_distinct, onlyShowAll)

    for mainClass in mainClassList:

        ras, decs, count = getCoordinateData(sql_select_coordinate, sql_select_coordinate_count, mainClass)

        try:
            plotSingleCLass(ras, decs, tag, mainClass, count)
        except Exception, ex:
            exUtil.printMessage(ex, "Density Plot Error", mainClass)
Beispiel #6
0
def plotScatter(sql_distinct, sql_select_coordinate, sql_select_coordinate_count, tag, onlyShowAll=False):
    mainClassList = getMainClassList(sql_distinct, onlyShowAll)

    for mainClass in mainClassList:

        ras, decs, count = getCoordinateData(sql_select_coordinate, sql_select_coordinate_count, mainClass)

        try:
            CommonPlot.plotGrid(plt)
            plt.title(tag + " - " + mainClass + "_Scatter")
            plt.plot(ras, decs, '.')

            CommonPlot.plotGalaxy(plt)
            filePath = "/media/zdwdong/my/fits/Scatter/Scatter_%s_%s.png" % (tag, mainClass)
            plt.savefig(filePath)
            print tag + " : " + mainClass + " saved"
            plt.close()
        except Exception, ex:
            exUtil.printMessage(ex, "Density Plot Error", mainClass)
Beispiel #7
0
def calcMinChi2(flux_target, templateDir, waveRange):
    minChi2 = 0
    templatePath = ""
    minCoeff = None

    templatePaths = util.listDirFiles(templateDir)
    for path in templatePaths:
        data = np.loadtxt(path)
        wave, flux = formatWaveAndFlux(data[:, 0], data[:, 1], waveRange)
        try:
            coeff = mathUtil.calcChi2Coeff(flux_target, flux, wave)
        except Exception, ex:
            exUtil.printTagMessage(ex, "error", path)
            continue
        chi2_value = mathUtil.chi2_ploy(wave, flux_target, flux, coeff[0], coeff[1], coeff[2])

        if minChi2 == 0 or chi2_value < minChi2:
            minChi2 = chi2_value
            templatePath = path
            minCoeff = coeff
def importLamostData(sql_select, sql_insert):
    conn = sqlHelper.getMySQLConn()
    conn45 = sqlHelper.getMySQL45Conn()

    count = 0
    data = sqlHelper.getFetchManyByConn(conn45, sql_select)

    for info in data:
        sqlRecord = []
        colIndex = 1
        try:
            for col in info:
                if colIndex == 13:
                    classType = info[10]
                    subClass = info[11]
                    mainClass = astroUtil.getMainClass(classType, subClass)
                    sqlRecord.append(mainClass)
                sqlRecord.append(col)
                colIndex += 1
            sqlHelper.execWithValues(conn, sql_insert, sqlRecord)
            count += 1
        except Exception, ex:
            exUtil.printMessage(ex, "Migration")
Beispiel #9
0
def getMySQLConn():
    try:
        return MySQLdb.connect(host='localhost', user='******', passwd='zdwdong', db='dr3', port=3306)
    except Exception, ex:
        exUtil.printMessage(ex, exceptionTag)
Beispiel #10
0
def getMySQL45Conn():
    try:
        return MySQLdb.connect(host='10.51.0.45', user='******', passwd='lamost', port=3306)
    except Exception, ex:
        exUtil.printMessage(ex, exceptionTag)