FROM = SIMP(statut = "o", typ = "TXM", into=(${data_into}), defaut=${data_default}),
SCRIPT_DATA = BLOC ( condition = " FROM in ( 'Script', ) ",
- SCRIPT_FILE = SIMP(statut = "o", typ = "Fichier"),
+ SCRIPT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr())),
),
STRING_DATA = BLOC ( condition = " FROM in ( 'String', ) ",
),
FUNCTIONDICT_DATA = BLOC ( condition = " FROM in ( 'FunctionDict', ) ",
- FUNCTIONDICT_FILE = SIMP(statut = "o", typ = "Fichier"),
+ FUNCTIONDICT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr())),
),
)
"""
)
def F_Init(statut) : return FACT(statut = statut,
- INIT_FILE = SIMP(statut = "o", typ = "Fichier"),
+ INIT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr())),
TARGET_LIST = SIMP(statut = "o", typ = "TXM", min=1, max="**", into=F_InitChoice(), validators=(VerifExiste(2))),
)
"""
# --
import sys
+import os
import traceback
import logging
if "Debug" not in study_config:
study_config["Debug"] = "0"
+ # Repertory
+ check_repertory = False
+ repertory = ""
+ if "Repertory" in study_config.keys():
+ repertory = study_config["Repertory"]
+ check_repertory = True
+ if not os.path.isabs(repertory):
+ logging.fatal("Study repertory should be an absolute path")
+ logging.fatal("Repertory provided is %s" % repertory)
+ sys.exit(1)
+
# Check if all the data is provided
for key in AlgoDataRequirements[study_config["Algorithm"]]:
if key not in study_config.keys():
# Data
for key in study_config.keys():
if key in AssimData:
- check_data(key, study_config[key])
+ check_data(key, study_config[key], check_repertory, repertory)
+
+ # UserDataInit
+ if "UserDataInit" in study_config.keys():
+ check_data("UserDataInit", study_config["UserDataInit"], check_repertory, repertory)
# Analyse
if "UserPostAnalysis" in study_config.keys():
logging.fatal("Analysis found but Data is not defined in the analysis configuration !")
sys.exit(1)
+ if analysis_config["From"] == "Script":
+ check_file_name = ""
+ if repertory_check:
+ check_file_name = os.path.join(repertory, os.path.basename(analysis_config["Data"]))
+ else:
+ check_file_name = analysis_config["Data"]
+ if not os.path.exists(check_file_name):
+ logging.fatal("A script file cannot be found")
+ logging.fatal("File is %s" % check_file_name)
+ sys.exit(1)
-def check_data(data_name, data_config):
+def check_data(data_name, data_config, repertory_check=False, repertory=""):
logging.debug("[check_data] " + data_name)
data_name_data = "Data"
+ "\n You can have : " + str(FromNumpyList[data_config[data_name_type]]))
sys.exit(1)
+ # Check des fichiers
+ from_type = data_config["From"]
+ if from_type == "Script":
+ check_file_name = ""
+ if repertory_check:
+ check_file_name = os.path.join(repertory, os.path.basename(data_config["Data"]))
+ else:
+ check_file_name = data_config["Data"]
+ if not os.path.exists(check_file_name):
+ logging.fatal("A script file cannot be found")
+ logging.fatal("File is %s" % check_file_name)
+ sys.exit(1)
+ elif from_type == "FunctionDict":
+ FunctionDict = data_config["Data"]
+ for FunctionName in FunctionDict["Function"]:
+ check_file_name = ""
+ if repertory_check:
+ check_file_name = os.path.join(repertory, os.path.basename(FunctionDict["Script"][FunctionName]))
+ else:
+ check_file_name = FunctionDict["Script"][FunctionName]
+ if not os.path.exists(check_file_name):
+ logging.fatal("A script file cannot be found")
+ logging.fatal("File is %s" % check_file_name)
+ sys.exit(1)
AssimType["ObservationError"] = ["Matrix"]
AssimType["ObservationOperator"] = ["Matrix", "Function"]
AssimType["AlgorithmParameters"] = ["Dict"]
+AssimType["UserDataInit"] = ["Dict"]
#AssimType["ObservationOperatorAppliedToX"] = ["List"]
FromNumpyList = {}
AssimDataDict["ObservationError"] = ["Matrix"]
AssimDataDict["ObservationOperator"] = ["Matrix", "Function"]
AssimDataDict["AlgorithmParameters"] = ["Dict"]
+AssimDataDict["UserDataInit"] = ["Dict"]
AssimDataDefaultDict = {}
AssimDataDefaultDict["Background"] = "Vector"
AssimDataDefaultDict["ObservationError"] = "Matrix"
AssimDataDefaultDict["ObservationOperator"] = "Function"
AssimDataDefaultDict["AlgorithmParameters"] = "Dict"
+AssimDataDefaultDict["UserDataInit"] = "Dict"
# Assimilation optional nodes
OptDict = {}
t_pyobj = proc.getTypeCode("pyobj")
t_string = proc.getTypeCode("string")
+ repertory = False
+ base_repertory = ""
+ if "Repertory" in study_config.keys():
+ base_repertory = study_config["Repertory"]
+ repertory = True
+
# Step 0: create AssimilationStudyObject
factory_CAS_node = catalogAd._nodeMap["CreateAssimilationStudy"]
CAS_node = factory_CAS_node.cloneNode("CreateAssimilationStudy")
init_config = study_config["UserDataInit"]
factory_init_node = catalogAd._nodeMap["UserDataInitFromScript"]
init_node = factory_init_node.cloneNode("UserDataInit")
- init_node.getInputPort("script").edInitPy(init_config["Data"])
+ if repertory:
+ init_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(init_config["Data"])))
+ else:
+ init_node.getInputPort("script").edInitPy(init_config["Data"])
proc.edAddChild(init_node)
# Step 1: get input data from user configuration
# Create node
factory_back_node = catalogAd._nodeMap["CreateDictFromScript"]
back_node = factory_back_node.cloneNode("Get" + key)
- back_node.getInputPort("script").edInitPy(data_config["Data"])
+ if repertory:
+ back_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(data_config["Data"])))
+ else:
+ back_node.getInputPort("script").edInitPy(data_config["Data"])
back_node.edAddOutputPort(key, t_pyobj)
proc.edAddChild(back_node)
# Connect node with CreateAssimilationStudy
# Create node
factory_back_node = catalogAd._nodeMap["CreateNumpyVectorFromScript"]
back_node = factory_back_node.cloneNode("Get" + key)
- back_node.getInputPort("script").edInitPy(data_config["Data"])
+ if repertory:
+ back_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(data_config["Data"])))
+ else:
+ back_node.getInputPort("script").edInitPy(data_config["Data"])
back_node.edAddOutputPort(key, t_pyobj)
proc.edAddChild(back_node)
# Connect node with CreateAssimilationStudy
# Create node
factory_back_node = catalogAd._nodeMap["CreateNumpyMatrixFromScript"]
back_node = factory_back_node.cloneNode("Get" + key)
- back_node.getInputPort("script").edInitPy(data_config["Data"])
+ if repertory:
+ back_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(data_config["Data"])))
+ else:
+ back_node.getInputPort("script").edInitPy(data_config["Data"])
back_node.edAddOutputPort(key, t_pyobj)
proc.edAddChild(back_node)
# Connect node with CreateAssimilationStudy
for FunctionName in FunctionDict["Function"]:
port_name = "ObservationOperator" + FunctionName
CAS_node.edAddInputPort(port_name, t_string)
- CAS_node.getInputPort(port_name).edInitPy(FunctionDict["Script"][FunctionName])
+ if repertory:
+ CAS_node.getInputPort(port_name).edInitPy(os.path.join(base_repertory, os.path.basename(FunctionDict["Script"][FunctionName])))
+ else:
+ CAS_node.getInputPort(port_name).edInitPy(FunctionDict["Script"][FunctionName])
# Step 3: create compute bloc
compute_bloc = runtime.createBloc("compute_bloc")
# We create a new pyscript node
opt_script_node = runtime.createScriptNode("", "FunctionNode")
- if not os.path.exists(script_filename):
- logging.fatal("Function script source file does not exists ! :" + script_filename)
- sys.exit(1)
+ if repertory:
+ script_filename = os.path.join(base_repertory, os.path.basename(script_filename))
try:
script_str= open(script_filename, 'r')
except:
factory_analysis_node = catalogAd._nodeMap["SimpleUserAnalysis"]
analysis_node = factory_analysis_node.cloneNode("UserPostAnalysis")
default_script = analysis_node.getScript()
- if not os.path.exists(analysis_config["Data"]):
- logging.fatal("Analysis source file does not exists ! :" + str(analysis_config["Data"]))
- sys.exit(1)
+ analysis_file_name = analysis_config["Data"]
+ if repertory:
+ analysis_file_name = os.path.join(base_repertory, os.path.basename(analysis_file_name))
try:
- analysis_file = open(analysis_config["Data"], 'r')
+ analysis_file = open(analysis_file_name, 'r')
except:
logging.fatal("Exception in opening analysis file : " + str(analysis_config["Data"]))
traceback.print_exc()