I am working with a computer science student who is playing with visualisation tools for UM data that is presently in .pp files. Their preference is to work in either C# or C++, are you aware of any utilities for reading .pp in these languages, or are we better off converting these to another format?
Hi Todd
CMS have spent years developing and continue to develop cf-python and cf-plot – python based utilities. Could your student benefit from those?
Grenville
My personal preference is to convert to netCDF as there is a much larger array of tools available for the format.
I use a basic utility using cf-python which is installed in its own conda env:
cfpython_pe_to_nc.py
import sys
import cf
def main():
if len(sys.argv) != 2:
print('Usage: python cfpython_pe_to_nc.py <pe_file>')
sys.exit(1)
ds = cf.read(sys.argv[1])
cf.write(ds, sys.argv[1]+'.nc')
print('Successfully wrote nc file: {0}'.format(sys.argv[1]+'.nc'))
if __name__ == "__main__":
main()
pe_to_nc.sh
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "Incorrect usage, only input should be input pe_file"
exit 1
fi
if [ -f "/home/rw796/miniconda3/etc/profile.d/conda.sh" ]; then
. "/home/rw796/miniconda3/etc/profile.d/conda.sh"
else
export PATH="/home/rw796/miniconda3/bin:$PATH"
fi
# ARGUMENTS
PE_FILE=$1
if [ ! -f "$PE_FILE" ]; then
echo "could not find provided pe_file"
exit 1
fi
if ! conda activate cfpython; then
echo "unable to activate cfpython env"
exit 1
fi
python /home/rw796/rw_utils/cfpython_pe_to_nc.py "$PE_FILE"
conda deactivate
Thanks, Rob and Grenville. I’m aware of the cf tools and have encouraged their use. The student reported vague installation troubles that I have not been able to assist with for lack of information, and I wanted to check whether anything closer to their comfort zone happened to exist.
Hi toddj
, to add to the thread, if you can encourage them to let us know more about the installation issues with cf-python or related libraries, here or otherwise, we can help them get set up. As for your original question:
I wanted to check whether anything closer to their comfort zone happened to exist.
I am not aware about any C# or C++ to directly read and work with PP, so…
or are we better off converting these to another format?
…yes, I think if they want to work with the original PP and those languages they would need to convert, e.g. your student could convert from PP to netCDF, e.g. with cf-python, as per Rob Waters example snippets or otherwise, and then use netCDF-C++ (GitHub - Unidata/netcdf-cxx4: Official GitHub repository for netCDF-C++ libraries and utilities.).