<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Maurel</id>
		<title>Planets - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Maurel"/>
		<link rel="alternate" type="text/html" href="http://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/index.php/Special:Contributions/Maurel"/>
		<updated>2026-06-11T03:55:17Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.7</generator>

	<entry>
		<id>http://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/index.php?title=Tool_Box&amp;diff=1060</id>
		<title>Tool Box</title>
		<link rel="alternate" type="text/html" href="http://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/index.php?title=Tool_Box&amp;diff=1060"/>
				<updated>2022-11-23T15:36:58Z</updated>
		
		<summary type="html">&lt;p&gt;Maurel: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Pre-processing Tools ==&lt;br /&gt;
=== newstart: a fortran program to modify start files ===&lt;br /&gt;
&lt;br /&gt;
Newstart is an interactive tool to modify the start files (''start.nc'' and ''startfi.nc''). &lt;br /&gt;
&lt;br /&gt;
To be usable, ''newstart'' should be compile in the ''LMDZ.COMMON'' directory by using the following command line:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./makelmdz_fcm -arch my_arch_file -p std -d 64x48x30 newstart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In the example, my_arch_file is the name the arch files (see [https://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/index.php/The_Target_Architecture_(%22arch%22)_Files arch] ) and 64x48x30 is the resolution of the physical grid.&lt;br /&gt;
Then copy the executable from the ''LMDZ.COMMON/bin'' directory to your bench directory.&lt;br /&gt;
&lt;br /&gt;
When you execute newstart, you can use both a ''start2archive'' file or the start files (''start.nc'' and ''startfi.nc''). Then the interactive interface will propose to modify several physical quantities such as the gravity, the surface pressure or the rotation of the planet. At the end of the procedure, two files are created: '' '''re'''start.nc'' and '' '''re'''startfi.nc''. They can be renamed and used as start files to initialize a new simulation.&lt;br /&gt;
&lt;br /&gt;
=== start2archive ===&lt;br /&gt;
&lt;br /&gt;
The start2archive tool is similar to newstart in the sense that it can be used to modify the start files. But start2archive can modify the resolution of the physical grid, the topography and the surface thermal inertia while newstart cannot. It is also useful to create an archive of different starting states, then extractable as start files.&lt;br /&gt;
The command line to compile start2archive is similar to the one used for newstart:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./makelmdz_fcm -arch my_arch_file -p std -d 64x48x30 start2archive&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To modify the resolution, you should first create a start_archive (by using start2archive) file at the used resolution, then compile a newstart file at the new resolution. Newstart will interpolate all the physical quantities on the new grid.&lt;br /&gt;
&lt;br /&gt;
=== other third party scripts and tools ===&lt;br /&gt;
&lt;br /&gt;
TO BE COMPLETED&lt;br /&gt;
&lt;br /&gt;
== Post-processing tools ==&lt;br /&gt;
=== zrecast ===&lt;br /&gt;
&lt;br /&gt;
With this program you can recast atmospheric (i.e.: 4D-dimentional longitude-latitude-altitude-time) data from&lt;br /&gt;
GCM outputs (e.g. as given in diagfi.nc files) onto either ''pressure'' or ''altitude'' above ''areoid vertical'' coordinates.&lt;br /&gt;
Since integrating the hydrostatic equation is required to recast the data, the input file must contain surface pressure&lt;br /&gt;
and atmospheric temperature, as well as the ground geopotential.&lt;br /&gt;
If recasting data onto ''pressure'' coordinates, then the output file name is given by the input file name to which ''_P.nc'' will be appened. If recasting data onto altitude above areoid coordinates, then a ''_A.nc'' will be appened.&lt;br /&gt;
&lt;br /&gt;
=== mass stream function ===&lt;br /&gt;
&lt;br /&gt;
The mass stream function (and the total angular momentum) can be computed from a diagfi.nc or a stats.nc, using the '''streamfunction.F90''' script. The script is located at&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
trunk/LMDZ.GENERIC/utilities&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To compile the script, open the ''compile'' file in the same directory and do the following:&lt;br /&gt;
* Replace &amp;quot;pgf90&amp;quot; with your favorite fortran compiler &lt;br /&gt;
* replace &amp;quot;/distrib/local/netcdf/pgi_7.1-6_32/lib&amp;quot; with the lib address and directory that contains your NetCDF library (file ''libnetcdf.a'').&lt;br /&gt;
* Replace &amp;quot;/distrib/local/netcdf/pgi_7.1-6_32/include&amp;quot; with the address of the directory that contains the NetCDF include file (''netcdf.inc'').&lt;br /&gt;
* You can mess with the compiling options but it is not mandatory.&lt;br /&gt;
&lt;br /&gt;
Once the script is compiled, copy it in the same directory as your '''.nc''' file and run &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./streamfunction.e&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The script will ask you for the name of your '''.nc''' file, and will run and produce a new '''nameofyourfile_stream.nc''' file.&lt;br /&gt;
&lt;br /&gt;
'''Be careful''' : In this new file, all fields are temporally and zonally averaged.&lt;br /&gt;
&lt;br /&gt;
If you want to use '''python''' instead of '''fortran''', you can take a look at this [https://github.com/aymeric-spiga/dynanalysis repo]. It hosts a tool to perform dynamical analysis of GCM simulations (and therefore, it computes the mass stream function and a lot of other stuff), but it is tailored for Dynamico only. This repo also takes care of recasting (it does the job of both ''zrecast.F90'' and ''streamfunction.F90'')&lt;br /&gt;
&lt;br /&gt;
== Continuing Simulations ==&lt;br /&gt;
&lt;br /&gt;
=== manually ===&lt;br /&gt;
&lt;br /&gt;
At the end of a simulation, the model generates restart files (files 'restart.nc' and 'restartfi.nc') which contain the final state of the model. The 'restart.nc' and 'restartfi.nc' files have the same format as the 'start.nc' and 'startfi.nc' files, respectively. &lt;br /&gt;
&lt;br /&gt;
These files can in fact be used as initial states to continue the simulation, using the following renaming command lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mv restart.nc start.nc&lt;br /&gt;
mv restartfi.nc startfi.nc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running a simulation with these start files will in fact resume the simulation from where the previous run ended.&lt;br /&gt;
&lt;br /&gt;
=== with bash scripts ===&lt;br /&gt;
&lt;br /&gt;
We have set up very simple bash scripts to automatize the launching of chain simulations. Here is an example of bash script that does the job:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
###########################################################################&lt;br /&gt;
# Script to perform several chained LMD Mars GCM simulations&lt;br /&gt;
# SET HERE the maximum total number of simulations&lt;br /&gt;
&lt;br /&gt;
nummax=100&lt;br /&gt;
&lt;br /&gt;
###########################################################################&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;---------------------------------------------------------&amp;quot;&lt;br /&gt;
echo &amp;quot;STARTING LOOP RUN&amp;quot;&lt;br /&gt;
echo &amp;quot;---------------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
dir=`pwd`&lt;br /&gt;
machine=`hostname`&lt;br /&gt;
address=`whoami`&lt;br /&gt;
&lt;br /&gt;
# Look for file &amp;quot;num_run&amp;quot; which should contain &lt;br /&gt;
# the value of the previously computed season&lt;br /&gt;
# (defaults to 0 if file &amp;quot;num_run&amp;quot; does not exist)&lt;br /&gt;
if [[ -r num_run ]] ; then&lt;br /&gt;
  echo &amp;quot;found file num_run&amp;quot;&lt;br /&gt;
  numold=`cat num_run`&lt;br /&gt;
else&lt;br /&gt;
  numold=0&lt;br /&gt;
fi&lt;br /&gt;
echo &amp;quot;numold is set to&amp;quot; ${numold}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Set value of current season &lt;br /&gt;
(( numnew = ${numold} + 1 ))&lt;br /&gt;
echo &amp;quot;numnew is set to&amp;quot; ${numnew}&lt;br /&gt;
&lt;br /&gt;
# Look for initialization data files (exit if none found)&lt;br /&gt;
if [[ ( -r start${numold}.nc  &amp;amp;&amp;amp;  -r startfi${numold}.nc ) ]] ; then&lt;br /&gt;
   \cp -f start${numold}.nc start.nc&lt;br /&gt;
   \cp -f startfi${numold}.nc startfi.nc&lt;br /&gt;
else&lt;br /&gt;
   if (( ${numold} == 99999 )) ; then&lt;br /&gt;
    echo &amp;quot;No run because previous run crashed ! (99999 in num_run)&amp;quot;&lt;br /&gt;
    exit&lt;br /&gt;
   else&lt;br /&gt;
   echo &amp;quot;Where is file start&amp;quot;${numold}&amp;quot;.nc??&amp;quot;&lt;br /&gt;
   exit&lt;br /&gt;
   fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Run GCM -- THIS LINE NEEDS TO BE MODIFIED WITH THE CORRECT GCM EXECUTION COMMAND&lt;br /&gt;
mpirun -np 8 gcm_64x48x26_phystd_para.e &amp;lt; diagfi.def &amp;gt; lrun${numnew}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Check if run ended normaly and copy datafiles&lt;br /&gt;
if [[ ( -r restartfi.nc  &amp;amp;&amp;amp;  -r restart.nc ) ]] ; then&lt;br /&gt;
  echo &amp;quot;Run seems to have ended normaly&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  \mv -f restart.nc start${numnew}.nc&lt;br /&gt;
  \mv -f restartfi.nc startfi${numnew}.nc  &lt;br /&gt;
    &lt;br /&gt;
else&lt;br /&gt;
  if [[ -r num_run ]] ; then&lt;br /&gt;
    \mv -f num_run num_run.crash&lt;br /&gt;
  else&lt;br /&gt;
    echo &amp;quot;No file num_run to build num_run.crash from !!&amp;quot;&lt;br /&gt;
    # Impose a default value of 0 for num_run&lt;br /&gt;
    echo 0 &amp;gt; num_run.crash&lt;br /&gt;
  fi&lt;br /&gt;
 echo 99999 &amp;gt; num_run&lt;br /&gt;
 exit&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Copy other datafiles that may have been generated&lt;br /&gt;
if [[ -r diagfi.nc ]] ; then&lt;br /&gt;
  \mv -f diagfi.nc diagfi${numnew}.nc&lt;br /&gt;
fi&lt;br /&gt;
if [[ -r diagsoil.nc ]] ; then&lt;br /&gt;
  \mv -f diagsoil.nc diagsoil${numnew}.nc&lt;br /&gt;
fi&lt;br /&gt;
if [[ -r stats.nc ]] ; then&lt;br /&gt;
  \mv -f stats.nc stats${numnew}.nc&lt;br /&gt;
fi&lt;br /&gt;
if [[ -f profiles.dat ]] ; then&lt;br /&gt;
  \mv -f profiles.dat profiles${numnew}.dat&lt;br /&gt;
  \mv -f profiles.hdr profiles${numnew}.hdr&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Prepare things for upcoming runs by writing&lt;br /&gt;
# value of computed season in file num_run&lt;br /&gt;
echo ${numnew} &amp;gt; num_run&lt;br /&gt;
&lt;br /&gt;
# If we are over nummax : stop&lt;br /&gt;
if (( $numnew + 1 &amp;gt; $nummax )) ; then&lt;br /&gt;
   exit&lt;br /&gt;
# If not : restart the loop (copy the executable and run the copy)&lt;br /&gt;
else&lt;br /&gt;
   \cp -f run_gnome exe_mars&lt;br /&gt;
   ./exe_mars&lt;br /&gt;
fi &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Summary of what this bash script does''':&lt;br /&gt;
&lt;br /&gt;
* It reads the file 'num_run' which contains the step of the simulation. &lt;br /&gt;
If num_run is&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then the script expects to read start5.nc and startfi5.nc.&lt;br /&gt;
* It modifies start5.nc and startfi5.nc into start.nc and startfi.nc, respectively.&lt;br /&gt;
* It runs the GCM.&lt;br /&gt;
* It modifies restart.nc and restartfi.nc into start6.nc and startfi6.nc&lt;br /&gt;
* It rewrite num_run as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
6&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* It restarts the loop until num_run reaches the value (defined in nummax):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
100&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Processing Output Files with NCOs ==&lt;br /&gt;
&lt;br /&gt;
NCOs (NetCdf OperatorS) are a set of powerful command-line utilities – available on Linux, Mac and PC – that allow to perform useful (and very fast!) post-processing operations on netCDF GCM output files. Full documentation can be found on http://research.jisao.washington.edu/data_sets/nco/, but we provide below a few examples of command lines.&lt;br /&gt;
&lt;br /&gt;
* How to calculate a time mean of a netCDF 'diagfi.nc' file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ncra -F -d Time,1,,1 diagfi.nc diagfi_MEAN.nc # format is &amp;quot;-d dimension,minimum,maximum,stride&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Subsetting time in a netCDF 'diagfi.nc' file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ncea -F -d Time,first,last diagfi.nc diagfi_subset.nc # format is &amp;quot;-d dimension,minimum,maximum&amp;quot; ; we recall you can type &amp;quot;ncdump -v time diagfi.nc&amp;quot; to see the Time values in the netCDF file.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Decimating a netCDF 'diagfi.nc' file in time&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ncks -F -d Time,1,,8 diagfi.nc diagfi_decimated.nc # format is &amp;quot;-d dimension,minimum,maximum,stride&amp;quot; ; In this example, this means that data is extracted 1 time every 8 time steps, starting from the first time step (number 1), ending at the last time step).&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Extract a variable from a netCDF 'diagfi.nc' file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ncks -v tsurf,temp,p diagfi.nc diagfi_out.nc # Here we created a new file named 'diagfi_out.nc' in which we only kept variables named 'tsurf' (surface temperatures), 'temp' (atmospheric temperatures) and p (atmospheric pressures).&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Again, more examples can be found on http://research.jisao.washington.edu/data_sets/nco/ .&lt;br /&gt;
&lt;br /&gt;
== Data Handling and Visualization Software ==&lt;br /&gt;
&lt;br /&gt;
There are several data handling and visualization tools that can be used to analyse and plot the results from GCM simulations (using the diagfi.nc NetCDF files). We provide below a panorama of most widely used solutions.&lt;br /&gt;
&lt;br /&gt;
=== panoply ===&lt;br /&gt;
Panoply is a user-friendly tool for viewing raw NetCDF data, available here: https://www.giss.nasa.gov/tools/panoply/ . It is very convenient to make pretty visuals (see an example for the exoplanet TRAPPIST-1e). There are many options that can be used (map projections, masks, colorbars, shadows, etc.) to make your plots fancy. However, the tool is not very well suited for manipulating data (compute averages, statistics, etc.).&lt;br /&gt;
&lt;br /&gt;
[[File:Example panoply.png|thumb|Screenshot of panoply showing here Generic PCM results for the exoplanet TRAPPIST-1e (surface temperatures)]]&lt;br /&gt;
&lt;br /&gt;
=== ncview ===&lt;br /&gt;
ncview is another useful user-friendly tool for viewing raw NetCDF data. This is kind of a very archaic version of panoply, but it is convenient because it allows to have a very quick first look at netCDF data files.&lt;br /&gt;
&lt;br /&gt;
Command line tool to visualize NetCDF data:&lt;br /&gt;
* Installation on Linux:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install ncview&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Run on Linux:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ncview diagfi.nc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Example ncview.png|thumb|Screenshot of ncview showing here Generic PCM results for the exoplanet Proxima b (OLR - Thermal Emission)]]&lt;br /&gt;
&lt;br /&gt;
=== python scripts ===&lt;br /&gt;
&lt;br /&gt;
Python scripts provide a very useful mean to analyse and visualize netCDF files.&lt;br /&gt;
&lt;br /&gt;
You can use the netCDF4 python library to open a netCDF file and put data in tables that can then be manipulated and plotted.&lt;br /&gt;
&lt;br /&gt;
Here is an exemple of how to open and read a netCDF file with Python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
import numpy&lt;br /&gt;
from netCDF4 import Dataset&lt;br /&gt;
&lt;br /&gt;
# HERE WE OPEN THE NETCDF FILE&lt;br /&gt;
nc = Dataset('diagfi.nc')&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ THE VARIABLES (1D OUTPUT)&lt;br /&gt;
Time=nc.variables['Time'][:]&lt;br /&gt;
lat=nc.variables['latitude'][:]&lt;br /&gt;
lon=nc.variables['longitude'][:]&lt;br /&gt;
al=nc.variables['altitude'][:]&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ THE AREA (2D OUTPUT)&lt;br /&gt;
aire_GCM=nc.variables['aire'][:][:]&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ 3D OUTPUTS&lt;br /&gt;
tsurf=nc.variables['tsurf'][:][:][:] # this is the surface temperature 3D field (time, latitude, longitude, altitude)&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ 4D OUTPUTS&lt;br /&gt;
temp=nc.variables['temp'][:][:][:][:] # this is the atmospheric temperature 4D field (time, latitude, longitude, altitude)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here is an exemple of how to manipulate the netCDF data (here to compute the time averaged surface temperatures):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
from numpy import *&lt;br /&gt;
import numpy as np&lt;br /&gt;
&lt;br /&gt;
mean_tsurf=np.zeros((len(lat),len(lon)),dtype='f')&lt;br /&gt;
&lt;br /&gt;
for i in range(0,len(Time)):&lt;br /&gt;
    for j in range(0,len(lat)):&lt;br /&gt;
        for k in range(0,len(lon)):&lt;br /&gt;
            mean_tsurf[j,k]=mean_tsurf[j,k]+tsurf[i,j,k]*(1./len(Time))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here is a last exemple of how to plot the data (using matplotlib):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
plt.figure(1)&lt;br /&gt;
plt.contourf(lon_GCM,lat_GCM,mean_tsurf)&lt;br /&gt;
plt.colorbar(label='Surface Temperature (K)')&lt;br /&gt;
plt.xlabel('Longitude ($^{\circ}$)')&lt;br /&gt;
plt.ylabel('Latitude ($^{\circ}$)')&lt;br /&gt;
plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another useful library to deal with netcdf files is ''xarray''. We provide a code snippet below, doing the same thing as the snippets above.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
import numpy as np&lt;br /&gt;
import xarray as xr &lt;br /&gt;
import matplotlib.pyplot as plt &lt;br /&gt;
&lt;br /&gt;
# HERE WE OPEN THE NETCDF FILE&lt;br /&gt;
data = xr.open_dataset('diagfi.nc',&lt;br /&gt;
                       decode_times=False)&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ THE VARIABLES (1D OUTPUT)&lt;br /&gt;
Time=data['Time']&lt;br /&gt;
lat=data['latitude']&lt;br /&gt;
lon=data['longitude']&lt;br /&gt;
al=data['altitude']&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ THE AREA (2D OUTPUT)&lt;br /&gt;
aire_GCM=data['aire']&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ 3D OUTPUTS&lt;br /&gt;
tsurf=data['tsurf'] # this is the surface temperature 3D field (time, latitude, longitude, altitude)&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ 4D OUTPUTS&lt;br /&gt;
temp=data['temp'] # this is the atmospheric temperature 4D field (time, latitude, longitude, altitude)&lt;br /&gt;
&lt;br /&gt;
## let's take the time-averaged surface temperature&lt;br /&gt;
mean_tsurf = np.mean(tsurf,axis=0)&lt;br /&gt;
&lt;br /&gt;
##Let's plot a lon-lat map&lt;br /&gt;
fig = plt.figure()&lt;br /&gt;
plt.contourf(lon,lat,mean_tsurf)&lt;br /&gt;
plt.colorbar(label='Surface Temperature (K)')&lt;br /&gt;
plt.xlabel('Longitude ($^{\circ}$)')&lt;br /&gt;
plt.ylabel('Latitude ($^{\circ}$)')&lt;br /&gt;
plt.show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
For more examples on how to use ''xarray'', take a look at the [https://docs.xarray.dev/en/stable/index.html documentation].&lt;br /&gt;
Here is another example of how one can use xarray with multiples netcdfiles.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import xarray as xr&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
# your folder where output files are stored&lt;br /&gt;
FOLDER = './your_folder_with_output_files/'&lt;br /&gt;
&lt;br /&gt;
# take back the files from your FOLDER&lt;br /&gt;
list_files_folder=os.listdir(FOLDER)&lt;br /&gt;
&lt;br /&gt;
# If there are several files.&lt;br /&gt;
# Sort your simulation files by date,&lt;br /&gt;
# so beginning of simulation will be top of the list&lt;br /&gt;
# and end of simulation will be end of the list.&lt;br /&gt;
list_files_folder.sort()&lt;br /&gt;
&lt;br /&gt;
files = [FOLDER+str(f) for f in list_files_folder]&lt;br /&gt;
# if you want to keep only files of special_year you can add this option :&lt;br /&gt;
# files = [FOLDER+str(f) for f in list_files_folder if f.startswith(&amp;quot;special_year&amp;quot;)]&lt;br /&gt;
&lt;br /&gt;
# xarray will magically concatenate your outfiles by 'Time' (or any other 'concat_dime' you want)&lt;br /&gt;
nc=xr.open_mfdataset(files,decode_times=False, concat_dim='Time', combine='nested')&lt;br /&gt;
&lt;br /&gt;
# to check your keys&lt;br /&gt;
for key in nc.keys():&lt;br /&gt;
    print(key)&lt;br /&gt;
&lt;br /&gt;
# to load keys (example here with keys for a mesoscale simulation)&lt;br /&gt;
Times = nc['Times'][:]&lt;br /&gt;
PTOT = nc['PTOT'][:]&lt;br /&gt;
T = nc['T'][:]&lt;br /&gt;
W = nc['W'][:]&lt;br /&gt;
&lt;br /&gt;
# you can use some functions to make averages etc&lt;br /&gt;
&lt;br /&gt;
T_moy = T.mean(dim=['Time','south_north','west_east'])&lt;br /&gt;
&lt;br /&gt;
# other functions&lt;br /&gt;
# .cumsum (cumulative sum)&lt;br /&gt;
# .rename (change the name of the object)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NB: ADD SOMETHING HERE ABOUT XARRAY LIBRARY? AYMERIC? (with a simple tutorial?) TBD&lt;br /&gt;
&lt;br /&gt;
We provide a tutorial on how to make pretty visuals using Generic PCM 3-D simulations [https://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/index.php/Plots_With_PyVista here].&lt;br /&gt;
&lt;br /&gt;
=== Planetoplot ===&lt;br /&gt;
&lt;br /&gt;
Planetoplot is a in-house, python based library developped to vizualize Generic PCM data.&lt;br /&gt;
&lt;br /&gt;
The code and documentation can be found at: https://nbviewer.org/github/aymeric-spiga/planetoplot/blob/master/tutorial/planetoplot_tutorial.ipynb&lt;/div&gt;</summary>
		<author><name>Maurel</name></author>	</entry>

	<entry>
		<id>http://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/index.php?title=Tool_Box&amp;diff=1059</id>
		<title>Tool Box</title>
		<link rel="alternate" type="text/html" href="http://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/index.php?title=Tool_Box&amp;diff=1059"/>
				<updated>2022-11-23T15:25:02Z</updated>
		
		<summary type="html">&lt;p&gt;Maurel: comment in the bash script for continuing sims for the restart of the loop&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Pre-processing Tools ==&lt;br /&gt;
=== newstart: a fortran program to modify start files ===&lt;br /&gt;
&lt;br /&gt;
Newstart is an interactive tool to modify the start files (''start.nc'' and ''startfi.nc''). &lt;br /&gt;
&lt;br /&gt;
To be usable, ''newstart'' should be compile in the ''LMDZ.COMMON'' directory by using the following command line:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./makelmdz_fcm -arch my_arch_file -p std -d 64x48x30 newstart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In the example, my_arch_file is the name the arch files (see [https://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/index.php/The_Target_Architecture_(%22arch%22)_Files arch] ) and 64x48x30 is the resolution of the physical grid.&lt;br /&gt;
Then copy the executable from the ''LMDZ.COMMON/bin'' directory to your bench directory.&lt;br /&gt;
&lt;br /&gt;
When you execute newstart, you can use both a ''start2archive'' file or the start files (''start.nc'' and ''startfi.nc''). Then the interactive interface will propose to modify several physical quantities such as the gravity, the surface pressure or the rotation of the planet. At the end of the procedure, two files are created: '' '''re'''start.nc'' and '' '''re'''startfi.nc''. They can be renamed and used as start files to initialize a new simulation.&lt;br /&gt;
&lt;br /&gt;
=== start2archive ===&lt;br /&gt;
&lt;br /&gt;
The start2archive tool is similar to newstart in the sense that it can be used to modify the start files. But start2archive can modify the resolution of the physical grid, the topography and the surface thermal inertia while newstart cannot. It is also useful to create an archive of different starting states, then extractable as start files.&lt;br /&gt;
The command line to compile start2archive is similar to the one used for newstart:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./makelmdz_fcm -arch my_arch_file -p std -d 64x48x30 start2archive&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To modify the resolution, you should first create a start_archive (by using start2archive) file at the used resolution, then compile a newstart file at the new resolution. Newstart will interpolate all the physical quantities on the new grid.&lt;br /&gt;
&lt;br /&gt;
=== other third party scripts and tools ===&lt;br /&gt;
&lt;br /&gt;
TO BE COMPLETED&lt;br /&gt;
&lt;br /&gt;
== Post-processing tools ==&lt;br /&gt;
=== zrecast ===&lt;br /&gt;
&lt;br /&gt;
With this program you can recast atmospheric (i.e.: 4D-dimentional longitude-latitude-altitude-time) data from&lt;br /&gt;
GCM outputs (e.g. as given in diagfi.nc files) onto either ''pressure'' or ''altitude'' above ''areoid vertical'' coordinates.&lt;br /&gt;
Since integrating the hydrostatic equation is required to recast the data, the input file must contain surface pressure&lt;br /&gt;
and atmospheric temperature, as well as the ground geopotential.&lt;br /&gt;
If recasting data onto ''pressure'' coordinates, then the output file name is given by the input file name to which ''_P.nc'' will be appened. If recasting data onto altitude above areoid coordinates, then a ''_A.nc'' will be appened.&lt;br /&gt;
&lt;br /&gt;
=== mass stream function ===&lt;br /&gt;
&lt;br /&gt;
The mass stream function (and the total angular momentum) can be computed from a diagfi.nc or a stats.nc, using the '''streamfunction.F90''' script. The script is located at&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
trunk/LMDZ.GENERIC/utilities&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To compile the script, open the ''compile'' file in the same directory and do the following:&lt;br /&gt;
* Replace &amp;quot;pgf90&amp;quot; with your favorite fortran compiler &lt;br /&gt;
* replace &amp;quot;/distrib/local/netcdf/pgi_7.1-6_32/lib&amp;quot; with the lib address and directory that contains your NetCDF library (file ''libnetcdf.a'').&lt;br /&gt;
* Replace &amp;quot;/distrib/local/netcdf/pgi_7.1-6_32/include&amp;quot; with the address of the directory that contains the NetCDF include file (''netcdf.inc'').&lt;br /&gt;
* You can mess with the compiling options but it is not mandatory.&lt;br /&gt;
&lt;br /&gt;
Once the script is compiled, copy it in the same directory as your '''.nc''' file and run &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./streamfunction.e&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The script will ask you for the name of your '''.nc''' file, and will run and produce a new '''nameofyourfile_stream.nc''' file.&lt;br /&gt;
&lt;br /&gt;
'''Be careful''' : In this new file, all fields are temporally and zonally averaged.&lt;br /&gt;
&lt;br /&gt;
If you want to use '''python''' instead of '''fortran''', you can take a look at this [https://github.com/aymeric-spiga/dynanalysis repo]. It hosts a tool to perform dynamical analysis of GCM simulations (and therefore, it computes the mass stream function and a lot of other stuff), but it is tailored for Dynamico only. This repo also takes care of recasting (it does the job of both ''zrecast.F90'' and ''streamfunction.F90'')&lt;br /&gt;
&lt;br /&gt;
== Continuing Simulations ==&lt;br /&gt;
&lt;br /&gt;
=== manually ===&lt;br /&gt;
&lt;br /&gt;
At the end of a simulation, the model generates restart files (files 'restart.nc' and 'restartfi.nc') which contain the final state of the model. The 'restart.nc' and 'restartfi.nc' files have the same format as the 'start.nc' and 'startfi.nc' files, respectively. &lt;br /&gt;
&lt;br /&gt;
These files can in fact be used as initial states to continue the simulation, using the following renaming command lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mv restart.nc start.nc&lt;br /&gt;
mv restartfi.nc startfi.nc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running a simulation with these start files will in fact resume the simulation from where the previous run ended.&lt;br /&gt;
&lt;br /&gt;
=== with bash scripts ===&lt;br /&gt;
&lt;br /&gt;
We have set up very simple bash scripts to automatize the launching of chain simulations. Here is an example of bash script that does the job:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
###########################################################################&lt;br /&gt;
# Script to perform several chained LMD Mars GCM simulations&lt;br /&gt;
# SET HERE the maximum total number of simulations&lt;br /&gt;
&lt;br /&gt;
nummax=100&lt;br /&gt;
&lt;br /&gt;
###########################################################################&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;---------------------------------------------------------&amp;quot;&lt;br /&gt;
echo &amp;quot;STARTING LOOP RUN&amp;quot;&lt;br /&gt;
echo &amp;quot;---------------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
dir=`pwd`&lt;br /&gt;
machine=`hostname`&lt;br /&gt;
address=`whoami`&lt;br /&gt;
&lt;br /&gt;
# Look for file &amp;quot;num_run&amp;quot; which should contain &lt;br /&gt;
# the value of the previously computed season&lt;br /&gt;
# (defaults to 0 if file &amp;quot;num_run&amp;quot; does not exist)&lt;br /&gt;
if [[ -r num_run ]] ; then&lt;br /&gt;
  echo &amp;quot;found file num_run&amp;quot;&lt;br /&gt;
  numold=`cat num_run`&lt;br /&gt;
else&lt;br /&gt;
  numold=0&lt;br /&gt;
fi&lt;br /&gt;
echo &amp;quot;numold is set to&amp;quot; ${numold}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Set value of current season &lt;br /&gt;
(( numnew = ${numold} + 1 ))&lt;br /&gt;
echo &amp;quot;numnew is set to&amp;quot; ${numnew}&lt;br /&gt;
&lt;br /&gt;
# Look for initialization data files (exit if none found)&lt;br /&gt;
if [[ ( -r start${numold}.nc  &amp;amp;&amp;amp;  -r startfi${numold}.nc ) ]] ; then&lt;br /&gt;
   \cp -f start${numold}.nc start.nc&lt;br /&gt;
   \cp -f startfi${numold}.nc startfi.nc&lt;br /&gt;
else&lt;br /&gt;
   if (( ${numold} == 99999 )) ; then&lt;br /&gt;
    echo &amp;quot;No run because previous run crashed ! (99999 in num_run)&amp;quot;&lt;br /&gt;
    exit&lt;br /&gt;
   else&lt;br /&gt;
   echo &amp;quot;Where is file start&amp;quot;${numold}&amp;quot;.nc??&amp;quot;&lt;br /&gt;
   exit&lt;br /&gt;
   fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Run GCM -- THIS LINE NEEDS TO BE MODIFIED WITH THE CORRECT GCM EXECUTION COMMAND&lt;br /&gt;
mpirun -np 8 gcm_64x48x26_phystd_para.e &amp;lt; diagfi.def &amp;gt; lrun${numnew}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Check if run ended normaly and copy datafiles&lt;br /&gt;
if [[ ( -r restartfi.nc  &amp;amp;&amp;amp;  -r restart.nc ) ]] ; then&lt;br /&gt;
  echo &amp;quot;Run seems to have ended normaly&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  \mv -f restart.nc start${numnew}.nc&lt;br /&gt;
  \mv -f restartfi.nc startfi${numnew}.nc  &lt;br /&gt;
    &lt;br /&gt;
else&lt;br /&gt;
  if [[ -r num_run ]] ; then&lt;br /&gt;
    \mv -f num_run num_run.crash&lt;br /&gt;
  else&lt;br /&gt;
    echo &amp;quot;No file num_run to build num_run.crash from !!&amp;quot;&lt;br /&gt;
    # Impose a default value of 0 for num_run&lt;br /&gt;
    echo 0 &amp;gt; num_run.crash&lt;br /&gt;
  fi&lt;br /&gt;
 echo 99999 &amp;gt; num_run&lt;br /&gt;
 exit&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Copy other datafiles that may have been generated&lt;br /&gt;
if [[ -r diagfi.nc ]] ; then&lt;br /&gt;
  \mv -f diagfi.nc diagfi${numnew}.nc&lt;br /&gt;
fi&lt;br /&gt;
if [[ -r diagsoil.nc ]] ; then&lt;br /&gt;
  \mv -f diagsoil.nc diagsoil${numnew}.nc&lt;br /&gt;
fi&lt;br /&gt;
if [[ -r stats.nc ]] ; then&lt;br /&gt;
  \mv -f stats.nc stats${numnew}.nc&lt;br /&gt;
fi&lt;br /&gt;
if [[ -f profiles.dat ]] ; then&lt;br /&gt;
  \mv -f profiles.dat profiles${numnew}.dat&lt;br /&gt;
  \mv -f profiles.hdr profiles${numnew}.hdr&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Prepare things for upcoming runs by writing&lt;br /&gt;
# value of computed season in file num_run&lt;br /&gt;
echo ${numnew} &amp;gt; num_run&lt;br /&gt;
&lt;br /&gt;
# If we are over nummax : stop&lt;br /&gt;
if (( $numnew + 1 &amp;gt; $nummax )) ; then&lt;br /&gt;
   exit&lt;br /&gt;
# If not : restart the loop (copy the executable and run the copy)&lt;br /&gt;
else&lt;br /&gt;
   \cp -f run_gnome exe_mars&lt;br /&gt;
   ./exe_mars&lt;br /&gt;
fi &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Summary of what this bash script does''':&lt;br /&gt;
&lt;br /&gt;
* It reads the file 'num_run' which contains the step of the simulation. &lt;br /&gt;
If num_run is&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then the script expects to read start5.nc and startfi5.nc.&lt;br /&gt;
* It modifies start5.nc and startfi5.nc into start.nc and startfi.nc, respectively.&lt;br /&gt;
* It runs the GCM.&lt;br /&gt;
* It modifies restart.nc and restartfi.nc into start6.nc and startfi6.nc&lt;br /&gt;
* It rewrite num_run as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
6&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* It restarts the loop until num_run reaches the value (defined in nummax):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
100&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Processing Output Files with NCOs ==&lt;br /&gt;
&lt;br /&gt;
NCOs (NetCdf OperatorS) are a set of powerful command-line utilities – available on Linux, Mac and PC – that allow to perform useful (and very fast!) post-processing operations on netCDF GCM output files. Full documentation can be found on http://research.jisao.washington.edu/data_sets/nco/, but we provide below a few examples of command lines.&lt;br /&gt;
&lt;br /&gt;
* How to calculate a time mean of a netCDF 'diagfi.nc' file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ncra -F -d Time,1,,1 diagfi.nc diagfi_MEAN.nc # format is &amp;quot;-d dimension,minimum,maximum,stride&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Subsetting time in a netCDF 'diagfi.nc' file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ncea -F -d Time,first,last diagfi.nc diagfi_subset.nc # format is &amp;quot;-d dimension,minimum,maximum&amp;quot; ; we recall you can type &amp;quot;ncdump -v time diagfi.nc&amp;quot; to see the Time values in the netCDF file.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Decimating a netCDF 'diagfi.nc' file in time&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ncks -F -d Time,1,,8 diagfi.nc diagfi_decimated.nc # format is &amp;quot;-d dimension,minimum,maximum,stride&amp;quot; ; In this example, this means that data is extracted 1 time every 8 time steps, starting from the first time step (number 1), ending at the last time step).&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Extract a variable from a netCDF 'diagfi.nc' file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ncks -v tsurf,temp,p diagfi.nc diagfi_out.nc # Here we created a new file named 'diagfi_out.nc' in which we only kept variables named 'tsurf' (surface temperatures), 'temp' (atmospheric temperatures) and p (atmospheric pressures).&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Again, more examples can be found on http://research.jisao.washington.edu/data_sets/nco/ .&lt;br /&gt;
&lt;br /&gt;
== Data Handling and Visualization Software ==&lt;br /&gt;
&lt;br /&gt;
There are several data handling and visualization tools that can be used to analyse and plot the results from GCM simulations (using the diagfi.nc NetCDF files). We provide below a panorama of most widely used solutions.&lt;br /&gt;
&lt;br /&gt;
=== panoply ===&lt;br /&gt;
Panoply is a user-friendly tool for viewing raw NetCDF data, available here: https://www.giss.nasa.gov/tools/panoply/ . It is very convenient to make pretty visuals (see an example for the exoplanet TRAPPIST-1e). There are many options that can be used (map projections, masks, colorbars, shadows, etc.) to make your plots fancy. However, the tool is not very well suited for manipulating data (compute averages, statistics, etc.).&lt;br /&gt;
&lt;br /&gt;
[[File:Example panoply.png|thumb|Screenshot of panoply showing here Generic PCM results for the exoplanet TRAPPIST-1e (surface temperatures)]]&lt;br /&gt;
&lt;br /&gt;
=== ncview ===&lt;br /&gt;
ncview is another useful user-friendly tool for viewing raw NetCDF data. This is kind of a very archaic version of panoply, but it is convenient because it allows to have a very quick first look at netCDF data files.&lt;br /&gt;
&lt;br /&gt;
Command line tool to visualize NetCDF data:&lt;br /&gt;
* Installation on Linux:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install ncview&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Run on Linux:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ncview diagfi.nc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Example ncview.png|thumb|Screenshot of ncview showing here Generic PCM results for the exoplanet Proxima b (OLR - Thermal Emission)]]&lt;br /&gt;
&lt;br /&gt;
=== python scripts ===&lt;br /&gt;
&lt;br /&gt;
Python scripts provide a very useful mean to analyse and visualize netCDF files.&lt;br /&gt;
&lt;br /&gt;
You can use the netCDF4 python library to open a netCDF file and put data in tables that can then be manipulated and plotted.&lt;br /&gt;
&lt;br /&gt;
Here is an exemple of how to open and read a netCDF file with Python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
import numpy&lt;br /&gt;
from netCDF4 import Dataset&lt;br /&gt;
&lt;br /&gt;
# HERE WE OPEN THE NETCDF FILE&lt;br /&gt;
nc = Dataset('diagfi.nc')&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ THE VARIABLES (1D OUTPUT)&lt;br /&gt;
Time=nc.variables['Time'][:]&lt;br /&gt;
lat=nc.variables['latitude'][:]&lt;br /&gt;
lon=nc.variables['longitude'][:]&lt;br /&gt;
al=nc.variables['altitude'][:]&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ THE AREA (2D OUTPUT)&lt;br /&gt;
aire_GCM=nc.variables['aire'][:][:]&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ 3D OUTPUTS&lt;br /&gt;
tsurf=nc.variables['tsurf'][:][:][:] # this is the surface temperature 3D field (time, latitude, longitude, altitude)&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ 4D OUTPUTS&lt;br /&gt;
temp=nc.variables['temp'][:][:][:][:] # this is the atmospheric temperature 4D field (time, latitude, longitude, altitude)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here is an exemple of how to manipulate the netCDF data (here to compute the time averaged surface temperatures):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
from numpy import *&lt;br /&gt;
import numpy as np&lt;br /&gt;
&lt;br /&gt;
mean_tsurf=np.zeros((len(lat_GCM),len(lon_GCM)),dtype='f')&lt;br /&gt;
&lt;br /&gt;
for i in range(0,len(Time)):&lt;br /&gt;
    for j in range(0,len(lat)):&lt;br /&gt;
        for k in range(0,len(lon)):&lt;br /&gt;
            mean_tsurf[j,k]=mean_tsurf[j,k]+tsurf[i,j,k]*(1./len(Time))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here is a last exemple of how to plot the data (using matplotlib):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
plt.figure(1)&lt;br /&gt;
plt.contourf(lon_GCM,lat_GCM,mean_tsurf)&lt;br /&gt;
plt.colorbar(label='Surface Temperature (K)')&lt;br /&gt;
plt.xlabel('Longitude ($^{\circ}$)')&lt;br /&gt;
plt.ylabel('Latitude ($^{\circ}$)')&lt;br /&gt;
plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another useful library to deal with netcdf files is ''xarray''. We provide a code snippet below, doing the same thing as the snippets above.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
import numpy as np&lt;br /&gt;
import xarray as xr &lt;br /&gt;
import matplotlib.pyplot as plt &lt;br /&gt;
&lt;br /&gt;
# HERE WE OPEN THE NETCDF FILE&lt;br /&gt;
data = xr.open_dataset('diagfi.nc',&lt;br /&gt;
                       decode_times=False)&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ THE VARIABLES (1D OUTPUT)&lt;br /&gt;
Time=data['Time']&lt;br /&gt;
lat=data['latitude']&lt;br /&gt;
lon=data['longitude']&lt;br /&gt;
al=data['altitude']&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ THE AREA (2D OUTPUT)&lt;br /&gt;
aire_GCM=data['aire']&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ 3D OUTPUTS&lt;br /&gt;
tsurf=data['tsurf'] # this is the surface temperature 3D field (time, latitude, longitude, altitude)&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ 4D OUTPUTS&lt;br /&gt;
temp=data['temp'] # this is the atmospheric temperature 4D field (time, latitude, longitude, altitude)&lt;br /&gt;
&lt;br /&gt;
## let's take the time-averaged surface temperature&lt;br /&gt;
mean_tsurf = np.mean(tsurf,axis=0)&lt;br /&gt;
&lt;br /&gt;
##Let's plot a lon-lat map&lt;br /&gt;
fig = plt.figure()&lt;br /&gt;
plt.contourf(lon,lat,mean_tsurf)&lt;br /&gt;
plt.colorbar(label='Surface Temperature (K)')&lt;br /&gt;
plt.xlabel('Longitude ($^{\circ}$)')&lt;br /&gt;
plt.ylabel('Latitude ($^{\circ}$)')&lt;br /&gt;
plt.show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
For more examples on how to use ''xarray'', take a look at the [https://docs.xarray.dev/en/stable/index.html documentation].&lt;br /&gt;
Here is another example of how one can use xarray with multiples netcdfiles.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import xarray as xr&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
# your folder where output files are stored&lt;br /&gt;
FOLDER = './your_folder_with_output_files/'&lt;br /&gt;
&lt;br /&gt;
# take back the files from your FOLDER&lt;br /&gt;
list_files_folder=os.listdir(FOLDER)&lt;br /&gt;
&lt;br /&gt;
# If there are several files.&lt;br /&gt;
# Sort your simulation files by date,&lt;br /&gt;
# so beginning of simulation will be top of the list&lt;br /&gt;
# and end of simulation will be end of the list.&lt;br /&gt;
list_files_folder.sort()&lt;br /&gt;
&lt;br /&gt;
files = [FOLDER+str(f) for f in list_files_folder]&lt;br /&gt;
# if you want to keep only files of special_year you can add this option :&lt;br /&gt;
# files = [FOLDER+str(f) for f in list_files_folder if f.startswith(&amp;quot;special_year&amp;quot;)]&lt;br /&gt;
&lt;br /&gt;
# xarray will magically concatenate your outfiles by 'Time' (or any other 'concat_dime' you want)&lt;br /&gt;
nc=xr.open_mfdataset(files,decode_times=False, concat_dim='Time', combine='nested')&lt;br /&gt;
&lt;br /&gt;
# to check your keys&lt;br /&gt;
for key in nc.keys():&lt;br /&gt;
    print(key)&lt;br /&gt;
&lt;br /&gt;
# to load keys (example here with keys for a mesoscale simulation)&lt;br /&gt;
Times = nc['Times'][:]&lt;br /&gt;
PTOT = nc['PTOT'][:]&lt;br /&gt;
T = nc['T'][:]&lt;br /&gt;
W = nc['W'][:]&lt;br /&gt;
&lt;br /&gt;
# you can use some functions to make averages etc&lt;br /&gt;
&lt;br /&gt;
T_moy = T.mean(dim=['Time','south_north','west_east'])&lt;br /&gt;
&lt;br /&gt;
# other functions&lt;br /&gt;
# .cumsum (cumulative sum)&lt;br /&gt;
# .rename (change the name of the object)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NB: ADD SOMETHING HERE ABOUT XARRAY LIBRARY? AYMERIC? (with a simple tutorial?) TBD&lt;br /&gt;
&lt;br /&gt;
We provide a tutorial on how to make pretty visuals using Generic PCM 3-D simulations [https://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/index.php/Plots_With_PyVista here].&lt;br /&gt;
&lt;br /&gt;
=== Planetoplot ===&lt;br /&gt;
&lt;br /&gt;
Planetoplot is a in-house, python based library developped to vizualize Generic PCM data.&lt;br /&gt;
&lt;br /&gt;
The code and documentation can be found at: https://nbviewer.org/github/aymeric-spiga/planetoplot/blob/master/tutorial/planetoplot_tutorial.ipynb&lt;/div&gt;</summary>
		<author><name>Maurel</name></author>	</entry>

	<entry>
		<id>http://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/index.php?title=Tool_Box&amp;diff=1058</id>
		<title>Tool Box</title>
		<link rel="alternate" type="text/html" href="http://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/index.php?title=Tool_Box&amp;diff=1058"/>
				<updated>2022-11-23T15:14:51Z</updated>
		
		<summary type="html">&lt;p&gt;Maurel: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Pre-processing Tools ==&lt;br /&gt;
=== newstart: a fortran program to modify start files ===&lt;br /&gt;
&lt;br /&gt;
Newstart is an interactive tool to modify the start files (''start.nc'' and ''startfi.nc''). &lt;br /&gt;
&lt;br /&gt;
To be usable, ''newstart'' should be compile in the ''LMDZ.COMMON'' directory by using the following command line:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./makelmdz_fcm -arch my_arch_file -p std -d 64x48x30 newstart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In the example, my_arch_file is the name the arch files (see [https://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/index.php/The_Target_Architecture_(%22arch%22)_Files arch] ) and 64x48x30 is the resolution of the physical grid.&lt;br /&gt;
Then copy the executable from the ''LMDZ.COMMON/bin'' directory to your bench directory.&lt;br /&gt;
&lt;br /&gt;
When you execute newstart, you can use both a ''start2archive'' file or the start files (''start.nc'' and ''startfi.nc''). Then the interactive interface will propose to modify several physical quantities such as the gravity, the surface pressure or the rotation of the planet. At the end of the procedure, two files are created: '' '''re'''start.nc'' and '' '''re'''startfi.nc''. They can be renamed and used as start files to initialize a new simulation.&lt;br /&gt;
&lt;br /&gt;
=== start2archive ===&lt;br /&gt;
&lt;br /&gt;
The start2archive tool is similar to newstart in the sense that it can be used to modify the start files. But start2archive can modify the resolution of the physical grid, the topography and the surface thermal inertia while newstart cannot. It is also useful to create an archive of different starting states, then extractable as start files.&lt;br /&gt;
The command line to compile start2archive is similar to the one used for newstart:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./makelmdz_fcm -arch my_arch_file -p std -d 64x48x30 start2archive&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To modify the resolution, you should first create a start_archive (by using start2archive) file at the used resolution, then compile a newstart file at the new resolution. Newstart will interpolate all the physical quantities on the new grid.&lt;br /&gt;
&lt;br /&gt;
=== other third party scripts and tools ===&lt;br /&gt;
&lt;br /&gt;
TO BE COMPLETED&lt;br /&gt;
&lt;br /&gt;
== Post-processing tools ==&lt;br /&gt;
=== zrecast ===&lt;br /&gt;
&lt;br /&gt;
With this program you can recast atmospheric (i.e.: 4D-dimentional longitude-latitude-altitude-time) data from&lt;br /&gt;
GCM outputs (e.g. as given in diagfi.nc files) onto either ''pressure'' or ''altitude'' above ''areoid vertical'' coordinates.&lt;br /&gt;
Since integrating the hydrostatic equation is required to recast the data, the input file must contain surface pressure&lt;br /&gt;
and atmospheric temperature, as well as the ground geopotential.&lt;br /&gt;
If recasting data onto ''pressure'' coordinates, then the output file name is given by the input file name to which ''_P.nc'' will be appened. If recasting data onto altitude above areoid coordinates, then a ''_A.nc'' will be appened.&lt;br /&gt;
&lt;br /&gt;
=== mass stream function ===&lt;br /&gt;
&lt;br /&gt;
The mass stream function (and the total angular momentum) can be computed from a diagfi.nc or a stats.nc, using the '''streamfunction.F90''' script. The script is located at&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
trunk/LMDZ.GENERIC/utilities&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To compile the script, open the ''compile'' file in the same directory and do the following:&lt;br /&gt;
* Replace &amp;quot;pgf90&amp;quot; with your favorite fortran compiler &lt;br /&gt;
* replace &amp;quot;/distrib/local/netcdf/pgi_7.1-6_32/lib&amp;quot; with the lib address and directory that contains your NetCDF library (file ''libnetcdf.a'').&lt;br /&gt;
* Replace &amp;quot;/distrib/local/netcdf/pgi_7.1-6_32/include&amp;quot; with the address of the directory that contains the NetCDF include file (''netcdf.inc'').&lt;br /&gt;
* You can mess with the compiling options but it is not mandatory.&lt;br /&gt;
&lt;br /&gt;
Once the script is compiled, copy it in the same directory as your '''.nc''' file and run &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./streamfunction.e&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The script will ask you for the name of your '''.nc''' file, and will run and produce a new '''nameofyourfile_stream.nc''' file.&lt;br /&gt;
&lt;br /&gt;
'''Be careful''' : In this new file, all fields are temporally and zonally averaged.&lt;br /&gt;
&lt;br /&gt;
If you want to use '''python''' instead of '''fortran''', you can take a look at this [https://github.com/aymeric-spiga/dynanalysis repo]. It hosts a tool to perform dynamical analysis of GCM simulations (and therefore, it computes the mass stream function and a lot of other stuff), but it is tailored for Dynamico only. This repo also takes care of recasting (it does the job of both ''zrecast.F90'' and ''streamfunction.F90'')&lt;br /&gt;
&lt;br /&gt;
== Continuing Simulations ==&lt;br /&gt;
&lt;br /&gt;
=== manually ===&lt;br /&gt;
&lt;br /&gt;
At the end of a simulation, the model generates restart files (files 'restart.nc' and 'restartfi.nc') which contain the final state of the model. The 'restart.nc' and 'restartfi.nc' files have the same format as the 'start.nc' and 'startfi.nc' files, respectively. &lt;br /&gt;
&lt;br /&gt;
These files can in fact be used as initial states to continue the simulation, using the following renaming command lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mv restart.nc start.nc&lt;br /&gt;
mv restartfi.nc startfi.nc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running a simulation with these start files will in fact resume the simulation from where the previous run ended.&lt;br /&gt;
&lt;br /&gt;
=== with bash scripts ===&lt;br /&gt;
&lt;br /&gt;
We have set up very simple bash scripts to automatize the launching of chain simulations. Here is an example of bash script that does the job:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
###########################################################################&lt;br /&gt;
# Script to perform several chained LMD Mars GCM simulations&lt;br /&gt;
# SET HERE the maximum total number of simulations&lt;br /&gt;
&lt;br /&gt;
nummax=100&lt;br /&gt;
&lt;br /&gt;
###########################################################################&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;---------------------------------------------------------&amp;quot;&lt;br /&gt;
echo &amp;quot;STARTING LOOP RUN&amp;quot;&lt;br /&gt;
echo &amp;quot;---------------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
dir=`pwd`&lt;br /&gt;
machine=`hostname`&lt;br /&gt;
address=`whoami`&lt;br /&gt;
&lt;br /&gt;
# Look for file &amp;quot;num_run&amp;quot; which should contain &lt;br /&gt;
# the value of the previously computed season&lt;br /&gt;
# (defaults to 0 if file &amp;quot;num_run&amp;quot; does not exist)&lt;br /&gt;
if [[ -r num_run ]] ; then&lt;br /&gt;
  echo &amp;quot;found file num_run&amp;quot;&lt;br /&gt;
  numold=`cat num_run`&lt;br /&gt;
else&lt;br /&gt;
  numold=0&lt;br /&gt;
fi&lt;br /&gt;
echo &amp;quot;numold is set to&amp;quot; ${numold}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Set value of current season &lt;br /&gt;
(( numnew = ${numold} + 1 ))&lt;br /&gt;
echo &amp;quot;numnew is set to&amp;quot; ${numnew}&lt;br /&gt;
&lt;br /&gt;
# Look for initialization data files (exit if none found)&lt;br /&gt;
if [[ ( -r start${numold}.nc  &amp;amp;&amp;amp;  -r startfi${numold}.nc ) ]] ; then&lt;br /&gt;
   \cp -f start${numold}.nc start.nc&lt;br /&gt;
   \cp -f startfi${numold}.nc startfi.nc&lt;br /&gt;
else&lt;br /&gt;
   if (( ${numold} == 99999 )) ; then&lt;br /&gt;
    echo &amp;quot;No run because previous run crashed ! (99999 in num_run)&amp;quot;&lt;br /&gt;
    exit&lt;br /&gt;
   else&lt;br /&gt;
   echo &amp;quot;Where is file start&amp;quot;${numold}&amp;quot;.nc??&amp;quot;&lt;br /&gt;
   exit&lt;br /&gt;
   fi&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Run GCM -- THIS LINE NEEDS TO BE MODIFIED WITH THE CORRECT GCM EXECUTION COMMAND&lt;br /&gt;
mpirun -np 8 gcm_64x48x26_phystd_para.e &amp;lt; diagfi.def &amp;gt; lrun${numnew}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Check if run ended normaly and copy datafiles&lt;br /&gt;
if [[ ( -r restartfi.nc  &amp;amp;&amp;amp;  -r restart.nc ) ]] ; then&lt;br /&gt;
  echo &amp;quot;Run seems to have ended normaly&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  \mv -f restart.nc start${numnew}.nc&lt;br /&gt;
  \mv -f restartfi.nc startfi${numnew}.nc  &lt;br /&gt;
    &lt;br /&gt;
else&lt;br /&gt;
  if [[ -r num_run ]] ; then&lt;br /&gt;
    \mv -f num_run num_run.crash&lt;br /&gt;
  else&lt;br /&gt;
    echo &amp;quot;No file num_run to build num_run.crash from !!&amp;quot;&lt;br /&gt;
    # Impose a default value of 0 for num_run&lt;br /&gt;
    echo 0 &amp;gt; num_run.crash&lt;br /&gt;
  fi&lt;br /&gt;
 echo 99999 &amp;gt; num_run&lt;br /&gt;
 exit&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Copy other datafiles that may have been generated&lt;br /&gt;
if [[ -r diagfi.nc ]] ; then&lt;br /&gt;
  \mv -f diagfi.nc diagfi${numnew}.nc&lt;br /&gt;
fi&lt;br /&gt;
if [[ -r diagsoil.nc ]] ; then&lt;br /&gt;
  \mv -f diagsoil.nc diagsoil${numnew}.nc&lt;br /&gt;
fi&lt;br /&gt;
if [[ -r stats.nc ]] ; then&lt;br /&gt;
  \mv -f stats.nc stats${numnew}.nc&lt;br /&gt;
fi&lt;br /&gt;
if [[ -f profiles.dat ]] ; then&lt;br /&gt;
  \mv -f profiles.dat profiles${numnew}.dat&lt;br /&gt;
  \mv -f profiles.hdr profiles${numnew}.hdr&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Prepare things for upcoming runs by writing&lt;br /&gt;
# value of computed season in file num_run&lt;br /&gt;
echo ${numnew} &amp;gt; num_run&lt;br /&gt;
&lt;br /&gt;
# If we are over nummax : stop&lt;br /&gt;
if (( $numnew + 1 &amp;gt; $nummax )) ; then&lt;br /&gt;
   exit&lt;br /&gt;
else&lt;br /&gt;
   \cp -f run_gnome exe_mars&lt;br /&gt;
   ./exe_mars&lt;br /&gt;
fi &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Summary of what this bash script does''':&lt;br /&gt;
&lt;br /&gt;
* It reads the file 'num_run' which contains the step of the simulation. &lt;br /&gt;
If num_run is&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then the script expects to read start5.nc and startfi5.nc.&lt;br /&gt;
* It modifies start5.nc and startfi5.nc into start.nc and startfi.nc, respectively.&lt;br /&gt;
* It runs the GCM.&lt;br /&gt;
* It modifies restart.nc and restartfi.nc into start6.nc and startfi6.nc&lt;br /&gt;
* It rewrite num_run as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
6&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* It restarts the loop until num_run reaches the value (defined in nummax):&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
100&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Processing Output Files with NCOs ==&lt;br /&gt;
&lt;br /&gt;
NCOs (NetCdf OperatorS) are a set of powerful command-line utilities – available on Linux, Mac and PC – that allow to perform useful (and very fast!) post-processing operations on netCDF GCM output files. Full documentation can be found on http://research.jisao.washington.edu/data_sets/nco/, but we provide below a few examples of command lines.&lt;br /&gt;
&lt;br /&gt;
* How to calculate a time mean of a netCDF 'diagfi.nc' file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ncra -F -d Time,1,,1 diagfi.nc diagfi_MEAN.nc # format is &amp;quot;-d dimension,minimum,maximum,stride&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Subsetting time in a netCDF 'diagfi.nc' file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ncea -F -d Time,first,last diagfi.nc diagfi_subset.nc # format is &amp;quot;-d dimension,minimum,maximum&amp;quot; ; we recall you can type &amp;quot;ncdump -v time diagfi.nc&amp;quot; to see the Time values in the netCDF file.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Decimating a netCDF 'diagfi.nc' file in time&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ncks -F -d Time,1,,8 diagfi.nc diagfi_decimated.nc # format is &amp;quot;-d dimension,minimum,maximum,stride&amp;quot; ; In this example, this means that data is extracted 1 time every 8 time steps, starting from the first time step (number 1), ending at the last time step).&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Extract a variable from a netCDF 'diagfi.nc' file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ncks -v tsurf,temp,p diagfi.nc diagfi_out.nc # Here we created a new file named 'diagfi_out.nc' in which we only kept variables named 'tsurf' (surface temperatures), 'temp' (atmospheric temperatures) and p (atmospheric pressures).&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Again, more examples can be found on http://research.jisao.washington.edu/data_sets/nco/ .&lt;br /&gt;
&lt;br /&gt;
== Data Handling and Visualization Software ==&lt;br /&gt;
&lt;br /&gt;
There are several data handling and visualization tools that can be used to analyse and plot the results from GCM simulations (using the diagfi.nc NetCDF files). We provide below a panorama of most widely used solutions.&lt;br /&gt;
&lt;br /&gt;
=== panoply ===&lt;br /&gt;
Panoply is a user-friendly tool for viewing raw NetCDF data, available here: https://www.giss.nasa.gov/tools/panoply/ . It is very convenient to make pretty visuals (see an example for the exoplanet TRAPPIST-1e). There are many options that can be used (map projections, masks, colorbars, shadows, etc.) to make your plots fancy. However, the tool is not very well suited for manipulating data (compute averages, statistics, etc.).&lt;br /&gt;
&lt;br /&gt;
[[File:Example panoply.png|thumb|Screenshot of panoply showing here Generic PCM results for the exoplanet TRAPPIST-1e (surface temperatures)]]&lt;br /&gt;
&lt;br /&gt;
=== ncview ===&lt;br /&gt;
ncview is another useful user-friendly tool for viewing raw NetCDF data. This is kind of a very archaic version of panoply, but it is convenient because it allows to have a very quick first look at netCDF data files.&lt;br /&gt;
&lt;br /&gt;
Command line tool to visualize NetCDF data:&lt;br /&gt;
* Installation on Linux:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install ncview&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Run on Linux:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ncview diagfi.nc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Example ncview.png|thumb|Screenshot of ncview showing here Generic PCM results for the exoplanet Proxima b (OLR - Thermal Emission)]]&lt;br /&gt;
&lt;br /&gt;
=== python scripts ===&lt;br /&gt;
&lt;br /&gt;
Python scripts provide a very useful mean to analyse and visualize netCDF files.&lt;br /&gt;
&lt;br /&gt;
You can use the netCDF4 python library to open a netCDF file and put data in tables that can then be manipulated and plotted.&lt;br /&gt;
&lt;br /&gt;
Here is an exemple of how to open and read a netCDF file with Python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
import numpy&lt;br /&gt;
from netCDF4 import Dataset&lt;br /&gt;
&lt;br /&gt;
# HERE WE OPEN THE NETCDF FILE&lt;br /&gt;
nc = Dataset('diagfi.nc')&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ THE VARIABLES (1D OUTPUT)&lt;br /&gt;
Time=nc.variables['Time'][:]&lt;br /&gt;
lat=nc.variables['latitude'][:]&lt;br /&gt;
lon=nc.variables['longitude'][:]&lt;br /&gt;
al=nc.variables['altitude'][:]&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ THE AREA (2D OUTPUT)&lt;br /&gt;
aire_GCM=nc.variables['aire'][:][:]&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ 3D OUTPUTS&lt;br /&gt;
tsurf=nc.variables['tsurf'][:][:][:] # this is the surface temperature 3D field (time, latitude, longitude, altitude)&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ 4D OUTPUTS&lt;br /&gt;
temp=nc.variables['temp'][:][:][:][:] # this is the atmospheric temperature 4D field (time, latitude, longitude, altitude)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here is an exemple of how to manipulate the netCDF data (here to compute the time averaged surface temperatures):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
from numpy import *&lt;br /&gt;
import numpy as np&lt;br /&gt;
&lt;br /&gt;
mean_tsurf=np.zeros((len(lat_GCM),len(lon_GCM)),dtype='f')&lt;br /&gt;
&lt;br /&gt;
for i in range(0,len(Time)):&lt;br /&gt;
    for j in range(0,len(lat)):&lt;br /&gt;
        for k in range(0,len(lon)):&lt;br /&gt;
            mean_tsurf[j,k]=mean_tsurf[j,k]+tsurf[i,j,k]*(1./len(Time))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here is a last exemple of how to plot the data (using matplotlib):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
plt.figure(1)&lt;br /&gt;
plt.contourf(lon_GCM,lat_GCM,mean_tsurf)&lt;br /&gt;
plt.colorbar(label='Surface Temperature (K)')&lt;br /&gt;
plt.xlabel('Longitude ($^{\circ}$)')&lt;br /&gt;
plt.ylabel('Latitude ($^{\circ}$)')&lt;br /&gt;
plt.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another useful library to deal with netcdf files is ''xarray''. We provide a code snippet below, doing the same thing as the snippets above.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
import numpy as np&lt;br /&gt;
import xarray as xr &lt;br /&gt;
import matplotlib.pyplot as plt &lt;br /&gt;
&lt;br /&gt;
# HERE WE OPEN THE NETCDF FILE&lt;br /&gt;
data = xr.open_dataset('diagfi.nc',&lt;br /&gt;
                       decode_times=False)&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ THE VARIABLES (1D OUTPUT)&lt;br /&gt;
Time=data['Time']&lt;br /&gt;
lat=data['latitude']&lt;br /&gt;
lon=data['longitude']&lt;br /&gt;
al=data['altitude']&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ THE AREA (2D OUTPUT)&lt;br /&gt;
aire_GCM=data['aire']&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ 3D OUTPUTS&lt;br /&gt;
tsurf=data['tsurf'] # this is the surface temperature 3D field (time, latitude, longitude, altitude)&lt;br /&gt;
&lt;br /&gt;
# HERE WE READ 4D OUTPUTS&lt;br /&gt;
temp=data['temp'] # this is the atmospheric temperature 4D field (time, latitude, longitude, altitude)&lt;br /&gt;
&lt;br /&gt;
## let's take the time-averaged surface temperature&lt;br /&gt;
mean_tsurf = np.mean(tsurf,axis=0)&lt;br /&gt;
&lt;br /&gt;
##Let's plot a lon-lat map&lt;br /&gt;
fig = plt.figure()&lt;br /&gt;
plt.contourf(lon,lat,mean_tsurf)&lt;br /&gt;
plt.colorbar(label='Surface Temperature (K)')&lt;br /&gt;
plt.xlabel('Longitude ($^{\circ}$)')&lt;br /&gt;
plt.ylabel('Latitude ($^{\circ}$)')&lt;br /&gt;
plt.show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
For more examples on how to use ''xarray'', take a look at the [https://docs.xarray.dev/en/stable/index.html documentation].&lt;br /&gt;
Here is another example of how one can use xarray with multiples netcdfiles.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import xarray as xr&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
# your folder where output files are stored&lt;br /&gt;
FOLDER = './your_folder_with_output_files/'&lt;br /&gt;
&lt;br /&gt;
# take back the files from your FOLDER&lt;br /&gt;
list_files_folder=os.listdir(FOLDER)&lt;br /&gt;
&lt;br /&gt;
# If there are several files.&lt;br /&gt;
# Sort your simulation files by date,&lt;br /&gt;
# so beginning of simulation will be top of the list&lt;br /&gt;
# and end of simulation will be end of the list.&lt;br /&gt;
list_files_folder.sort()&lt;br /&gt;
&lt;br /&gt;
files = [FOLDER+str(f) for f in list_files_folder]&lt;br /&gt;
# if you want to keep only files of special_year you can add this option :&lt;br /&gt;
# files = [FOLDER+str(f) for f in list_files_folder if f.startswith(&amp;quot;special_year&amp;quot;)]&lt;br /&gt;
&lt;br /&gt;
# xarray will magically concatenate your outfiles by 'Time' (or any other 'concat_dime' you want)&lt;br /&gt;
nc=xr.open_mfdataset(files,decode_times=False, concat_dim='Time', combine='nested')&lt;br /&gt;
&lt;br /&gt;
# to check your keys&lt;br /&gt;
for key in nc.keys():&lt;br /&gt;
    print(key)&lt;br /&gt;
&lt;br /&gt;
# to load keys (example here with keys for a mesoscale simulation)&lt;br /&gt;
Times = nc['Times'][:]&lt;br /&gt;
PTOT = nc['PTOT'][:]&lt;br /&gt;
T = nc['T'][:]&lt;br /&gt;
W = nc['W'][:]&lt;br /&gt;
&lt;br /&gt;
# you can use some functions to make averages etc&lt;br /&gt;
&lt;br /&gt;
T_moy = T.mean(dim=['Time','south_north','west_east'])&lt;br /&gt;
&lt;br /&gt;
# other functions&lt;br /&gt;
# .cumsum (cumulative sum)&lt;br /&gt;
# .rename (change the name of the object)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NB: ADD SOMETHING HERE ABOUT XARRAY LIBRARY? AYMERIC? (with a simple tutorial?) TBD&lt;br /&gt;
&lt;br /&gt;
We provide a tutorial on how to make pretty visuals using Generic PCM 3-D simulations [https://lmdz-forge.lmd.jussieu.fr/mediawiki/Planets/index.php/Plots_With_PyVista here].&lt;br /&gt;
&lt;br /&gt;
=== Planetoplot ===&lt;br /&gt;
&lt;br /&gt;
Planetoplot is a in-house, python based library developped to vizualize Generic PCM data.&lt;br /&gt;
&lt;br /&gt;
The code and documentation can be found at: https://nbviewer.org/github/aymeric-spiga/planetoplot/blob/master/tutorial/planetoplot_tutorial.ipynb&lt;/div&gt;</summary>
		<author><name>Maurel</name></author>	</entry>

	</feed>