Using Herbie in a Colab notebook #282
-
Hello Brian, long time since the UVA and NASA internships! And everyone else who might help! I am using Herbie in a google colab notebook as part of a lesson on training a random forest model to predict next-hour fire radiative power. I thought using Herbie to pull the RAP files from the mighty web would be a good idea. My understanding is that Herbie bypasses the more classes "xr.open_Dataset pynio" commands for grib2. So my question is that before, I pulled RAP files and stored them in a directory, and then opened the grib2 with pynio, and extracted the variables I needed and was further able to only extract the grid cell info I needed with a closest point formula from the fire lat/lon. But if I use Herbie, how do I treat the Herbie RAP file like what I'm used to so that I can save a variable in an array? For instance, it used to be something like "temp = grbs['TMP_P0_L103_GRLL0'].values.flatten()" to make an array. The "ds" command in the tutorial makes a dataset.. I just need the values to be honest and none of the meta data. Thanks - Christina |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi Christina! It has been a while. Good to hear from you. Sounds interesting what you are doing. I don't have any experience using colab and haven't used pynio in a very long time. Let's see how I do at answering your questions and giving some ideas... If you like using pynio, you could just use Herbie to download the files you want and then use pynio to read those downloaded file. from herbie import Herbie
H = Herbie('2024-01-01', model='rap')
my_file = H.download()
# The value of `my_file` is PosixPath('/home/blaylock/data/rap/20240101/rap.t00z.awp130pgrbf00.grib2')
# Use pynio to read/process that file When you download a Herbie object, it returns the path to the downloaded file. You could use that file with pynio however you are familiar. If the file has already been downloaded, Herbie won't redownload unless you tell it to. Going the xarray route, Herbie uses cfgrib to read the GRIB2 file into a DataFrame. You can select a specific variable/level you want using the searchString argument (you can use From an xarray dataset, it's easy to convert the dataset data into numpy arrays/vectors easily so you don't have to deal with extra metadata. H = Herbie("2024-01-01", model="rap")
# Get just 2-m temperature data as a dataset
ds = H.xarray(searchString="TMP:2 m")
# these are all numpy vectors
lat = ds.latitude.values.flatten()
lon = ds.longitude.values.flatten()
tmp_2m = ds.t2m.values.flatten() You might be interested in Herbie's nearest neighbor xarray accessor that you can read more about here; it throws some warnings, but it does work. Does any of that give you some ideas? |
Beta Was this translation helpful? Give feedback.
Hi Christina! It has been a while. Good to hear from you.
Sounds interesting what you are doing. I don't have any experience using colab and haven't used pynio in a very long time.
Let's see how I do at answering your questions and giving some ideas...
If you like using pynio, you could just use Herbie to download the files you want and then use pynio to read those downloaded file.
When you download a Herbie object, it returns the path to the downloaded file. Y…