def upload_cog_into_eeImgCol(dataPath,
                             gs_dir,
                             fileList=None,
                             upload_flag=True,
                             eeUser="******"):
    cogPath = dataPath / "COG"

    # eeUser = "******"
    eeImgCol_name = os.path.split(gs_dir)[-1]
    # print(os.path.split(gs_dir))
    eeImgCol = f"users/{eeUser}/{eeImgCol_name}"
    print(f"eeImgCol: {eeImgCol}")

    if not os.path.exists(cogPath): os.makedirs(cogPath)

    S1 = ee.ImageCollection("COPERNICUS/S1_GRD")
    S2 = ee.ImageCollection("COPERNICUS/S2")

    if fileList is None:
        fileList = [
            filename[:-4] for filename in os.listdir(dataPath)
            if (".tif" in filename)
        ]
    fileList = [
        filename for filename in fileList
        # if (".tif" in filename) # this product doesn't exist in GEE
        if (S1.filter(ee.Filter.eq("system:index", filename)).size().getInfo()
            == 0  # if not exist in S1 of GEE
            and S2.filter(ee.Filter.eq("PRODUCT_ID", filename)).size().getInfo(
            ) == 0  # if not exist in S2 of GEE
            )
    ]

    pprint(fileList)
    """ To COG GeoTiff """
    if upload_flag:
        """ Upload to earth engine asset """
        task_dict = {}
        for filename in fileList:
            print(f"\n{filename}")
            print(
                "--------------------------------------------------------------------"
            )

            asset_id = f"{eeImgCol}/{filename}"
            ee_upload_image = f"earthengine upload image --force --asset_id={asset_id} {gs_dir}/{filename}.tif"

            ee_upload_response = subprocess.getstatusoutput(ee_upload_image)[1]
            task_id = ee_upload_response.split("ID: ")[-1]
            task_dict.update(
                {filename: {
                    'task_id': task_id,
                    'asset_id': asset_id
                }})

            print(f"{asset_id}")
            pprint(f"task id: {task_id}")
            print()

        return task_dict
Ejemplo n.º 2
0
    def spawn(self,
              verify: bool = False,
              sign: bool = False,
              send: bool = False,
              locktime: int = 0,
              **kwargs) -> None:
        '''prepare deck spawn transaction'''

        deck = self.__new(**kwargs)

        spawn = pa.deck_spawn(provider=provider,
                              inputs=provider.select_inputs(
                                  Settings.key.address, 0.02),
                              deck=deck,
                              change_address=Settings.change,
                              locktime=locktime)

        if verify:
            print(cointoolkit_verify(
                spawn.hexlify()))  # link to cointoolkit - verify

        if sign:

            tx = signtx(spawn)

            if send:
                pprint({'txid': sendtx(tx)})

            return {'hex': tx.hexlify()}

        return spawn.hexlify()
    def evaluate(self):
        """ run episodes until evaluation is complete """
        while not self.env.evaluation_complete:
            episode_reward = self.play_single_episode()

        pprint(self.env.results)
        self.env.close()
Ejemplo n.º 4
0
def print_setup_attrs(root_dir=None):
    root_dir = root_dir or os.getcwd()
    setup_attrs = get_setup_attrs(root_dir)
    long_description = setup_attrs['long_description']
    if long_description and len(long_description) > 205:
        setup_attrs['long_description'] = long_description[:200] + '...'
    pprint(setup_attrs)
Ejemplo n.º 5
0
    def model_transfer(self):
        for fireName in transfer_dataset.keys():
            print(f"transfer to {fireName}")
            firePath = self.transferPath / f"{fireName}_Progression_Data_20m"

            refName = transfer_dataset[fireName][0]
            ref_url = firePath / "A0_Opt_Ref_Mask" / f"{refName}.png"
            if os.path.isfile(ref_url):
                ref = imread(ref_url) / 255.0
                print(ref.shape)
                if len(ref.shape) > 2: ref = ref[:, :, 0]

            transferSavePath = self.modelPath / f"transfer_to_{fireName}"
            if not os.path.exists(transferSavePath): os.mkdir(transferSavePath)
            transferDataPath = firePath / self.transfer_folder
            pprint(os.listdir(transferDataPath))
            for dataName in sorted(os.listdir(transferDataPath)):
                url = transferDataPath / dataName
                # print(f"{file}")
                # -------------> model inference <---------------------
                pred_mask = self.inference(url, transferSavePath)
                pred_mask_bin = pred_mask.round()

                if transfer_dataset[fireName][1] in dataName:
                    # print("test accuracy")
                    self.compute_test_accuarcy(pred_mask_bin, ref, False,
                                               fireName)
                    self.compute_test_accuarcy(pred_mask_bin, ref, True,
                                               fireName)
