示例#1
0
def main():
    print('main')

    # ボタンの場所などを確認
    gp.getParameter()

    # ウィンドウのアクティブ化
    gp.clickLeft()

    for i in range(500):
        print('---------------------------')

        # C級育成
        gp.clickLeft()

        gp.getSS()

        gp.getText()
    def __init__(self,categoryName,pageNum = 1,**urlParameter):
        'Define attributes for ScraperProducer'
        
        self.presentDay = str(time.strftime('%Y-%m-%d',time.localtime(time.time())))
        self.presentTime = str(time.strftime('%H-%M-%S',time.localtime(time.time())))
        self.logTime = '[{} {}]'.format(self.presentDay,str(time.strftime('%H:%M:%S',time.localtime(time.time()))))

        self.categoryName = categoryName
        self.pageNum = pageNum
        self.parameters = getParameter(**urlParameter)
        self.pageURL = unparseURL(categoryName,self.parameters,(pageNum-1)*60)
        self.html = getPageHTML(self.pageURL)
示例#3
0
    def __init__(self, categoryName, pageNum=1, **urlParameter):
        'Define attributes for ScraperProducer'

        self.presentDay = str(
            time.strftime('%Y-%m-%d', time.localtime(time.time())))
        self.presentTime = str(
            time.strftime('%H-%M-%S', time.localtime(time.time())))
        self.logTime = '[{} {}]'.format(
            self.presentDay,
            str(time.strftime('%H:%M:%S', time.localtime(time.time()))))

        self.categoryName = categoryName
        self.pageNum = pageNum
        self.parameters = getParameter(**urlParameter)
        self.pageURL = unparseURL(categoryName, self.parameters,
                                  (pageNum - 1) * 60)
        self.html = getPageHTML(self.pageURL)
示例#4
0
def prepareHypFiles(path, hyp):
    hypDir = "HYP"
    createCleanDir(hypDir)

    if path is None:
        tmpPath = "."
    else:
        tmpPath = path

    dir_cnt = 0
    for myfile in os.listdir(tmpPath):
        if path is not None:
            myfile = os.path.join(path, myfile)
        testName = os.path.join(path, myfile)
        if os.path.isdir(testName) and (
                len(glob.glob("{}/*_unw_phase.tif".format(testName))) > 0
                or len(glob.glob("{}/*_unwrapped.tif".format(testName))) > 0):
            linkFile = os.path.join(hypDir, os.path.basename(myfile))
            if not os.path.exists(linkFile):
                os.symlink(testName, linkFile)
            dir_cnt = dir_cnt + 1

    if dir_cnt == 0:
        logging.error(
            "ERROR: Unable to find any direcories in {}".format(tmpPath))
        exit(1)

    os.chdir(hypDir)

    unw_cnt = len(glob.glob("*/*_unw_phase.tif"))
    cor_cnt = len(glob.glob("*/*_corr.tif"))

    old_coh = False
    if cor_cnt == 0:
        cor_cnt = len(glob.glob("*/*_coh.tif"))
        if cor_cnt != 0:
            old_coh = True

    old_snap = False
    if unw_cnt == 0:
        unw_cnt = len(glob.glob("*/*_unwrapped.tif"))
        if unw_cnt != 0:
            old_snap = True

    if unw_cnt != cor_cnt:
        logging.error(
            "ERROR: You are missing files!!! unw_cnt = %s; cor_cnt = %s" %
            (unw_cnt, cor_cnt))
        exit(1)

    f = open('../igram_list.txt', 'w')
    if old_snap:
        ext = "_unwrapped.tif"
    else:
        ext = "_unw_phase.tif"

    for myfile in glob.glob("*/*{}".format(ext)):
        logging.debug("Checking file {}".format(myfile))
        mdate = os.path.basename(myfile).split("_")[0]
        sdate = os.path.basename(myfile).split("_")[1]

        # Catch the case of S1TBX names
        if not len(mdate) == 15 and not len(mdate) == 8:
            logging.debug(
                "mdate is not a date or date time {}; reparsing".format(mdate))
            mdate = os.path.basename(myfile.split("_")[5])
            sdate = myfile.split("_")[6]

        pFile = os.path.basename(myfile)
        if not old_coh:
            cFile = os.path.basename(myfile.replace(ext, "_corr.tif"))
        else:
            cFile = os.path.basename(myfile.replace(ext, "_coh.tif"))
        txtFile = glob.glob("{}/*20*_20*.txt".format(
            os.path.dirname(myfile)))[0]
        baseline = getParameter(txtFile, "Baseline")
        f.write("{} {} {} {} {}\n".format(mdate, sdate, pFile, cFile,
                                          baseline))

    # Older zipfiles don't unzip into their own directory!
    for myfile in glob.glob("*{}".format(ext)):
        mdate = myfile.split("_")[0]
        sdate = myfile.split("_")[1]
        pFile = myfile
        cFile = myfile.replace(ext, "_corr.tif")
        txtFile = myfile.replace(ext, ".txt")
        baseline = getParameter(txtFile, "Baseline")
        f.write("{} {} {} {} {}\n".format(mdate, sdate, pFile, cFile,
                                          baseline))

    f.close()

    os.chdir("..")
    createCleanDir("DATA")
    os.chdir("DATA")
    for myfile in glob.glob("../{}/*/*{}".format(hypDir, ext)):
        if not os.path.exists(os.path.basename(myfile)):
            os.symlink(myfile, os.path.basename(myfile))
    if not old_coh:
        for myfile in glob.glob("../{}/*/*_corr.tif".format(hypDir)):
            if not os.path.exists(os.path.basename(myfile)):
                os.symlink(myfile, os.path.basename(myfile))
    else:
        for myfile in glob.glob("../{}/*/*_coh.tif".format(hypDir)):
            if not os.path.exists(os.path.basename(myfile)):
                os.symlink(myfile, os.path.basename(myfile))

    # Older zipfiles don't unzip into their own directory!
    for myfile in glob.glob("../{}/*_unw_phase.tif".format(hypDir)):
        if not os.path.exists(os.path.basename(myfile)):
            os.symlink(myfile, os.path.basename(myfile))
    for myfile in glob.glob("../{}/*_corr.tif".format(hypDir)):
        if not os.path.exists(os.path.basename(myfile)):
            os.symlink(myfile, os.path.basename(myfile))

    os.chdir("..")

    return ('igram_list.txt', hypDir)
