Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble rotating wind vectors u and v from CONUS404 #489

Open
gtyree01 opened this issue Jun 17, 2024 · 4 comments
Open

Trouble rotating wind vectors u and v from CONUS404 #489

gtyree01 opened this issue Jun 17, 2024 · 4 comments

Comments

@gtyree01
Copy link

gtyree01 commented Jun 17, 2024

Hello all,

I want to calculate wind direction from the U10 and V10 components provided in the CONUS404 dataset. To correctly calculate wind direction, I need to first correct the components to Earth-relative coordinates. To do this, I'm following this guide posted by @theobarnhart-USGS.

Correcting the vectors to lat/lon is no issue, but when I try to rotate the vectors to the basemap, I get the following error:
TypeError: Basemap.rotate_vector() missing 1 required positional argument: 'lats'

Additionally, when I try to calculate wind direction from the lat/lon-corrected (i.e., not fully corrected!) vectors, I get this error about the (lost) units:
ValueError: wind_directiongiven arguments with incorrect units:urequires "[speed]" but given "dimensionless",v requires "[speed]" but given "dimensionless".

The code I'm running is pasted below. I've been using the HyTEST Jupyter Server to run my code. Any help with resolving these errors would be fantastic! @AndreasPrein tagging you here because @sfoks recommended that I reach out to you about this!

`import os
os.environ['USE_PYGEOS'] = '0'

import fsspec
import xarray as xr
import hvplot.xarray
import intake
import metpy
import cartopy.crs as ccrs
import geopandas as gpd
import numpy as np
import metpy.calc as mpcalc

hytest_cat = intake.open_catalog("https://raw.githubusercontent.com/hytest-org/hytest/main/dataset_catalog/hytest_intake_catalog.yml")
cat = hytest_cat['conus404-catalog']

dataset = 'conus404-hourly-osn'

print(f"Reading {dataset} metadata...", end='')
ds = cat[dataset].to_dask().metpy.parse_cf()

vars = ['COSALPHA', 'SINALPHA', 'U10', 'V10']
ds_vars = ds[vars]

Uearth = ds_vars.U10ds_vars.COSALPHA - ds_vars.V10ds_vars.SINALPHA
Vearth = ds_vars.V10ds_vars.COSALPHA + ds_vars.U10ds_vars.SINALPHA

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
lons = ds_vars.lon[0]
lats = ds_vars.lat[0]
Urot, Vrot = Basemap.rotate_vector(Uearth, Vearth, lons, lats, returnxy=True)

wind_dir = mpcalc.wind_direction(Uearth[1,1,1], Vearth[1,1,1], convention="from")`

@theobarnhart-USGS
Copy link

theobarnhart-USGS commented Jun 17, 2024 via email

@gtyree01
Copy link
Author

@theobarnhart-USGS I don't think so - I tried pulling out the full arrays to use for the lons and lats arguments, and unfortunately got the same error as reported here.

@theobarnhart-USGS
Copy link

theobarnhart-USGS commented Jun 17, 2024 via email

@gtyree01
Copy link
Author

Thanks @theobarnhart-USGS! I'll give this a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants