The Chinese University of Hong Kong | 香港中文大學
Faculty of Science | 理學院
Header

Tools > R

We use R extensively for our research. R can be downloaded here, and RStudio (a more attractive interface) can be downloaded here. To learn the basics of the R language and computing environment, please go through the Introduction to R here. To get an easy start on R (and Python!), you may take a free online course offered by DataCamp here.

Prof. Amos Tai has given an R tutorial for atmospheric scientists, and written many functions useful for analyzing spatial and time series data in various formats, all of which can be downloaded here. Most important of them include:
  • R_Intro_for_Atmos_Sci/: You may go through the scripts R_Intro_1.R and R_Intro_2.R for an introduction to R. The required datasets for the tutorial and other useful references are also included therein.
  • get_geo.R: Functions for spatial analysis and visualization, e.g., interpolation, regridding, geostatistics, mapping. Particularly useful: plot.field, sp.regrid
  • get_met.R: Functions for handling time series and meteorological data, e.g., moving average, monthly statistics.
  • get_stat.R: Functions for statistical and numerical methods, e.g., optimization, regression, cumulative probability)
  • ncdf_hdf5_example.R: Examples for reading/writing NetCDF and HDF data in R using the "ncdf4" and "rhdf5" packages. You may not have those data in the examples, but you can see how the functions work.

To begin learning how to read, process and visualize data in NetCDF format, you may download one month (July 2010) of hourly surface meteorological fields of the NASA/GMAO MERRA2 reanalysis product here (warning: large size!). A recommended exercise is to:
  1) Write a little program to extract 2-m air temperature (T2M) for all hours and all days for the whole world, and store the data in a single array of dimensions length(lon) x length(lat) x (24*31). Make sure you also extract the lon and lat variables. You may either use the load.nc function in get_geo.R, or follow the examples in ncdf_hdf5_example.R.
  2) Compute the monthly mean T2M grid cell by grid cell using the built-in apply function.
  3) Regrid monthly mean T2M from 2°x2.5° to 4°x5° (latitude by longitude) using the sp.regrid function in get_geo.R
  4) Visualize the original and regridded monthly mean T2M using the plot.field function in get_geo.R, and compare between them.

Please contact us should you find any errors, and acknowledge us should find them useful for your work.


Tools > Terrestrial Ecosystem Model in R (TEMIR)

We have developed a Terrestrial Ecosystem Model in R (TEMIR) v1 that computes ecophysiological processes and responses of local and global terrestrial ecosystems (e.g., canopy radiative transfer, photosynthesis, conductance, dry deposition of air pollutants) driven by prescribed meteorological and land surface input data. The primary purpose is to evaluate changes in ecosystem functions in response to changes in the terrestrial and atmospheric environment (e.g., CO2, ozone, temperature, humidity, soil moisture, plant type distribution), and to evaluate how changes in ecosystem functions influence atmospheric chemistry and climate.

In this version, we use default meteorological inputs from the NASA/GMAO MERRA2 and GEOS-FP reanalysis products, so that ecosystem simulations are entirely consistent and can be asynchronously coupled with atmospheric chemistry simulations by the GEOS-Chem chemical transport model. Land surface (e.g., plant function type, soil type) inputs are mostly from the Community Land Model (CLM) v4.5, with 24 plant function types (PFTs) including several individual midlatitude crops. The model is, however, highly customizable, and users can liberally replace the default inputs with their own data. The model can be run parallelly on multiple cores, and computational speed is scalable almost linearly to the number of cores used.

The following components are required to run the model:
  • Model code
  • Required input data (email Prof. Tai for password to access data; contains meteorological data only for a few days for testing; more data are available below)
  • MERRA2 meteorological fields (email Prof. Tai for password to access data; to be put into TEMIR_inputs/met_data/; data are very large, so only download the years that you need)
  • Gridded hourly ozone concentrations (optional; 2010 GEOS-Chem-simulated ozone already put into TEMIR_inputs/O3_data/; see Fu and Tai, 2015)
  • Monthly leaf area index (LAI) used by GEOS-Chem (optional; 2010 data already put into TEMIR_inputs/LAI_data/; see here for more info)

Quick start:
  1) Follow the quick start guide TEMIR_manual_v1.0.docx.
  2) A more detailed user manual will be available soon. The input_TEMIR.R script should be self-explanatory for now.

The model physics is mostly consistent with CLM4.5 and GEOS-Chem. Details can be found in the CLM4.5 Technical Note and GEOS-Chem dry deposition page. For a background reading on the necessary scientific concepts, we highly recommend Ch.12-17 from Gordon Bonan's Ecological Climatology: Concepts and Applications (3rd Ed). A manuscript describing the model details and validation is currently under preparation. Model updates are available here.

New capacities to simulate biogenic emissions, plant phenology, biogeochemistry, and crop growth are currently under development. Stay tuned!

Last updated: Apr 2020


PHD Comics