mlso-api-client package
Submodules
mlso.api.client module
Module defining the Python and command-line client. The programmatic interface is typically used like:
>>> from mlso.api import client
>>> client.about()
{'documentation': 'https://mlso-api-client.readthedocs.io/en/latest/',
'homepage': 'https://www2.hao.ucar.edu/mlso',
'support': 'mlso_data_requests@ucar.edu',
'version': '0.3.1'}
The Unix command-line interface, mlsoapi, is also available:
usage: mlsoapi [-h] [-v] [-u BASE_URL] [--verbose] [-q] {instruments,products,files} ...
MLSO API command line interface (mlso-api-client 1.0.0)
positional arguments:
{instruments,products,files}
sub-command help
instruments MLSO instruments
products MLSO instruments
files MLSO data files
options:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-u BASE_URL, --base-url BASE_URL
base URL for MLSO API
--verbose output warnings
-q, --quiet surpress informational messages
- exception mlso.api.client.ServerError[source]
Bases:
ExceptionException raised when there is a problem with the server not returning a valid result.
- exception mlso.api.client.UserNotFound[source]
Bases:
ExceptionException raised when a username is not found in the registration database.
- mlso.api.client.about(base_url: str = 'http://api.mlso.ucar.edu', api_version: str = 'v1', verbose: bool = False)[source]
Retrieve basic facts about the MLSO API server, i.e., the results of the
/aboutendpoint. For example:>>> client.about() {'documentation': 'https://mlso-api-client.readthedocs.io/en/latest/', 'homepage': 'https://www2.hao.ucar.edu/mlso', 'support': 'mlso_data_requests@ucar.edu', 'version': '1.0.0'}
aboutcan raise aServerErrorif the server response is not valid.
- mlso.api.client.authenticate(username: str = None, base_url: str = 'http://api.mlso.ucar.edu', api_version: str = 'v1', verbose: bool = False)[source]
Authenticate username within the session. The username is registered with the MLSO website first. Then authenticate must be called before calling
download_file. For example:>>> client.authenticate(my_email_address)
You only need to call
authenticateonce per session.This routine can raise a
UserNotFoundexception if theusernamehas not already been registered with the MLSO website or aServerErrorexception if there is a problem with the web request.
- mlso.api.client.download_file(file, output_dir)[source]
Download a single file to the given output directory. The
fileargument is a dict with at least fields “url” and “filename”.output_diris simply the directory to put the downloaded file.>>> from mlso.api import client >>> client.authenticate(my_email_address) >>> filters = {"start-date": "2025-3-24", "wave-region": "789"} >>> files_info = client.files("ucomp", "l2", filters=filters) >>> for f in files_info["files"]: ... download_file(f, ".")
Can raise
ServerErrorif there is a problem with the web request.
- mlso.api.client.files(instrument: str, product: str, filters: dict[str, str] | None = None, base_url: str | None = 'http://api.mlso.ucar.edu', api_version: str | None = 'v1', verbose=False, client: str | None = 'python')[source]
Retrieve metadata about files from a given instrument/product and filtered by various optional filters, i.e., handle retrieving the results of the
/instruments/{instrument}/products/{product}endpoint. For example:>>> from mlso.api import client >>> client.files("ucomp", "l2", filters={"start-date": "2025-3-24", "wave-region": "789"}) {'end-date': '2025-03-24T21:03:55', 'files': [{ 'date-obs': '2025-03-24T20:06:52', 'filename': '20250324.200652.ucomp.789.l2.fts', 'filesize': 0, 'instrument': 'ucomp', 'obs-plan': 'synoptic-original-lines.cbk', 'product': 'l2', 'url': 'http://api.mlso.ucar.edu/v1/download?obsday-id=10136&instrument=ucomp&filename=20250324.200652.ucomp.789.l2.fts', 'wave-region': '789', 'wavelengths': 5 }], 'instrument': 'ucomp', 'product': 'l2', 'start-date': '2025-3-24', 'total_filesize': 0}
Use
download_fileto download the file(s) returned with this routine.The available filters are listed below. Note that some filters are available only for certain instruments.
Parameter
Description
start‑dateReturn only files after the “start-date”.
end‑dateReturn only files before the “end-date”.
crReturn only files matching Carrington Rotation number “cr”.
everyReturn only a single file for every time period matching “every”. The recognized time periods are:
second,
minute,
hour,
day,
week,
month,
quarter, or
year
(optionally ending in “s”). This parameter is an integer followed by one of these time periods, e.g.,
every=2hours,every=1day, orevery=12hours.
wave‑regionReturn only files for the given wave region (UCoMP only). Valid values are “637”, “706”, “789”, 1074”, “1079”.
obs‑planReturn only files matching the given observing plan, e.g.:
“waves”
“synoptic”
(UCoMP only).
Can raise a
ServerErrorif there is a problem with the web request.
- mlso.api.client.instruments(base_url: str = 'http://api.mlso.ucar.edu', api_version: str = 'v1', verbose: bool = False)[source]
Retrieve list of instruments from the
/instruments/{instrument}endpoint with some of their properties. For example:>>> from mlso.api import client >>> client.instruments() [{'id': 'kcor', 'start-date': '2013-09-30T18:57:54', 'end-date': '2025-03-24T21:04:20', 'name': 'COSMO K-Coronagraph (KCor)'}, {'id': 'ucomp', 'start-date': '2021-07-15T17:31:43', 'end-date': '2025-03-24T21:03:55', 'name': 'Upgraded Coronal Multi-Polarimeter (UCoMP)'}]
Or:
>>> [i["id"] for i in client.instruments()] ['kcor', 'ucomp']
instrumentscan raise aServerErrorif there is a problem with the web request.
- mlso.api.client.main()[source]
Entry point for MLSO API command-line utility.
$ mlsoapi --help usage: mlsoapi [-h] [-v] [-u BASE_URL] [--verbose] [-q] {instruments,products,files} ... MLSO API command line interface (mlso-api-client 0.3.2) positional arguments: {instruments,products,files} sub-command help instruments MLSO instruments products MLSO instruments files MLSO data files options: -h, --help show this help message and exit -v, --version show program's version number and exit -u BASE_URL, --base-url BASE_URL base URL for MLSO API --verbose output warnings -q, --quiet surpress informational messages
- mlso.api.client.products(instrument, base_url: str = 'http://api.mlso.ucar.edu', api_version: str = 'v1', verbose: bool = False)[source]
Retrieve the available products for the given instruments, i.e., retreive the results of the
/instruments/{instrument}/productsendpoint. For example:>>> from mlso.api import client >>> client.products("ucomp") {'products': [{'description': 'IQUV and backgrounds for various wavelengths', 'id': 'l1', 'title': 'Level 1'}, {'description': 'intensity-only level 1', 'id': 'intensity', 'title': 'Level 1 intensity'}, {'description': 'mean of level 1 files', 'id': 'mean', 'title': 'Level 1 mean'}, {'description': 'median of level 1 files', 'id': 'median', 'title': 'Level 1 median'}, {'description': 'standard deviation of level 1 files', 'id': 'sigma', 'title': 'Level 1 sigma'}, {'description': 'level 2 products', 'id': 'l2', 'title': 'Level 2'}, {'description': 'mean, median, standard deviation of level 2 files', 'id': 'l2average', 'title': 'Level 2 average'}, {'description': 'density', 'id': 'density', 'title': 'Density'}, {'description': 'level 2 dynamics products', 'id': 'dynamics', 'title': 'Dynamics'}, {'description': 'level 2 polarization products', 'id': 'polarization', 'title': 'Polarization'}, {'description': 'all products', 'id': 'all', 'title': 'All'}]}
And:
>>> [p["id"] for p in client.products("ucomp", base_url=base_url)["products"]] ['l1', 'intensity', 'mean', 'median', 'sigma', 'l2', 'l2average', 'density', 'dynamics', 'polarization', 'all']
productscan raise aServerErrorif there is a problem with the web request.