| 22 | {{{ |
| 23 | #!/usr/bin/env python |
| 24 | #------------------------------------------------------------------- |
| 25 | # Objectives |
| 26 | #------------------------------------------------------------------- |
| 27 | # The script opens the limit file from LMDZOR and perturbs the |
| 28 | # initial temperature (TETA) as described by Fisher et al. |
| 29 | |
| 30 | #------------------------------------------------------------------- |
| 31 | # Load modules and functions Definitions |
| 32 | #------------------------------------------------------------------- |
| 33 | import netCDF4 |
| 34 | from netCDF4 import Dataset |
| 35 | import numpy as np |
| 47 | #---------------------------------------------------------------- |
| 48 | # Open file and extract some dimensions |
| 49 | #---------------------------------------------------------------- |
| 50 | fullfile_name = path+file_name |
| 51 | ncfile = Dataset(fullfile_name, mode='r+') |
| 52 | lon = ncfile.variables['rlonu'] |
| 53 | lat = ncfile.variables['rlatu'] |
| 54 | lev = ncfile.variables['nivsigs'] |
| 55 | teta = ncfile.variables['teta'] |
| 56 | n_lon = len(lon) |
| 57 | n_lat = len(lat) |
| 58 | n_lev = len(lev) |
| 59 | print teta[:,:,:,:] |
| 60 | perturbation = np.random.normal(mu, sigma,[1,n_lev,n_lat,n_lon]) |
| 61 | ncfile.variables['teta'][:,:,:,:] = teta[:,:,:,:] + perturbation[:,:,:,:] |
| 62 | ncfile.close() |
| 63 | }}} |
| 64 | |
| 65 | Before running the script, copy the initial start file because the script will overwrite it. If something goes wrong you will loose the initial values of the ELI simulation. Remember to change the permissions so that python can write the changes into the netcdf file. |
| 66 | {{{ |
| 67 | cd /ccc/store/cont003/dsm/p529luy/IGCM_OUT/LMDZ/ELI-128x118x39-2010-R2/ATM/Output/Restart/ |
| 68 | cp JOBNAME_FIRESTYEAR_start.nc JOBNAME_FIRSTYEAR_start_original.nc |
| 69 | chmod 744 JOBNAME_FIRESTYEAR_start.nc |
| 70 | }}} |
| 71 | |
| 72 | If all went well JOBNAME_FIRESTYEAR_start.nc should have been changed. This can be easily checked by comparing TETA in JOBNAME_FIRESTYEAR_start.nc against JOBNAME_FIRESTYEAR_start_original.nc. A map with the random perturbations should appear. For example, |
| 73 | {{{ |
| 74 | ferret |
| 75 | use JOBNAME_FIRESTYEAR_start.nc; use JOBNAME_FIRESTYEAR_start_original.nc; shade TETA[k=1,d=1]-TETA[k=1,d=2]; go land |
| 76 | }}} |