Transfer CDM files using Remote Procedure Calls.
Project description
pygcdm
A python API for transferring Common Data Model (CDM) files using Remote Procedure Calls.
Installation
TODO
Usage
Create Environment
To activate the conda environment we'll use the environment.yml
file. If you don't have conda
installed on your machine, install if following these instructions. Start by cloning the repo and creating/activating the conda environment:
git clone https://github.com/rmcsqrd/netcdf-grpc
cd netcdf-grpc
conda env create --name [environment name] -f environment.yml
conda activate [environment name]
Note that you can omit the --name
flag and the environment will default to netcdf-grpc-env
.
Encode/Decode API
This demonstrates how to encode/decode gRPC messages within a python shell:
# import/instantiate encoder object
from src.netcdf_encode import netCDF_Encode
encoder = netCDF_Encode()
# import and define header request
import src.protogen.gcdm_netcdf_pb2 as grpc_msg
file_loc = "test/data/test.nc"
header_request = grpc_msg.HeaderRequest(location=file_loc)
header_response = encoder.generate_header_from_request(header_request)
# define data request
var_spec = "analysed_sst"
data_request = grpc_msg.DataRequest(location=file_loc, variable_spec=var_spec)
data_response = encoder.generate_data_from_request(data_request)
# decode header/data into xarray object
from src.netcdf_decode import netCDF_Decode
decoder = netCDF_Decode()
ds = decoder.generate_file_from_response(header_response, data_response)
Transfer Files using gRPC
This demonstrates how to implement the python encode/decode API and transmit netCDF files via gRPC. Start by opening up two separate tabs in your terminal. Make sure that whatever python environment you installed the requirements into is active in both. Make sure that you are in base folder of this repo.
In the first tab, start the gRPC server by running the following command:
python grpc_netcdf_server.py
If it is working properly you should see something that says starting server...
.
In the second tab, make a client request by running the following command:
python grpc_netcdf_client.py
Something resembling an xarray dataset should print to the terminal if everything is working. Feel free to modify the loc
and variable_spec
variables in grpc_netcdf_client.py
to modify what data is transmitted.
Generating Python Source Code from proto
Files
In order to generate the grpc python source code from the .proto
files in protos/src/protogen
, we need to use the protoc
compiler (the reason for the weird subfolder structure is so that protoc
generates files with proper import namespaces). The python package with protoc
can be installed by following the instructions here.
To compile our code, and put the resulting functions into src/protogen/
, we can use the following commands (from the root directory where this README is located):
$ python -m grpc_tools.protoc -I protos/ --python_out=. --grpc_python_out=. protos/src/protogen/*.proto
More information on the protoc
compiler can be found by loading the module in python and using the help
command:
$ python
>>> import grpc_tools.protoc
>>> help(grpc_tools.protoc)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pygcdm-0.0.6.tar.gz
.
File metadata
- Download URL: pygcdm-0.0.6.tar.gz
- Upload date:
- Size: 22.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e94e897d511f94249d2055033966a41ebbbcd4c0d54d239182715ce883765a0 |
|
MD5 | 2205cc2a01e48d4106d42ff9466913a4 |
|
BLAKE2b-256 | 3bb646e23fa87d1889e699fa4ddfca40bc788e4b2acccaec125542ca9240d9b9 |
File details
Details for the file pygcdm-0.0.6-py2.py3-none-any.whl
.
File metadata
- Download URL: pygcdm-0.0.6-py2.py3-none-any.whl
- Upload date:
- Size: 23.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3db306628073b61e1fa47444c0b8f22f65eb7cc16b51316efcc0e21c8a7f1ea |
|
MD5 | 891e6758d3b5a15576a75c3a1119957d |
|
BLAKE2b-256 | 745f54411c33b0a06c65e8a090e50bc288fba946c72c3a865f1e64e0af4c78c6 |