|
2 | 2 | Usage |
3 | 3 | ===== |
4 | 4 |
|
| 5 | +Folder structure |
| 6 | +---------------- |
| 7 | + |
| 8 | +A recommended folder structure in Equinor is (assuming the revision folder is 21.2.0 |
| 9 | +in this example): |
| 10 | + |
| 11 | +.. code-block:: bash |
| 12 | +
|
| 13 | + 21.2.0/fmuconfig/input |
| 14 | + /bin |
| 15 | + /output |
| 16 | +
|
| 17 | +The ``input`` has a file ``global_master_config.yml`` a possibly a few include files, |
| 18 | +and these are edited by users. |
| 19 | + |
| 20 | +The ``bin`` has shell scripts that process the input to a set of YAML and/or IPL |
| 21 | +which is stored at ``output``. The files in output shall never be edited by hand. |
| 22 | + |
| 23 | + |
5 | 24 | Run from script |
6 | 25 | --------------- |
7 | 26 |
|
8 | | -The fmu.config module is accessed through a script, which is run like this:: |
| 27 | +The ``fmu.config`` module is accessed through a script, and assuming the file structure |
| 28 | +above, is to be run like this: |
9 | 29 |
|
10 | | - fmuconfig global_master_config.yml <options...> |
| 30 | +.. code-block:: shell |
11 | 31 |
|
12 | | -The global master config *shall* be placed at ``rNNN/share/config`` or |
13 | | -``rNNN/share/config/input``, where *rNNN* is |
14 | | -the revision number. |
| 32 | + # go to fmuconfig/bin |
| 33 | + fmuconfig ../input/global_master_config.yml <options...> |
15 | 34 |
|
16 | | -Here is an example of a shell script that runs `fmuconfig` from the rms/bin folder: |
| 35 | +Here is an example of a shell script that runs `fmuconfig` from the ``bin`` folder: |
17 | 36 |
|
18 | 37 | .. code-block:: bash |
19 | 38 |
|
20 | 39 | #!/bin/bash |
21 | | - # |
22 | | - # Run the global configuration for RMS, both making IPL and YAML versions |
23 | | - # from a common global config |
24 | | - # |
25 | | - source /project/res/SDP_bashrc |
26 | | - source /project/res/komodo/stable/enable |
27 | 40 |
|
28 | | - MASTER="../../share/config/input/global_master_config.yml" |
29 | | - DEST="../input/global_variables" |
30 | | - TMPL="../../ert/input/templates" |
31 | | - ROOTIPL="global_variables" |
32 | | - ROOTYML="global_variables_rms" |
| 41 | + MASTER="../../fmuconfig/input/global_master_config.yml" # all updates here |
| 42 | + OUTFOLDER="../../fmuconfig/output" # location of result files |
| 43 | + ROOTNAME="global_variables" # root name of result files |
33 | 44 |
|
34 | | - # run command for IPL version |
35 | | - fmuconfig $MASTER --rootname $ROOTIPL --mode ipl --destination $DEST \ |
36 | | - --template $TMPL --tool rms |
| 45 | + # clean up (be careful with syntax) |
| 46 | + rm -f ${OUTFOLDER}/ROOTNAME* |
37 | 47 |
|
38 | | - # run command for YAML version |
39 | | - fmuconfig $MASTER --rootname $ROOTYML --mode yml --destination $DEST \ |
40 | | - --template $TMPL --tool rms |
| 48 | + # run command for creating YAML version (+ ert tmpl version; yml.tmpl) |
| 49 | + fmuconfig $MASTER --rootname $ROOTNAME --mode yml --destination $OUTFOLDER \ |
| 50 | + --template $OUTFOLDER |
| 51 | +
|
| 52 | + # optional! |
| 53 | + # run command for creating IPL version if needed (+ ert tmpl version; ipl.tmpl) |
| 54 | + fmuconfig $MASTER --rootname $ROOTNAME --mode ipl --destination $OUTFOLDER \ |
| 55 | + --template $OUTFOLDER --tool rms |
41 | 56 |
|
42 | 57 |
|
43 | 58 | Run from python inside or outside RMS |
44 | 59 | ------------------------------------- |
45 | 60 |
|
46 | | -The config can also be ran from a python script, e.g. inside RMS. In that case you |
| 61 | +In RMS there are two options to run global variables: |
| 62 | + |
| 63 | +* Run shell script above using system command (recommended) |
| 64 | +* Run from RMS python |
| 65 | + |
| 66 | +For shell script for RMS, use a system command job as this: |
| 67 | + |
| 68 | +.. code-block:: shell |
| 69 | +
|
| 70 | + cd ../../fmuconfig/bin; run_external sh global_variables_update.sh |
| 71 | +
|
| 72 | +The config can also be run from a python script inside RMS. In that case you |
47 | 73 | need to initiate the Class instance and run a few methods. Here is an example: |
48 | 74 |
|
49 | 75 | .. code-block:: python |
50 | 76 |
|
| 77 | + """Run global config in RMS python.""" |
| 78 | + from pathlib import Path |
51 | 79 | import fmu.config |
52 | 80 |
|
53 | | - cfg = fmu.config.ConfigParserFMU() |
54 | | -
|
55 | | - global_master = '../../share/config/input/global_master_config.yml' |
56 | | - path_ipl = '../input/global_variables' |
57 | | - path_ipl_tmpl = '../../ert/input/templates' |
58 | | - root_ipl = 'global_variables' |
59 | 81 |
|
60 | | - root_yml = 'global_variables_rms' # to avoid name conflict |
| 82 | + MASTER = "../../fmuconfig/input/global_master_config.yml" |
| 83 | + OUTPUT = "../../fmuconfig/output" |
| 84 | + ROOT = "global_variables" |
61 | 85 |
|
62 | | - cfg.parse(global_master) |
| 86 | + def cleanup(): |
| 87 | + for file in Path(OUTPUT).glob(ROOT + "*"): |
| 88 | + file.unlink() |
| 89 | + print(f"Removed old {file}") |
63 | 90 |
|
64 | | - # make IPL |
65 | | - cfg.to_ipl(rootname=root_ipl, destination=path_ipl, template=path_ipl_tmpl, |
66 | | - tool='rms') |
67 | | - cfg.to_yaml(rootname=root_yml, destination=path_ipl, template=path_ipl_tmpl, |
68 | | - tool='rms') |
69 | 91 |
|
70 | | - print('\n\nGlobal IPL and YML are updated') |
| 92 | + def main(): |
| 93 | + cfg = fmu.config.ConfigParserFMU() |
| 94 | + cfg.parse(MASTER) |
71 | 95 |
|
| 96 | + # make IPL, optional! |
| 97 | + cfg.to_ipl(rootname=ROOT, destination=OUTPUT, template=OUTPUT, tool="rms") |
72 | 98 |
|
| 99 | + # YAML |
| 100 | + cfg.to_yaml(rootname=ROOT, destination=OUTPUT, template=OUTPUT) |
73 | 101 |
|
| 102 | + print("\n\nGlobal IPL and YML are updated") |
74 | 103 |
|
75 | | -Learn by examples! |
76 | | ------------------- |
77 | 104 |
|
78 | | -Learn the format by studying the following examples. |
| 105 | + if __name__ == "__main__": |
| 106 | + cleanup() |
| 107 | + main() |
0 commit comments