Skip to content

Commit

Permalink
Addresses review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vanroekel committed Nov 1, 2024
1 parent 2b3ccad commit b427336
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def __init__(self, test_case):
ntasks=512, min_tasks=1)

self.add_input_file(
filename='woa_decav_0.25_sss_monthly_extrap.20241031.nc',
target='woa_decav_0.25_sss_monthly_extrap.20241031.nc',
filename='woa23_decav_0.25_sss_monthly_extrap.20241031.nc',
target='woa23_decav_0.25_sss_monthly_extrap.20241031.nc',
database='initial_condition_database')

self.add_output_file(filename='sss.WOA23_monthlyClimatology.nc')
Expand Down
2 changes: 1 addition & 1 deletion compass/ocean/tests/utility/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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.ocean.tests.utility.create_salinity_restoring import CreateSalinRestoring
from compass.ocean.tests.utility.create_salin_restoring import CreateSalinRestoring
from compass.testgroup import TestGroup


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from compass.ocean.tests.utility.create_salinity_restoring.salinity_restoring import Salinity
from compass.ocean.tests.utility.create_salinity_restoring.extrap_salin import ExtrapSalin
from compass.ocean.tests.utility.create_salin_restoring.salinity_restoring import Salinity
from compass.ocean.tests.utility.create_salin_restoring.extrap_salin import ExtrapSalin
from compass.testcase import TestCase


Expand All @@ -19,7 +19,7 @@ def __init__(self, test_group):
test_group : compass.ocean.tests.utility.Utility
The test group that this test case belongs to
"""
super().__init__(test_group=test_group, name='create_salinity_restoring')
super().__init__(test_group=test_group, name='create_salin_restoring')

self.add_step(Salinity(test_case=self))
self.add_step(ExtrapSalin(test_case=self))
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import xarray as xr
from datetime import datetime
from scipy.signal import convolve2d

from compass.step import Step
Expand All @@ -8,7 +9,7 @@
class ExtrapSalin(Step):
"""
Extrapolate WOA 2023 monthly sea surface salinity data into missing ocean
regions, including ice cavities and coasts
regions, including ice cavities and coasts
Attributes
----------
Expand All @@ -22,7 +23,7 @@ def __init__(self, test_case):
Parameters
----------
test_case : compass.ocean.tests.utility.extrap_woa.ExtrapWoa
test_case : compass.ocean.tests.utility.create_salin_restoring.CreateSalinRestoring
The test case this step belongs to
"""
Expand All @@ -39,7 +40,12 @@ def setup(self):
"""
Determine the output filename
"""
self.woa_filename = 'woa_surface_salinity_monthly_extrap.nc'

now = datetime.now()

datestring = now.strftime("%Y%m%d")

self.woa_filename = f'woa23_decav_0.25_sss_monthly_extrap.{datestring}.nc'
self.add_output_file(self.woa_filename)

def run(self):
Expand All @@ -48,9 +54,9 @@ def run(self):
cavities.
"""
# extrapolate horizontally using the ocean mask
_extrap_level(self.woa_filename)
_extrap(self.woa_filename)

def _extrap_level(out_filename):
def _extrap(out_filename):

in_filename = 'woa_surface_salinity_monthly.nc'
ds = xr.open_dataset(in_filename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Salinity(Step):
"""
A step for combining January through December sea surface salinity
data into a single file for salinity restoring in G-cases.
The top level data of the monthly woa is utilized.
The top level data of the monthly WOA23 is utilized.
"""

def __init__(self, test_case):
Expand All @@ -18,7 +18,7 @@ def __init__(self, test_case):
Parameters
----------
test_case : compass.ocean.tests.utility.extrap_woa.ExtraWoa
test_case : compass.ocean.tests.utility.create_salin_restoring.CreateSalinRestoring
The test case this step belongs to
"""
super().__init__(test_case, name='salinity_restoring', ntasks=1, min_tasks=1)
Expand Down Expand Up @@ -84,29 +84,28 @@ def run(self):
ds_out['s_an'] = xr.concat(slices, dim='time')
ds_out['s_an'].attrs = ds_jan['s_an'].attrs

#Change names of variables and alter attributes
# Change names of variables and alter attributes
ds_out = ds_out.rename_dims({'time':'Time'})
ds_out = ds_out.rename_vars({'s_an':'SALT'})
#ds_out.SALT.attrs['coordinates'] = "Time lat lon"
ds_out = ds_out.drop_vars('time')

# Create a time index
time_var = np.arange(1,12.1,1)
time_var = np.arange(1, 12.1, 1)
ds_out = ds_out.assign(Time=xr.DataArray(time_var, dims=['Time']))

# Create a xtime array
xtime_list = []
for i in range(1,13):
for i in range(1, 13):
xtime_string = f"0000-{i:02d}-15_00:00:00"
xtime_list.append(xtime_string)
xtime_out = np.array(xtime_list,dtype='S64')

ds_out = ds_out.assign(xtime=xr.DataArray(xtime_out, dims=['Time']))

#Change attributes to be consistent with PHC restoring file
# Change attributes to be consistent with PHC restoring file
ds_out.Time.attrs['long_name'] = "Month Index"
ds_out.Time.attrs['units'] = "month"
ds_out.Time.attrs['axis'] = "T"

#Save file and change time dimension to unlimited
write_netcdf(ds_out,'woa_surface_salinity_monthly.nc')
# Save file and change time dimension to unlimited
write_netcdf(ds_out, 'woa_surface_salinity_monthly.nc')
14 changes: 5 additions & 9 deletions compass/ocean/tests/utility/extrap_woa/extrap_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,12 @@ def __init__(self, test_case):
min_cpus_per_task=1, openmp_threads=1)

self.add_input_file(
filename='woa_surface_salinity_monthly.nc',
target='../salinity_restoring/woa_surface_salinity_monthly.nc')
filename='woa.nc',
target='../combine/woa_combined.nc')

# self.add_input_file(
# filename='woa.nc',
# target='../combine/woa_combined.nc')

# self.add_input_file(
# filename='topography.nc',
# target='../remap_topography/topography_remapped.nc')
self.add_input_file(
filename='topography.nc',
target='../remap_topography/topography_remapped.nc')

self.woa_filename = None

Expand Down

0 comments on commit b427336

Please sign in to comment.