Last active
December 3, 2015 04:37
-
-
Save chrisb13/62b159a374bb0763c569 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadnc() #load netcdf file in python | |
{ | |
if [[ ( $# -eq 0 ) || ( $1 == "--help" ) || ( $1 == "-h" ) ]] ; then | |
echo "Usage: loadnc FILENAME_PATHNAME" | |
echo "Purpose: loads path of file into ipython (creates loadvar.py in your current dir). Prints file info and available variables. 'ifile' is name of netCDF4 object." | |
echo " " | |
echo "Requires: python netCDF4" | |
echo " " | |
echo "Mandatory arguments: " | |
echo "FILENAME_PATHNAME: path to netCDF file" | |
echo " " | |
echo "Examples:" | |
echo "loadnc netcdffilename.nc" | |
echo "loadnc /path/to/netcdffilename.nc" | |
echo " " | |
return 1 | |
fi | |
OUTPUT="$(readlink -e ${1}|tr -d '\n')" | |
cat << EOF > loadvar.py | |
import os | |
from netCDF4 import Dataset | |
infile='${OUTPUT}' | |
ifile=Dataset(infile, 'r') | |
#varone=ifile.variables[''] | |
print "" | |
print "NetCDF file loaded with bash loadnc function..." | |
print os.path.basename(infile) | |
print "" | |
print "File Details" | |
print ifile | |
print "" | |
print "Variable Names: " | |
print "" | |
print ifile.variables.keys() | |
print "" | |
print "" | |
print "'ifile' is name of netCDF4 object... " | |
print "" | |
EOF | |
ipython -i loadvar.py | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment