File: create_datastack_bash.py

package info (click to toggle)
doris 5.0.3~beta%2Bdfsg-19
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 6,944 kB
  • sloc: cpp: 43,560; python: 8,213; csh: 3,636; sh: 2,527; ansic: 649; makefile: 337; xml: 208
file content (80 lines) | stat: -rw-r--r-- 3,059 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# This function creates the bash script in the data folder to run the final datastack.
# please note that you still have to define your start and end dates!

import os
import xml.etree.ElementTree as ET

class CreateBash(object):


    def __init__(self):
        return

    def create(self, stack_folder, root_folder, nodes):

        # xml_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
        #                         'install/doris_config.xml')
        xml_file = os.environ.get('DORIS_CONFIG_FILE', os.path.expanduser('~/.doris_config.xml'))
        if not os.path.isfile(xml_file):
            xml_file = '/etc/doris_config.xml'
        tree = ET.parse(xml_file)
        settings = tree.getroot()

        source_path = settings.find('.source_path').text
        doris_folder = os.path.dirname(settings.find('.doris_path').text)
        cpxfiddle_folder = os.path.dirname(settings.find('.cpxfiddle_path').text)
        snaphu_folder = os.path.dirname(settings.find('.snaphu_path').text)

        file_path=os.path.join(stack_folder, 'doris_stack.sh')

        f = open(file_path, 'w')

        doris_run_script = os.path.join(source_path, 'doris_stack', 'main_code', 'doris_main.py')
        processing = stack_folder

        f.write('#!/bin/bash \n')
        f.write('\n')
        f.write('#PBS -l nodes=1:ppn=' + nodes + ' \n')
        f.write('\n')
        f.write('source_path=' + source_path + '\n')
        f.write('export PYTHONPATH=$source_path:$PYTHONPATH \n')
        f.write('export PATH=' + doris_folder + ':' + cpxfiddle_folder + ':' + snaphu_folder + ':' + '$PATH \n')
        f.write(sys.executable + ' ' + doris_run_script + ' -p ' + processing + ' \n')

        f.close()

        # make sure the file is executable
        os.chmod(file_path, 0o744)

        # Also create a download and dem creation bash script.
        file_path = os.path.join(stack_folder, 'create_dem.sh')
        f = open(file_path, 'w')

        doris_run_script = os.path.join(source_path, 'prepare_stack', 'create_dem.py')
        processing = stack_folder

        f.write('#!/bin/bash \n')
        f.write('\n')
        f.write('source_path=' + source_path + '\n')
        f.write('export PYTHONPATH=$source_path:$PYTHONPATH \n')
        f.write(sys.executable + ' ' + doris_run_script + ' ' + processing + ' SRTM3 \n')
        f.close()

        # make sure the file is executable
        os.chmod(file_path, 0o744)

        file_path = os.path.join(stack_folder, 'download_sentinel.sh')
        f = open(file_path, 'w')
        f.write('source_path=' + source_path + '\n')
        f.write('export PYTHONPATH=$source_path:$PYTHONPATH \n')
        doris_run_script = os.path.join(source_path, 'prepare_stack', 'download_sentinel_data_orbits.py')
        processing = stack_folder

        f.write('#!/bin/bash \n')
        f.write('\n')

        f.write(sys.executable + ' ' + doris_run_script + ' ' + processing + ' \n')
        f.close()

        # make sure the file is executable
        os.chmod(file_path, 0o744)