From 3542c1531fefcb7cb3e177109b6234184911e34d Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Fri, 6 Mar 2020 21:52:05 +0100 Subject: [PATCH 1/9] Fix typo in ocean_initial_state Remove some trailing white space. --- .../global_ocean/scripts/create_E3SM_coupling_files.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py index abffe5e69f..7bda35eeff 100755 --- a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py +++ b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py @@ -5,7 +5,7 @@ Load the lastest e3sm-unified conda package. """ -# import modules # {{{ +# import modules # {{{ import os import shutil import subprocess @@ -508,7 +508,7 @@ def mapping_runoff(config, mesh_name, date_string, ice_shelf_cavities): # Alter runoff mapping so runoff does not go under ice shelves # WARNING: this is not hooked up yet. I need to know which mapping files this applies to. - # Also, this is pointing to the correct -w and -n flags, but it only works if I + # Also, this is pointing to the correct -w and -n flags, but it only works if I # switch those files. if ice_shelf_cavities: make_link('../copy_cell_indices_ISC.py', 'copy_cell_indices_ISC.py') @@ -521,7 +521,7 @@ def mapping_runoff(config, mesh_name, date_string, ice_shelf_cavities): '-n', 'no_ISC_culled_mesh.nc.nc' ] run_command(args) - + # make links in output directories files = glob.glob('map*.nc') os.chdir('../assembled_files_for_upload/inputdata/cpl/cpl6') @@ -572,7 +572,7 @@ def salinity_restoring(config, mesh_name, date_string, ice_shelf_cavities): print('salinity_restoring must be run on compute node') # remap from 1x1 to model grid - args = ['ncremap', + args = ['ncremap', '-i', 'salinity_restoring_input_file.nc', '-o', 'intermediate_file.nc', '-m', map_Levitus_file, From 251bd2bcaa3b97e146ade1399e120c25aed7b0f4 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Fri, 6 Mar 2020 22:00:14 +0100 Subject: [PATCH 2/9] Include traceback when e3sm coupling substeps fail --- .../ocean/global_ocean/scripts/create_E3SM_coupling_files.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py index 7bda35eeff..d93c496791 100755 --- a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py +++ b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py @@ -14,6 +14,8 @@ import numpy as np import glob from datetime import datetime +import traceback +import sys # }}} def main(): @@ -108,6 +110,7 @@ def main(): print('SUCCESS') except BaseException: print('!!! FAILURE !!!') + traceback.print_exc(file=sys.stdout) success = False os.chdir(currentDir) print(" ") From d423607965566eeb2262bfaca39ca8d6513ff4c8 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Fri, 6 Mar 2020 22:05:46 +0100 Subject: [PATCH 3/9] A bit of PEP8 clean-up --- .../scripts/create_E3SM_coupling_files.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py index d93c496791..ab644dbd26 100755 --- a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py +++ b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py @@ -18,6 +18,7 @@ import sys # }}} + def main(): # {{{ @@ -99,7 +100,7 @@ def main(): function_name = function.__name__ print("****** " + function_name + " ******") - if (config.get(function_name, 'enable').lower() == 'false'): + if config.get(function_name, 'enable').lower() == 'false': print("Disabled in .ini file") else: make_dir(function_name) @@ -121,6 +122,7 @@ def main(): print("!!!!!! FAILURE: One or more steps failed. See output above !!!!!!") # }}} + def initial_condition_ocean(config, mesh_name, date_string, ice_shelf_cavities): # {{{ @@ -176,6 +178,7 @@ def graph_partition_ocean(config, mesh_name, date_string, ice_shelf_cavities): make_link('../../../../../graph_partition_ocean/' + file, './' + file) # }}} + def initial_condition_seaice(config, mesh_name, date_string, ice_shelf_cavities): # {{{ @@ -204,6 +207,7 @@ def initial_condition_seaice(config, mesh_name, date_string, ice_shelf_cavities) mesh_name + '.nc', 'seaice.' + mesh_name + '.nc') # }}} + def scrip(config, mesh_name, date_string, ice_shelf_cavities): # {{{ @@ -238,6 +242,7 @@ def scrip(config, mesh_name, date_string, ice_shelf_cavities): make_link('../../../../../scrip/' + scrip_file_mask, scrip_file_mask) # }}} + def transects_and_regions(config, mesh_name, date_string, ice_shelf_cavities): # {{{ @@ -266,6 +271,7 @@ def transects_and_regions(config, mesh_name, date_string, ice_shelf_cavities): 'masks_SingleRegionAtlanticWTransportTransects.' + mesh_name + '.nc') # }}} + def mapping_CORE_Gcase(config, mesh_name, date_string, ice_shelf_cavities): # {{{ atm_scrip_tag = config.get('mapping_CORE_Gcase', 'atm_scrip_tag') @@ -278,6 +284,7 @@ def mapping_CORE_Gcase(config, mesh_name, date_string, ice_shelf_cavities): make_link('../../../../mapping_CORE_Gcase/' + file, './' + file) # }}} + def mapping_JRA_Gcase(config, mesh_name, date_string, ice_shelf_cavities): # {{{ atm_scrip_tag = config.get('mapping_JRA_Gcase', 'atm_scrip_tag') @@ -290,6 +297,7 @@ def mapping_JRA_Gcase(config, mesh_name, date_string, ice_shelf_cavities): make_link('../../../../mapping_JRA_Gcase/' + file, './' + file) # }}} + def mapping_ne30(config, mesh_name, date_string, ice_shelf_cavities): # {{{ atm_scrip_tag = config.get('mapping_ne30', 'atm_scrip_tag') @@ -302,6 +310,7 @@ def mapping_ne30(config, mesh_name, date_string, ice_shelf_cavities): make_link('../../../../mapping_CORE_Gcase/' + file, './' + file) # }}} + def mapping(config, mesh_name, date_string, ice_shelf_cavities, atm_scrip_tag): # {{{ @@ -380,6 +389,7 @@ def mapping(config, mesh_name, date_string, ice_shelf_cavities, atm_scrip_tag): print('mapping_CORE_Gcase must be run on one compute node') # }}} + def domain_CORE_Gcase(config, mesh_name, date_string, ice_shelf_cavities): # {{{ # obtain configuration settings @@ -407,6 +417,7 @@ def domain_CORE_Gcase(config, mesh_name, date_string, ice_shelf_cavities): make_link('../../../../domain/' + file, './' + file) # }}} + def domain_JRA_Gcase(config, mesh_name, date_string, ice_shelf_cavities): # {{{ # obtain configuration settings @@ -434,6 +445,7 @@ def domain_JRA_Gcase(config, mesh_name, date_string, ice_shelf_cavities): make_link('../../../../domain/' + file, './' + file) # }}} + def domain_ne30(config, mesh_name, date_string, ice_shelf_cavities): # {{{ # obtain configuration settings @@ -461,6 +473,7 @@ def domain_ne30(config, mesh_name, date_string, ice_shelf_cavities): make_link('../../../../domain/' + file, './' + file) # }}} + def mapping_runoff(config, mesh_name, date_string, ice_shelf_cavities): # {{{ @@ -532,6 +545,7 @@ def mapping_runoff(config, mesh_name, date_string, ice_shelf_cavities): make_link('../../../../mapping_runoff/' + file, './' + file) # }}} + def salinity_restoring(config, mesh_name, date_string, ice_shelf_cavities): # {{{ @@ -638,6 +652,7 @@ def write_command_history(text): pass # }}} + def run_command(args): # {{{ try: @@ -650,6 +665,7 @@ def run_command(args): pass # }}} + if __name__ == '__main__': # If called as a primary module, run main main() From 535549dfa5e9db6132feb37ee4840116ab5f74dc Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Fri, 6 Mar 2020 22:18:18 +0100 Subject: [PATCH 4/9] Update MOC regions and transects to use mpas_tools This way, we make the geojson file on the fly rather than having to symlink to it. We also use the new southern transect that is the true southern boundary of each MOC region, rather than the approximate transect from previously. --- .../scripts/config_E3SM_coupling_files.ini | 5 ++- .../scripts/create_E3SM_coupling_files.py | 35 ++++++++++--------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/testing_and_setup/compass/ocean/global_ocean/scripts/config_E3SM_coupling_files.ini b/testing_and_setup/compass/ocean/global_ocean/scripts/config_E3SM_coupling_files.ini index 7c4c983c1a..f3acdf33cc 100644 --- a/testing_and_setup/compass/ocean/global_ocean/scripts/config_E3SM_coupling_files.ini +++ b/testing_and_setup/compass/ocean/global_ocean/scripts/config_E3SM_coupling_files.ini @@ -20,7 +20,6 @@ enable = true [transects_and_regions] enable = true -transect_region_geojson = /usr/projects/climate/mpeterse/analysis_input_files/geojson_files/SingleRegionAtlanticWTransportTransects.geojson [mapping_CORE_Gcase] enable = true @@ -34,7 +33,7 @@ atm_scrip_tag = JRA025 [mapping_ne30] enable = false # need to add complete name here: -atm_scrip_tag = ne30 +atm_scrip_tag = ne30 [domain_CORE_Gcase] enable = true @@ -55,7 +54,7 @@ runoff_map_exe = /usr/projects/climate/mpeterse/repos/E3SM/compiled_cime_tools/c runoff_map_lnd_file = /lustre/scratch3/turquoise/mpeterse/E3SM/input_data/lnd/dlnd7/RX1/runoff.daitren.annual.090225.nc [salinity_restoring] -enable = true +enable = true # This file needs to be added to a standard repo. Local copy for now: grid_Levitus_1x1_scrip_file = /usr/projects/climate/mpeterse/mapping_files/test_SSS_mapping_190821/EC60to30Rev4/genRemapFiles/grid_Levitus_1x1_scrip.nc # This file needs to be added to a standard repo. Local copy for now: diff --git a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py index ab644dbd26..a26eb75812 100755 --- a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py +++ b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py @@ -16,6 +16,8 @@ from datetime import datetime import traceback import sys +from geometric_features import GeometricFeatures +from mpas_tools.ocean.moc import make_moc_basins_and_transects # }}} @@ -246,29 +248,28 @@ def scrip(config, mesh_name, date_string, ice_shelf_cavities): def transects_and_regions(config, mesh_name, date_string, ice_shelf_cavities): # {{{ - # obtain configuration settings - transect_region_geojson = config.get( - 'transects_and_regions', - 'transect_region_geojson') + # make the geojson file + gf = GeometricFeatures() - maskfile = 'masks_SingleRegionAtlanticWTransportTransects.' + mesh_name + '.nc' + mesh_filename = '../init.nc' - # make links - make_link('../init.nc', mesh_name + '.nc') - make_link(transect_region_geojson, - 'SingleRegionAtlanticWTransportTransects.geojson') + mask_filename = '{}_moc_masks.nc'.format(mesh_name) + mask_and_transect_filename = '{}_moc_masks_and_transects.nc'.format( + mesh_name) - # check: how does this call MpasMaskCreator? - args = ['MpasMaskCreator.x', mesh_name + '.nc', maskfile, - '-f', 'SingleRegionAtlanticWTransportTransects.geojson'] - run_command(args) + geojson_filename = 'moc_basins.geojson' + + make_moc_basins_and_transects(gf, mesh_filename, mask_and_transect_filename, + geojson_filename=geojson_filename, + mask_filename=mask_filename) + output_dir = '../assembled_files_for_upload/inputdata/ocn/mpas-o/{}'.format( + mesh_name) # make links in output directory - os.chdir('../assembled_files_for_upload/inputdata/ocn/mpas-o/' + mesh_name) make_link( - '../../../../../transects_and_regions/masks_SingleRegionAtlanticWTransportTransects.' + - mesh_name + '.nc', - 'masks_SingleRegionAtlanticWTransportTransects.' + mesh_name + '.nc') + '../../../../../transects_and_regions/{}'.format( + mask_and_transect_filename), + '{}/{}'.format(output_dir, mask_and_transect_filename)) # }}} From 8bb2a20d53a19a05794f439e7b24ebb660989b91 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Sat, 7 Mar 2020 12:33:06 +0100 Subject: [PATCH 5/9] Add more mask creation for analysis This merge adds functionality for creating antartics- region, ocean-basin, ice-shelf and transport-transect masks. --- .../scripts/create_E3SM_coupling_files.py | 305 ++++++++++++++++-- 1 file changed, 285 insertions(+), 20 deletions(-) diff --git a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py index a26eb75812..930419f1f0 100755 --- a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py +++ b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py @@ -12,12 +12,15 @@ import configparser import argparse import numpy as np +import xarray as xr import glob from datetime import datetime import traceback import sys -from geometric_features import GeometricFeatures +from geometric_features import GeometricFeatures, FeatureCollection from mpas_tools.ocean.moc import make_moc_basins_and_transects +from mpas_tools.io import write_netcdf +import mpas_tools.conversion # }}} @@ -95,6 +98,9 @@ def main(): make_dir('assembled_files_for_upload/inputdata/ice/mpas-cice/' + mesh_name) make_dir('assembled_files_for_upload/inputdata/cpl/cpl6') make_dir('assembled_files_for_upload/inputdata/share/domains') + make_dir('assembled_files_for_upload/diagnostics/mpas_analysis/maps') + make_dir('assembled_files_for_upload/diagnostics/mpas_analysis/' + 'region_masks') success = True print() @@ -246,31 +252,33 @@ def scrip(config, mesh_name, date_string, ice_shelf_cavities): def transects_and_regions(config, mesh_name, date_string, ice_shelf_cavities): -# {{{ + # {{{ + make_moc_masks(mesh_name) - # make the geojson file gf = GeometricFeatures() - mesh_filename = '../init.nc' - - mask_filename = '{}_moc_masks.nc'.format(mesh_name) - mask_and_transect_filename = '{}_moc_masks_and_transects.nc'.format( - mesh_name) + features = ['Southern Ocean', 'Southern Ocean 60S', + 'Eastern Weddell Sea Shelf', 'Eastern Weddell Sea Deep', + 'Western Weddell Sea Shelf', 'Western Weddell Sea Deep', + 'Weddell Sea Shelf', 'Weddell Sea Deep', + 'Bellingshausen Sea Shelf', 'Bellingshausen Sea Deep', + 'Amundsen Sea Shelf', 'Amundsen Sea Deep', + 'Eastern Ross Sea Shelf', 'Eastern Ross Sea Deep', + 'Western Ross Sea Shelf', 'Western Ross Sea Deep', + 'East Antarctic Seas Shelf', 'East Antarctic Seas Deep'] + fcMask = gf.read('ocean', 'region', features) + make_region_masks(mesh_name, suffix='antarcticRegions', fcMask=fcMask) - geojson_filename = 'moc_basins.geojson' + fcMask = make_ocean_basins_masks(gf) + make_region_masks(mesh_name, suffix='oceanBasins', fcMask=fcMask) - make_moc_basins_and_transects(gf, mesh_filename, mask_and_transect_filename, - geojson_filename=geojson_filename, - mask_filename=mask_filename) + fcMask = gf.read('ocean', 'transect') + make_region_masks(mesh_name, suffix='transportTransects', fcMask=fcMask) - output_dir = '../assembled_files_for_upload/inputdata/ocn/mpas-o/{}'.format( - mesh_name) - # make links in output directory - make_link( - '../../../../../transects_and_regions/{}'.format( - mask_and_transect_filename), - '{}/{}'.format(output_dir, mask_and_transect_filename)) -# }}} + if ice_shelf_cavities: + fcMask = make_ice_shelf_masks(gf) + make_region_masks(mesh_name, suffix='iceShelfMasks', fcMask=fcMask) + # }}} def mapping_CORE_Gcase(config, mesh_name, date_string, ice_shelf_cavities): @@ -667,6 +675,263 @@ def run_command(args): # }}} +def make_moc_masks(mesh_name): # {{{ + gf = GeometricFeatures() + + mesh_filename = '../init.nc' + + mask_filename = '{}_mocMasks.nc'.format(mesh_name) + mask_and_transect_filename = '{}_mocMasksAndTransects.nc'.format( + mesh_name) + + geojson_filename = 'mocBasins.geojson' + + make_moc_basins_and_transects(gf, mesh_filename, mask_and_transect_filename, + geojson_filename=geojson_filename, + mask_filename=mask_filename) + + # make links in output directories (both inputdata and diagnostics) + output_dir = '../assembled_files_for_upload/inputdata/ocn/mpas-o/{}'.format( + mesh_name) + make_link( + '../../../../../transects_and_regions/{}'.format( + mask_and_transect_filename), + '{}/{}'.format(output_dir, mask_and_transect_filename)) + + output_dir = '../assembled_files_for_upload/diagnostics/mpas_analysis/' \ + 'region_masks' + make_link( + '../../../../transects_and_regions/{}'.format( + mask_and_transect_filename), + '{}/{}'.format(output_dir, mask_and_transect_filename)) + + # }}} + + +def make_ocean_basins_masks(gf): # {{{ + """ + Builds features defining the major ocean basins + Parameters + ---------- + gf : ``GeometricFeatures`` + An object that knows how to download and read geometric featuers + + Returns + ------- + fc : ``FeatureCollection`` + The new feature collection + """ + # Authors + # ------- + # Xylar Asay-Davis + + fc = FeatureCollection() + fc.set_group_name(groupName='OceanBasinRegionsGroup') + + # build ocean basins from regions with the appropriate tags + for oceanName in ['Atlantic', 'Pacific', 'Indian', 'Arctic', + 'Southern_Ocean', 'Mediterranean']: + + basinName = '{}_Basin'.format(oceanName) + print(oceanName) + + print(' * merging features') + fcBasin = gf.read(componentName='ocean', objectType='region', + tags=[basinName]) + + print(' * combining features') + fcBasin = fcBasin.combine(featureName=basinName) + + fc.merge(fcBasin) + + # add the global ocean, global ocean between 65S and 65S, and + # equatorial region + fc.merge(gf.read(componentName='ocean', objectType='region', + featureNames=['Global Ocean', + 'Global Ocean 65N to 65S', + 'Global Ocean 15S to 15N'])) + + return fc # }}} + + +def make_ice_shelf_masks(gf): # {{{ + iceShelfNames = ['Abbot', + 'Amery', + 'Atka', + 'Aviator', + 'Bach', + 'Baudouin', + 'Borchgrevink', + 'Brahms', + 'Brunt_Stancomb', + 'Campbell', + 'Cheetham', + 'Conger_Glenzer', + 'Cook', + 'Cosgrove', + 'Crosson', + 'Dennistoun', + 'Dibble', + 'Dotson', + 'Drygalski', + 'Edward_VIII', + 'Ekstrom', + 'Ferrigno', + 'Filchner', + 'Fimbul', + 'Fitzgerald', + 'Frost', + 'GeikieInlet', + 'George_VI', + 'Getz', + 'Gillet', + 'Hamilton', + 'Hannan', + 'HarbordGlacier', + 'Helen', + 'Holmes', + 'HolmesWest', + 'Hull', + 'Jelbart', + 'Land', + 'Larsen_B', + 'Larsen_C', + 'Larsen_D', + 'Larsen_E', + 'Larsen_F', + 'Larsen_G', + 'Lazarev', + 'Lillie', + 'Mariner', + 'Matusevitch', + 'Mendelssohn', + 'Mertz', + 'Moscow_University', + 'Moubray', + 'Mulebreen', + 'Myers', + 'Nansen', + 'Nickerson', + 'Ninnis', + 'Nivl', + 'Noll', + 'Nordenskjold', + 'Pine_Island', + 'PourquoiPas', + 'Prince_Harald', + 'Publications', + 'Quar', + 'Rayner_Thyer', + 'Rennick', + 'Richter', + 'Riiser-Larsen', + 'Ronne', + 'Ross_East', + 'Ross_West', + 'Shackleton', + 'Shirase', + 'Slava', + 'SmithInlet', + 'Stange', + 'Sulzberger', + 'Suvorov', + 'Swinburne', + 'Thwaites', + 'Tinker', + 'Totten', + 'Tracy_Tremenchus', + 'Tucker', + 'Underwood', + 'Utsikkar', + 'Venable', + 'Verdi', + 'Vigrid', + 'Vincennes', + 'Voyeykov', + 'West', + 'Wilkins', + 'Wilma_Robert_Downer', + 'Withrow', + 'Wordie', + 'Wylde', + 'Zubchatyy'] + + combinedIceShelves = {'Filchner-Ronne': ['Filchner', 'Ronne'], + 'Ross': ['Ross_East', 'Ross_West'], + 'Antarctica': ['AntarcticPenninsulaIMBIE', + 'WestAntarcticaIMBIE', + 'EastAntarcticaIMBIE'], + 'Peninsula': ['AntarcticPenninsulaIMBIE'], + 'West Antarctica': ['WestAntarcticaIMBIE'], + 'East Antarctica': ['EastAntarcticaIMBIE']} + + nIMBIEBasins = 27 + for basinNumber in range(1, nIMBIEBasins + 1): + basinName = 'Antarctica_IMBIE{}'.format(basinNumber) + combinedIceShelves['IMBIE{}'.format(basinNumber)] = [basinName] + + # create a FeatureCollection containing all ice shelves and combined ice-shelf + # regions + fc = FeatureCollection() + + # build analysis regions from combining ice shelves from regions with the + # appropriate tags + for shelfName in combinedIceShelves: + subNames = combinedIceShelves[shelfName] + print(shelfName) + + print(' * merging features') + fcShelf = gf.read(componentName='iceshelves', objectType='region', + tags=subNames, allTags=False) + + print(' * combining features') + fcShelf = fcShelf.combine(featureName=shelfName) + + # merge the feature for the basin into the collection of all basins + fc.merge(fcShelf) + + # build ice shelves from regions with the appropriate tags + for shelfName in iceShelfNames: + print(shelfName) + + print(' * merging features') + fcShelf = gf.read(componentName='iceshelves', objectType='region', + tags=[shelfName]) + + print(' * combining features') + fcShelf = fcShelf.combine(featureName=shelfName) + + # merge the feature for the basin into the collection of all basins + fc.merge(fcShelf) + + return fc # }}} + + +def make_region_masks(mesh_name, suffix, fcMask): # {{{ + mesh_filename = '../init.nc' + + geojson_filename = '{}.geojson'.format(suffix) + mask_filename = '{}_{}.nc'.format(mesh_name, suffix) + + fcMask.to_geojson(geojson_filename) + + dsMesh = xr.open_dataset(mesh_filename) + + dsMask = mpas_tools.conversion.mask(dsMesh, fcMask=fcMask) + + write_netcdf(dsMask, mask_filename) + + # make links in output directory + output_dir = '../assembled_files_for_upload/diagnostics/mpas_analysis/' \ + 'region_masks' + make_link( + '../../../../transects_and_regions/{}'.format( + mask_filename), + '{}/{}'.format(output_dir, mask_filename)) + + # }}} + + if __name__ == '__main__': # If called as a primary module, run main main() From 6250ee84ed6b421f37e6b9be7846989d673b2948 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Sat, 7 Mar 2020 12:37:54 +0100 Subject: [PATCH 6/9] Test cases wISC point to IC after ssh adjustment For runs with ice-shelf cavities, the E3SM initial condition needs to come at least after ssh adjustment. All initial conditions should probably come after spin-up as well. --- .../global_ocean/config_files_ISC/config_e3sm_coupling.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing_and_setup/compass/ocean/global_ocean/config_files_ISC/config_e3sm_coupling.xml b/testing_and_setup/compass/ocean/global_ocean/config_files_ISC/config_e3sm_coupling.xml index 96b2b13246..138bef8220 100644 --- a/testing_and_setup/compass/ocean/global_ocean/config_files_ISC/config_e3sm_coupling.xml +++ b/testing_and_setup/compass/ocean/global_ocean/config_files_ISC/config_e3sm_coupling.xml @@ -1,7 +1,7 @@ - + From 5d33398732c9a0817325e57315c53220ca7e887c Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Sat, 7 Mar 2020 18:02:59 +0100 Subject: [PATCH 7/9] Change MOC mask file names to match MPAS-Analysis --- .../global_ocean/scripts/create_E3SM_coupling_files.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py index 930419f1f0..cfa7226317 100755 --- a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py +++ b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py @@ -680,11 +680,11 @@ def make_moc_masks(mesh_name): # {{{ mesh_filename = '../init.nc' - mask_filename = '{}_mocMasks.nc'.format(mesh_name) - mask_and_transect_filename = '{}_mocMasksAndTransects.nc'.format( + mask_filename = '{}_moc_masks.nc'.format(mesh_name) + mask_and_transect_filename = '{}_moc_masks_and_transects.nc'.format( mesh_name) - geojson_filename = 'mocBasins.geojson' + geojson_filename = 'moc_basins.geojson' make_moc_basins_and_transects(gf, mesh_filename, mask_and_transect_filename, geojson_filename=geojson_filename, From ad4d86a647f20ffed2adc0ea9dc8417f8e4a7307 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Sat, 7 Mar 2020 21:33:53 +0100 Subject: [PATCH 8/9] Create analysis mapping files in e3sm_coupling step --- .../scripts/config_E3SM_coupling_files.ini | 14 +++ .../scripts/create_E3SM_coupling_files.py | 86 ++++++++++++++++++- 2 files changed, 96 insertions(+), 4 deletions(-) diff --git a/testing_and_setup/compass/ocean/global_ocean/scripts/config_E3SM_coupling_files.ini b/testing_and_setup/compass/ocean/global_ocean/scripts/config_E3SM_coupling_files.ini index f3acdf33cc..b8005d85b7 100644 --- a/testing_and_setup/compass/ocean/global_ocean/scripts/config_E3SM_coupling_files.ini +++ b/testing_and_setup/compass/ocean/global_ocean/scripts/config_E3SM_coupling_files.ini @@ -21,6 +21,20 @@ enable = true [transects_and_regions] enable = true +[mapping_analysis] +enable = true +# The comparison lat/lon grid resolution in degrees +comparisonLatResolution = 0.5 +comparisonLonResolution = 0.5 + +# The comparison Antarctic polar stereographic grid size and resolution in km +comparisonAntarcticStereoWidth = 6000. +comparisonAntarcticStereoResolution = 10. + +# The comparison Arctic polar stereographic grid size and resolution in km +comparisonArcticStereoWidth = 6000. +comparisonArcticStereoResolution = 10. + [mapping_CORE_Gcase] enable = true atm_scrip_tag = T62_040121 diff --git a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py index cfa7226317..6f8ee2badc 100755 --- a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py +++ b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py @@ -21,6 +21,8 @@ from mpas_tools.ocean.moc import make_moc_basins_and_transects from mpas_tools.io import write_netcdf import mpas_tools.conversion +from pyremap import MpasMeshDescriptor, Remapper, get_lat_lon_descriptor, \ + get_polar_descriptor # }}} @@ -37,6 +39,7 @@ def main(): initial_condition_seaice, scrip, transects_and_regions, + mapping_analysis, mapping_CORE_Gcase, mapping_JRA_Gcase, mapping_ne30, @@ -281,6 +284,24 @@ def transects_and_regions(config, mesh_name, date_string, ice_shelf_cavities): # }}} +def mapping_analysis(config, mesh_name, date_string, ice_shelf_cavities): + # {{{ + make_analysis_lat_lon_map(config, mesh_name) + make_analysis_polar_map(config, mesh_name, projection='antarctic') + make_analysis_polar_map(config, mesh_name, projection='arctic') + + # make links in output directory + files = glob.glob('map_*') + + # make links in output directory + output_dir = '../assembled_files_for_upload/diagnostics/mpas_analysis/maps' + for filename in files: + make_link('../../../../mapping_analysis/{}'.format(filename), + '{}/{}'.format(output_dir, filename)) + + # }}} + + def mapping_CORE_Gcase(config, mesh_name, date_string, ice_shelf_cavities): # {{{ atm_scrip_tag = config.get('mapping_CORE_Gcase', 'atm_scrip_tag') @@ -708,7 +729,7 @@ def make_moc_masks(mesh_name): # {{{ # }}} -def make_ocean_basins_masks(gf): # {{{ +def make_ocean_basins_masks(gf): # {{{ """ Builds features defining the major ocean basins Parameters @@ -751,7 +772,7 @@ def make_ocean_basins_masks(gf): # {{{ 'Global Ocean 65N to 65S', 'Global Ocean 15S to 15N'])) - return fc # }}} + return fc # }}} def make_ice_shelf_masks(gf): # {{{ @@ -904,10 +925,10 @@ def make_ice_shelf_masks(gf): # {{{ # merge the feature for the basin into the collection of all basins fc.merge(fcShelf) - return fc # }}} + return fc # }}} -def make_region_masks(mesh_name, suffix, fcMask): # {{{ +def make_region_masks(mesh_name, suffix, fcMask): # {{{ mesh_filename = '../init.nc' geojson_filename = '{}.geojson'.format(suffix) @@ -932,6 +953,63 @@ def make_region_masks(mesh_name, suffix, fcMask): # {{{ # }}} +def make_analysis_lat_lon_map(config, mesh_name): + # {{{ + mesh_filename = '../init.nc' + + inDescriptor = MpasMeshDescriptor(mesh_filename, mesh_name) + + comparisonLatResolution = config.getfloat('mapping_analysis', + 'comparisonLatResolution') + comparisonLonResolution = config.getfloat('mapping_analysis', + 'comparisonLonResolution') + + # modify the resolution of the global lat-lon grid as desired + outDescriptor = get_lat_lon_descriptor(dLon=comparisonLatResolution, + dLat=comparisonLonResolution) + outGridName = outDescriptor.meshName + + mappingFileName = 'map_{}_to_{}_bilinear.nc'.format(mesh_name, outGridName) + + remapper = Remapper(inDescriptor, outDescriptor, mappingFileName) + + mpiTasks = config.getint('main', 'nprocs') + remapper.build_mapping_file(method='bilinear', mpiTasks=mpiTasks) + # }}} + + +def make_analysis_polar_map(config, mesh_name, projection): + # {{{ + mesh_filename = '../init.nc' + + upperProj = projection[0].upper() + projection[1:] + + inDescriptor = MpasMeshDescriptor(mesh_filename, mesh_name) + + comparisonStereoWidth = config.getfloat( + 'mapping_analysis', 'comparison{}StereoWidth'.format(upperProj)) + comparisonStereoResolution = config.getfloat( + 'mapping_analysis', 'comparison{}StereoResolution'.format(upperProj)) + + outDescriptor = get_polar_descriptor(Lx=comparisonStereoWidth, + Ly=comparisonStereoWidth, + dx=comparisonStereoResolution, + dy=comparisonStereoResolution, + projection=projection) + + outGridName = '{}x{}km_{}km_{}_stereo'.format( + comparisonStereoWidth, comparisonStereoWidth, + comparisonStereoResolution, upperProj) + + mappingFileName = 'map_{}_to_{}_bilinear.nc'.format(mesh_name, outGridName) + + remapper = Remapper(inDescriptor, outDescriptor, mappingFileName) + + mpiTasks = config.getint('main', 'nprocs') + remapper.build_mapping_file(method='bilinear', mpiTasks=mpiTasks) + # }}} + + if __name__ == '__main__': # If called as a primary module, run main main() From cc114b130340611ad8c87ec94e343077ec673fad Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Mon, 9 Mar 2020 16:09:50 +0100 Subject: [PATCH 9/9] Add mask creation for Arctic regions --- .../ocean/global_ocean/scripts/create_E3SM_coupling_files.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py index 6f8ee2badc..6dffe193f8 100755 --- a/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py +++ b/testing_and_setup/compass/ocean/global_ocean/scripts/create_E3SM_coupling_files.py @@ -272,6 +272,9 @@ def transects_and_regions(config, mesh_name, date_string, ice_shelf_cavities): fcMask = gf.read('ocean', 'region', features) make_region_masks(mesh_name, suffix='antarcticRegions', fcMask=fcMask) + fcMask = gf.read('ocean', 'region', tags=['Arctic']) + make_region_masks(mesh_name, suffix='arcticRegions', fcMask=fcMask) + fcMask = make_ocean_basins_masks(gf) make_region_masks(mesh_name, suffix='oceanBasins', fcMask=fcMask)