-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
381 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,190 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Write ISMIP7 grid files in CDO format\n", | ||
"\n", | ||
"import numpy as np\n", | ||
"from generate_CDO_files_nc import generate_CDO_files" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# for checking\n", | ||
"def isaninteger(x):\n", | ||
" return np.mod(x, 1) == 0" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 24, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"##### Typically the only part a user needs to modify\n", | ||
"# Specify various ISM grids at different resolution\n", | ||
"#rk = [16]\n", | ||
"rk = [32, 16, 8, 4, 2]\n", | ||
"#rk = [0.5]\n", | ||
"\n", | ||
"# Choose which output file to write\n", | ||
"flag_nc = True\n", | ||
"flag_xy = True\n", | ||
"flag_af2 = True\n", | ||
"\n", | ||
"# Output path\n", | ||
"pout = \"/data/projects/generateismip7gridfiles/files/output\"\n", | ||
"#pout = \"../output\"\n", | ||
"\n", | ||
"# Output angle type (degrees or radians)\n", | ||
"output_data_type = 'degrees'\n", | ||
"\n", | ||
"# Write additional g0 grid files\n", | ||
"flag_g0 = False" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 25, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Mapping information. This is EPSG 3031 for AIS\n", | ||
"proj_info = {}\n", | ||
"proj_info['earthradius'] = 6378137.0\n", | ||
"proj_info['eccentricity'] = 0.081819190842621\n", | ||
"proj_info['standard_parallel'] = 71.\n", | ||
"proj_info['longitude_rot'] = 0.\n", | ||
"proj_info['hemisphere'] = 'south'\n", | ||
"# Offset of grid node centers. Lower left corner coordinates.\n", | ||
"# Note sign change compared to matlab version!\n", | ||
"proj_info['falseeasting'] = -3040000\n", | ||
"proj_info['falsenorthing'] = -3040000\n", | ||
"\n", | ||
"# Grid dimensions of 1 km base grid\n", | ||
"nx_base = 6081\n", | ||
"ny_base = 6081" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 26, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Generating /data/projects/generateismip7gridfiles/files/output/xy_ISMIP7_g1_AIS_32000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/grid_ISMIP7_g1_AIS_32000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/af2_ISMIP7_g1_AIS_32000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/xy_ISMIP7_g1_AIS_16000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/grid_ISMIP7_g1_AIS_16000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/af2_ISMIP7_g1_AIS_16000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/xy_ISMIP7_g1_AIS_08000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/grid_ISMIP7_g1_AIS_08000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/af2_ISMIP7_g1_AIS_08000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/xy_ISMIP7_g1_AIS_04000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/grid_ISMIP7_g1_AIS_04000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/af2_ISMIP7_g1_AIS_04000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/xy_ISMIP7_g1_AIS_02000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/grid_ISMIP7_g1_AIS_02000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/af2_ISMIP7_g1_AIS_02000m.nc\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# g1 grid where ice thickness and SMB are defined\n", | ||
"grids1 = []\n", | ||
"for r in rk:\n", | ||
" # For any resolution but check integer grid numbers\n", | ||
" nx = ((nx_base-1)/r)+1\n", | ||
" ny = ((ny_base-1)/r)+1\n", | ||
" if isaninteger(nx) and isaninteger(ny):\n", | ||
" agrid = {}\n", | ||
" agrid['dx'] = r*1000.\n", | ||
" agrid['dy'] = r*1000.\n", | ||
" agrid['nx'] = int(nx)\n", | ||
" agrid['ny'] = int(ny)\n", | ||
" agrid['offsetx'] = 0.\n", | ||
" agrid['offsety'] = 0.\n", | ||
" agrid['LatLonOutputFileName'] = pout+'/'+'grid_ISMIP7_g1_AIS_{:05d}m.nc'.format(int(r*1000))\n", | ||
" agrid['xyOutputFileName'] = pout+'/'+'xy_ISMIP7_g1_AIS_{:05d}m.nc'.format(int(r*1000))\n", | ||
" agrid['af2OutputFileName'] = pout+'/'+'af2_ISMIP7_g1_AIS_{:05d}m.nc'.format(int(r*1000))\n", | ||
" grids1.append(agrid)\n", | ||
" else:\n", | ||
" print('Warning: resolution {} km is not comensurable, skipped.'.format(r))\n", | ||
"\n", | ||
"# Create grids and write out\n", | ||
"for agrid in grids1:\n", | ||
" #print(agrid)\n", | ||
" success = generate_CDO_files(agrid, proj_info, output_data_type, flag_nc, flag_xy, flag_af2)\n", | ||
"\n", | ||
"\n", | ||
"if flag_g0:\n", | ||
" # g0 grid where horizontal velocities are defined e.g. for CISM \n", | ||
" grids0 = []\n", | ||
" for r in rk:\n", | ||
" # For any resolution but check integer grid numbers\n", | ||
" nx = ((nx_base-1)/r)\n", | ||
" ny = ((ny_base-1)/r)\n", | ||
" if isaninteger(nx) and isaninteger(ny):\n", | ||
" agrid = {}\n", | ||
" agrid['dx'] = r*1000.\n", | ||
" agrid['dy'] = r*1000.\n", | ||
" agrid['nx'] = int(nx)\n", | ||
" agrid['ny'] = int(ny)\n", | ||
" # g0 grid is offset by half a grid size\n", | ||
" agrid['offsetx'] = r*1000./2.\n", | ||
" agrid['offsety'] = r*1000./2.\n", | ||
" agrid['LatLonOutputFileName'] = pout+'/'+'grid_ISMIP7_g0_AIS_{:05d}m.nc'.format(int(r*1000))\n", | ||
" agrid['xyOutputFileName'] = pout+'/'+'xy_ISMIP7_g0_AIS_{:05d}m.nc'.format(int(r*1000))\n", | ||
" agrid['af2OutputFileName'] = pout+'/'+'af2_ISMIP7_g0_AIS_{:05d}m.nc'.format(int(r*1000))\n", | ||
" grids0.append(agrid)\n", | ||
" else:\n", | ||
" print('Warning: resolution {} km is not comensurable, skipped.'.format(r))\n", | ||
" \n", | ||
" # Create grids and write out\n", | ||
" for agrid in grids0:\n", | ||
" #print(agrid)\n", | ||
" success = generate_CDO_files(agrid, proj_info, output_data_type, flag_nc, flag_xy, flag_af2)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python3 (ICESHEET)", | ||
"language": "python", | ||
"name": "icesheet" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.15" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains 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,191 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Write ISMIP7 grid files in CDO format\n", | ||
"\n", | ||
"import numpy as np\n", | ||
"from generate_CDO_files_nc import generate_CDO_files" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# for checking\n", | ||
"def isaninteger(x):\n", | ||
" return np.mod(x, 1) == 0" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 18, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"##### Typically the only part a user needs to modify\n", | ||
"# Specify various ISM grids at different resolution\n", | ||
"#rk = [20]\n", | ||
"#rk = [16]\n", | ||
"rk = [16, 8, 4, 2, 1]\n", | ||
"#rk = [0.5]\n", | ||
"\n", | ||
"# Choose which output file to write\n", | ||
"flag_nc = True\n", | ||
"flag_xy = True\n", | ||
"flag_af2 = True\n", | ||
"\n", | ||
"# Output path\n", | ||
"pout = \"/data/projects/generateismip7gridfiles/files/output\"\n", | ||
"#pout = \"../output\"\n", | ||
"\n", | ||
"# Output angle type (degrees or radians)\n", | ||
"output_data_type = 'degrees'\n", | ||
"\n", | ||
"# Write additional g0 grid files\n", | ||
"flag_g0 = False" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 19, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Mapping information. This is EPSG 3413 for GrIS\n", | ||
"proj_info = {}\n", | ||
"proj_info['earthradius'] = 6378137.0\n", | ||
"proj_info['eccentricity'] = 0.081819190842621\n", | ||
"proj_info['standard_parallel'] = 70.\n", | ||
"proj_info['longitude_rot'] = 315.\n", | ||
"proj_info['hemisphere'] = 'north'\n", | ||
"# Offset of grid node centers. Lower left corner coordinates.\n", | ||
"# Note sign change compared to matlab version!\n", | ||
"proj_info['falseeasting'] = -720000\n", | ||
"proj_info['falsenorthing'] = -3450000\n", | ||
"\n", | ||
"# Grid dimensions of 1 km base grid\n", | ||
"nx_base = 1681\n", | ||
"ny_base = 2881" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 20, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Generating /data/projects/generateismip7gridfiles/files/output/xy_ISMIP7_g1_GrIS_16000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/grid_ISMIP7_g1_GrIS_16000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/af2_ISMIP7_g1_GrIS_16000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/xy_ISMIP7_g1_GrIS_08000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/grid_ISMIP7_g1_GrIS_08000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/af2_ISMIP7_g1_GrIS_08000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/xy_ISMIP7_g1_GrIS_04000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/grid_ISMIP7_g1_GrIS_04000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/af2_ISMIP7_g1_GrIS_04000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/xy_ISMIP7_g1_GrIS_02000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/grid_ISMIP7_g1_GrIS_02000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/af2_ISMIP7_g1_GrIS_02000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/xy_ISMIP7_g1_GrIS_01000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/grid_ISMIP7_g1_GrIS_01000m.nc\n", | ||
"Generating /data/projects/generateismip7gridfiles/files/output/af2_ISMIP7_g1_GrIS_01000m.nc\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# g1 grid where ice thickness and SMB are defined\n", | ||
"grids1 = []\n", | ||
"for r in rk:\n", | ||
" # For any resolution but check integer grid numbers\n", | ||
" nx = ((nx_base-1)/r)+1\n", | ||
" ny = ((ny_base-1)/r)+1\n", | ||
" if isaninteger(nx) and isaninteger(ny):\n", | ||
" agrid = {}\n", | ||
" agrid['dx'] = r*1000.\n", | ||
" agrid['dy'] = r*1000.\n", | ||
" agrid['nx'] = int(nx)\n", | ||
" agrid['ny'] = int(ny)\n", | ||
" agrid['offsetx'] = 0.\n", | ||
" agrid['offsety'] = 0.\n", | ||
" agrid['LatLonOutputFileName'] = pout+'/'+'grid_ISMIP7_g1_GrIS_{:05d}m.nc'.format(int(r*1000))\n", | ||
" agrid['xyOutputFileName'] = pout+'/'+'xy_ISMIP7_g1_GrIS_{:05d}m.nc'.format(int(r*1000))\n", | ||
" agrid['af2OutputFileName'] = pout+'/'+'af2_ISMIP7_g1_GrIS_{:05d}m.nc'.format(int(r*1000))\n", | ||
" grids1.append(agrid)\n", | ||
" else:\n", | ||
" print('Warning: resolution {} km is not comensurable, skipped.'.format(r))\n", | ||
"\n", | ||
"# Create grids and write out\n", | ||
"for agrid in grids1:\n", | ||
" #print(agrid)\n", | ||
" success = generate_CDO_files(agrid, proj_info, output_data_type, flag_nc, flag_xy, flag_af2)\n", | ||
"\n", | ||
"\n", | ||
"if flag_g0:\n", | ||
" # g0 grid where horizontal velocities are defined e.g. for CISM \n", | ||
" grids0 = []\n", | ||
" for r in rk:\n", | ||
" # For any resolution but check integer grid numbers\n", | ||
" nx = ((nx_base-1)/r)\n", | ||
" ny = ((ny_base-1)/r)\n", | ||
" if isaninteger(nx) and isaninteger(ny):\n", | ||
" agrid = {}\n", | ||
" agrid['dx'] = r*1000.\n", | ||
" agrid['dy'] = r*1000.\n", | ||
" agrid['nx'] = int(nx)\n", | ||
" agrid['ny'] = int(ny)\n", | ||
" # g0 grid is offset by half a grid size\n", | ||
" agrid['offsetx'] = r*1000./2.\n", | ||
" agrid['offsety'] = r*1000./2.\n", | ||
" agrid['LatLonOutputFileName'] = pout+'/'+'grid_ISMIP7_g0_GrIS_{:05d}m.nc'.format(int(r*1000))\n", | ||
" agrid['xyOutputFileName'] = pout+'/'+'xy_ISMIP7_g0_GrIS_{:05d}m.nc'.format(int(r*1000))\n", | ||
" agrid['af2OutputFileName'] = pout+'/'+'af2_ISMIP7_g0_GrIS_{:05d}m.nc'.format(int(r*1000))\n", | ||
" grids0.append(agrid)\n", | ||
" else:\n", | ||
" print('Warning: resolution {} km is not comensurable, skipped.'.format(r))\n", | ||
" \n", | ||
" # Create grids and write out\n", | ||
" for agrid in grids0:\n", | ||
" #print(agrid)\n", | ||
" success = generate_CDO_files(agrid, proj_info, output_data_type, flag_nc, flag_xy, flag_af2)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python3 (ICESHEET)", | ||
"language": "python", | ||
"name": "icesheet" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.15" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |