async def main(path_to_csv_file, serve_bootstrap=True, host=None, port=None, 
    id=None, name="CSV Timeseries Service", description=None, use_async=False):

    config = {
        "path_to_csv_file": path_to_csv_file,
        "id_col_name": "id",
        "port": port, 
        "host": host,
        "id": id,
        "name": name,
        "description": description,
        "serve_bootstrap": serve_bootstrap,
        "use_async": use_async
    }
    # read commandline args only if script is invoked directly from commandline
    if len(sys.argv) > 1 and __name__ == "__main__":
        for arg in sys.argv[1:]:
            k, v = arg.split("=")
            if k in config:
                config[k] = bool(v) if v.lower() in ["true", "false"] else v 
    print(config)

    restorer = common.Restorer()
    service = csv_based.TimeSeries.from_csv_file(config["path_to_csv_file"], \
        header_map={}, #{"windspeed": "wind"}, 
        pandas_csv_config={} #{"sep": ";"}
    )
    if use_async:
        await serv.async_init_and_run_service({"service": service}, config["host"], config["port"], 
        serve_bootstrap=config["serve_bootstrap"], restorer=restorer)
    else:
        
        serv.init_and_run_service({"service": service}, config["host"], config["port"], 
            serve_bootstrap=config["serve_bootstrap"], restorer=restorer)
Ejemplo n.º 2
0
async def main(path_to_csv,
               serve_bootstrap=True,
               host=None,
               port=None,
               id=None,
               name="Jobs Service",
               description=None,
               use_async=False):

    config = {
        "path_to_csv": path_to_csv,
        "id_col_name": "dummy_id",
        "port": port,
        "host": host,
        "id": id,
        "name": name,
        "description": description,
        "serve_bootstrap": serve_bootstrap,
        "use_async": use_async
    }
    # read commandline args only if script is invoked directly from commandline
    if len(sys.argv) > 1 and __name__ == "__main__":
        for arg in sys.argv[1:]:
            k, v = arg.split("=")
            if k in config:
                config[k] = bool(v) if v.lower() in ["true", "false"] else v
    print(config)

    restorer = common.Restorer()
    jobs = csv.read_csv(config["path_to_csv"], config["id_col_name"])
    jobs2 = [json.dumps(v) for k, v in jobs.items()]
    service = Service(jobs2,
                      id=config["id"],
                      name=config["name"],
                      description=config["description"],
                      restorer=restorer)
    if use_async:
        await serv.async_init_and_run_service(
            {"service": service},
            config["host"],
            config["port"],
            serve_bootstrap=config["serve_bootstrap"],
            restorer=restorer)
    else:

        serv.init_and_run_service({"service": service},
                                  config["host"],
                                  config["port"],
                                  serve_bootstrap=config["serve_bootstrap"],
                                  restorer=restorer)
Ejemplo n.º 3
0
async def main(use_async,
               path_to_csv,
               serve_bootstrap=True,
               host=None,
               port=None,
               id=None,
               name="Jobs Service",
               description=None):

    config = {
        "path_to_csv": path_to_csv,
        "id_col_name": "id",
        "port": port,
        "host": host,
        "id": id,
        "name": name,
        "description": description,
        "serve_bootstrap": str(serve_bootstrap)
    }
    # read commandline args only if script is invoked directly from commandline
    if len(sys.argv) > 1 and __name__ == "__main__":
        for arg in sys.argv[1:]:
            k, v = arg.split("=")
            if k in config:
                config[k] = v
    print(config)

    jobs = csv.read_csv(config["path_to_csv"], config["id_col_name"])
    jobs2 = [json.dumps(v) for k, v in jobs.items()]
    service = Service(jobs2)
    if use_async:
        await serv.async_init_and_run_service(
            {"service": service},
            config["host"],
            config["port"],
            serve_bootstrap=config["serve_bootstrap"])
    else:

        serv.init_and_run_service({"service": service},
                                  config["host"],
                                  config["port"],
                                  serve_bootstrap=config["serve_bootstrap"])
