Skip to content

Conversation

ezhilsabareesh8
Copy link
Collaborator

This script processes and smooths sea water salinity data from the initial conditions NetCDF files generated using https://github.com/COSIMA/initial_conditions_access-om2 . It applies a uniform smoothing filter to the surface layer (0m depth) of the salinity for each month and concatenates the smoothed data into a single output NetCDF file.

@ezhilsabareesh8 ezhilsabareesh8 marked this pull request as ready for review September 19, 2024 05:19
@anton-seaice
Copy link
Contributor

Thanks @ezhilsabareesh8 - I will review soon.

I assume this uses the hh5 conda/analysis module ?

If you run black on the script and commit the change, then the formatting test should pass.

From the Readme:

Python scripts are formatted using the black formatter. This is enforced using a github action running on pull requests. You will need to have pre-commit and black installed in your python environment. It is included in the conda/analysis enviornments in hh5, otherwise it can be installed through pip or conda. Then run pre-commit install once to ensure your commits have black run on them before committing.

@ezhilsabareesh8
Copy link
Collaborator Author

Thanks @anton-seaice, I just reformatted it using black.

Copy link
Contributor

@anton-seaice anton-seaice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ezhilsabareesh8

If you keep the data as an xarray object, it will save having to recreate all the attributes and dimensions etc. See the suggestions


# Create a new NetCDF file using netCDF4
output_file = f"{output_path}/salt_sfc_restore.nc"
with nc.Dataset(output_file, "w", format="NETCDF4") as ncfile:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use xarray suggestions above, the only extra attributes you need are these (i think):

    salt_var.standard_name = "sea_water_salinity"
    salt_var.long_name = "Smoothed sea water salinity at level 0m"
    salt_var.units = "1"

you should just be able to set those and then say

salt_smoothed_da.to_netcdf()

@anton-seaice
Copy link
Contributor

Have a look now @ezhilsabareesh8 - this should work if we fix the time:units attribute in the source data

@anton-seaice
Copy link
Contributor

This change will contribute to https://github.com/COSIMA/access-om3/issues/207

@anton-seaice
Copy link
Contributor

anton-seaice commented Oct 1, 2024

@ezhilsabareesh8
Copy link
Collaborator Author

@anton-seaice I noticed that the time variable was changed to match the initial conditions, but the salinity restoring should actually begin at the middle of each month. In my original code, I had overwritten the time variable with:

times[:] = np.arange(0.5, 12.5, 1)  # Time values from 0.5 to 11.5
times.units = "months since 0001-01-01 00:00:00"

Could you please revert the changes made to the time variable in this commit 8b0c207?

@anton-seaice
Copy link
Contributor

@ezhilsabareesh8 - I think this script should go in https://github.com/ACCESS-NRI/initial_conditions_access-om3/ ?

@anton-seaice
Copy link
Contributor

Hi @ezhilsabareesh8

I pushed a couple of refinements to go with COSIMA/initial_conditions_access-om2#6

This is the time coordinate now, which should be correct by cf-conventions and be the middle of the month

 time = 15.5, 45, 74.5, 105, 135.5, 166, 196.5, 227.5, 258, 288.5, 319, 349.5 ;

 double time(time) ;
                time:_FillValue = NaN ;
                time:standard_name = "time" ;
                time:long_name = "time" ;
                time:axis = "T" ;
                time:climatology = "climatology_bounds" ;
                time:units = "days since 1955-01-01" ;
                time:calendar = "gregorian" ;

I am running some tests now, can you see any issues ?

This is the diff between /g/data/vk83/prerelease/configurations/inputs/access-om3/mom/surface_salt_restoring/global.25km/2025.01.30/salt_sfc_restore.nc and my new one in January. Its bigger than expected, can that be explained by the changes we made to the initial conditions (e.g. 75 levels instead of 150 ?)

image

@ezhilsabareesh8
Copy link
Collaborator Author

Its bigger than expected, can that be explained by the changes we made to the initial conditions (e.g. 75 levels instead of 150 ?)

We are using the surface salinity for restoring and smoothing it horizontally, as discussed here., so I don't think that the difference is due to the change in vertical levels.

@ezhilsabareesh8
Copy link
Collaborator Author

There's no surface salinity difference between the old initial conditions /g/data/vk83/prerelease/configurations/inputs/access-om3/mom/initial_conditions/global.25km/2025.03.19/ocean_temp_salt.res.nc and new initial conditions /g/data/vk83/prerelease/configurations/inputs/access-om3/mom/initial_conditions/global.25km/2025.06.17/ocean_temp_salt.res.nc.

Screenshot 2025-06-17 at 12 24 00 pm

@anton-seaice
Copy link
Contributor

Thanks - in the 25km we are using the 2025.01.30 version of the salinity restoring still.

Looking at the 2025.01.30 initial conditions, it has 38 levels, and the top layer is at 1.083m, however in the new initial conditions, the top layer is at 0m. That's why we are seeing the difference.

New-old, top layer:

image

New-old, 1.083m layer:
image

If you are happy, feel free to merge this :)

@anton-seaice
Copy link
Contributor

anton-seaice commented Jun 17, 2025

Oh I also ran the 25km for a year with the new salinity restore file and it appears to run ok

@ezhilsabareesh8
Copy link
Collaborator Author

Thanks @anton-seaice. It looks good to me.

@ezhilsabareesh8 ezhilsabareesh8 merged commit 53ffea8 into main Jun 19, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants