CSV_STACK
Stack columns in a CSV exported file.
All columns in your data set with a colon “:” in it, will be split such that the string after the colon will become a column value instead of its own column. Thus all columns called WOPT:A-1, WOPT:A-2, WOPT:A-3 etc will be merged into one column called WOPT, and you will have a column name called “WELL” that contains A-1, A-2, or A-3 as values.
If importing the output CSV into Spotfire, you may then view and filter WOPT and friends by wellname, instead of selecting individual columns.
usage: csv_stack [-h] [-o OUTPUT] [-s SPLIT] [--keepconstantcolumns]
[--keepminimal] [-v] [--version]
csvfile
Positional Arguments
- csvfile
Input CSV file. If you use -, it will read from stdin
Named Arguments
- -o, --output
Name of output csv file. Use - to write to stdout.
Default: “stacked.csv”
- -s, --split
Type of column to be split/unpivoted/stacked. Choose from the the predefined set: well, region, group, block, all
Default: “well”
- --keepconstantcolumns
Keep constant columns before stacking
Default: False
- --keepminimal
Keep only REAL, ENSEMBLE, ITER, DATE and unpivoted columns. Implies dropping constant columns
Default: False
- -v, --verbose
Be verbose
Default: False
- --version
show program’s version number and exit
Example
If a CSV file contains:
REALIZATION, DATE, poro, WOPT:A1, WOPT:A2, RPR:1, RPR:2
1, 2015-01-01, 6, 1, 2, 3, 4
1, 2015-02-01, 7, 2, 3, 4, 5
1, 2015-02-03, 8, 3, 4, 5, 6
2, 2015-01-01, 9, 4, 5, 6, 7
2, 2015-02-01, 10, 5, 6, 7, 8
2, 2015-03-01, 4, 3, 2, 4, 5
2, 2015-04-01, 11, 6, 7, 8, 9
If you then want to plot WOPT
for all wells, you might want to
colour by the name of the well. Then you can stack your dataset into
a layout more favourable for that purpose:
WELL, DATE, RPR:1, RPR:2, REALIZATION, WOPT, poro
A1, 2015-01-01, 3.0, 4.0, 1.0, 1.0, 6.0
A2, 2015-01-01, 3.0, 4.0, 1.0, 2.0, 6.0
A1, 2015-02-01, 4.0, 5.0, 1.0, 2.0, 7.0
A2, 2015-02-01, 4.0, 5.0, 1.0, 3.0, 7.0
A1, 2015-02-03, 5.0, 6.0, 1.0, 3.0, 8.0
A2, 2015-02-03, 5.0, 6.0, 1.0, 4.0, 8.0
A1, 2015-01-01, 6.0, 7.0, 2.0, 4.0, 9.0
A2, 2015-01-01, 6.0, 7.0, 2.0, 5.0, 9.0
A1, 2015-02-01, 7.0, 8.0, 2.0, 5.0, 10.0
A2, 2015-02-01, 7.0, 8.0, 2.0, 6.0, 10.0
A1, 2015-03-01, 4.0, 5.0, 2.0, 3.0, 4.0
A2, 2015-03-01, 4.0, 5.0, 2.0, 2.0, 4.0
A1, 2015-04-01, 8.0, 9.0, 2.0, 6.0, 11.0
A2, 2015-04-01, 8.0, 9.0, 2.0, 7.0, 11.0
where the columns WOPT:A1
and WOPT:A2
has been condensed into only one
column called WOPT
, but the name of the well now occurs as a column value
(in the column called WELL
).
Note that you might also want to stack on the region pressures instead, RPR:*
.
This can be accomplished by an option, see below. You may also stack on
well parameters and region parameters at the same time.
Be careful stacking large datasets (gigabytes), the memory usage during stacking and filesize can blow up.