def test_initialize_object_wo_auth_raises():
    with pytest.raises(RuntimeError):
        up42.initialize_project()
    with pytest.raises(RuntimeError):
        up42.initialize_catalog()
    with pytest.raises(RuntimeError):
        up42.initialize_workflow(workflow_id=WORKFLOW_ID)
    with pytest.raises(RuntimeError):
        up42.initialize_job(job_id=JOB_ID)
    with pytest.raises(RuntimeError):
        up42.initialize_jobtask(job_id=JOB_ID, jobtask_id=JOBTASK_ID)
Exemple #2
0
def test_initialize_object_wo_auth_raises():
    with pytest.raises(RuntimeError):
        up42.initialize_project()
    with pytest.raises(RuntimeError):
        up42.initialize_catalog()
    with pytest.raises(RuntimeError):
        up42.initialize_workflow(workflow_id="1234")
    with pytest.raises(RuntimeError):
        up42.initialize_job(job_id="1234")
    with pytest.raises(RuntimeError):
        up42.initialize_jobtask(job_id="1234", jobtask_id="1234")
Exemple #3
0
        def test_workflow(selected_blocks):
            assert self.ensure_variables(
                (self.full_coverage,
                 self.catalog)), "Please run steps before (optimize coverage)!"

            self.project = up42.initialize_project()
            self.project.update_project_settings(max_concurrent_jobs=10)
            self.workflow = self.project.create_workflow("mosaicking",
                                                         use_existing=True)

            blocks = up42.get_blocks(basic=True)
            self.workflow.add_workflow_tasks(
                [blocks[selected] for selected in selected_blocks.value])

            # Test workflow & availability of sections
            parameters = []
            for _, row in self.full_coverage.iterrows():

                test_parameters = self.workflow.construct_parameters(
                    geometry=row.geometry,
                    geometry_operation="intersects",
                    scene_ids=[row["sceneId"]],
                )
                parameters.append(test_parameters)

            test_jobs = self.workflow.test_jobs_parallel(
                parameters, name="mosaicking_tests")

            test_jobs_df = {}
            for i, test_job in enumerate(test_jobs):
                estimation = self.workflow.estimate_job(parameters[i])
                test_df = test_job.get_results_json(as_dataframe=True)
                test_df["minEstimatedCredits"] = sum([
                    block["blockConsumption"]["credit"]["min"] +
                    block["machineConsumption"]["credit"]["min"]
                    for block in estimation.values()
                ])
                test_df["maxEstimatedCredits"] = sum([
                    block["blockConsumption"]["credit"]["max"] +
                    block["machineConsumption"]["credit"]["max"]
                    for block in estimation.values()
                ])
                display(test_df)

                test_jobs_df[test_job.job_id] = test_df

            test_jobs_df = pd.concat(test_jobs_df.values(),
                                     keys=test_jobs_df.keys())
            display(test_jobs)
            print("=======================================================")
            print("Generating this mosaic is estimated to cost:")
            print(
                f"{test_jobs_df['minEstimatedCredits'].sum()} - {test_jobs_df['maxEstimatedCredits'].sum()} "
                "UP42 credits")
            print("=======================================================")

            self.selected_blocks = selected_blocks.value

            print("finished")
Exemple #4
0
def test_initialize_object_wo_auth_raises():
    with pytest.raises(RuntimeError):
        up42.initialize_project()
    with pytest.raises(RuntimeError):
        up42.initialize_catalog()
    with pytest.raises(RuntimeError):
        up42.initialize_workflow(workflow_id=WORKFLOW_ID)
    with pytest.raises(RuntimeError):
        up42.initialize_job(job_id=JOB_ID)
    with pytest.raises(RuntimeError):
        up42.initialize_jobtask(job_id=JOB_ID, jobtask_id=JOBTASK_ID)
    with pytest.raises(RuntimeError):
        up42.initialize_jobcollection(job_ids=[JOB_ID, JOB_ID])
    with pytest.raises(RuntimeError):
        up42.initialize_storage()
    with pytest.raises(RuntimeError):
        up42.initialize_order(order_id=ORDER_ID)
    with pytest.raises(RuntimeError):
        up42.initialize_asset(asset_id=ASSET_ID)
