Skip to content

Commit

Permalink
Add z_top to clm artifacts and rename them
Browse files Browse the repository at this point in the history
Adds Canopy height to both clm data artifacts.
Also rename the low res artifact from clm_data
to clm_data_0.9x1.25 and the high res artifact from
clm_data_0.125 to clm_data_0.125x0.125
  • Loading branch information
imreddyTeja committed Feb 12, 2025
1 parent 5490145 commit 982e6f2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
20 changes: 10 additions & 10 deletions clm_data/OutputArtifacts.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[clm_data]
git-tree-sha1 = "3f6873a3e67722bda1fd23f7d5a05f5e2df1fe8c"
["clm_data_0.9x1.25"]
git-tree-sha1 = "283c62220fca8c4afe36a62348d3e9a159af2ee9"

[[clm_data.download]]
sha256 = "830136abec15551a343b7884d657fb6a79b16a37237681a2becf65bd845aa692"
url = "https://caltech.box.com/shared/static/6pu2f6c99g29qawvjjh3j56drkonpd3z.gz"
[clm_data_highres]
git-tree-sha1 = "e68ba26e07c135f66d1ad678795b4a25c929b1b6"
[["clm_data_0.9x1.25".download]]
sha256 = "88d5899a729de800017a74bd8a7278582c2c55c0d8730a529bae384425d70e4e"
url = "https://caltech.box.com/shared/static/mxs3l1c1dppjwy81assk8w8ofn9d70pu.gz"
["clm_data_0.125x0.125"]
git-tree-sha1 = "6284ddefbc7937d9c1fb68fa731ff3f00b68e917"

[[clm_data_highres.download]]
sha256 = "2c7e6ba3c11e1e6ef209c7437aa18fb4cf15edd11332527bf0b41495dccbed19"
url = "https://caltech.box.com/shared/static/kk72iah76p99yggm8knu6me8fh9eiid0.gz"
[["clm_data_0.125x0.125".download]]
sha256 = "8d2a61baad53346515f4a66c4342f8aafce37ca9520020c17f99cc4f4aa98b15"
url = "https://caltech.box.com/shared/static/uteaw1l6fg7wmwhb3ey1c0jq4r8vg0ts.gz"
7 changes: 5 additions & 2 deletions clm_data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ To recreate the artifact:

### 1. `surfdata_0.9x1.25_16pfts__CMIP6_simyr2000_c170616.nc` and `surfdata_0.125x0.125_16pfts_simyr2000_c151014.nc`
These netCDF files includes comprehensive environmental data with a focus on vegetation represented through different Plant Functional Types (PFTs). These PFTs play a crucial role in modeling biophysical processes and ecosystem functions within CLM simulations. It also contains soil color data, which is used to calculate soil alebdo. `surfdata_0.9x1.25_16pfts__CMIP6_simyr2000_c170616.nc` is on a 0.8x1.25 degree grid and is used to create the
clm_data artifact, while `surfdata_0.125x0.125_16pfts_simyr2000_c151014.nc` is on a 0.125x0.125 degree
grid and is used to create the clm_data_highres artifact. Both input files contain tge following PFTs:
clm_data_0.9x1.25 artifact, while `surfdata_0.125x0.125_16pfts_simyr2000_c151014.nc` is on a 0.125x0.125 degree
grid and is used to create the clm_data_0.125x0.125 artifact. Both input files contain the following PFTs:

- **Plant Functional Types**:
- `not_vegetated`
Expand Down Expand Up @@ -115,6 +115,9 @@ value of 0.0 if C4 is dominant.
- `rooting_depth(lat, lon)` parameter for root_distribution (m)
- Describes the depth where ~2/3 of the roots are above
- `xl(lat, lon)` Leaf/stem orientation index
- `z_top(lat, lon)` height top (m) **NOTE**: This variable is always calculated using the
0.9x1.25 surface data file, because the `MONTHLY_HEIGHT_TOP` variable is
zero at every point in the 0.125x0.125 surface data file.

