Intermezzo: WRF and xarray#
In this exercise we are going to start exploring a WRF output file using xarray, which we will both need again later in our term project. You can download a sample WRF output file from here. The file contains only a very small number of variables to reduce the file size. To open the file with xarray, you need to install both xarray and netcdf4.
A) Open the file with xarray and explore the content of the Dataset. Which variables does the file contain? What is the type of the whole Dataset and of an individual variable within the Dataset?
B) The global attributes DX and DY contain the horizontal grid spacing. What is the grid spacing for this simulation?
C) One of the variables in the file is called HFX. What is it and what are its units? The information is stored together with the variable (as attributes). What are the dimensions of the variable?
D) Use the isel method to extract the horizontal cross section of HFX at the end of the simulation (i.e., the last time). What are the dimensions of this new array? Plot the new array using the DataArray.plot() method.
E) Calculate the sum of HFX and LH and assign the result to a new variable. What is the type of this new variable? Add your new variable to the existing Dataset.