conversion utility from standard LPJ-GUESS output file format to netCDF. No warranties provided, but it should not eat your data (it never did before).
.cfg
file in the current working directory and in case only a single file found, it use it.time.calendar
attribute and it will override the content of the file. Useful when the simulation year is present in the out files, but the calendar year is desired for the netcdf files.default_config.cfg
-d/--dir
switch, so that full relative or absolute paths need to be provided, rather than file names only. If these paths do not have corresponding entries in the configuration files, a strip-down conversion will be attempted.This program is written in Python and requires at minimum version 3.4 of the interpreter. Along with it the following packages are mandatory: numpy, netCDF4 and pandas. All of them can be installed using pip. On recent Debian-based distribution: installing python3-netcdf4 and python3-pandas would be sufficient.
To create proper standard-compliant files, the tool relies on provision of metadata by the user. The configuration file should be in ini format (without relying on interpolation or Windows Registry features). The configuration filename can be passed using the -f/--file
switch otherwise the program will try to use a .cfg
file from the current directory (only when a single .cfg file found).
Without a specified configuration a strip-down conversion with default settings would be attempted, but is likely to be incorrect and not standard-compliant. A sample configuration file can be obtained by passing --init-config
with an optional filename. Content of the configuration file should be as follows:
The section should be named metadata
in lower case. This section may contain both freeform options that will be turned into global attributes as well as the following options:
netcdf4
, netcdf4_classic
, netcdf3_classic
or netcdf3_64bit
, defaults to netcdf4_classic
. Is a format of a generated netCDF file.{var}.nc
Possible elements:
{var}
variable name{start}
start year{end}
end year{tres}
month
or year
{parent}
name of the parent directory, multiples grand-parent directories can be specified by adding a g
per directory level{i}
consecutive index, specific to an invocation of this commandfor example, the following value of filename_format:
lpj-guess_{gparent}_{parent}_{var}_{tres}_{start}_{end}.nc4
could be interpolated to the final output filename:
lpj-guess_gcm_rcp_tair_year_1901_2001.nc4
For an annual file of air temperatures located in gcm/rcp
directory.
Each remaining section will represent a single variable that could be extracted from the .out
files. The name of the section will be taken as a variable name as well as used as {var}
element for filename. Therefore, section (variable) names must be unique. Each section may have the following options:
If the section name or a name option contain a {}
, the variable will be replaced with a number of variables corresponding to the column names in the file. For example, the following section:
[fpc_{}] name: FPC of {} standard_name: fpc file: fpc.out
referring to the fpc.out
with columns: trees, grass and total; will be internally replaced by three variables as follows:
[fpc_trees] name: FPC of trees standard_name: fpc file: fpc.out column: trees [fpc_grass] name: FPC of grass standard_name: fpc file: fpc.out column: grass [fpc_total] name: FPC of total standard_name: fpc file: fpc.out column: total
Only variable (section) name and name option are affected by this expansion. The '{}' can be present only in section name or name option, i.e., it does not have be found in both elements.
Author: | Michael Mischurow |
---|---|
Date: | 2016-08-26 |
Copyright: | public domain |
Version: | 1.5 |