From 9ce214f94244dcb1cec2d0e9e4e1a60aabe41982 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 25 Mar 2024 15:36:29 +0000 Subject: [PATCH] Update documentation --- .../_modules/compass/ocean/tests/utility.html | 4 +- .../ocean/tests/utility/combine_topo.html | 498 ++++++++++++++++++ latest/_modules/index.html | 3 +- .../developers_guide/ocean/api.rst.txt | 5 + ...tests.utility.combine_topo.Combine.rst.txt | 37 ++ ...s.utility.combine_topo.Combine.run.rst.txt | 6 + ...utility.combine_topo.Combine.setup.rst.txt | 6 + ...s.utility.combine_topo.CombineTopo.rst.txt | 27 + .../ocean/test_groups/utility.rst.txt | 16 + .../ocean/test_groups/utility.rst.txt | 9 + latest/developers_guide/ocean/api.html | 12 + .../compass.ocean.tests.utility.Utility.html | 4 +- ...an.tests.utility.combine_topo.Combine.html | 236 +++++++++ ...ests.utility.combine_topo.Combine.run.html | 171 ++++++ ...ts.utility.combine_topo.Combine.setup.html | 172 ++++++ ...ests.utility.combine_topo.CombineTopo.html | 206 ++++++++ ...ts.utility.cull_restarts.CullRestarts.html | 4 +- .../ocean/test_groups/utility.html | 21 +- latest/genindex.html | 16 +- latest/objects.inv | Bin 34943 -> 35037 bytes latest/searchindex.js | 2 +- .../ocean/test_groups/utility.html | 10 + 22 files changed, 1455 insertions(+), 10 deletions(-) create mode 100644 latest/_modules/compass/ocean/tests/utility/combine_topo.html create mode 100644 latest/_sources/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.Combine.rst.txt create mode 100644 latest/_sources/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.Combine.run.rst.txt create mode 100644 latest/_sources/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.Combine.setup.rst.txt create mode 100644 latest/_sources/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.CombineTopo.rst.txt create mode 100644 latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.Combine.html create mode 100644 latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.Combine.run.html create mode 100644 latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.Combine.setup.html create mode 100644 latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.CombineTopo.html diff --git a/latest/_modules/compass/ocean/tests/utility.html b/latest/_modules/compass/ocean/tests/utility.html index ac27f79410..9d26621a83 100644 --- a/latest/_modules/compass/ocean/tests/utility.html +++ b/latest/_modules/compass/ocean/tests/utility.html @@ -111,7 +111,8 @@

Source code for compass.ocean.tests.utility

-from compass.ocean.tests.utility.cull_restarts import CullRestarts
+from compass.ocean.tests.utility.combine_topo import CombineTopo
+from compass.ocean.tests.utility.cull_restarts import CullRestarts
 from compass.ocean.tests.utility.extrap_woa import ExtrapWoa
 from compass.testgroup import TestGroup
 
@@ -132,6 +133,7 @@ 

