-
Notifications
You must be signed in to change notification settings - Fork 13
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
Comments
Is the problem because you are pulling out lat[0] and lon[0] instead of the full arrays?
Theodore Barnhart, PhD<https://urldefense.com/v3/__https://scholar.google.com/citations?hl=en&user=9XscEjAAAAAJ__;!!JYXjzlvb!jG7c_LnXMMCqTep_NF6TMq8BdGCKT7V6hPndMtVrjyPdWY1m2Svc19QK6E0ynyh2U87x8PEZECGNHwTBZi4BbNQ$>
Research Physical Scientist
***@***.***
+1-406-459-8707 (mobile)
Pronouns: he/him<https://urldefense.com/v3/__https://www.mypronouns.org/__;!!JYXjzlvb!jG7c_LnXMMCqTep_NF6TMq8BdGCKT7V6hPndMtVrjyPdWY1m2Svc19QK6E0ynyh2U87x8PEZECGNHwTBf-SbMNQ$>
Wyoming-Montana Water Science Center
U.S. Geological Survey
3162 Bozeman Ave
Helena, MT 59601
…________________________________
From: gtyree01 ***@***.***>
Sent: Monday, June 17, 2024 3:20 PM
To: hytest-org/hytest ***@***.***>
Cc: Barnhart, Theodore B ***@***.***>; Mention ***@***.***>
Subject: [EXTERNAL] [hytest-org/hytest] Trouble rotating wind vectors u and v from CONUS404 (Issue #489)
This email has been received from outside of DOI - Use caution before clicking on links, opening attachments, or responding.
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<https://www-k12.atmos.washington.edu/~ovens/wrfwinds.html> posted by @theobarnhart-USGS<https://github.com/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 Traceback (most recent call last)
Cell In[9], line 1
----> 1 Urot, Vrot = Basemap.rotate_vector(Uearth, Vearth, lons, lats, returnxy=True)
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<https://github.com/AndreasPrein> tagging you here because @sfoks<https://github.com/sfoks> recommended that I reach out to you about this!
`# Import modules
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
open the hytest data intake catalog and the conus404 sub-catalog
hytest_cat = intake.open_catalog("https://raw.githubusercontent.com/hytest-org/hytest/main/dataset_catalog/hytest_intake_catalog.yml")
cat = hytest_cat['conus404-catalog']
Select the dataset you want to read into your notebook and preview its metadata
dataset = 'conus404-hourly-osn'
read in the dataset and use metpy to parse the crs information on the dataset
print(f"Reading {dataset} metadata...", end='')
ds = cat[dataset].to_dask().metpy.parse_cf()
Select the vars you need to calculate wind speed and direction
vars = ['COSALPHA', 'SINALPHA', 'U10', 'V10']
ds_vars = ds[vars]
Correct U10 and V10 to Earth-relative coordinates
Uearth = ds_vars.U10ds_vars.COSALPHA - ds_vars.V10ds_vars.SINALPHA
Vearth = ds_vars.V10ds_vars.COSALPHA + ds_vars.U10ds_vars.SINALPHA
Rotate the Earth-relative coordinates to an xy grid
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)
Check calculation of wind direction
wind_dir = mpcalc.wind_direction(Uearth[1,1,1], Vearth[1,1,1], convention="from")`
—
Reply to this email directly, view it on GitHub<#489>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AHG6IGTMXGT2X74KG5TF4PDZH5HILAVCNFSM6AAAAABJOYHNXCVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM2TQMRXHEZTKMI>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@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. |
Hmmm, here is how I have it implemented, it's very similar to what you have going on, but at line 192 I do some stuff to create the LAT and LON grids I used in the rotation.
wrf2sm/extractor.py · master · water-snow-hydro / WRF to SnowModel Input · GitLab (usgs.gov)<https://code.usgs.gov/water-snow-hydro/wrf2sm/-/blob/master/wrf2sm/extractor.py?ref_type=heads#L184>
Theodore Barnhart, PhD<https://urldefense.com/v3/__https://scholar.google.com/citations?hl=en&user=9XscEjAAAAAJ__;!!JYXjzlvb!jG7c_LnXMMCqTep_NF6TMq8BdGCKT7V6hPndMtVrjyPdWY1m2Svc19QK6E0ynyh2U87x8PEZECGNHwTBZi4BbNQ$>
Research Physical Scientist
***@***.***
+1-406-459-8707 (mobile)
Pronouns: he/him<https://urldefense.com/v3/__https://www.mypronouns.org/__;!!JYXjzlvb!jG7c_LnXMMCqTep_NF6TMq8BdGCKT7V6hPndMtVrjyPdWY1m2Svc19QK6E0ynyh2U87x8PEZECGNHwTBf-SbMNQ$>
Wyoming-Montana Water Science Center
U.S. Geological Survey
3162 Bozeman Ave
Helena, MT 59601
…________________________________
From: gtyree01 ***@***.***>
Sent: Monday, June 17, 2024 4:00 PM
To: hytest-org/hytest ***@***.***>
Cc: Barnhart, Theodore B ***@***.***>; Mention ***@***.***>
Subject: [EXTERNAL] Re: [hytest-org/hytest] Trouble rotating wind vectors u and v from CONUS404 (Issue #489)
This email has been received from outside of DOI - Use caution before clicking on links, opening attachments, or responding.
@theobarnhart-USGS<https://github.com/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.
—
Reply to this email directly, view it on GitHub<#489 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AHG6IGSVHPVYGGPAD6AD2TDZH5L6HAVCNFSM6AAAAABJOYHNXCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZUGUYDINRUHA>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
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
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",
vrequires "[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")`
The text was updated successfully, but these errors were encountered: