From 39277fea735381de2aedc2ebc25f3b694473455b Mon Sep 17 00:00:00 2001 From: ezhilsabareesh8 Date: Mon, 26 Feb 2024 15:34:31 +1100 Subject: [PATCH 01/13] Added Gen_CICE_grid.py to generate CICE grid from mom supergrid --- grid_generation/Gen_CICE_grid.py | 99 ++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 grid_generation/Gen_CICE_grid.py diff --git a/grid_generation/Gen_CICE_grid.py b/grid_generation/Gen_CICE_grid.py new file mode 100644 index 0000000..8e0f04d --- /dev/null +++ b/grid_generation/Gen_CICE_grid.py @@ -0,0 +1,99 @@ +""" +Script: generate_cice_grid.py + +Description: +This script generates a CICE grid from the MOM super grid provided in the input NetCDF file. + +Contact: +Name: Ezhilsabareesh Kannadasan + +Usage: +python generate_cice_grid.py +- input_superGridPath: Path to the MOM super grid NetCDF file. +- output_file: Path to the output CICE grid NetCDF file. +""" +import numpy as np +import xarray as xr +from netCDF4 import Dataset +import sys + +def generate_cice_grid(in_superGridPath, output_file): + # Read input files + in_superGridFile = xr.open_dataset(in_superGridPath) + + # Constants + ULAT = np.deg2rad(in_superGridFile['y'][1::2, 2::2]) + ULON = np.deg2rad(in_superGridFile['x'][1::2, 2::2]) + TLAT = np.deg2rad(in_superGridFile['y'][1::2, 1::2]) + TLON = np.deg2rad(in_superGridFile['x'][1::2, 1::2]) + + # MPI + HTN = in_superGridFile['dx'] * 100.0 # convert to cm + HTN = HTN[1::2, ::2] + HTN[1::2, 1::2] + HTE = in_superGridFile['dy'] * 100.0 # convert to cm + HTE = HTE[::2, 1::2] + HTE[1::2, 1::2] + + ANGLE = dtr * in_superGridFile['angle_dx'][1::2, 1::2] + + # Close input files + in_superGridFile.close() + + # Create a new NetCDF file + nc = Dataset(output_file, 'w', format='NETCDF4') + + # Define dimensions + ny, nx = ULAT.shape + nc.createDimension('ny', ny) + nc.createDimension('nx', nx) + + # Define variables + ulat = nc.createVariable('ulat', 'f8', ('ny', 'nx')) + ulon = nc.createVariable('ulon', 'f8', ('ny', 'nx')) + tlat = nc.createVariable('tlat', 'f8', ('ny', 'nx')) + tlon = nc.createVariable('tlon', 'f8', ('ny', 'nx')) + htn = nc.createVariable('htn', 'f8', ('ny', 'nx')) + hte = nc.createVariable('hte', 'f8', ('ny', 'nx')) + angle = nc.createVariable('angle', 'f8', ('ny', 'nx')) + + # Add attributes + ulat.units = "radians" + ulat.title = "Latitude of U points" + ulon.units = "radians" + ulon.title = "Longitude of U points" + tlat.units = "radians" + tlat.title = "Latitude of T points" + tlon.units = "radians" + tlon.title = "Longitude of T points" + htn.units = "cm" + htn.title = "Width of T cells on North side." + hte.units = "cm" + hte.title = "Width of T cells on East side." + angle.units = "radians" + angle.title = "Rotation angle of U cells." + + # Write data to variables + ulat[:] = ULAT + ulon[:] = ULON + tlat[:] = TLAT + tlon[:] = TLON + htn[:] = HTN + hte[:] = HTE + angle[:] = ANGLE + + # Close the file + nc.close() + + print("NetCDF file created successfully.") + +if __name__ == "__main__": + if len(sys.argv) != 3: + print("Usage: python script.py ") + sys.exit(1) + + input_superGridPath = sys.argv[1] + output_file = sys.argv[2] + + # Constants + dtr = np.pi / 180.0 # Degree to Radian conversion + + generate_cice_grid(input_superGridPath, output_file) From b7d84fa5fca9332d4f62122d63d590dbcf6de274 Mon Sep 17 00:00:00 2001 From: ezhilsabareesh8 <108497463+ezhilsabareesh8@users.noreply.github.com> Date: Mon, 26 Feb 2024 16:04:02 +1100 Subject: [PATCH 02/13] Use np.deg2rad instead of constants --- grid_generation/Gen_CICE_grid.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/grid_generation/Gen_CICE_grid.py b/grid_generation/Gen_CICE_grid.py index 8e0f04d..3093d1b 100644 --- a/grid_generation/Gen_CICE_grid.py +++ b/grid_generation/Gen_CICE_grid.py @@ -33,7 +33,7 @@ def generate_cice_grid(in_superGridPath, output_file): HTE = in_superGridFile['dy'] * 100.0 # convert to cm HTE = HTE[::2, 1::2] + HTE[1::2, 1::2] - ANGLE = dtr * in_superGridFile['angle_dx'][1::2, 1::2] + ANGLE = np.deg2rad(in_superGridFile['angle_dx'][1::2, 1::2]) # Close input files in_superGridFile.close() @@ -92,8 +92,5 @@ def generate_cice_grid(in_superGridPath, output_file): input_superGridPath = sys.argv[1] output_file = sys.argv[2] - - # Constants - dtr = np.pi / 180.0 # Degree to Radian conversion - + generate_cice_grid(input_superGridPath, output_file) From 0213e6e0526bac1a7e55ed92ad8ae3975ca2036a Mon Sep 17 00:00:00 2001 From: ezhilsabareesh8 <108497463+ezhilsabareesh8@users.noreply.github.com> Date: Mon, 26 Feb 2024 17:00:43 +1100 Subject: [PATCH 03/13] x index shifted to NE corner from cell centre --- grid_generation/Gen_CICE_grid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grid_generation/Gen_CICE_grid.py b/grid_generation/Gen_CICE_grid.py index 3093d1b..cd57beb 100644 --- a/grid_generation/Gen_CICE_grid.py +++ b/grid_generation/Gen_CICE_grid.py @@ -22,7 +22,7 @@ def generate_cice_grid(in_superGridPath, output_file): in_superGridFile = xr.open_dataset(in_superGridPath) # Constants - ULAT = np.deg2rad(in_superGridFile['y'][1::2, 2::2]) + ULAT = np.deg2rad(in_superGridFile['y'][2::2, 1::2]) ULON = np.deg2rad(in_superGridFile['x'][1::2, 2::2]) TLAT = np.deg2rad(in_superGridFile['y'][1::2, 1::2]) TLON = np.deg2rad(in_superGridFile['x'][1::2, 1::2]) From b902158faa9f153e70c9aaf76070f108860f4ad1 Mon Sep 17 00:00:00 2001 From: ezhilsabareesh8 <108497463+ezhilsabareesh8@users.noreply.github.com> Date: Tue, 27 Feb 2024 11:59:16 +1100 Subject: [PATCH 04/13] Updated ULAT and ULON indices --- grid_generation/Gen_CICE_grid.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grid_generation/Gen_CICE_grid.py b/grid_generation/Gen_CICE_grid.py index cd57beb..ad197f4 100644 --- a/grid_generation/Gen_CICE_grid.py +++ b/grid_generation/Gen_CICE_grid.py @@ -22,8 +22,8 @@ def generate_cice_grid(in_superGridPath, output_file): in_superGridFile = xr.open_dataset(in_superGridPath) # Constants - ULAT = np.deg2rad(in_superGridFile['y'][2::2, 1::2]) - ULON = np.deg2rad(in_superGridFile['x'][1::2, 2::2]) + ULAT = np.deg2rad(in_superGridFile['y'][2::2, 2::2]) + ULON = np.deg2rad(in_superGridFile['x'][2::2, 2::2]) TLAT = np.deg2rad(in_superGridFile['y'][1::2, 1::2]) TLON = np.deg2rad(in_superGridFile['x'][1::2, 1::2]) From 47a0014b59ecefcdc98b6bf6b16fb5c44ef7a286 Mon Sep 17 00:00:00 2001 From: ezhilsabareesh8 <108497463+ezhilsabareesh8@users.noreply.github.com> Date: Wed, 28 Feb 2024 10:04:31 +1100 Subject: [PATCH 05/13] Update attributes to match grid.nc Co-authored-by: Andrew Kiss <31054815+aekiss@users.noreply.github.com> --- grid_generation/Gen_CICE_grid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grid_generation/Gen_CICE_grid.py b/grid_generation/Gen_CICE_grid.py index ad197f4..26c8213 100644 --- a/grid_generation/Gen_CICE_grid.py +++ b/grid_generation/Gen_CICE_grid.py @@ -65,7 +65,7 @@ def generate_cice_grid(in_superGridPath, output_file): tlon.units = "radians" tlon.title = "Longitude of T points" htn.units = "cm" - htn.title = "Width of T cells on North side." + htn.title = "Width of T cells on N side." hte.units = "cm" hte.title = "Width of T cells on East side." angle.units = "radians" From 092d995e40895f3603009232ff324739cab06e10 Mon Sep 17 00:00:00 2001 From: ezhilsabareesh8 <108497463+ezhilsabareesh8@users.noreply.github.com> Date: Wed, 28 Feb 2024 10:05:02 +1100 Subject: [PATCH 06/13] update attributes to match grid.nc Co-authored-by: Andrew Kiss <31054815+aekiss@users.noreply.github.com> --- grid_generation/Gen_CICE_grid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grid_generation/Gen_CICE_grid.py b/grid_generation/Gen_CICE_grid.py index 26c8213..7641198 100644 --- a/grid_generation/Gen_CICE_grid.py +++ b/grid_generation/Gen_CICE_grid.py @@ -67,7 +67,7 @@ def generate_cice_grid(in_superGridPath, output_file): htn.units = "cm" htn.title = "Width of T cells on N side." hte.units = "cm" - hte.title = "Width of T cells on East side." + hte.title = "Width of T cells on E side." angle.units = "radians" angle.title = "Rotation angle of U cells." From 8cd8480585016d4f5023f3177b6ea0438c68e3c3 Mon Sep 17 00:00:00 2001 From: ezhilsabareesh8 <108497463+ezhilsabareesh8@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:06:19 +1100 Subject: [PATCH 07/13] Updated script filenames --- grid_generation/Gen_CICE_grid.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grid_generation/Gen_CICE_grid.py b/grid_generation/Gen_CICE_grid.py index 7641198..48b4dc0 100644 --- a/grid_generation/Gen_CICE_grid.py +++ b/grid_generation/Gen_CICE_grid.py @@ -1,5 +1,5 @@ """ -Script: generate_cice_grid.py +Script: Gen_CICE_grid.py Description: This script generates a CICE grid from the MOM super grid provided in the input NetCDF file. @@ -87,7 +87,7 @@ def generate_cice_grid(in_superGridPath, output_file): if __name__ == "__main__": if len(sys.argv) != 3: - print("Usage: python script.py ") + print("Usage: python Gen_CICE_grid.py ") sys.exit(1) input_superGridPath = sys.argv[1] From 09be9fbeb47dc49e3490b12b2238f126b4ed3082 Mon Sep 17 00:00:00 2001 From: ezhilsabareesh8 Date: Fri, 1 Mar 2024 11:37:12 +1100 Subject: [PATCH 08/13] Added TAREA and UAREA variables --- grid_generation/Gen_CICE_grid.py | 34 +++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/grid_generation/Gen_CICE_grid.py b/grid_generation/Gen_CICE_grid.py index 48b4dc0..21b5be4 100644 --- a/grid_generation/Gen_CICE_grid.py +++ b/grid_generation/Gen_CICE_grid.py @@ -33,7 +33,26 @@ def generate_cice_grid(in_superGridPath, output_file): HTE = in_superGridFile['dy'] * 100.0 # convert to cm HTE = HTE[::2, 1::2] + HTE[1::2, 1::2] - ANGLE = np.deg2rad(in_superGridFile['angle_dx'][1::2, 1::2]) + ANGLE = np.deg2rad(in_superGridFile['angle_dx'][2::2, 2::2]) + ANGLET= np.deg2rad(in_superGridFile['angle_dx'][1::2, 1::2]) + + # Area + AREA = (in_superGridFile['area']) + TAREA = AREA[::2,::2] + AREA[1::2,1::2] + AREA[::2,1::2] + AREA[1::2,::2] + + array_to_roll = AREA[2::2,2::2] + + # Roll the array along axis 0 and concatenate the last row as the first row + rolled_array_axis0 = np.concatenate(( + np.roll(array_to_roll, -1, axis=0), + array_to_roll[-1:, :]), axis=0) + + # Roll the rolled array along axis 1 and concatenate the last column as the first column + rolled_array = np.concatenate(( + np.roll(rolled_array_axis0, -1, axis=1), + rolled_array_axis0[:, -1:]), axis=1) + + UAREA = AREA[1::2,1::2] + np.concatenate((np.roll(AREA[1::2, 2::2], -1, axis=1), AREA[1::2, 2::2][:, :1]), axis=1) + np.concatenate((np.roll(AREA[2::2, 1::2], -1, axis=0), AREA[2::2, 1::2][:1, :]), axis=0) + rolled_array # Close input files in_superGridFile.close() @@ -54,6 +73,9 @@ def generate_cice_grid(in_superGridPath, output_file): htn = nc.createVariable('htn', 'f8', ('ny', 'nx')) hte = nc.createVariable('hte', 'f8', ('ny', 'nx')) angle = nc.createVariable('angle', 'f8', ('ny', 'nx')) + angleT = nc.createVariable('angleT', 'f8', ('ny', 'nx')) + tarea = nc.createVariable('tarea', 'f8', ('ny', 'nx')) + uarea = nc.createVariable('uarea', 'f8', ('ny', 'nx')) # Add attributes ulat.units = "radians" @@ -70,6 +92,13 @@ def generate_cice_grid(in_superGridPath, output_file): hte.title = "Width of T cells on E side." angle.units = "radians" angle.title = "Rotation angle of U cells." + angleT.units = "radians" + angleT.title = "Rotation angle of T cells." + tarea.units = "m^2" + tarea.title = "Area of T cells." + uarea.units = "m^2" + uarea.title = "Area of U cells." + # Write data to variables ulat[:] = ULAT @@ -79,6 +108,9 @@ def generate_cice_grid(in_superGridPath, output_file): htn[:] = HTN hte[:] = HTE angle[:] = ANGLE + angleT[:] = ANGLET + tarea[:] = TAREA + uarea[:] = UAREA # Close the file nc.close() From f7434b28ed63a4b6f20bc43dfed9bb598af99069 Mon Sep 17 00:00:00 2001 From: ezhilsabareesh8 Date: Mon, 4 Mar 2024 10:41:15 +1100 Subject: [PATCH 09/13] Added versioning information --- grid_generation/Gen_CICE_grid.py | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/grid_generation/Gen_CICE_grid.py b/grid_generation/Gen_CICE_grid.py index 21b5be4..02ff7f4 100644 --- a/grid_generation/Gen_CICE_grid.py +++ b/grid_generation/Gen_CICE_grid.py @@ -16,6 +16,39 @@ import xarray as xr from netCDF4 import Dataset import sys +import os +import subprocess +from datetime import datetime + + +def is_git_repo(): + """ + Return True/False depending on whether or not the current directory is a git repo. + """ + + return subprocess.call( + ['git', '-C', '.', 'status'], + stderr=subprocess.STDOUT, + stdout = open(os.devnull, 'w') + ) == 0 + +def git_info(): + """ + Return the git repo origin url, relative path to this file, and latest commit hash. + """ + + url = subprocess.check_output( + ["git", "remote", "get-url", "origin"] + ).decode('ascii').strip() + top_level_dir = subprocess.check_output( + ['git', 'rev-parse', '--show-toplevel'] + ).decode('ascii').strip() + rel_path = os.path.relpath(__file__, top_level_dir) + hash = subprocess.check_output( + ['git', 'rev-parse', 'HEAD'] + ).decode('ascii').strip() + + return url, rel_path, hash def generate_cice_grid(in_superGridPath, output_file): # Read input files @@ -99,6 +132,15 @@ def generate_cice_grid(in_superGridPath, output_file): uarea.units = "m^2" uarea.title = "Area of U cells." + # Add versioning information + if is_git_repo(): + git_url, git_hash, rel_path = git_info() + nc.inputfile = f"{in_superGridPath}" + nc.timeGenerated = f"{datetime.now()}" + nc.created_by = f"{os.environ.get('USER')}" + nc.history = f"Created using commit {git_hash} of {git_url}" + else: + nc.history = f"python Gen_CICE_grid.py {in_superGridPath} {output_file}" # Write data to variables ulat[:] = ULAT From 90f1e352f116bbda88632c7a4f667629f291c2f0 Mon Sep 17 00:00:00 2001 From: ezhilsabareesh8 Date: Mon, 4 Mar 2024 10:47:17 +1100 Subject: [PATCH 10/13] Amended versioning information --- grid_generation/Gen_CICE_grid.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/grid_generation/Gen_CICE_grid.py b/grid_generation/Gen_CICE_grid.py index 02ff7f4..c36c838 100644 --- a/grid_generation/Gen_CICE_grid.py +++ b/grid_generation/Gen_CICE_grid.py @@ -140,6 +140,9 @@ def generate_cice_grid(in_superGridPath, output_file): nc.created_by = f"{os.environ.get('USER')}" nc.history = f"Created using commit {git_hash} of {git_url}" else: + nc.inputfile = f"{in_superGridPath}" + nc.timeGenerated = f"{datetime.now()}" + nc.created_by = f"{os.environ.get('USER')}" nc.history = f"python Gen_CICE_grid.py {in_superGridPath} {output_file}" # Write data to variables From d3b4360fc12a88a29ee93e4fa5a041fb30f11187 Mon Sep 17 00:00:00 2001 From: ezhilsabareesh8 Date: Thu, 7 Mar 2024 14:21:32 +1100 Subject: [PATCH 11/13] UAREA wrapping changed similar to esmgrids --- grid_generation/Gen_CICE_grid.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/grid_generation/Gen_CICE_grid.py b/grid_generation/Gen_CICE_grid.py index c36c838..ec1ad93 100644 --- a/grid_generation/Gen_CICE_grid.py +++ b/grid_generation/Gen_CICE_grid.py @@ -60,12 +60,12 @@ def generate_cice_grid(in_superGridPath, output_file): TLAT = np.deg2rad(in_superGridFile['y'][1::2, 1::2]) TLON = np.deg2rad(in_superGridFile['x'][1::2, 1::2]) - # MPI HTN = in_superGridFile['dx'] * 100.0 # convert to cm HTN = HTN[1::2, ::2] + HTN[1::2, 1::2] HTE = in_superGridFile['dy'] * 100.0 # convert to cm HTE = HTE[::2, 1::2] + HTE[1::2, 1::2] + # The angle of rotation is a corner cell centres and applies to both t and u cells. ANGLE = np.deg2rad(in_superGridFile['angle_dx'][2::2, 2::2]) ANGLET= np.deg2rad(in_superGridFile['angle_dx'][1::2, 1::2]) @@ -73,19 +73,14 @@ def generate_cice_grid(in_superGridPath, output_file): AREA = (in_superGridFile['area']) TAREA = AREA[::2,::2] + AREA[1::2,1::2] + AREA[::2,1::2] + AREA[1::2,::2] - array_to_roll = AREA[2::2,2::2] - - # Roll the array along axis 0 and concatenate the last row as the first row - rolled_array_axis0 = np.concatenate(( - np.roll(array_to_roll, -1, axis=0), - array_to_roll[-1:, :]), axis=0) - - # Roll the rolled array along axis 1 and concatenate the last column as the first column - rolled_array = np.concatenate(( - np.roll(rolled_array_axis0, -1, axis=1), - rolled_array_axis0[:, -1:]), axis=1) - - UAREA = AREA[1::2,1::2] + np.concatenate((np.roll(AREA[1::2, 2::2], -1, axis=1), AREA[1::2, 2::2][:, :1]), axis=1) + np.concatenate((np.roll(AREA[2::2, 1::2], -1, axis=0), AREA[2::2, 1::2][:1, :]), axis=0) + rolled_array + # UAREA need to wrap around the globe. Copy ocn_area and + # add an extra column at the end. Also u-cells cross the + # tri-polar fold so add an extra row at the top. + area_ext = np.append(AREA[:], AREA[:, 0:1], axis=1) + area_ext = np.append(area_ext[:], area_ext[-1:, :], axis=0) + + UAREA = area_ext[1::2, 1::2] + area_ext[2::2, 1::2] + \ + area_ext[2::2, 2::2] + area_ext[1::2, 2::2] # Close input files in_superGridFile.close() @@ -156,7 +151,6 @@ def generate_cice_grid(in_superGridPath, output_file): angleT[:] = ANGLET tarea[:] = TAREA uarea[:] = UAREA - # Close the file nc.close() From aa898362d2980acd50a2294fda20fada87cc915c Mon Sep 17 00:00:00 2001 From: anton-climate Date: Thu, 7 Mar 2024 16:24:35 +1100 Subject: [PATCH 12/13] dx and dy are defined on the edges in mom, and include the bottom/left edge respectively. Therefore for cice we want the index to start from 2. --- grid_generation/Gen_CICE_grid.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grid_generation/Gen_CICE_grid.py b/grid_generation/Gen_CICE_grid.py index ec1ad93..3dbfe27 100644 --- a/grid_generation/Gen_CICE_grid.py +++ b/grid_generation/Gen_CICE_grid.py @@ -61,9 +61,9 @@ def generate_cice_grid(in_superGridPath, output_file): TLON = np.deg2rad(in_superGridFile['x'][1::2, 1::2]) HTN = in_superGridFile['dx'] * 100.0 # convert to cm - HTN = HTN[1::2, ::2] + HTN[1::2, 1::2] + HTN = HTN[2::2, ::2] + HTN[2::2, 1::2] HTE = in_superGridFile['dy'] * 100.0 # convert to cm - HTE = HTE[::2, 1::2] + HTE[1::2, 1::2] + HTE = HTE[::2, 2::2] + HTE[1::2, 2::2] # The angle of rotation is a corner cell centres and applies to both t and u cells. ANGLE = np.deg2rad(in_superGridFile['angle_dx'][2::2, 2::2]) From 4b85704a44778a9b0ad3b947cb021c8fb9dbe9a0 Mon Sep 17 00:00:00 2001 From: anton-climate Date: Fri, 8 Mar 2024 10:55:35 +1100 Subject: [PATCH 13/13] turn on compression --- grid_generation/Gen_CICE_grid.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/grid_generation/Gen_CICE_grid.py b/grid_generation/Gen_CICE_grid.py index 3dbfe27..a4d8780 100644 --- a/grid_generation/Gen_CICE_grid.py +++ b/grid_generation/Gen_CICE_grid.py @@ -65,7 +65,7 @@ def generate_cice_grid(in_superGridPath, output_file): HTE = in_superGridFile['dy'] * 100.0 # convert to cm HTE = HTE[::2, 2::2] + HTE[1::2, 2::2] - # The angle of rotation is a corner cell centres and applies to both t and u cells. + # The angle of rotation is at corner cell centres and applies to both t and u cells. ANGLE = np.deg2rad(in_superGridFile['angle_dx'][2::2, 2::2]) ANGLET= np.deg2rad(in_superGridFile['angle_dx'][1::2, 1::2]) @@ -80,7 +80,7 @@ def generate_cice_grid(in_superGridPath, output_file): area_ext = np.append(area_ext[:], area_ext[-1:, :], axis=0) UAREA = area_ext[1::2, 1::2] + area_ext[2::2, 1::2] + \ - area_ext[2::2, 2::2] + area_ext[1::2, 2::2] + area_ext[2::2, 2::2] + area_ext[1::2, 2::2] # Close input files in_superGridFile.close() @@ -94,16 +94,16 @@ def generate_cice_grid(in_superGridPath, output_file): nc.createDimension('nx', nx) # Define variables - ulat = nc.createVariable('ulat', 'f8', ('ny', 'nx')) - ulon = nc.createVariable('ulon', 'f8', ('ny', 'nx')) - tlat = nc.createVariable('tlat', 'f8', ('ny', 'nx')) - tlon = nc.createVariable('tlon', 'f8', ('ny', 'nx')) - htn = nc.createVariable('htn', 'f8', ('ny', 'nx')) - hte = nc.createVariable('hte', 'f8', ('ny', 'nx')) - angle = nc.createVariable('angle', 'f8', ('ny', 'nx')) - angleT = nc.createVariable('angleT', 'f8', ('ny', 'nx')) - tarea = nc.createVariable('tarea', 'f8', ('ny', 'nx')) - uarea = nc.createVariable('uarea', 'f8', ('ny', 'nx')) + ulat = nc.createVariable('ulat', 'f8', ('ny', 'nx'), compression='zlib', complevel=1) + ulon = nc.createVariable('ulon', 'f8', ('ny', 'nx'), compression='zlib', complevel=1) + tlat = nc.createVariable('tlat', 'f8', ('ny', 'nx'), compression='zlib', complevel=1) + tlon = nc.createVariable('tlon', 'f8', ('ny', 'nx'), compression='zlib', complevel=1) + htn = nc.createVariable('htn', 'f8', ('ny', 'nx'), compression='zlib', complevel=1) + hte = nc.createVariable('hte', 'f8', ('ny', 'nx'), compression='zlib', complevel=1) + angle = nc.createVariable('angle', 'f8', ('ny', 'nx'), compression='zlib', complevel=1) + angleT = nc.createVariable('angleT', 'f8', ('ny', 'nx'), compression='zlib', complevel=1) + tarea = nc.createVariable('tarea', 'f8', ('ny', 'nx'), compression='zlib', complevel=1) + uarea = nc.createVariable('uarea', 'f8', ('ny', 'nx'), compression='zlib', complevel=1) # Add attributes ulat.units = "radians"