0

I am having issues on how to calculate precipitable water using some of metpy's commands. Here's what I have so far for my code:

EDITED

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import scipy.ndimage as ndimage
from scipy.ndimage.filters import minimum_filter, maximum_filter
from mpl_toolkits.basemap import cm
import metpy.calc as mcalc
from metpy.units import units

filename='totalprecipitablewater'
title ='Total Precipitable Water'
cbarlabel = 'Millimeters (mm)'
boundaryColor = 'gray'
frequency = 3                   # frequency in hrs
ticks = np.arange(-10,120,10)
time = 0
pressure = []
vapor_pressure = []
dew_point = []

def plot(variables,prev_vars,pltenv):

    cont_int = 10
    cont_smooth = 0.5
    x = pltenv['x']
    y = pltenv['y']
    m = pltenv['map']

    bbox = dict(boxstyle="square",ec='None',fc=(1,1,1,0.75))
    mixing_ratio = variables['QVAPOR'][time]
    pressure = (variables['PB'][time] * units.pascals + variables['P'][time] * units.pascals)
    e = mcalc.vapor_pressure(pressure, mixing_ratio)
    td = mcalc.dewpoint(e)

    i = 0
    while i < 300:
      j = 0
      while j < 211:
        tpw = mcalc.precipitable_water(td[:,i,j], pressure[:,i,j], bottom=None, top=None)
        j+=1
      i+=1
    print(tpw)

"variables" calls the WRF model for my data. "tpw" represents the total precipitable water, which is what I am attempting to calculate.

  • Can you add what error you're currently getting? – DopplerShift Nov 16 '19 at 18:44
  • I'm not getting any errors, nothing is showing up. I'm mostly asking this question because I'm not sure if my calculation/logic makes sense. – DingierTrashcan Nov 16 '19 at 18:52
  • There's nothing obviously wrong with the code. Have you looked at what values are in the tpw array? We need to figure out if the plotting is the problem or the calculation is the problem. Or if you can link to the data somewhere, people can better try to reproduce the problem. – DopplerShift Nov 16 '19 at 20:42
  • I've edited my code and now the issue is that the program is running continuously with no output. – DingierTrashcan Nov 25 '19 at 23:30
  • How long are you waiting to see if it finishes? Each call to precipitable_water on my system takes 2.7ms; with your 63300 grid points, that's about 3 minutes. At which point for me it finishes. – DopplerShift Nov 26 '19 at 00:57
  • So I found that I failed to include [i,j] in tpw. So instead of 'tpw = ', I changed it to 'tpw[i,j].' However, the issue I'm having now is that I get the error "List indices must be integers, not tuples." – DingierTrashcan Nov 26 '19 at 16:58
  • If you initialized `tpw` as `[]`, then you've created a list, not an array, and lists only support indexing with single indices. What you probably need is to do `tpw = np.zeros(td.shape[1:])` – DopplerShift Nov 26 '19 at 20:38

0 Answers0