Source code for compass.ocean.tests.utility

         """
         super().__init__(mpas_core=mpas_core, name='utility')
 
+        self.add_test_case(CombineTopo(test_group=self))
         self.add_test_case(CullRestarts(test_group=self))
         self.add_test_case(ExtrapWoa(test_group=self))
diff --git a/latest/_modules/compass/ocean/tests/utility/combine_topo.html b/latest/_modules/compass/ocean/tests/utility/combine_topo.html new file mode 100644 index 0000000000..772d47cd9a --- /dev/null +++ b/latest/_modules/compass/ocean/tests/utility/combine_topo.html @@ -0,0 +1,498 @@ + + + + + + compass.ocean.tests.utility.combine_topo — compass latest documentation + + + + + + + + + + + + + + + +
+ + +
+ +
+
+
+ +
+
+
+
+ +

Source code for compass.ocean.tests.utility.combine_topo

+import numpy as np
+import progressbar
+import pyproj
+import xarray as xr
+from pyremap import LatLonGridDescriptor, ProjectionGridDescriptor, Remapper
+
+from compass.step import Step
+from compass.testcase import TestCase
+
+
+
+[docs] +class CombineTopo(TestCase): + """ + A test case for combining GEBCO 2023 with BedMachineAntarctica topography + datasets + """ + +
+[docs] + def __init__(self, test_group): + """ + Create the test case + + Parameters + ---------- + test_group : compass.ocean.tests.utility.Utility + The test group that this test case belongs to + """ + super().__init__(test_group=test_group, name='combine_topo') + + self.add_step(Combine(test_case=self))
+
+ + + +
+[docs] +class Combine(Step): + """ + A step for combining GEBCO 2023 with BedMachineAntarctica topography + datasets + """ + +
+[docs] + def __init__(self, test_case): + """ + Create a new step + + Parameters + ---------- + test_case : compass.ocean.tests.utility.extrap_woa.ExtraWoa + The test case this step belongs to + """ + super().__init__(test_case, name='combine', ntasks=None, + min_tasks=None)
+ + +
+[docs] + def setup(self): + """ + Set up the step in the work directory, including downloading any + dependencies. + """ + super().setup() + + config = self.config + section = config['combine_topo'] + antarctic_filename = section.get('antarctic_filename') + self.add_input_file(filename=antarctic_filename, + target=antarctic_filename, + database='bathymetry_database') + global_filename = section.get('global_filename') + self.add_input_file(filename=global_filename, + target=global_filename, + database='bathymetry_database') + + cobined_filename = section.get('cobined_filename') + self.add_output_file(filename=cobined_filename) + + self.ntasks = section.getint('ntasks') + self.min_tasks = section.getint('min_tasks')
+ + +
+[docs] + def run(self): + """ + Run this step of the test case + """ + self._downsample_gebco() + self._modify_bedmachine() + # we will work with bedmachine data at its original resolution + # self._downsample_bedmachine() + self._remap_bedmachine() + self._combine()
+ + + def _downsample_gebco(self): + """ + Average GEBCO to 0.0125 degree grid. GEBCO is on 15" grid, so average + every 3x3 block of cells + """ + config = self.config + logger = self.logger + + section = config['combine_topo'] + in_filename = section.get('global_filename') + out_filename = 'GEBCO_2023_0.0125_degree.nc' + + gebco = xr.open_dataset(in_filename) + + nlon = gebco.sizes['lon'] + nlat = gebco.sizes['lat'] + + block = 3 + norm = 1.0 / block**2 + + nx = nlon // block + ny = nlat // block + + chunks = 2 + nxchunk = nlon // chunks + nychunk = nlat // chunks + + gebco = gebco.chunk({'lon': nxchunk, 'lat': nychunk}) + + bathymetry = np.zeros((ny, nx)) + + logger.info('Averaging GEBCO to 0.0125 degree grid') + widgets = [progressbar.Percentage(), ' ', + progressbar.Bar(), ' ', progressbar.ETA()] + bar = progressbar.ProgressBar(widgets=widgets, + maxval=chunks**2).start() + for ychunk in range(chunks): + for xchunk in range(chunks): + gebco_chunk = gebco.isel( + lon=slice(nxchunk * xchunk, nxchunk * (xchunk + 1)), + lat=slice(nychunk * ychunk, nychunk * (ychunk + 1))) + elevation = gebco_chunk.elevation.values + nxblock = nxchunk // block + nyblock = nychunk // block + bathy_block = np.zeros((nyblock, nxblock)) + for y in range(block): + for x in range(block): + bathy_block += elevation[y::block, x::block] + bathy_block *= norm + xmin = xchunk * nxblock + xmax = (xchunk + 1) * nxblock + ymin = ychunk * nyblock + ymax = (ychunk + 1) * nyblock + bathymetry[ymin:ymax, xmin:xmax] = bathy_block + bar.update(ychunk * chunks + xchunk + 1) + bar.finish() + + lon_corner = np.linspace(-180., 180., bathymetry.shape[1] + 1) + lat_corner = np.linspace(-90., 90., bathymetry.shape[0] + 1) + lon = 0.5 * (lon_corner[0:-1] + lon_corner[1:]) + lat = 0.5 * (lat_corner[0:-1] + lat_corner[1:]) + gebco_low = xr.Dataset({'bathymetry': (['lat', 'lon'], bathymetry)}, + coords={'lon': (['lon',], lon), + 'lat': (['lat',], lat)}) + gebco_low.attrs = gebco.attrs + gebco_low.lon.attrs = gebco.lon.attrs + gebco_low.lat.attrs = gebco.lat.attrs + gebco_low.bathymetry.attrs = gebco.elevation.attrs + gebco_low.to_netcdf(out_filename) + + def _modify_bedmachine(self): + """ + Modify BedMachineAntarctica to compute the fields needed by MPAS-Ocean + """ + logger = self.logger + logger.info('Modifying BedMachineAntarctica with MPAS-Ocean names') + + config = self.config + + section = config['combine_topo'] + in_filename = section.get('antarctic_filename') + out_filename = 'BedMachineAntarctica-v3_mod.nc' + bedmachine = xr.open_dataset(in_filename) + mask = bedmachine.mask + ice_mask = (mask != 0).astype(float) + ocean_mask = (np.logical_or(mask == 0, mask == 3)).astype(float) + grounded_mask = np.logical_or(np.logical_or(mask == 1, mask == 2), + mask == 4).astype(float) + + bedmachine['bathymetry'] = bedmachine.bed.where(ocean_mask, 0.) + bedmachine['ice_draft'] = \ + (bedmachine.surface - + bedmachine.thickness).where(ocean_mask, 0.) + bedmachine.ice_draft.attrs['units'] = 'meters' + bedmachine['thickness'] = \ + bedmachine.thickness.where(ocean_mask, 0.) + + bedmachine['ice_mask'] = ice_mask + bedmachine['grounded_mask'] = grounded_mask + bedmachine['ocean_mask'] = ocean_mask + + varlist = ['bathymetry', 'ice_draft', 'thickness', 'ice_mask', + 'grounded_mask', 'ocean_mask'] + + bedmachine = bedmachine[varlist] + + bedmachine.to_netcdf(out_filename) + logger.info(' Done.') + + def _downsample_bedmachine(self): + """ + Downsample bedmachine from 0.5 to 1 km grid + """ + logger = self.logger + logger.info('Downsample BedMachineAntarctica from 500 m to 1 km') + + in_filename = 'BedMachineAntarctica-v3_mod.nc' + out_filename = 'BedMachineAntarctica-v3_1k.nc' + bedmachine = xr.open_dataset(in_filename) + x = bedmachine.x.values + y = bedmachine.y.values + + nx = len(x) // 2 + ny = len(y) // 2 + x = 0.5 * (x[0:2 * nx:2] + x[1:2 * nx:2]) + y = 0.5 * (y[0:2 * ny:2] + y[1:2 * ny:2]) + bedmachine1k = xr.Dataset() + for field in bedmachine.data_vars: + in_array = bedmachine[field].values + out_array = np.zeros((ny, nx)) + for yoffset in range(2): + for xoffset in range(2): + out_array += 0.25 * \ + in_array[yoffset:2 * ny:2, xoffset:2 * nx:2] + da = xr.DataArray(out_array, dims=('y', 'x'), + coords={'x': (('x',), x), + 'y': (('y',), y)}) + bedmachine1k[field] = da + bedmachine1k[field].attrs = bedmachine[field].attrs + + bedmachine1k.to_netcdf(out_filename) + logger.info(' Done.') + + def _remap_bedmachine(self): + """ + Remap BedMachine Antarctica to GEBCO lat-lon grid + """ + logger = self.logger + logger.info('Remap BedMachineAntarctica to GEBCO 1/80 deg grid') + + config = self.config + + section = config['combine_topo'] + renorm_thresh = section.getfloat('renorm_thresh') + + in_filename = 'BedMachineAntarctica-v3_mod.nc' + out_filename = 'BedMachineAntarctica_on_GEBCO_low.nc' + gebco_filename = 'GEBCO_2023_0.0125_degree.nc' + + projection = pyproj.Proj('+proj=stere +lat_ts=-71.0 +lat_0=-90 ' + '+lon_0=0.0 +k_0=1.0 +x_0=0.0 +y_0=0.0 ' + '+ellps=WGS84') + + bedmachine = xr.open_dataset(in_filename) + x = bedmachine.x.values + y = bedmachine.y.values + + in_descriptor = ProjectionGridDescriptor.create( + projection, x, y, 'BedMachineAntarctica_500m') + + out_descriptor = LatLonGridDescriptor.read(fileName=gebco_filename) + + mapping_filename = \ + 'map_BedMachineAntarctica_500m_to_GEBCO_0.0125deg_bilinear.nc' + + remapper = Remapper(in_descriptor, out_descriptor, mapping_filename) + remapper.build_mapping_file(method='bilinear', mpiTasks=self.ntasks, + esmf_parallel_exec='srun', tempdir='.') + bedmachine = xr.open_dataset(in_filename) + bedmachine_on_gebco_low = remapper.remap(bedmachine) + + for field in ['bathymetry', 'ice_draft', 'thickness']: + bedmachine_on_gebco_low[field].attrs['unit'] = 'meters' + + # renormalize the fields based on the ocean masks + ocean_mask = bedmachine_on_gebco_low.ocean_mask + + valid = ocean_mask > renorm_thresh + norm = ocean_mask.where(valid, 1.) + norm = 1. / norm + for field in ['bathymetry', 'ice_draft', 'thickness']: + bedmachine_on_gebco_low[field] = \ + norm * bedmachine_on_gebco_low[field].where(valid, 0.) + + bedmachine_on_gebco_low.to_netcdf(out_filename) + logger.info(' Done.') + + def _combine(self): + """ + Combine GEBCO with BedMachine Antarctica + """ + logger = self.logger + logger.info('Combine BedMachineAntarctica and GEBCO') + + config = self.config + section = config['combine_topo'] + + latmin = section.getfloat('latmin') + latmax = section.getfloat('latmax') + cobined_filename = section.get('cobined_filename') + + gebco_filename = 'GEBCO_2023_0.0125_degree.nc' + gebco = xr.open_dataset(gebco_filename) + + bedmachine_filename = 'BedMachineAntarctica_on_GEBCO_low.nc' + bedmachine = xr.open_dataset(bedmachine_filename) + + combined = xr.Dataset() + alpha = (gebco.lat - latmin) / (latmax - latmin) + alpha = np.maximum(np.minimum(alpha, 1.0), 0.0) + + bedmachine_bathy = bedmachine.bathymetry + valid = bedmachine_bathy.notnull() + bedmachine_bathy = bedmachine_bathy.where(valid, 0.) + + combined['bathymetry'] = \ + alpha * gebco.bathymetry.where(gebco.bathymetry < 0, 0.) + \ + (1.0 - alpha) * bedmachine_bathy + for field in ['ice_draft', 'thickness']: + combined[field] = bedmachine[field] + for field in ['bathymetry', 'ice_draft', 'thickness']: + combined[field].attrs['unit'] = 'meters' + + fill = {'ice_mask': 0., 'grounded_mask': 0., + 'ocean_mask': combined['bathymetry'] < 0.} + + for field, fill_val in fill.items(): + valid = bedmachine[field].notnull() + combined[field] = bedmachine[field].where(valid, fill_val) + + combined['water_column'] = \ + combined['ice_draft'] - combined['bathymetry'] + combined.water_column.attrs['units'] = 'meters' + + combined.to_netcdf(cobined_filename) + logger.info(' Done.') + + diff = xr.Dataset() + + diff['bathymetry'] = \ + gebco.bathymetry.where(gebco.bathymetry < 0, 0.) - \ + bedmachine.bathymetry + diff.to_netcdf('gebco_minus_bedmachine.nc')
+ +
+ +
+
+
+ +
+ +
+