示例#5
0
def procS1StackGIANT(type,
                     output,
                     descFile=None,
                     rxy=None,
                     nvalid=0.8,
                     nsbas=False,
                     filt=0.1,
                     path=None,
                     utcTime=None,
                     heading=None,
                     leave=False,
                     train=False,
                     hyp=None,
                     rawFlag=False,
                     mm=None,
                     errorFlag=False):

    logging.info(
        "***********************************************************************************"
    )
    logging.info("                 STARTING RUN {}".format(output))
    logging.info(
        "***********************************************************************************"
    )
    logging.info("Type of run is {}".format(type))

    if path is not None:
        if os.path.isdir(path):
            if path[0] != "/":
                root = os.getcwd()
                path = os.path.join(root, path)
        else:
            logging.error("ERROR: path {} is not a directory!".format(path))
            exit(1)
        logging.info("Data path is {}".format(path))

    templateDir = os.path.abspath(
        os.path.join(os.path.dirname(__file__), os.pardir, "etc"))
    logging.debug("Looking for templates in %s" % templateDir)

    if type == 'hyp':
        descFile, hypDir = prepareHypFiles(path, hyp)
    elif type == 'custom':
        if train:
            logging.warning(
                "***********************************************************************************"
            )
            logging.warning(
                "WARNING: Unable to run TRAIN model on custom inputs")
            logging.warning("WARNING: Switching off TRAIN corrections")
            logging.warning(
                "***********************************************************************************"
            )
            train = False
        if descFile is None:
            logging.error(
                "ERROR: Must specify a descriptor file when using custom option"
            )
            exit(1)
        if utcTime is None:
            logging.error(
                "ERROR: Must specify a UTC time when using custom option")
            exit(1)
        if heading is None:
            logging.error(
                "ERROR: Must specify a heading when using custom option")
            exit(1)
    elif type == 'aria':
        descFile, utcTime = prepGIAnT(intdir=path)
        heading = 12.0
    else:
        logging.error("ERROR: Unknown processing type {}".format(type))
        exit(1)

    if not os.path.isfile(descFile):
        logging.error(
            "ERROR: Unable to find descriptor file {}".format(descFile))
        exit(1)

    params = getFileList(descFile)
    params['type'] = type
    params['rxy'] = rxy
    params['nvalid'] = float(nvalid)
    params['train'] = train
    params['filt'] = filt

    if utcTime is None:
        os.chdir(hypDir)
        txtFile = glob.glob("*/*20*_20*.txt")[0]
        utcTime = getParameter(txtFile, "UTCtime")
        os.chdir("..")
    params['utctime'] = utcTime

    if heading is None:
        os.chdir(hypDir)
        txtFile = glob.glob("*/*20*_20*.txt")[0]
        heading = getParameter(txtFile, "Heading")
        os.chdir("..")
    params['heading'] = heading

    logging.info("Examining list of files to process...")
    for i in range(len(params['mdate'])):
        logging.debug("    found: {} {} {} {}".format(params['mdate'][i],
                                                      params['sdate'][i],
                                                      params['pFile'][i],
                                                      params['cFile'][i]))

    if type == 'custom':
        prepareCustomFiles(params, path)

    checkFileExistence(params)
    root = os.getcwd()

    logging.info("Reprojecting files...")
    reprojectFiles(params)

    logging.info("Cutting files...")
    os.chdir("DATA")
    if type != 'aria':
        cutFiles(params['pFile'])
        cutFiles(params['cFile'])

        for i in range(len(params['mdate'])):
            params['pFile'][i] = params['pFile'][i].replace(
                ".tif", "_clip.tif")
            params['cFile'][i] = params['cFile'][i].replace(
                ".tif", "_clip.tif")

    logging.info("Resizing files...")
    resizeFiles(params)

    if train:
        logging.info(
            "***********************************************************************************"
        )
        logging.info(
            "          PREPARING TO RUN THE TRAIN MERRA2 WEATHER MODEL")
        logging.info(
            "***********************************************************************************"
        )
        createCleanDir("TRAIN")
        os.chdir("TRAIN")
        makeParmsAPS(params, root)
        prepareFilesForTrain(params)
        myfile = os.path.join(os.pardir, params['pFile'][0])
        aps_weather_model("merra2", 1, 4, myfile)
        os.chdir("..")
        fixFileNamesTrain(params)

    logging.info("Translating files to raw format...")
    for i in range(len(params['pFile'])):
        params['pFile'][i] = toRaw(params['pFile'][i])
        params['cFile'][i] = toRaw(params['cFile'][i])

    if not leave:
        for myfile in glob.glob("*_wgs84.tif"):
            os.remove(myfile)
        for myfile in glob.glob("*_clip.tif"):
            os.remove(myfile)
        for myfile in glob.glob("*_resize.tif"):
            os.remove(myfile)

    width, length, trans, proj = saa.read_gdal_file_geo(
        saa.open_gdal_file(params['pFile'][0]))
    params['width'] = width
    params['length'] = length
    os.chdir("..")

    createIfgList(params)
    createExampleRSC(params)
    fixPrepDataXml(params, templateDir)
    fixUserfnPy(params, templateDir)
    fixPrepBasXml(params, templateDir)
    renameFiles(params)

    execute("python prepdataxml.py", uselogging=True)
    execute("PrepIgramStack.py", uselogging=True)
    execute("python prepsbasxml.py", uselogging=True)

    if nsbas == False:
        logging.info("Running SBAS inversion")
        if errorFlag:
            execute("SBASxval.py", uselogging=True)
            h5File = "LS-xval.h5"
        else:
            execute("SBASInvert.py", uselogging=True)
            h5File = "LS-PARAMS.h5"
    else:
        logging.info("Running NSBAS inversion")
        if errorFlag:
            h5File = "NSBAS-xval.h5"
            execute("NSBASxval.py -o {}".format(h5file), uselogging=True)
        else:
            execute("NSBASInvert.py", uselogging=True)
            h5File = "NSBAS-PARAMS.h5"

    os.chdir("Stack")
    filelist = makePNG.mkMovie(h5File, "recons", mm=mm)
    filelist.sort()

    if rawFlag:
        filelist2 = makePNG.mkMovie(h5File, "rawts", mm=mm)
        filelist2.sort()
    elif errorFlag:
        filelist2 = makePNG.mkMovie(h5File, "error", mm=mm)
        filelist2.sort()

    # Get the entire date range
    longList = np.unique(params['mdate'] + params['sdate'])
    dateList = []
    for i in range(len(longList)):
        dateList.append(longList[i][0:8])
    dateList = np.unique(dateList)
    dateList.sort()

    # Add annotations to files
    cnt = 0
    for myfile in filelist:
        execute(
            "convert {FILE} -gravity north  -annotate +0+5 '{DATE}' anno_{FILE}"
            .format(FILE=myfile, DATE=dateList[cnt]),
            uselogging=True)
        cnt = cnt + 1
    if train:
        name = "{}_train.gif".format(output)
    else:
        name = "{}.gif".format(output)
    # Make the animation
    execute("convert -delay 120 -loop 0 anno_*.png {}".format(name),
            uselogging=True)

    if rawFlag:
        for myfile in glob.glob("anno_*.png"):
            os.remove(myfile)
        cnt = 0
        for myfile in filelist2:
            execute(
                "convert {FILE} -gravity north  -annotate +0+5 '{DATE}' anno_{FILE}"
                .format(FILE=myfile, DATE=dateList[cnt]),
                uselogging=True)
            cnt = cnt + 1
        rawname = name.replace(".gif", "_rawts.gif")
        # Make the animation
        execute("convert -delay 120 -loop 0 anno_*.png {}".format(rawname),
                uselogging=True)
    elif errorFlag:
        for myfile in glob.glob("anno_*.png"):
            os.remove(myfile)
        cnt = 0
        for myfile in filelist2:
            execute(
                "convert {FILE} -gravity north  -annotate +0+5 '{DATE}' anno_{FILE}"
                .format(FILE=myfile, DATE=dateList[cnt]),
                uselogging=True)
            cnt = cnt + 1
        rawname = name.replace(".gif", "_error.gif")
        # Make the animation
        execute("convert -delay 120 -loop 0 anno_*.png {}".format(rawname),
                uselogging=True)

    # Get product directory ready
    os.chdir("..")
    prodDir = "PRODUCT_{}".format(output)
    createCleanDir(prodDir)

    os.chdir("Stack")

    shutil.move(name, "../{}".format(prodDir))
    if rawFlag or errorFlag:
        shutil.move(rawname, "../{}".format(prodDir))

    makeGeotiffFiles(h5File, "recons", params)
    if rawFlag:
        makeGeotiffFiles(h5File, "rawts", params)
    elif errorFlag:
        makeGeotiffFiles(h5File, "error", params)

    # Move files from Stack directory
    for myfile in glob.glob("*.tif"):
        shutil.move(myfile, "../{}".format(prodDir))
    shutil.move(h5File, "../{}/{}.h5".format(prodDir, output))
    os.chdir("..")

    shutil.copy(descFile, prodDir)

    if not leave:
        if type == 'hyp':
            shutil.rmtree(hypDir)
        shutil.rmtree("DATA")
        #        shutil.rmtree("LINKS")
        shutil.rmtree("Stack")
        shutil.rmtree("Figs")

        os.remove("data.xml")
        os.remove("userfn.pyc")
        os.remove("sbas.xml")
        os.remove("prepdataxml.py")
        os.remove("prepsbasxml.py")
        os.remove("userfn.py")
        os.remove("ifg.list")
        os.remove("example.rsc")

        if train:
            for myfile in glob.glob("merra/*/*.xyz"):
                os.remove(myfile)
    else:
        shutil.move("DATA", "DATA_{}".format(output))

    logging.info(
        "***********************************************************************************"
    )
    logging.info("                 END OF RUN {}".format(output))
    logging.info(
        "***********************************************************************************"
    )