Skip to content

Trouble rotating wind vectors u and v from CONUS404 #489

@gtyree01

Description

@gtyree01

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")`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions