-1

I am using ERA5 reanalysis data from the NCAR RDA. I am using metpy dewpoint_from_relative_humidity() to compute dewpoint, then I convert it to a DataArray object and assign coordinates and dimensions that match the Dataset object I have the ERA5 data in. I would like to compute precipitable water using precipitable_water() in metpy but I am struggling to figure out the most efficient way to perform this calculation since it is designed to work on arrays (soundings) rather than grids of data. I have looked at xr.apply_ufunc() but I am unsure if this would be an appropriate application of that xarray feature or frankly even how I would execute that. I could write nested for loops/while loops but I don't feel this is the best way to do this. Does anyone have any suggestions? I tried the line below but it's telling me too many positional arguments, and I don't think this can be done since ds['TD'] is not an array.

ds['TD']  = xr.DataArray(mpcalc.dewpoint_from_relative_humidity(ds['T'],ds['R']),dims=['level','latitude','longitude'],coords=ds.coords)
ds['PW'] = xr.DataArray(mpcalc.precipitable_water(ds['TD'],ds.level,1000.0,700.0),dims=['level','latitude','longitude'],coords=ds.coords)
  • Hi @DanielAdriaansen, I think the would be best to include the code on how to reproduce your problem here e.g. how the dataset, your working code. It's hard to reproduce based on your question – titipata Apr 16 '20 at 16:39

1 Answers1

0

I'm going to guess you're running MetPy 1.0 (rc1). For that, the calling for precipitable_water() function has changed to use keyword-only arguments for bottom and top. I'd expect the following to work:

pw = mpcalc.precipitable_water(ds['TD'], ds.level, bottom=1000.0, top=700.0)
DopplerShift
  • 5,472
  • 1
  • 21
  • 20
  • Correct, 1.0 (rc1). The kwargs fixed the positional argument errors I was getting, thanks. I am now getting an error telling me that `precipitable_water()` was given arguments with incorrect units: ValueError: `precipitable_water` given arguments with incorrect units: `pressure` requires "[pressure]" but given "dimensionless", `dewpoint` requires "[temperature]" but given "dimensionless". Printing ds['TD'], plevs, pbot, and ptop shows all are type "Quantity" with units of 'degree_Celsius', 'hectopascal', 'hectopascal', and 'hectopascal'. Thoughts? – DanielAdriaansen Apr 17 '20 at 18:03
  • This has to do with passing DataArray's I created myself that have no attributes associated with them. Even though I assign units inside my script using pint (e.g. ds['TD'] * units('degC')), MetPy assumes that the units are stored as an attribute on the DataArray itself, rather than however pint attaches units. I am going to move to GitHub issue if you think that's warranted here? – DanielAdriaansen Apr 17 '20 at 19:46
  • Since we probably need more discussion than question, it's probably appropriate to move over to GitHub, yes. – DopplerShift Apr 17 '20 at 22:33
  • I still have a question regarding passing 3D variables (TD/P) to the function rather than looping and passing 1D variables. Is it best to keep that conversation here or move to a different platform? I have a hard time understanding where it's best to ask for help rather than track bugs/issues (I created an issue about the dimensionless units this morning which was very helpful!). – DanielAdriaansen Apr 20 '20 at 20:49
  • 1
    I'm not sure where the best place is, but the short answer to your question is that, looking at the code, there are a couple places that assume 1D, but I think we could do something about that. If that's an important use case for you, you should open an issue and we can discuss more there and look at an implementation. – DopplerShift Apr 21 '20 at 00:20