-
Notifications
You must be signed in to change notification settings - Fork 3
Landcover from GLC2000 and soils from SOILGRIDS #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jjokella
wants to merge
18
commits into
main
Choose a base branch
from
EUR-11
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
51bbcae
update mkmapdata and mksurfdata scripts
03aa14a
update mod_domain.sh (only used for adjusting LONGXY and LATIXY)
e2b3e5c
Ignore compiled Fortran object and module files
0b640b4
Stop tracking compiled object and module files
f9f79b5
Update mksurfdata scripts for EUR-11 and README
9780fbb
Merge branch 'main' into EUR-11
jjokella 987b2b1
style change
jjokella 6ab7d82
remove executable from repo
jjokella 0a39834
remove executable from repo
jjokella 6dee077
re-introduce deleted scripts
jjokella 7e3c1b2
re-introduce .o and .mod files
jjokella 0d7baef
README: Add info about download_grids.sh
jjokella 2568088
remove user-specific changes from runscript_mkmapdata
jjokella e0111d3
remove unnecessary differences to main
jjokella 5de8289
mod_domain.sh back to main status
jjokella 996f152
documentation and style for replace_surfdata.py script
jjokella 8482593
Polishing
mvhulten 5b7fb06
Made new replacement script executable
mvhulten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #!/usr/bin/env bash | ||
| set -e | ||
|
|
||
| ### URL base for the grids | ||
| SVNBASE="https://svn-ccsm-inputdata.cgd.ucar.edu/trunk/inputdata/lnd/clm2/mappingdata/grids" | ||
|
|
||
| ### Local directory | ||
| myraw="$PWD/download_grids" | ||
| mkdir -p "$myraw" | ||
|
|
||
| ### List of files to download | ||
| files=( | ||
| SCRIPgrid_0.5x0.5_AVHRR_c110228.nc | ||
| SCRIPgrid_0.25x0.25_MODIS_c170321.nc | ||
| SCRIPgrid_3minx3min_LandScan2004_c120517.nc | ||
| SCRIPgrid_3minx3min_MODISv2_c190503.nc | ||
| SCRIPgrid_3minx3min_MODISwcspsea_c151020.nc | ||
| SCRIPgrid_3x3_USGS_c120912.nc | ||
| SCRIPgrid_5x5min_nomask_c110530.nc | ||
| SCRIPgrid_5x5min_IGBP-GSDP_c110228.nc | ||
| SCRIPgrid_5x5min_ISRIC-WISE_c111114.nc | ||
| SCRIPgrid_5x5min_ORNL-Soil_c170630.nc | ||
| SCRIPgrid_10x10min_nomask_c110228.nc | ||
| SCRIPgrid_10x10min_IGBPmergeICESatGIS_c110818.nc | ||
| SCRIPgrid_3minx3min_GLOBE-Gardner_c120922.nc | ||
| SCRIPgrid_3minx3min_GLOBE-Gardner-mergeGIS_c120922.nc | ||
| SCRIPgrid_0.9x1.25_GRDC_c130307.nc | ||
| SCRIPgrid_360x720_cruncep_c120830.nc | ||
| UGRID_1km-merge-10min_HYDRO1K-merge-nomask_c130402.nc | ||
| ) | ||
|
|
||
| echo "Downloading grid files to $myraw ..." | ||
| for file in "${files[@]}"; do | ||
| localf="${myraw}/${file}" | ||
| url="${SVNBASE}/${file}" | ||
| if [ ! -f "$localf" ]; then | ||
| echo "Downloading $file ..." | ||
| svn export "$url" "$localf" | ||
| else | ||
| echo "File $file already exists — skipping download." | ||
| fi | ||
| done | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,20 @@ do | |
| ;; | ||
| *) | ||
| echo "Creating conservative remapping files for your grid ${GRIDNAME}..." | ||
| srun $ESMFBIN_PATH/ESMF_RegridWeightGen --ignore_unmapped -s ${rawpath}/${file} -d $(realpath $GRIDFILE) -m conserve -w ${OUTPUT}/${OUTFILE} --dst_regional --netcdf4 | ||
|
|
||
| # Conservative remapping: Specify UGRID source type | ||
| # | ||
| # In general automatic detection should work: | ||
| # https://earthsystemmodeling.org/docs/release/latest/ESMF_refdoc/node3.html#SECTION03020000000000000000 | ||
| # | ||
| # This overrides the automatic detection. | ||
| if [[ "$basename" == UGRID* ]]; then | ||
| SRCTYPE="--src_type UGRID" | ||
| else | ||
| SRCTYPE="" | ||
| fi | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does |
||
|
|
||
| srun $ESMFBIN_PATH/ESMF_RegridWeightGen --ignore_unmapped -s ${rawpath}/${file} -d $(realpath $GRIDFILE) -m conserve $SRCTYPE -w ${OUTPUT}/${OUTFILE} --dst_regional --netcdf4 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #!/usr/bin/env python3 | ||
| import xarray as xr | ||
| import numpy as np | ||
| # import sys | ||
|
|
||
| file_clm5 = "/p/project1/cjibg36/jibg3674/eCLM_static-file-generator/surfdata_EUR-11_hist_78pfts_CMIP6_simyr2005_c251022.nc" | ||
| file_glc2000 = "/p/project1/cjibg36/jibg3674/TSMP_EUR-11/static.resource/08_LandCover/GLC2000_PFT_urban.nc" | ||
| file_clm = "/p/project/cjibg36/jibg3674/shared_DA/setup_eclm_cordex_444x432_v9/input_clm/surfdata_EUR-11_hist_16pfts_Irrig_CMIP6_simyr2000_c230808_GLC2000.nc" | ||
| file_dest = "/p/project/cjibg36/jibg3674/shared_DA/setup_eclm_cordex_444x432_v9/input_clm/surfdata_EUR-11_hist_78pfts_CMIP6_simyr2005_c251022_GLC2000.nc" | ||
|
|
||
| open_clm5 = xr.open_dataset(file_clm5) | ||
| open_glc2000 = xr.open_dataset(file_glc2000) | ||
| open_clm = xr.open_dataset(file_clm) | ||
|
|
||
| # print(open_clm5["PCT_CLAY"].dims, open_clm["PCT_CLAY"].dims) | ||
| # print(open_clm5["PCT_CLAY"].shape, open_clm["PCT_CLAY"].shape) | ||
|
|
||
| open_clm5["PCT_CLAY"][:] = open_clm["PCT_CLAY"].values | ||
| open_clm5["PCT_SAND"][:] = open_clm["PCT_SAND"].values | ||
| open_clm5["ORGANIC"][:] = open_clm["ORGANIC"].values | ||
|
|
||
| open_clm5["PCT_WETLAND"][:] = 0 | ||
| open_clm5["PCT_URBAN"][2, :, :] = open_glc2000["PCT_PFT"][19, :, :].values | ||
| open_clm5["PCT_URBAN"][1, :, :] = 0 | ||
| open_clm5["PCT_GLACIER"][:, :] = open_glc2000["PCT_PFT"][18, :, :].values | ||
| open_clm5["PCT_LAKE"][:, :] = open_glc2000["PCT_PFT"][17, :, :].values | ||
|
|
||
| open_clm5["PCT_CROP"][:, :] = open_glc2000["PCT_PFT"][15, :, :].values | ||
| open_clm5["PCT_NATVEG"][:, :] = np.sum( | ||
| open_glc2000["PCT_PFT"][0:15, :, :].values, axis=0 | ||
| ) | ||
| open_clm5["PCT_NAT_PFT"][0:15, :, :] = open_glc2000["PCT_PFT"][0:15, :, :].values | ||
|
|
||
| sum_gridcell = ( | ||
| open_clm5["PCT_NATVEG"].values | ||
| + open_clm5["PCT_CROP"].values | ||
| + np.sum(open_clm5["PCT_URBAN"].values, axis=0) | ||
| + open_clm5["PCT_LAKE"].values | ||
| + open_clm5["PCT_GLACIER"].values | ||
| ) | ||
| print("Min sum_gridcell:", np.nanmin(sum_gridcell)) | ||
| print("Max sum_gridcell:", np.nanmax(sum_gridcell)) | ||
|
|
||
| # Compute scaling factor, with safety margin | ||
| scale = np.where(sum_gridcell > 0, 100 / sum_gridcell, 1.0) | ||
| for v in ["PCT_NATVEG", "PCT_CROP", "PCT_LAKE", "PCT_GLACIER", "PCT_URBAN"]: | ||
| open_clm5[v].values *= scale | ||
| print( | ||
| "New sum_gridcell (min, max):", | ||
| np.nanmin(sum_gridcell * scale), | ||
| np.nanmax(sum_gridcell * scale), | ||
| ) | ||
|
|
||
|
|
||
| pctspec = ( | ||
| open_clm5["PCT_LAKE"].values | ||
| + open_clm5["PCT_WETLAND"].values | ||
| + open_clm5["PCT_GLACIER"].values | ||
| + np.sum(open_clm5["PCT_URBAN"].values, axis=0) | ||
| ) | ||
| print("Max pctspec:", np.nanmax(pctspec)) | ||
|
|
||
| natpft = open_clm5["PCT_NAT_PFT"].values | ||
| sum_natpft = np.sum(natpft, axis=0) | ||
| sum_crop = np.sum(open_clm5["PCT_CFT"].values, axis=0) | ||
| print("Min sum_natpft:", np.nanmin(sum_natpft)) | ||
| print("Max sum_natpft:", np.nanmax(sum_natpft)) | ||
| print("Min sum_crop:", np.nanmin(sum_crop)) | ||
| print("Max sum_crop:", np.nanmax(sum_crop)) | ||
|
|
||
| mask = sum_natpft > 0 | ||
| natpft[:, mask] = natpft[:, mask] * (100.0 / sum_natpft[mask]) | ||
| open_clm5["PCT_NAT_PFT"].values = natpft | ||
|
|
||
| mask_zero = sum_natpft == 0 | ||
| open_clm5["PCT_NAT_PFT"].values[0, mask_zero] = 100.0 | ||
|
|
||
| print( | ||
| "New sum_natpft (min, max):", | ||
| np.nanmin(np.sum(open_clm5["PCT_NAT_PFT"].values, axis=0)), | ||
| np.nanmax(np.sum(open_clm5["PCT_NAT_PFT"].values, axis=0)), | ||
| ) | ||
|
|
||
| open_clm5.to_netcdf(file_dest) | ||
| print(f"Saved modified surfdata to:\n{file_dest}") | ||
|
|
||
| open_clm5.close() | ||
| open_glc2000.close() | ||
| open_clm.close() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice—need for Bash (not POSIX) is waranted.