© Copyright Copyright (c) 2013-2021, Los Alamos National Security, LLC (LANS) (Ocean: LA-CC-13-047;Land Ice: LA-CC-13-117) and the University Corporation for Atmospheric Research (UCAR)..

+
+ + Built with Sphinx using a + theme + provided by Read the Docs. + + +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/latest/_modules/index.html b/latest/_modules/index.html index 544c294590..1d5a27878c 100644 --- a/latest/_modules/index.html +++ b/latest/_modules/index.html @@ -422,7 +422,8 @@

All modules for which code is available

  • compass.ocean.tests.tides.init.remap_bathymetry
  • compass.ocean.tests.tides.mesh
  • compass.ocean.tests.utility
  • -

    diff --git a/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.Combine.html b/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.Combine.html new file mode 100644 index 0000000000..1fdeff881b --- /dev/null +++ b/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.Combine.html @@ -0,0 +1,236 @@ + + + + + + + compass.ocean.tests.utility.combine_topo.Combine — compass latest documentation + + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    compass.ocean.tests.utility.combine_topo.Combine

    +
    +
    +class compass.ocean.tests.utility.combine_topo.Combine(test_case)[source]
    +

    A step for combining GEBCO 2023 with BedMachineAntarctica topography +datasets

    +
    +
    +__init__(test_case)[source]
    +

    Create a new step

    +
    +
    Parameters:
    +

    test_case (compass.ocean.tests.utility.extrap_woa.ExtraWoa) – The test case this step belongs to

    +
    +
    +
    + +

    Methods

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

    __init__(test_case)

    Create a new step

    add_input_file([filename, target, database, ...])

    Add an input file to the step (but not necessarily to the MPAS model).

    add_model_as_input()

    make a link to the model executable and add it to the inputs

    add_namelist_file(package, namelist[, ...])

    Add a file with updates to namelist options to the step to be parsed when generating a complete namelist file if and when the step gets set up.

    add_namelist_options(options[, out_name, mode])

    Add the namelist replacements to be parsed when generating a namelist file if and when the step gets set up.

    add_output_file(filename)

    Add the output file that must be produced by this step and may be made available as an input to steps, perhaps in other test cases.

    add_streams_file(package, streams[, ...])

    Add a streams file to the step to be parsed when generating a complete streams file if and when the step gets set up.

    constrain_resources(available_resources)

    Constrain cpus_per_task and ntasks based on the number of cores available to this step

    process_inputs_and_outputs()

    Process the inputs to and outputs from a step added with compass.Step.add_input_file() and compass.Step.add_output_file().

    run()

    Run this step of the test case

    runtime_setup()

    Update attributes of the step at runtime before calling the run() method.

    set_resources([cpus_per_task, ...])

    Update the resources for the subtask.

    setup()

    Set up the step in the work directory, including downloading any dependencies.

    update_namelist_at_runtime(options[, out_name])

    Update an existing namelist file with additional options.

    update_namelist_pio([out_name])

    Modify the namelist so the number of PIO tasks and the stride between them consistent with the number of nodes and cores (one PIO task per node).

    update_streams_at_runtime(package, streams, ...)

    Update the streams files during the run phase of this step using the given template and replacements.

    +
    + +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.Combine.run.html b/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.Combine.run.html new file mode 100644 index 0000000000..047b1e1e7a --- /dev/null +++ b/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.Combine.run.html @@ -0,0 +1,171 @@ + + + + + + + compass.ocean.tests.utility.combine_topo.Combine.run — compass latest documentation + + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    compass.ocean.tests.utility.combine_topo.Combine.run

    +
    +
    +Combine.run()[source]
    +

    Run this step of the test case

    +
    + +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.Combine.setup.html b/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.Combine.setup.html new file mode 100644 index 0000000000..6f01c1200f --- /dev/null +++ b/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.Combine.setup.html @@ -0,0 +1,172 @@ + + + + + + + compass.ocean.tests.utility.combine_topo.Combine.setup — compass latest documentation + + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    compass.ocean.tests.utility.combine_topo.Combine.setup

    +
    +
    +Combine.setup()[source]
    +

    Set up the step in the work directory, including downloading any +dependencies.

    +
    + +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.CombineTopo.html b/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.CombineTopo.html new file mode 100644 index 0000000000..3f56aea417 --- /dev/null +++ b/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.combine_topo.CombineTopo.html @@ -0,0 +1,206 @@ + + + + + + + compass.ocean.tests.utility.combine_topo.CombineTopo — compass latest documentation + + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    compass.ocean.tests.utility.combine_topo.CombineTopo

    +
    +
    +class compass.ocean.tests.utility.combine_topo.CombineTopo(test_group)[source]
    +

    A test case for combining GEBCO 2023 with BedMachineAntarctica topography +datasets

    +
    +
    +__init__(test_group)[source]
    +

    Create the test case

    +
    +
    Parameters:
    +

    test_group (compass.ocean.tests.utility.Utility) – The test group that this test case belongs to

    +
    +
    +
    + +

    Methods

    + + + + + + + + + + + + + + + + + + + + + +

    __init__(test_group)

    Create the test case

    add_step(step[, run_by_default])

    Add a step to the test case

    check_validation()

    Check the test case's "validation" dictionary to see if validation failed.

    configure()

    Modify the configuration options for this test case.

    run()

    This method is deprecated.

    validate()

    Test cases can override this method to perform validation of variables and timers

    +
    + +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.cull_restarts.CullRestarts.html b/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.cull_restarts.CullRestarts.html index 0cefcaf761..809d285148 100644 --- a/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.cull_restarts.CullRestarts.html +++ b/latest/developers_guide/ocean/generated/compass.ocean.tests.utility.cull_restarts.CullRestarts.html @@ -20,7 +20,7 @@ - + @@ -176,7 +176,7 @@

    compass.ocean.tests.utility.cull_restarts.CullRestarts