Cloud#

These functions are used by the OpenGHG cloud platform.

openghg.cloud.create_file_package(filepath, obs_type)[source]#

Reads file metadata and compresses data to be sent to the serverless function

Parameters:
  • filepath (Path) – Path of data

  • obs_type (str) – Observation type

Returns:

Compressed data as bytes and dictionary of file metadata

Return type:

tuple

openghg.cloud.create_post_dict(function_name, data, metadata, file_metadata, precision_data=None, precision_file_metadata=None)[source]#

Create the dictionary to POST to the remote function

Parameters:
  • function – Function name

  • data (bytes) – Compressed data

  • metadata (Dict) – Metadata dictionary

  • file_metadata (Dict) – File metadata

  • precision_data (Optional[Dict]) – GCWERKS precision data

  • precision_file_metadata (Optional[Dict]) – GCWERKS precision file metadata

Returns:

Dictionary ready for function call

Return type:

dict

openghg.cloud.call_function(data)[source]#

Calls an OpenGHG serverless function and returns its response

Parameters:

data (Dict) – Data to POST. Must be a dictionary created using the create_post_dict function.

Returns:

Dictionary containing response status, headers and content.

Return type:

dict

openghg.cloud.package_from_function(data, metadata=None)[source]#

Creates a package of data ready to be sent back to the caller. This calculates the SHA1 sum of the passed data and compresses it. If metadata is passed this is added to the returned dictionary. No SHA1 is calculated for the metadata.

NOTE: This function should only be used internally by a serverless function.

Parameters:
  • data (bytes) – Binary data

  • metadata (Optional[str]) – Result of json.dumps

Returns:

Dictionary of compressed data and file metadata.

Return type:

dict

openghg.cloud.unpackage(data)[source]#

Unpackages and checks a dictionary created by the package_from_function function. This checks the SHA1 sums and decompresses the data.

Parameters:

data (Dict) – Dictionary

Returns:

Dictionary containing data and metadata if given

Return type:

dict