Changes between Version 4 and Version 5 of Documentation/UserGuide/Perturb


Ignore:
Timestamp:
2017-01-19T10:30:22+01:00 (7 years ago)
Author:
luyssaert
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/UserGuide/Perturb

    v4 v5  
    2020The folder /ccc/store/cont003/dsm/p529luy/IGCM_OUT/LMDZ/ELI-128x118x39-2010-R2 should now look as an independent folder. The initial atmospheric conditions are given in /ccc/store/cont003/dsm/p529luy/IGCM_OUT/LMDZ/ELI-128x118x39-2010-R2/ATM/Output/Restart/ in the file JOBNAME_YEAR_start.nc as the variable called TETA. Subsequently we will open this file, perturb TETA by a random field of small perturbations and then save the file with a perturbed value for TETA. Several libraries with ncdf4 functionality (confirmed for nco, R and python) contain commands that enable you to manipulate a variable in a netcdf file. In this example a python script was used to perform these tasks. 
    2121 
     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#------------------------------------------------------------------- 
     33import netCDF4 
     34from netCDF4 import Dataset 
     35import numpy as np 
    2236 
     37#---------------------------------------------------------------- 
     38# Simulation settings 
     39#---------------------------------------------------------------- 
     40year = 2101 
     41mu = 0.0 
     42sigma = 0.00001 
     43jobname = 'ELI-128x118x39-2100-RCP85-P2' 
     44path = '/ccc/store/cont003/dsm/p529luy/IGCM_OUT/LMDZ/'+ jobname+'/ATM/Output/Restart/' 
     45file_name = jobname +'_'+str(year)+'_start.nc' 
    2346 
     47#---------------------------------------------------------------- 
     48# Open file and extract some dimensions  
     49#---------------------------------------------------------------- 
     50fullfile_name = path+file_name 
     51ncfile = Dataset(fullfile_name, mode='r+') 
     52lon = ncfile.variables['rlonu'] 
     53lat = ncfile.variables['rlatu'] 
     54lev = ncfile.variables['nivsigs'] 
     55teta = ncfile.variables['teta'] 
     56n_lon = len(lon) 
     57n_lat = len(lat) 
     58n_lev = len(lev) 
     59print teta[:,:,:,:] 
     60perturbation = np.random.normal(mu, sigma,[1,n_lev,n_lat,n_lon]) 
     61ncfile.variables['teta'][:,:,:,:] = teta[:,:,:,:] + perturbation[:,:,:,:] 
     62ncfile.close() 
     63}}} 
     64 
     65Before 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{{{ 
     67cd /ccc/store/cont003/dsm/p529luy/IGCM_OUT/LMDZ/ELI-128x118x39-2010-R2/ATM/Output/Restart/ 
     68cp JOBNAME_FIRESTYEAR_start.nc JOBNAME_FIRSTYEAR_start_original.nc 
     69chmod 744 JOBNAME_FIRESTYEAR_start.nc 
     70}}} 
     71 
     72If 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{{{ 
     74ferret 
     75use JOBNAME_FIRESTYEAR_start.nc; use JOBNAME_FIRESTYEAR_start_original.nc; shade TETA[k=1,d=1]-TETA[k=1,d=2]; go land 
     76}}} 
    2477 
    2578