Ejemplo n.º 6
0
def main():
    checkout_dev_branch(sys.argv[1], project)
    lookml_errors = sdk.validate_project(project_id=project).errors
    prettyprinter.pprint((lookml_errors))
    # Assert no new errors introduced in dev branch
    for error in lookml_errors:
        assert error.kind != 'error', """
Ejemplo n.º 7
0
    def transfer(self,
                 deckid: str,
                 receiver: list = None,
                 amount: list = None,
                 asset_specific_data: str = None,
                 locktime: int = 0,
                 verify: bool = False,
                 sign: bool = False,
                 send: bool = False) -> Optional[dict]:
        '''prepare CardTransfer transaction'''

        card = self.__new(deckid, receiver, amount, asset_specific_data)

        issue = pa.card_transfer(provider=provider,
                                 inputs=provider.select_inputs(
                                     Settings.key.address, 0.02),
                                 card=card,
                                 change_address=Settings.change,
                                 locktime=locktime)

        if verify:
            return cointoolkit_verify(
                issue.hexlify())  # link to cointoolkit - verify

        if sign:

            tx = signtx(issue)

            if send:
                pprint({'txid': sendtx(tx)})

            pprint({'hex': tx.hexlify()})

        return issue.hexlify()
Ejemplo n.º 8
0
    def issue_modes(self):

        im = tuple(
            {mode.name: mode.value}
            for mode_name, mode in pa.protocol.IssueMode.__members__.items())

        pprint(im)
Ejemplo n.º 9
0
def mdc_compile(source, verbose=False):
    lexer = MindusLexer()
    parser = MindusParser()
    asm = []
    index = 0

    # Lex and parse raw source into AST
    ast = parser.parse(lexer.tokenize(source))
    if not ast:
        print("error: compilation failed")
        return

    if verbose:
        pprint(ast)

    # Compile into instructions
    instructions = ast.compile()

    # Store jump targets and jump sources for each instruction
    for instruction in instructions:
        instruction.jump_sources = set()
    for i, instruction in enumerate(instructions):
        if isinstance(instruction, JumpInstruction):
            instruction.jump_target = instructions[i + instruction.offset]
            instructions[i + instruction.offset].jump_sources.add(instruction)

    # Assign canonical indices
    for instruction in instructions:
        instruction.index = index
        index += 1

    # Emit asm
    for instruction in instructions:
        asm.append(instruction.emit())
    return asm
Ejemplo n.º 10
0
def run(jobfile: str, scheduler: str):
    if scheduler is not None:
        Client(scheduler)
    else:
        Client()
    res = proc.submit(jobfile)
    prettyprinter.pprint(res)
Ejemplo n.º 11
0
 def render(self, mode='human'):
     '''Standard console Log'''
     wallet_ = self.account.get_wallet()
     pprint(wallet_)
     profit = wallet_[PFT] - wallet_[LSS]
     print('Your Balance is currently at {} btc'.format(profit))
     print('######' * 25)
Ejemplo n.º 12
0
    def generate_quickref(self, curdict, fname):

        self.all_paths = set()

        self._find_structure(curdict)
        refined = []
        for p in sorted(self.all_paths):
            if p[-2:] == '[]':
                refined.pop()
            if p:
                refined.append(p)

        jsonroot = {}

        for p in refined:
            cur = jsonroot
            cur_paths = resolve_path(p)
            leaf = cur_paths.pop()
            for x in cur_paths:
                cur = cur[x]
            cur[leaf] = {}

        output = StringIO()

        pprint(jsonroot, stream=output)

        output.seek(0)
        output = output.read()

        output = output.replace(": {}", "").replace("'", "")
        self.md.append((fname, output))
Ejemplo n.º 13
0
def test_parser():
    content = """
    {
        a = 1;
        b = 1;
        while (a < 3) {
            b = a + b * b;
        }
        if ( b < 10) {
            b = b + 3 ;
        }
    }