Ejemplo n.º 4
0
async def main(path_to_ascii_grid, grid_crs, val_type, serve_bootstrap=True, host=None, port=None, 
    id=None, name="Grid Service", description=None, use_async=False):

    config = {
        "path_to_ascii_grid": path_to_ascii_grid,
        "grid_crs": grid_crs,
        "val_type": val_type,
        "port": port, 
        "host": host,
        "id": id,
        "name": name,
        "description": description,
        "serve_bootstrap": serve_bootstrap,
        "use_async": use_async,
        "fbp": False,
        "in_sr": None,
        "out_sr": None,
        "from_attr": None, #"latlon"
        "to_attr": None, #"dgm",
    }
    # read commandline args only if script is invoked directly from commandline
    if len(sys.argv) > 1 and __name__ == "__main__":
        for arg in sys.argv[1:]:
            k, v = arg.split("=")
            if k in config:
                config[k] = bool(v) if v.lower() in ["true", "false"] else v 
    print(config)

    restorer = common.Restorer()
    service = Grid(path_to_ascii_grid=config["path_to_ascii_grid"], 
        grid_crs=geo.name_to_crs(config["grid_crs"]), val_type=int if config["val_type"] == "int" else float,
        id=config["id"], name=config["name"], description=config["description"], restorer=restorer)
    if config["fbp"]:
        fbp(config, grid_capnp.Grid._new_client(service))
    else:
        if config["use_async"]:
            await serv.async_init_and_run_service({"service": service}, config["host"], config["port"], 
            serve_bootstrap=config["serve_bootstrap"], restorer=restorer)
        else:
            
            serv.init_and_run_service({"service": service}, config["host"], config["port"], 
                serve_bootstrap=config["serve_bootstrap"], restorer=restorer)
Ejemplo n.º 5
0
async def main(path_to_data, serve_bootstrap=True, host=None, port=None, 
    id=None, name="DWD - historical - 1991-2019", description=None, use_async=False):

    config = {
        "path_to_data": path_to_data,
        "port": port, 
        "host": host,
        "id": id,
        "name": name,
        "description": description,
        "serve_bootstrap": serve_bootstrap,
        "in_sr": None,
        "out_sr": None,
        "fbp": False,
        "no_fbp": False,
        "use_async": use_async,
        "to_attr": None, #"climate",
        "latlon_attr": "latlon",
        "start_date_attr": "startDate",
        "end_date_attr": "endDate",
        "mode": "sturdyref", # sturdyref | capability | data
    }
    common.update_config(config, sys.argv, print_config=True, allow_new_keys=False)

    restorer = common.Restorer()
    interpolator, rowcol_to_latlon = ccdi.create_lat_lon_interpolator_from_json_coords_file(config["path_to_data"] + "/" + "latlon-to-rowcol.json")
    meta_plus_data = create_meta_plus_datasets(config["path_to_data"] + "/germany", interpolator, rowcol_to_latlon, restorer)
    service = ccdi.Service(meta_plus_data, id=config["id"], name=config["name"], description=config["description"], restorer=restorer)
    if config["fbp"]:
        fbp(config, climate_capnp.Service._new_client(service))
    else:
        if config["use_async"]:
            await serv.async_init_and_run_service({"service": service}, config["host"], config["port"], 
            serve_bootstrap=config["serve_bootstrap"], restorer=restorer)
        else:
            
            serv.init_and_run_service({"service": service}, config["host"], config["port"], 
                serve_bootstrap=config["serve_bootstrap"], restorer=restorer)
