Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add salinity restoring file generation #36

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ezhilsabareesh8
Copy link
Contributor

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
Contributor 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 COSIMA/access-om3#207

@anton-seaice
Copy link
Contributor

@ezhilsabareesh8
Copy link
Contributor 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?

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