Exemple #5
0
        def test_workflow(selected_blocks):
            assert self.ensure_variables(
                (self.full_coverage,
                 self.catalog)), "Please run steps before (optimize coverage)!"

            self.project = up42.initialize_project()
            self.project.update_project_settings(max_concurrent_jobs=10)
            self.workflow = self.project.create_workflow("mosaicking",
                                                         use_existing=True)

            blocks = up42.get_blocks(basic=True)
            self.workflow.add_workflow_tasks(
                [blocks[selected] for selected in selected_blocks.value])

            # Test workflow & availability of sections
            parameters = []
            for _, row in self.full_coverage.iterrows():

                test_parameters = self.workflow.construct_parameters(
                    geometry=row.geometry,
                    geometry_operation="intersects",
                    scene_ids=[row["scene_id"]],
                )
                parameters.append(test_parameters)

            test_jobs = self.workflow.test_jobs_parallel(
                parameters, name="mosaicking_tests")

            test_jobs_df = {}
            for test_job in test_jobs:
                try:
                    estimated_credits = list(
                        test_job.get_jobtasks_results_json().values(
                        ))[0]["features"][0]["estimatedCredits"]
                except (KeyError, IndexError):
                    estimated_credits = 0

                test_df = test_job.get_results_json(as_dataframe=True)
                test_df["estimatedCredits"] = estimated_credits
                display(test_df)

                test_jobs_df[test_job.job_id] = test_df

            test_jobs_df = pd.concat(test_jobs_df.values(),
                                     keys=test_jobs_df.keys())
            display(test_jobs)
            print("=======================================================")
            print("Generating this mosaic is estimated to cost:")
            print(f"{test_jobs_df['estimatedCredits'].sum()} UP42 credits")
            print("=======================================================")

            self.selected_blocks = selected_blocks.value

            print("finished")
def test_global_auth_initialize_objects():
    up42.authenticate(
        project_id=PROJECT_ID,
        project_api_key=PROJECT_APIKEY,
        authenticate=False,
        get_info=False,
        retry=False,
    )
    project = up42.initialize_project()
    assert isinstance(project, up42.Project)
    catalog = up42.initialize_catalog()
    assert isinstance(catalog, up42.Catalog)
    workflow = up42.initialize_workflow(workflow_id=WORKFLOW_ID)
    assert isinstance(workflow, up42.Workflow)
    job = up42.initialize_job(job_id=JOB_ID)
    assert isinstance(job, up42.Job)
    jobtask = up42.initialize_jobtask(job_id=JOB_ID, jobtask_id=JOBTASK_ID)
    assert isinstance(jobtask, up42.JobTask)
Exemple #7
0
def test_global_auth_initialize_objects():
    up42.authenticate(
        project_id="1234",
        project_api_key="1234",
        authenticate=False,
        get_info=False,
        retry=False,
    )
    project = up42.initialize_project()
    assert isinstance(project, up42.Project)
    catalog = up42.initialize_catalog()
    assert isinstance(catalog, up42.Catalog)
    workflow = up42.initialize_workflow(workflow_id="1234")
    assert isinstance(workflow, up42.Workflow)
    job = up42.initialize_job(job_id="1234")
    assert isinstance(job, up42.Job)
    jobtask = up42.initialize_jobtask(job_id="1234", jobtask_id="1234")
    assert isinstance(jobtask, up42.JobTask)
Exemple #8
0
def test_global_auth_initialize_objects(
    auth_mock,
    project_mock,
    workflow_mock,
    job_mock,
    jobtask_mock,
    jobcollection_single_mock,
    storage_mock,
    order_mock,
    asset_mock,
):
    up42.authenticate(
        project_id=PROJECT_ID,
        project_api_key=PROJECT_APIKEY,
        authenticate=True,
        get_info=False,
        retry=False,
    )
    project = up42.initialize_project()
    assert isinstance(project, up42.Project)
    catalog = up42.initialize_catalog()
    assert isinstance(catalog, up42.Catalog)
    workflow = up42.initialize_workflow(workflow_id=WORKFLOW_ID)
    assert isinstance(workflow, up42.Workflow)
    job = up42.initialize_job(job_id=JOB_ID)
    assert isinstance(job, up42.Job)
    jobtask = up42.initialize_jobtask(job_id=JOB_ID, jobtask_id=JOBTASK_ID)
    assert isinstance(jobtask, up42.JobTask)
    jobcollection = up42.initialize_jobcollection(job_ids=[JOB_ID, JOB_ID])
    assert isinstance(jobcollection, up42.JobCollection)
    storage = up42.initialize_storage()
    assert isinstance(storage, up42.Storage)
    order = up42.initialize_order(order_id=ORDER_ID)
    assert isinstance(order, up42.Order)
    asset = up42.initialize_asset(asset_id=ASSET_ID)
    assert isinstance(asset, up42.Asset)
Exemple #9
0
import os
from pathlib import Path

import up42

if __name__ == "__main__":
    # 30 seconds example with slight changes and production.
    up42.authenticate(
        project_id=os.getenv("TEST_UP42_PROJECT_ID"),
        project_api_key=os.getenv("TEST_UP42_PROJECT_API_KEY"),
    )
    project = up42.initialize_project()
    workflow = project.create_workflow(name="up42-py-test", use_existing=True)
    input_tasks = [
        "3a381e6b-acb7-4cec-ae65-50798ce80e64",
        "e374ea64-dc3b-4500-bb4b-974260fb203e",
    ]
    workflow.add_workflow_tasks(input_tasks=input_tasks)
    aoi = workflow.get_example_aoi(location="Berlin")
    input_parameters = workflow.construct_parameters(geometry=aoi,
                                                     geometry_operation="bbox",
                                                     limit=1)

    job = workflow.run_job(input_parameters=input_parameters)
    job.track_status()
    results_fp = job.download_results(output_directory="/tmp")

    for fp in results_fp:
        assert Path(fp).exists()