async def main(path_to_config,
               serve_bootstrap=True,
               host=None,
               port=None,
               id=None,
               name="DWD Core Ensemble",
               description=None,
               reg_sturdy_ref=None,
               use_async=False):

    config = {
        "path_to_config": path_to_config,
        "config_toml_file": "metadata.toml",
        "port": port,
        "host": host,
        "id": id,
        "name": name,
        "description": description,
        "serve_bootstrap": serve_bootstrap,
        "reg_sturdy_ref": reg_sturdy_ref,
        "reg_category": "climate",
        "use_async": use_async,
    }
    common.update_config(config,
                         sys.argv,
                         print_config=True,
                         allow_new_keys=False)

    path_to_config = Path(config["path_to_config"])
    with open(path_to_config / config["config_toml_file"], "rb") as f:
        datasets_config = tomli.load(f)

    if not datasets_config:
        print("Couldn't load datasets configuration from:",
              str(path_to_config / config["config_toml_file"]))
        exit(1)

    general = datasets_config["general"]

    conman = async_helpers.ConnectionManager()
    restorer = common.Restorer()
    interpolator, rowcol_to_latlon = ccdi.create_lat_lon_interpolator_from_json_coords_file(
        path_to_config / general["latlon_to_rowcol_mapping"])
    meta_plus_data = create_meta_plus_datasets(path_to_config, datasets_config,
                                               interpolator, rowcol_to_latlon,
                                               restorer)
    service = ccdi.Service(meta_plus_data,
                           id=config["id"],
                           name=config["name"],
                           description=config["description"],
                           restorer=restorer)

    if config["reg_sturdy_ref"]:
        registrator = await conman.try_connect(config["reg_sturdy_ref"],
                                               cast_as=reg_capnp.Registrator)
        if registrator:
            unreg = await registrator.register(
                ref=service, categoryId=config["reg_category"]).a_wait()
            print("Registered ", config["name"], "climate service.")
            #await unreg.unregister.unregister().a_wait()
        else:
            print("Couldn't connect to registrator at sturdy_ref:",
                  config["reg_sturdy_ref"])

    if config["use_async"]:
        await serv.async_init_and_run_service(
            {"service": service},
            config["host"],
            config["port"],
            serve_bootstrap=config["serve_bootstrap"],
            restorer=restorer,
            conman=conman)
    else:

        serv.init_and_run_service({"service": service},
                                  config["host"],
                                  config["port"],
                                  serve_bootstrap=config["serve_bootstrap"],
                                  restorer=restorer,
                                  conman=conman)
async def main(path_to_sqlite_db,
               path_to_ascii_soil_grid,
               grid_crs=None,
               grid_epsg=None,
               serve_bootstrap=True,
               host=None,
               port=None,
               id=None,
               name="Soil service",
               description=None,
               use_async=False):

    config = {
        "path_to_sqlite_db": path_to_sqlite_db,
        "path_to_ascii_soil_grid": path_to_ascii_soil_grid,
        "grid_crs": grid_crs,
        "grid_epsg": grid_epsg,
        "port": port,
        "host": host,
        "id": id,
        "name": name,
        "description": description,
        "serve_bootstrap": serve_bootstrap,
        "use_async": use_async,
        "fbp": False,
        "in_sr": None,
        "out_sr": None,
        "mandatory": """["soilType","organicCarbon","rawDensity"]""",
        "to_attr": None,  #"soil",
        "from_attr": None,  #"latlon"
    }
    # read commandline args only if script is invoked directly from commandline
    if len(sys.argv) > 1 and __name__ == "__main__":
        for arg in sys.argv[1:]:
            k, v = arg.split("=")
            if k in config:
                config[k] = bool(v) if v.lower() in ["true", "false"] else v
    print(config)

    if config["grid_epsg"]:
        grid_crs = CRS.from_epsg(int(config["grid_epsg"]))
    elif config["grid_crs"]:
        grid_crs = geo.name_to_crs(config["grid_crs"])
    else:
        try:
            epsg = int(
                Path(config["path_to_ascii_soil_grid"]).name.split("_")[2])
            grid_crs = CRS.from_epsg(epsg)
        except:
            print("Couldn't create CRS from soil grid name:",
                  config["path_to_ascii_soil_grid"])
            exit(0)

    restorer = common.Restorer()
    service = Service(path_to_sqlite_db=config["path_to_sqlite_db"],
                      path_to_ascii_grid=config["path_to_ascii_soil_grid"],
                      grid_crs=grid_crs,
                      id=config["id"],
                      name=config["name"],
                      description=config["description"],
                      restorer=restorer)
    if config["fbp"]:
        fbp(config, soil_capnp.Service._new_client(service))
    else:
        if config["use_async"]:
            await serv.async_init_and_run_service(
                {"service": service},
                config["host"],
                config["port"],
                serve_bootstrap=config["serve_bootstrap"],
                restorer=restorer)
        else:
            serv.init_and_run_service(
                {"service": service},
                config["host"],
                config["port"],
                serve_bootstrap=config["serve_bootstrap"],
                restorer=restorer)