"""
    # content = '{ 1 < 2 <= 3;}'

    parser = Parser(Lexer(content))
    root = parser.program()

    def asdict(x):
        d = dict(x)
        if 'op' in d:
            d.pop('type', None)
        elif 'type' in d:
            d['type'] = str(d['type'])
            return d['type'], d['text']
        return d

    # prettyprinter.pprint(dataclasses.asdict(root, dict_factory=asdict))
    prettyprinter.pprint(root)
Ejemplo n.º 14
0
def download_and_upload(url, save_folder, bucket="sar4wildfire"):
    filename = os.path.split(url)[-1][:-4]

    downloader = Downloader()
    downloader.download(url, save_folder)
    # # downloader.un_zip(save_folder / f"{filename}.zip")

    asset_id = f"users/omegazhangpzh/NRT_AF/{filename}"
    
    upload_to_bucket = f"gsutil -m cp -r {save_folder}/{filename}.zip gs://{bucket}/active_fire/{filename}.zip"
    # remove_asset = f"earthengine rm {asset_id}"
    ee_upload_table = f"earthengine upload table --force --asset_id={asset_id} gs://{bucket}/active_fire/{filename}.zip"

    os.system(upload_to_bucket)
    # if asset_id in asset_list:
    #     os.system(remove_asset)
    
    # os.system(ee_upload_table)

    ee_upload_response = subprocess.getstatusoutput(ee_upload_table)[1]
    task_id = ee_upload_response.split("ID: ")[-1]
    
    print(f"\n{asset_id}")
    pprint(f"task id: {task_id}")

    return filename, task_id
Ejemplo n.º 15
0
def format_data():
    try:
        coins = get_api_info()
        portfolio_profit_loos = 0
        for coin in coins:
            for sym in my_portfolio:
                if sym["symbol"] == coin["symbol"]:
                    total_paid = sym["price_payed_per_unit"] * sym[
                        "amount_owned"]
                    total_current_value = sym["amount_owned"] * float(
                        coin["quote"]["USD"]["price"])
                    profit = total_current_value - total_paid
                    profit_percentage = profit / total_paid * 100
                    profit_per_coin = float(coin["quote"]["USD"]["price"]
                                            ) - sym["price_payed_per_unit"]
                    my_coin_msg = f'Name: {coin["name"]} \n' \
                                  f'Symbol: {coin["symbol"]} \n' \
                                  f'Rank: {coin["cmc_rank"]} \n' \
                                  f'Current Price: ${float(coin["quote"]["USD"]["price"]):.2f} \n' \
                                  f'24 Hour Change: {float(coin["quote"]["USD"]["percent_change_24h"]):.2f}% \n' \
                                  f'Paid per coin: ${sym["price_payed_per_unit"]:.2f} \n' \
                                  f'Amount Owned: {sym["amount_owned"]} units \n' \
                                  f'Total current value: ${total_current_value:.2f} \n' \
                                  f'Total Paid: ${total_paid:.2f} \n' \
                                  f'Profit/Loss per coin:${profit_per_coin:.2f} \n' \
                                  f'Profit/Loss: ${profit:.2f} \n' \
                                  f'Profit/Loss percentage: {profit_percentage:.2f}%'
                    portfolio_profit_loos += profit
                    add_coin_msg_to_gui(my_coin_msg)
        show_portfolio_profit_loss_on_gui(portfolio_profit_loos)

    except (ConnectionError, Timeout, TooManyRedirects) as e:
        pprint(e)
Ejemplo n.º 16
0
async def main():
    client = await AsyncDispatcher.init()

    s = time.time()
    res = None

    async with aiohttp.ClientSession(json_serialize=ujson.dumps) as session:

        # if len(sys.argv) > 1 and sys.argv[1] == 'g':
        #     res = await client.batch_geocode([
        #         '500 Rutherford Ave, Charlestown MA',
        #         'Cake Factory',
        #         '21 Henr St, Bristol, UK',
        #         'TD Bank 250 Cambridge Street Boston, MA 02114',
        #         m.GeoPoint(lon=-94.5823, lat=34.1368)
        #     ], session=session)
        # else:
        res = await client.distance_matrix(origins=np.array([
            (37.1165, -92.2353), (34.1368, -94.5823), (37.1165, -92.2353)
        ]),
                                           destinations=np.array([
                                               (34.1368, -94.5823),
                                               (36.3408, -96.0384),
                                               (32.2834, -92.0286),
                                               (32.2834, -92.0286)
                                           ]),
                                           session=session,
                                           provider='google')

    t = time.time() - s
    prettyprinter.pprint(res)
    print('Duration: %dms' % (t * 1000))
Ejemplo n.º 17
0
def make_request(private_key, account, url, payload, count=10):
    if (count == 0):
        return
    request_headers = {}
    request_headers['Content-Type'] = 'application/jose+json'

    jws_params = get_jws_params(private_key, url, account)

    data = {
        'payload':
        base64_encode_as_string(encode_json_as_bytes(payload))
        if payload != None else '',
        'signature':
        jws_encode_sign(private_key, payload, jws_params),
        'protected':
        base64_encode_as_string(encode_json_as_bytes(jws_params)),
    }

    r = requests.post(url,
                      data=json.dumps(data),
                      headers=request_headers,
                      verify=ACME_SERVER_CERT)

    if DEBUG: prettyprinter.pprint(r.headers)

    try:
        if r.json().get('type') == 'urn:ietf:params:acme:error:badNonce':
            if DEBUG:
                print('Retrying due to bad nonce....')
            return make_request(private_key, account, url, payload, count - 1)
        else:
            return r.headers, r.json()
    except json.decoder.JSONDecodeError:
        return r.headers, r.text
Ejemplo n.º 18
0
def pstruct(structure, name: str = "generic structure") -> None:
    """Print given structure in a pretty way with prettyprinter"""

    sys.stdout = sys.stderr
    print(f"{name}".center(80, "-"))
    pprint(structure, indent=2)
    print(" ")
    sys.stdout = sys.__stdout__
Ejemplo n.º 19
0
 def print_attrs():
     setup_attrs_copy = setup_attrs.copy()
     from prettyprinter import pprint
     long_description = setup_attrs.get('long_description')
     if long_description and len(long_description) > 205:
         setup_attrs_copy[
             'long_description'] = long_description[:200] + '...'
     pprint(setup_attrs_copy)
Ejemplo n.º 20
0
def download_certificate(private_key, account, order):
    payload = None
    headers, response = make_request(private_key, account,
                                     order['certificate'], payload)
    if DEBUG:
        print('CERTIFICATE_RESPONSE')
        prettyprinter.pprint(response)
    return response
Ejemplo n.º 21
0
 def get_Weather_info(self, cityName):
     url = self.weather_url + cityName
     response = requests.get(url)
     weather_dic = json.loads(response.content)
     pprint(weather_dic)
     for dayDic in weather_dic['results'][0]['weather_data']:
         print('{}'.format(dayDic['date']))
         print('温度:{}'.format(dayDic['temperature']))
Ejemplo n.º 22
0
    def parse(self, deckid: str, cardid: str) -> None:
        '''parse card from txid and print data'''

        deck = self.__find_deck(deckid)
        cards = list(get_card_transfer(provider, deck, cardid))

        for i in cards:
            pprint(i.to_json())
Ejemplo n.º 23
0
def read_file(f_path):
    if os.path.isdir(f_path):  #判断是否为文件夹
        f_list = os.listdir(f_path)  # 获得目录下所有文件
        for file in f_list:
            read_file(f_path + '\\' + file)  # 递归再进行读取
    else:
        with open(f_path) as f:
            pprint(f.name)  # 打印文件路径
 def get_device_running_config(self, ip):
     device = self.__find_device_by_ip(ip)
     if device is not None:
         pprint(type(device))
         device.connect(init_config_commands=[])
         return device.learn('config')
     else:
         return None
Ejemplo n.º 25
0
    def decode(self, hex: str) -> dict:
        '''decode card protobuf'''

        script = NulldataScript.unhexlify(hex).decompile().split(' ')[1]

        pprint(
            parse_card_transfer_metainfo(bytes.fromhex(script),
                                         Settings.deck_version))
Ejemplo n.º 26
0
    def random(self, n: int = 1) -> list:
        '''generate <n> of random addresses, useful when testing'''

        rand_addr = [
            pa.Kutil(network=Settings.network).address for i in range(n)
        ]

        pprint(rand_addr)
Ejemplo n.º 27
0
    def encode(self, json: bool = False, **kwargs) -> None:
        '''compose a new deck and print out the protobuf which
           is to be manually inserted in the OP_RETURN of the transaction.'''

        if json:
            pprint(self.__new(**kwargs).metainfo_to_dict)

        pprint({'hex': self.__new(**kwargs).metainfo_to_protobuf.hex()})
Ejemplo n.º 28
0
    def checksum(self, deckid: str) -> bool:
        '''show deck card checksum'''

        cards, deck = self.__list(deckid).values()

        state = pa.protocol.DeckState(cards)

        pprint({'checksum': state.checksum})
Ejemplo n.º 29
0
def test_top_level_str():
    """Tests that top level strings are not indented or surrounded with parentheses"""

    pprint('ab' * 50)
    expected = (
        "'ababababababababababababababababababababababababababababababababababa'"
        "\n'bababababababababababababababab'")
    assert pformat('ab' * 50) == expected
Ejemplo n.º 30
0
    def decode(self, hex: str) -> None:
        '''decode deck protobuf'''

        script = NulldataScript.unhexlify(hex).decompile().split(' ')[1]

        pprint(
            parse_deckspawn_metainfo(bytes.fromhex(script),
                                     Settings.deck_version))