### 3. `soil_properties_map.nc`
Contains the mapped soil albedos for each grid cell.
Expand Down
8 changes: 4 additions & 4 deletions clm_data/create_artifact.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const FILE_PATHS = [
const OUTPUT_FILES =
["dominant_PFT_map.nc", "vegetation_properties_map.nc", "soil_properties_map.nc"]

output_dir = basename(@__DIR__) * "_artifact"
output_dir_highres = basename(@__DIR__) * "_highres_artifact"
output_dir = basename(@__DIR__) * "_0.9x1.25_artifact"
output_dir_highres = basename(@__DIR__) * "_0.125x0.125_artifact"
for dir in [output_dir, output_dir_highres]
if isdir(dir)
@warn "$dir already exists. Content will end up in the artifact and may be overwritten."
Expand Down Expand Up @@ -67,10 +67,10 @@ for output_file in OUTPUT_FILES
Base.mv(output_file, output_path; force = true)
end

create_artifact_guided(output_dir; artifact_name = basename(@__DIR__))
create_artifact_guided(output_dir; artifact_name = basename(@__DIR__) * "_0.9x1.25")

create_artifact_guided(
output_dir_highres;
artifact_name = basename(@__DIR__) * "_highres",
artifact_name = basename(@__DIR__) * "_0.125x0.125",
append = true,
)
24 changes: 24 additions & 0 deletions clm_data/pft_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
# Get photosynthesis mechanisms from surface data file
surface_dataset = nc.Dataset(surface_file, 'r')
pft_values = surface_dataset.variables['PCT_NAT_PFT'][:]
# the 0.125x0.125 file has all `MONTHLY_HEIGHT_TOP` values of zero everywhere, so we use the 0.9x1.25 file
if args.detailed:
height_dataset = nc.Dataset('surfdata_0.9x1.25_16pfts__CMIP6_simyr2000_c170616.nc', 'r')
height_values = height_dataset.variables['MONTHLY_HEIGHT_TOP'][:, :, :, :]
height_lon = np.mean(height_dataset.variables['LONGXY'][:, :], axis=0)
height_lat = np.mean(height_dataset.variables['LATIXY'][:, :], axis=1)
else:
height_values = surface_dataset.variables['MONTHLY_HEIGHT_TOP'][:, :, :, :]
pft_dominant_values = np.argmax(pft_values, axis = 0)
# pft index 14 is the only C4 pft
c3_dominant_map = pft_dominant_values != 14
Expand All @@ -49,6 +57,7 @@
xl_values = pft_physiology_dataset.variables['xl'][:]

# Create arrays to store the mapped values for each grid point
canopy_height_map = np.zeros(dominant_pft.shape, dtype=np.float32)
medlynslope_map = np.zeros_like(dominant_pft, dtype=np.float32)
medlynintercept_map = np.zeros_like(dominant_pft, dtype=np.float32)
rholnir_map = np.zeros_like(dominant_pft, dtype=np.float32)
Expand All @@ -66,6 +75,16 @@
for j in range(dominant_pft.shape[1]):
pft_index = dominant_pft[i, j] # PFTs are directly indexed
if pft_index >= 0:
if args.detailed:
# here we use the lower resolution height data to map the canopy height
lon_point = lon[i, j]
lat_point = lat[i, j]
canopy_height_lon_index = np.argmin(np.abs(height_lon - lon_point))
canopy_height_lat_index = np.argmin(np.abs(height_lat - lat_point))
canopy_height_map[i,j] = np.mean(height_values[:, pft_index,\
canopy_height_lat_index, canopy_height_lon_index], axis = 0)
else:
canopy_height_map[i,j] = np.mean(height_values[:, pft_index, i, j])
medlynslope_map[i, j] = medlynslope_values[pft_index]
medlynintercept_map[i, j] = medlynintercept_values[pft_index]
# convert beta parameter to rooting depth parameter for root probability distribution
Expand All @@ -88,6 +107,7 @@
# Create variables
latitudes = output_dataset.createVariable('lat', 'f4', ('lat',))
longitudes = output_dataset.createVariable('lon', 'f4', ('lon',))
canopy_height_var = output_dataset.createVariable('z_top', 'f4', ('lat', 'lon'), fill_value=np.nan)
c3_dominant_var = output_dataset.createVariable('c3_dominant', 'f4', ('lat', 'lon',), fill_value=np.nan)
medlynslope_var = output_dataset.createVariable('medlynslope', 'f4', ('lat', 'lon',), fill_value=np.nan)
medlynintercept_var = output_dataset.createVariable('medlynintercept', 'f4', ('lat', 'lon',), fill_value=np.nan)
Expand All @@ -105,6 +125,7 @@
# Assign data to variables
latitudes[:] = np.mean(lat, axis=1) # Assuming LATIXY and LONGXY are 2D arrays
longitudes[:] = np.mean(lon, axis=0) # Averaging to get 1D lat/lon
canopy_height_var[:, :] = canopy_height_map
c3_dominant_var[:, :] = c3_dominant_map
medlynslope_var[:, :] = medlynslope_map
medlynintercept_var[:, :] = medlynintercept_map
Expand All @@ -122,6 +143,9 @@
# Assign attributes
latitudes.units = 'degrees_north'
longitudes.units = 'degrees_east'
canopy_height_var.units = 'm'
canopy_height_var.long_name = 'Canopy top height'
canopy_height_var.short_name = 'z_top'
c3_dominant_var.units = '0. = c4, 1. = c3'
c3_dominant_var.long_name = 'c3 dominant'
medlynslope_var.units = 'kPa^0.5'
Expand Down

0 comments on commit 982e6f2

Please sign in to comment.