IO API
Input and output handling
- pyrcmip.io.ensure_dir_exists(fp)
Ensure directory exists
- Parameters:
fp (str) – Filepath of which to ensure the directory exists
- pyrcmip.io.read_results_submission(results)
Read results submission
- pyrcmip.io.read_submission_model_comments(fp)
Read the submission comments.
- Parameters:
fp (str) – Filepath to read
- Return type:
pd.DataFrame
- pyrcmip.io.read_submission_model_metadata(fp)
Read the model metadata component of a submission
- Parameters:
fp (str) – Filepath to read
- Return type:
pd.DataFrame
- pyrcmip.io.read_submission_model_reported(fp)
Read the model reported component of a submission
- Parameters:
fp (str) – Filepath to read
- Return type:
pd.DataFrame
- pyrcmip.io.temporary_file_to_upload(df, max_size=1024, compress=False, file_format='csv')
Create a gzipped temporary serialized version of a file to upload
Attempts to keep the file in memory until it exceeds max_size. The file is then stored on-disk and cleaned up at the end of the context.
The temporary location can be overriden using the TMPDIR environment variable as per https://docs.python.org/3/library/tempfile.html#tempfile.gettempdir
Notice that this only supports taking an
scmdata.ScmRun`|:obj:`xarray.Datasetif the target format is CSV (file_format=”csv”), andxarray.Datasetif the target format is netCDF (file_format=”nc”).- Parameters:
df (
scmdata.ScmRun|pd.DataFrame|xarray.Dataset) – Run to storemax_size (int or float) – Max size in MB before file is temporarily streamed to disk. Defaults to 1GB
compress (bool) – whether to compress the file to upload
file_format (str) – File format for the target file to upload. Allowed values are: “csv” and “nc”.
- Returns:
Open file object ready to be streamed
- Return type: