-
Notifications
You must be signed in to change notification settings - Fork 11
/
pre_main_spatial.py
60 lines (44 loc) · 1.76 KB
/
pre_main_spatial.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This script generates the correlated parameter maps needed for
spatial propagation. It can be considered a necessary pre-processor
in case of enabling spatial propagation.
Author: Esteban Alonso González - [email protected]
"""
import modules.spatialMuSA as spM
import modules.internal_fns as ifn
import sys
import config as cfg
import numpy as np
import os
def main():
if cfg.implementation != 'Spatial_propagation':
print("implementation != 'Spatial_propagation',"
" this script is not necesary")
return None
# get DA steps
ini_DA_window = spM.domain_steps()
if cfg.parallelization == "multiprocessing":
if cfg.MPI:
raise Exception('MPI not suppoted yet for pre_main_spatial.py')
# Sample prior parameters
spM.generate_prior_maps_onenode(ini_DA_window)
elif cfg.parallelization == "HPC.array":
HPC_task_number = int(sys.argv[1])
HPC_task_id = int(sys.argv[2])-1
if HPC_task_number > len(ini_DA_window):
print('There are {DAW} DAWs and {tasks} tasks were requested,'
' It is recommended to reduce the number of jobs'
' in the array'.format(DAW=str(len(ini_DA_window)),
tasks=str(HPC_task_number)
))
ids = np.arange(0, len(ini_DA_window))
ids = ids % HPC_task_number == HPC_task_id
spM.generate_prior_maps_onenode(ini_DA_window[ids])
if __name__ == "__main__":
print('Running MuSA pre-processor')
main()
dist_name = os.path.join(cfg.spatial_propagation_storage_path,
'dist_0.nc')
ifn.change_chunk_size_nccopy(dist_name)