Network API¶
All network operations are handled by the pollyxt_pipelines.scc_access module and specifically,
the SCC class. The code is based the work of Ioannis Binietoglou on
SCC Access.
To programmatically access SCC, begin by importing pollyxt_pipelines.scc_access and creating
a SCC_Credentials object.
from pollyxt_pipelines.config import Config
import pollyxt_pipelines.scc_access
# TODO remove dependency on Config
credentials = SCC_Credentials(Config())
Afterwards, you can access SCC as follows:
# As a context
with scc_access.scc_session(credentials) as scc:
# Do stuff with scc
# ...
scc.upload_file(...)
# As a class
scc = scc_access.SCC(credentials)
scc.login()
# ...
The context manager handles login/logout automatically. If you use the class yourself,
you should call login() before attempting to call any other method.
API¶
Tools for communicating with the SCC backend
Author: Thanasis Georgiou <ageorgiou@noa.gr>
Based on scc-access by Iannis Binietoglou <i.binietoglou@impworks.gr>: https://repositories.imaa.cnr.it/public/scc_access
- class pollyxt_pipelines.scc_access.SCC(credentials)[source]¶
Bases:
objectRepresents a session with SCC. Before making any calls, the user should login using
login()!It’s recommended to use the
scc_session()context manager, which handles logging in and out.- delete_measurement(measurement_id)[source]¶
Deletes a measurement from SCC
- Parameters:
measurement_id (
str) – Which measurement to delete
- download_file(url, path)[source]¶
Downloads a single file from SCC to the given path
- Parameters:
url (
str) – Which URL to download the file frompath (
Path) – Where to store the downloaded file
- download_products(measurement_id, download_path, hirelpp=True, cloudmask=True, elpp=True, optical=True, elic=True)[source]¶
Downloads products for a given measurement (ID) to the given path. This function is a generator, yielding the filename of each downloaded file.
- Parameters:
measurement_id (
str) – Which measurement to download products fordownload_path (
Path) – Where to store the downloaded productshirelpp – Whether to download HiRELPP files
cloudmask – Whether to download Cloudmask files
elpp – Whether to download ELPP files
optical – Whether to download optical (ELDA or ELDEC) files
elic – Whether to download ELIC files
- get_anchillary(file_id, file_type)[source]¶
Uses the SCC API to fetch information about anchillary files.
- Parameters:
file_id (
str) – File ID to lookupfile_type (
str) – What kind of file to lookup (‘sounding’, ‘overlap’ or ‘lidarratio’)
- Return type:
Optional[APIObject]- Returns:
The API response about the file
- get_lidar_consants(date_start, date_end, location, page=1)[source]¶
Fetches the Lidar constants from SCC
- Parameters:
date_start (
date) – First day of resultsdate_end (
date) – Last day of resultslocation (
Optional[Location]) – Optionally, filter results by a locationpage – Which page to return (starts from 1, default value is 1)
- Return type:
Tuple[int,List[Measurement]]- Returns:
The number of pages and the list of measurements
- get_measurement(measurement_id)[source]¶
Fetches information about one measurement from SCC.
- Parameters:
measurement_id (
str) – Which measurement to lookup- Return type:
Optional[Measurement]- Returns:
The measurement if it exists, None otherwise
- login()[source]¶
Login to SCC
This function starts a session with the SCC backend, storing the authentication cookies so they can be used by the rest of the methods. Remember to call
logout()!
- query_measurements(date_start, date_end, location, page=1)[source]¶
Searches SCC for uploaded measurements
- Parameters:
date_start (
date) – First day of resultsdate_end (
date) – Last day of resultslocation (
Optional[Location]) – Optionally, filter results by a locationpage – Which page to return (starts from 1, default value is 1)
- Return type:
Tuple[int,List[Measurement]]- Returns:
The number of pages and the list of measurements
- rerun_processing(measurement_id)[source]¶
Asks SCC to re-run processing routines for a given measurement ID
- Parameters:
measurement_id (
str) – Which measurement to re-run
- upload_file(filename, system_id, rs_filename=None, ov_filename=None, lr_filename=None)[source]¶
Uploads a file to SCC, together with the auxilary files. There is no return value, but it will throw for potential errors.
- Parameters:
filename (
Path) – Path to the SCC netCDF filesystem_id (
str) – SCC Lidar System ID for the system that made the measurementrs_filename (
Optional[Path]) – Path to the radiosonde netCDF fileov_filename (
Optional[Path]) – Path to the overlap netCDF filelr_filename (
Optional[Path]) – Path to the lidar ratio netCDF file
- class pollyxt_pipelines.scc_access.SCC_Credentials(config)[source]¶
Bases:
objectContains all required credentials to authenticate with SCC
- pollyxt_pipelines.scc_access.scc_session(credentials)[source]¶
An SCC session as a context, to use with
with:Example:
with scc_access(credentials) as scc: # Use scc # ...
Exceptions¶
Exceptions that might occur while working with SCC
- exception pollyxt_pipelines.scc_access.exceptions.MeasurementNotFound(measurement_id)[source]¶
Bases:
ExceptionRaised when the requested measurement does not exist in the SCC database
- exception pollyxt_pipelines.scc_access.exceptions.PageNotAccessible(page_url, status_code)[source]¶
Bases:
ExceptionRaised when a page cannot be accessed
- exception pollyxt_pipelines.scc_access.exceptions.SCCError(errors)[source]¶
Bases:
ExceptionRaised when an error message from SCC is parsed from the page body
Container types¶
Various container classes and utility functions for handling SCC responses
- class pollyxt_pipelines.scc_access.types.APIObject(response_body)[source]¶
Bases:
objectSCC generic API response object
The only objects fetched from the API are Anchillary files, so this class doesn’t do much.
- class pollyxt_pipelines.scc_access.types.LidarConstant(measurement_id, channel_id, system_id, product_id, detection_wavelength, lidar_constant, lidar_constant_stat_err, profile_start_time, profile_end_time, calibration_window_bottom, calibration_window_top, creation_date, elda_version)[source]¶
Bases:
object- static from_table_row(tr)[source]¶
Create a measurement object from a table row. Table rows are formatted like in https://scc.imaa.cnr.it/admin/database/lidarconstant/
- class pollyxt_pipelines.scc_access.types.Measurement(id, station_code, date_start, date_end, date_creation, date_updated, is_uploaded, hirelpp, cloudmask, elpp, elda, eldec, elic, elquick, is_queued, is_processing)[source]¶
Bases:
object- static from_table_row(tr)[source]¶
Create a measurement object from a table row. Table rows are formatted like in https://scc.imaa.cnr.it/admin/database/measurements/
- class pollyxt_pipelines.scc_access.types.ProductStatus(*values)[source]¶
Bases:
EnumRepresents the status of a product (ie ELDA) on SCC
- pollyxt_pipelines.scc_access.types.scc_bool(node)[source]¶
Convert a table cell to a bool
- Return type:
bool