Skip to content
Snippets Groups Projects
Commit 1fdea7f9 authored by Aiko Voigt's avatar Aiko Voigt
Browse files

Fixes nan values in MAC-SP input aerosol file that cause crash in year 2017 and beyond

parent 159420fa
Branches
No related tags found
No related merge requests found
%% Cell type:markdown id:ddd5af91-af0b-4379-88d4-6edc6ef337b2 tags:
# Fix MAC-SP input data to use beyond year 2016.
Reason: all runs crash on Jan 5, 2017. This indicates that the crash is caused by some issue in the input data, instead of a model instability.
Indeed, it turns out to be caused by the fact that the MAC-SP aerosol data is nan beyond year 2016. This is fixed here by using the 2016 year values to extend the dataset to year 2100.
%% Cell type:code id:3b52083f-c1f5-406e-917c-97b385ccd6fd tags:
``` python
import numpy as np
import xarray as xr
import matplotlib.pyplot as plt
```
%% Cell type:code id:6ca6b837-288f-4d4f-8d21-521fe4b4ed57 tags:
``` python
# Load MAC SP
path="/home/fs72044/avoigt_teach/climlab_s2024/icon-esm-univie/data/"
macsp = xr.open_dataset(path+"MACv2.0-SP_v1.nc")
```
%% Cell type:markdown id:82cc7e00-3d3c-42cf-bea7-e60c6faa7129 tags:
The problem is caused by macsp.years_weight=nan beyond year 2016.
%% Cell type:code id:56b85c79-01c0-4feb-939a-2984e3b08fa5 tags:
``` python
macsp.year_weight.sel(years=slice(2015,2020)).values
```
%% Output
array([[0.71, 0.71, nan, nan, nan, nan],
[0.53, 0.53, nan, nan, nan, nan],
[0.99, 0.99, nan, nan, nan, nan],
[1.28, 1.28, nan, nan, nan, nan],
[1.23, 1.23, nan, nan, nan, nan],
[1.09, 1.09, nan, nan, nan, nan],
[1.1 , 1.1 , nan, nan, nan, nan],
[1.29, 1.29, nan, nan, nan, nan],
[0.94, 0.94, nan, nan, nan, nan]], dtype=float32)
%% Cell type:markdown id:a1d9f144-1a3e-421f-9028-c6f318b8b043 tags:
Create new dataset with year 2016 values used to fill the values from 2017 to 2100.
%% Cell type:code id:cc3b433e-835c-4d3b-8f29-df2f7149e684 tags:
``` python
macsp_beyond2016 = macsp.copy(deep=True)
for ind in np.arange(167,251):
macsp_beyond2016.year_weight[:,ind] = macsp.year_weight[:,166]
```
%% Cell type:code id:027f417c-9e45-44d4-b0e5-b4584326c54a tags:
``` python
# check
macsp_beyond2016["year_weight"].sel(years=slice(2016,2020)).values
```
%% Output
array([[0.71, 0.71, 0.71, 0.71, 0.71],
[0.53, 0.53, 0.53, 0.53, 0.53],
[0.99, 0.99, 0.99, 0.99, 0.99],
[1.28, 1.28, 1.28, 1.28, 1.28],
[1.23, 1.23, 1.23, 1.23, 1.23],
[1.09, 1.09, 1.09, 1.09, 1.09],
[1.1 , 1.1 , 1.1 , 1.1 , 1.1 ],
[1.29, 1.29, 1.29, 1.29, 1.29],
[0.94, 0.94, 0.94, 0.94, 0.94]], dtype=float32)
%% Cell type:code id:be3ea71b-1a0d-4176-8367-f502c8949dd0 tags:
``` python
# save to netcdf file
macsp_beyond2016.to_netcdf(path+"MACv2.0-SP_v1.fixed-for-use-beyond2016.nc")
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment