{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# ORIGINAL HEADER:\n", "# Brody Fuchs, CSU, November 2015\n", "# brfuchs@atmos.colostate.edu\n", "\n", "\n", "## Update the skewT code to be smarter using classes and what not\n", "# use the KUILsounding.txt as an example or KBMXsounding.txt\n", "\n", "# Modified by Zane Martin, Columbia University, zkm2102@columbia.edu for PISTON cruise and for use with iPython \n", "# notebook\n", "\n", "# Start out by just plotting the raw data first\n", "\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from skewPy import SkewT\n", "import os\n", "from datetime import datetime\n", "import glob\n", "import sys\n", "\n", "import argparse\n" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "usage: __main__.py [-h] [--file FILE] [--filepath FILEPATH]\n", " [--outpath OUTPATH]\n", "__main__.py: error: unrecognized arguments: -f /Users/zanemartin/Library/Jupyter/runtime/kernel-a57a232f-64c4-40b5-98a0-5ead169d16da.json\n" ] }, { "ename": "SystemExit", "evalue": "2", "output_type": "error", "traceback": [ "An exception has occurred, use %tb to see the full traceback.\n", "\u001b[0;31mSystemExit\u001b[0m\u001b[0;31m:\u001b[0m 2\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/zanemartin/anaconda/lib/python3.6/site-packages/IPython/core/interactiveshell.py:2889: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.\n", " warn(\"To exit: use 'exit', 'quit', or Ctrl-D.\", stacklevel=1)\n" ] } ], "source": [ "parser = argparse.ArgumentParser(description='Put in a file to be processed')\n", "\n", "#parser.add_argument('--noarg', action=\"store_true\", default=False)\n", "parser.add_argument('--file', action=\"store\", dest=\"file\", default=None)\n", "\n", "# location of sounding files\n", "parser.add_argument('--filepath', action='store', dest='filepath', default='.')\n", "# where you want to output skewTs\n", "parser.add_argument('--outpath', action='store', dest='outpath', default='.')\n", "# the first part of the sounding raw data file, need it to search for possible files\n", " # other possibilities are 'K' for K*** UWYO soundings, could also be 'EDT' for Vaisala soundings\n", "parser.add_argument('--prefix', action=\"store\", dest=\"prefix\", default='')\n", "# This can currently be 'EC' for Canadian format, 'UWYO' for Wyoming soundings or 'EDT' for Vaisala CSU soundings\n", "# Or XML, so some dumb*** reason. Gave us something to do on the SPURS2 cruise, I suppose\n", "parser.add_argument('--format', action='store', dest='format', default='XML')\n", "# put this in if want to override the station name in the title of the skewT, default is fmt above\n", " # otherwise just put None\n", "parser.add_argument('--station', action='store', dest='station', default=None)\n", "# turning this switch on will just print more stuff, maybe needed if trying to debug\n", "parser.add_argument('--debug', action='store', dest='debug', type=int, default=0)\n", "# This will process a certain file in the filepath. The number will correspond to the index of the file\n", "parser.add_argument('--number', action='store', dest='number', default=None)\n", "# This will process the last file in the filepath\n", "parser.add_argument('--last', action='store', dest='last', default=None)\n", "\n", "\n", "pargs = parser.parse_args()\n", "\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "ename": "NameError", "evalue": "name 'pargs' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0margv\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 17\u001b[0;31m \u001b[0;32mif\u001b[0m \u001b[0mpargs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfile\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 18\u001b[0m \u001b[0msounding_files\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mpargs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfile\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 19\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mNameError\u001b[0m: name 'pargs' is not defined" ] } ], "source": [ "\n", "##### PARAMETERS YOU CAN CHANGE HERE #########\n", "\n", "file_path = './' \n", "out_path = './' \n", "prefix = 'Revelle' # the first part of the sounding raw data file, need it to search for possible files\n", "# # other possibilities are 'K' for K*** UWYO soundings, could also be 'EDT' for Vaisala soundings\n", "fmt = 'XML' \n", "# station_name = None # put this in if want to override the station name in the title of the skewT, default is fmt above\n", "# # otherwise just put None\n", "\n", "########### DON'T NEED TO WORRY ABOUT ANYTHING BELOW HERE ############\n", "\n", "\n", "if len(sys.argv) > 1:\n", "\n", " if pargs.file is not None:\n", " \tsounding_files = [pargs.file]\n", "\n", " elif pargs.number is not None:\n", " number_loc = int(pargs.number) + 1\n", " sounding_files = glob.glob('%s/%s*'%(pargs.filepath, pargs.prefix))[number_loc]\n", "\n", " elif pargs.number is not None: \n", " sounding_files = [glob.glob('%s/%s*'%(pargs.filepath, pargs.prefix))[-1]]\n", " else:\n", " sounding_files = glob.glob('%s/%s*'%(pargs.filepath, pargs.prefix))\n", "\n", "else: \n", " sounding_files = sorted(glob.glob('%s/%s*'%(pargs.filepath, pargs.prefix)))\n", "\n", "\n", "print('processing the following files: {}', format(sounding_files))\n", "\n", "\n", "\n", "CAPEs = [] ## added during SPURS-2 for CAPE v dBZ plots\n", "p_top = []\n", "datestr = []\n", "TW = np.arange(0)\n", "RH_sfc = []\n", "q_sfc = []\n", "q_ml = []\n", "for fname in sounding_files:\n", " #file_title = os.path.basename(fname)[4:-4]\n", "\n", " #print 'Processing %s'%os.path.basename(fname)\n", "\n", " S = SkewT.Sounding(fname, fmt=pargs.format, station_name=pargs.station)\n", " CAPE, pres_last, date, tw, RH, q, qm = S.cape()\n", " datestr.append(date)\n", " CAPEs.append(CAPE) ## added during SPURS-2 for CAPE v dBZ plots\n", " p_top.append(pres_last)\n", " TW = np.append(TW,tw)\n", " RH_sfc.append(RH)\n", " q_sfc.append(q)\n", " q_ml.append(qm)\n", "\n", " plt.savefig('%s/%s_sounding.png'%(pargs.outpath, S.sounding_date), dpi=150)\n", " plt.close('all')\n", "\n", "print('\\n%d total soundings in %s\\n', (len(sounding_files), pargs.filepath))\n", "#np.savetxt('CAPE.txt', np.transpose([datestr, CAPEs, p_top]), delimiter=',', fmt=(('%s'),('%.2f'),('%.2f'))) ## added during SPURS-2 for CAPE v dBZ plots\n", "np.savez_compressed('CAPE.npz', times=datestr, cape=CAPEs, p_top=p_top, TW=TW, RH_sfc=RH_sfc, q_sfc=q_sfc, q_ml=q_ml)\n", "\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "ename": "SyntaxError", "evalue": "invalid syntax (, line 1)", "output_type": "error", "traceback": [ "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m except(KeyError)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" ] } ], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.0" } }, "nbformat": 4, "nbformat_minor": 2 }