Open gtyree01 opened 2 weeks ago
Is the problem because you are pulling out lat[0] and lon[0] instead of the full arrays?
Theodore Barnhart, PhDhttps://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/himhttps://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 guidehttps://www-k12.atmos.washington.edu/~ovens/wrfwinds.html posted by @theobarnhart-USGShttps://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! @AndreasPreinhttps://github.com/AndreasPrein tagging you here because @sfokshttps://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 GitHubhttps://github.com/hytest-org/hytest/issues/489, or unsubscribehttps://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, PhDhttps://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/himhttps://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-USGShttps://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 GitHubhttps://github.com/hytest-org/hytest/issues/489#issuecomment-2174504648, or unsubscribehttps://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.
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")`