Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

sliderule

The SlideRule Python API sliderule.py is used to access the services provided by the base SlideRule server. From Python, the module can be imported via:

import sliderule

Functions

init

sliderule.init(url='slideruleearth.io', verbose=False, loglevel=20, organization='sliderule', desired_nodes=None, time_to_live=60, plugins=None, log_handler=None, github_token=None, rethrow=False, user_service=False)

Initializes the Python client for use with SlideRule, and should be called before other ICESat-2 API calls. This function is a wrapper for a handful of sliderule functions that would otherwise all have to be called in order to initialize the client.

Parameters

Returns

bool

Status of version check

Examples

>>> import sliderule
>>> sliderule.init()

source

sliderule.source(api, parm=None, stream=False, callbacks=None, path='/source', session=None, rethrow=False, sign=False)

Perform API call to SlideRule service

Parameters

Returns

dictionary

response data

Examples

>>> import sliderule
>>> sliderule.set_url("slideruleearth.io")
>>> rqst = {
...     "time": "NOW",
...     "input": "NOW",
...     "output": "GPS"
... }
>>> rsps = sliderule.source("datetime", rqst)
>>> print(rsps)
{'time': 1300556199523.0, 'format': 'GPS'}

set_url

sliderule.set_url(domain, session=None)

Configure sliderule package with URL of service

Parameters

Examples

>>> import sliderule
>>> sliderule.set_url("service.my-sliderule-server.org")

set_verbose

sliderule.set_verbose(enable, loglevel=20, session=None)

Sets up a console logger to print log messages to screen

Parameters

Examples

>>> import sliderule
>>> sliderule.set_verbose(True, loglevel=logging.INFO)

set_rqst_timeout

sliderule.set_rqst_timeout(timeout, session=None)

Sets the TCP/IP connection and reading timeouts for future requests made to sliderule servers. Setting it lower means the client will failover more quickly, but may generate false positives if a processing request stalls or takes a long time returning data. Setting it higher means the client will wait longer before designating it a failed request which in the presence of a persistent failure means it will take longer for the client to remove the node from its available servers list.

Parameters

Examples

>>> import sliderule
>>> sliderule.set_rqst_timeout((10, 60))

update_available_servers

sliderule.update_available_servers(desired_nodes=None, time_to_live=None, session=None)

Manages the number of servers in the cluster. If the desired_nodes parameter is set, then a request is made to change the number of servers in the cluster to the number specified. In all cases, the number of nodes currently running in the cluster are returned - even if desired_nodes is set; subsequent calls to this function is needed to check when the current number of nodes matches the desired_nodes.

Parameters

Returns

int

number of nodes currently in the cluster

int number of nodes available for work in the cluster

Examples

>>> import sliderule
>>> num_servers, max_workers = sliderule.update_available_servers(10)

scaleout

sliderule.scaleout(desired_nodes, time_to_live, session=None)

Scale the cluster and wait for cluster to reach desired state

Parameters

Examples

>>> import sliderule
>>> sliderule.scaleout(4, 300)

gps2utc

sliderule.gps2utc(gps_time, as_str=True, session=None)

Convert a GPS based time returned from SlideRule into a UTC time.

Parameters

Returns

datetime

UTC time (i.e. GMT, or Zulu time)

Examples

>>> import sliderule
>>> sliderule.gps2utc(1235331234)
'2019-02-27 19:34:03'

get_version

sliderule.get_version(session=None)

Get the version information for the running servers and Python client

Returns

dict

dictionary of version information

check_version

sliderule.check_version(plugins=None, session=None)

Check that the version of the client matches the version of the server and any additionally requested plugins

Parameters

Returns

bool

True (always; kept for backward compatibility)

toregion

sliderule.toregion(source, tolerance=0.0, cellsize=0.01, n_clusters=1, tif_parms=None)

Convert a GeoJSON/Shapefile/GeoDataFrame/list representation of a set of geospatial regions into a list of lat,lon coordinates and raster image recognized by SlideRule

Parameters

Returns

dict

a list of longitudes and latitudes containing the region of interest that can be used for the poly and raster parameters in a processing request to SlideRule.

region = {

"gdf": <GeoDataFrame of region>

"poly": [{"lat": <lat1>, "lon": <lon1> }, ...],

"raster": {"data": <geojson file as string>,

"clusters": [[{"lat": <lat1>, "lon": <lon1>}, ...], [{"lat": <lat1>, "lon": <lon1>}, ...]] }

Examples

>>> import sliderule, json
>>> region = sliderule.toregion("tests/data/grandmesa.geojson")
>>> print(json.dumps(region["poly"], indent=4))
[   {"lon": -108.20772968780051,"lat": 38.8232055291981},
    {"lon": -108.07460164311031,"lat": 38.8475137825863},
    {"lon": -107.72839858755752,"lat": 39.01510930230633},
    {"lon": -107.78724142490994,"lat": 39.195630349659986},
    {"lon": -108.17287000970857,"lat": 39.15920066396116},
    {"lon": -108.31168256553767,"lat": 39.13757646212944},
    {"lon": -108.34115668325224,"lat": 39.03758987613325},
    {"lon": -108.2878686387796,"lat": 38.89051431295789},
    {"lon": -108.20772968780051,"lat": 38.8232055291981}    ]

run

sliderule.run(api, parms, aoi=None, resources=None, session=None)

Execute the requested endpoint and return the results as a GeoDataFrame

Parameters

Returns

GeoDataFrame

result of executing the request endpoint