From: André Date: Wed, 21 Apr 2010 14:15:51 +0000 (+0200) Subject: Ajout des fichiers daSalome X-Git-Tag: V6_4_0rc3~173 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f07c13389e3b26d51d7bdb364fc6d06d7ff294fc;p=modules%2Fadao.git Ajout des fichiers daSalome --- diff --git a/configure.ac b/configure.ac index 4874a45..53b02b0 100644 --- a/configure.ac +++ b/configure.ac @@ -72,5 +72,6 @@ AC_CONFIG_FILES([ resources/Makefile src/Makefile src/daComposant/Makefile + src/daSalome/Makefile ]) AC_OUTPUT diff --git a/resources/DATASSIMSchemaCatalog.xml b/resources/DATASSIMSchemaCatalog.xml new file mode 100644 index 0000000..8984357 --- /dev/null +++ b/resources/DATASSIMSchemaCatalog.xml @@ -0,0 +1,98 @@ + + + + + pyobj + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/Makefile.am b/resources/Makefile.am index a571055..18cfec9 100644 --- a/resources/Makefile.am +++ b/resources/Makefile.am @@ -1,5 +1,7 @@ include $(top_srcdir)/adm_local/make_common_starter.am -DATA_INST = DATASSIMCatalog.xml + +DATA_INST = DATASSIMCatalog.xml DATASSIMSchemaCatalog.xml + salomeres_DATA = ${DATA_INST} EXTRA_DIST = ${DATA_INST} diff --git a/src/Makefile.am b/src/Makefile.am index 1ce4fbd..72c2d40 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1 +1 @@ -SUBDIRS= daComposant +SUBDIRS= daComposant daSalome diff --git a/src/daSalome/Makefile.am b/src/daSalome/Makefile.am new file mode 100644 index 0000000..a28f59e --- /dev/null +++ b/src/daSalome/Makefile.am @@ -0,0 +1,14 @@ +include $(top_srcdir)/adm_local/make_common_starter.am + +EXTRA_DIST = daYacsSchemaCreator + +DIR = $(top_srcdir)/src/daSalome/ + +install-data-local: + ${mkinstalldirs} $(DESTDIR)$(salomepythondir) + cp -R $(DIR)daYacsSchemaCreator $(DESTDIR)$(salomepythondir) + +uninstall-local: + chmod -R +w $(DESTDIR)$(salomepythondir) + rm -rf $(DESTDIR)$(salomepythondir)/daYacsSchemaCreator + diff --git a/src/daSalome/daYacsSchemaCreator/YacsSchemaCreator.py b/src/daSalome/daYacsSchemaCreator/YacsSchemaCreator.py new file mode 100755 index 0000000..cb78d76 --- /dev/null +++ b/src/daSalome/daYacsSchemaCreator/YacsSchemaCreator.py @@ -0,0 +1,75 @@ +#!/usr/bin/python +#-*-coding:iso-8859-1-*- +# Copyright (C) 2008-2009 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# -- +# Author : André RIBES (EDF R&D) +# -- + +import sys +import os +import traceback +import logging +from optparse import OptionParser +from daYacsSchemaCreator.methods import * +from daYacsSchemaCreator.help_methods import * + +# Variables globales +global my_parser + +# Init part +def init(): + + logging.basicConfig(level=logging.DEBUG, format='%(levelname)-8s %(message)s') + usage = "usage: %prog [options] config_file yacs_schema_filename" + version="%prog 0.1" + global my_parser + my_parser = OptionParser(usage=usage, version=version) + +# Start application +def main(): + + print "-- Starting YacsSchemaCreator --" + (options, args) = my_parser.parse_args() + check_args(args) + config_file = args[0] + yacs_schema_filename = args[1] + + # Import config_file + try: + execfile(config_file) + except: + logging.fatal("Exception in loading " + config_file) + traceback.print_exc() + sys.exit(1) + + if "study_config" not in locals(): + logging.fatal("Cannot found study_config in " + str(config_file)) + sys.exit(1) + else: + globals()['study_config'] = locals()['study_config'] + + if "DATASSIM_ROOT_DIR" not in os.environ: + logging.fatal("You have to define DATASSIM_ROOT_DIR") + sys.exit(1) + + check_study(study_config) + proc = create_yacs_proc(study_config) + write_yacs_proc(proc, yacs_schema_filename) + +init() +main() diff --git a/src/daSalome/daYacsSchemaCreator/__init__.py b/src/daSalome/daYacsSchemaCreator/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/daSalome/daYacsSchemaCreator/help_methods.py b/src/daSalome/daYacsSchemaCreator/help_methods.py new file mode 100644 index 0000000..b61588b --- /dev/null +++ b/src/daSalome/daYacsSchemaCreator/help_methods.py @@ -0,0 +1,99 @@ +#-*-coding:iso-8859-1-*- +# Copyright (C) 2010 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# -- +# Author : André RIBES (EDF R&D) +# -- + +import sys +import traceback +import logging + +from daYacsSchemaCreator.infos_daComposant import * + +def check_args(args): + + logging.debug("Arguments are :" + str(args)) + if len(args) != 2: + logging.fatal("Bad number of arguments: you have to provide two arguments (%d given)" % (len(args))) + sys.exit(1) + +def check_study(study_config): + + logging.debug("[check_env] study_config : " + str(study_config)) + + # Check study_config + if not isinstance(study_config, dict): + logging.fatal("Study configuration is not a dictionnary") + sys.exit(1) + + # Name + if "Name" not in study_config: + logging.fatal("Cannot found Name in the study configuration") + sys.exit(1) + + # Algorithm + if "Algorithm" not in study_config: + logging.fatal("Cannot found Algorithm in the study configuration") + sys.exit(1) + else: + if study_config["Algorithm"] not in AssimAlgos: + logging.fatal("Algorithm provided is unknow : " + str(study_config["Algorithm"]) + + "\n You can choose between : " + str(AssimAlgos)) + sys.exit(1) + + # Check if all the data is provided + for key in AlgoDataRequirements[study_config["Algorithm"]]: + if key not in study_config.keys(): + logging.fatal("Cannot found " + key + " in your study configuration !" + + "\n This key is mandatory into a study with " + study_config["Algorithm"] + " algorithm." + + "\n " + study_config["Algorithm"] + " requirements are " + str(AlgoDataRequirements[study_config["Algorithm"]])) + sys.exit(1) + + # Data + for key in study_config.keys(): + if key in AssimData: + check_data(key, study_config[key]) + +def check_data(data_name, data_config): + + logging.debug("[check_data] " + data_name) + data_name_data = "Data" + data_name_type = "Type" + data_name_from = "From" + + if data_name_data not in data_config: + logging.fatal(data_name +" found but " + data_name_data +" is not defined in the study configuration !") + sys.exit(1) + + if data_name_type not in data_config: + logging.fatal(data_name +" found but " + data_name_type +" is not defined in the study configuration !") + sys.exit(1) + else: + if data_config[data_name_type] not in AssimType[data_name]: + logging.fatal(data_name_type + " defined in the study configuration does not have a correct type : " + str(data_config[data_name_type]) + + "\n You can have : " + str(AssimType[data_name])) + sys.exit(1) + if data_name_from not in data_config: + logging.fatal(data_name + " found but " + data_name_from + " is not defined in the study configuration !") + sys.exit(1) + else: + if data_config[data_name_from] not in FromNumpyList[data_config[data_name_type]]: + logging.fatal(data_name_from + " defined in the study configuration does not have a correct value : " + str(data_config[data_name_from]) + + "\n You can have : " + str(FromNumpyList[data_config[data_name_type]])) + sys.exit(1) + diff --git a/src/daSalome/daYacsSchemaCreator/infos_daComposant.py b/src/daSalome/daYacsSchemaCreator/infos_daComposant.py new file mode 100644 index 0000000..25efba6 --- /dev/null +++ b/src/daSalome/daYacsSchemaCreator/infos_daComposant.py @@ -0,0 +1,48 @@ +#-*-coding:iso-8859-1-*- +# Copyright (C) 2010 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# -- +# Author : André RIBES (EDF R&D) +# -- + + +# -- Infos from daCore -- +AssimData = ["Background", "BackgroundError", + "Observation", "ObservationError", "ObservationOperator", "ObservationOperatorAppliedToX", + "EvolutionModel", "EvolutionError"] + +AssimType = {} +AssimType["Background"] = ["Vector"] +AssimType["BackgroundError"] = ["Matrix"] +AssimType["Observation"] = ["Vector"] +AssimType["ObservationError"] = ["Matrix"] +AssimType["ObservationOperator"] = ["Matrix", "Function"] +AssimType["ObservationOperatorAppliedToX"] = ["List"] + +FromNumpyList = {} +FromNumpyList["Vector"] = ["string"] +FromNumpyList["Matrix"] = ["string"] +FromNumpyList["Function"] = ["Dict"] +FromNumpyList["List"] = ["List"] + +# -- Infos from daAlgorithms -- +AssimAlgos = ["Blue", "EnsembleBlue", "Kalman", "LinearLeastSquares", "3DVAR"] + +AlgoDataRequirements = {} +AlgoDataRequirements["Blue"] = ["Background", "BackgroundError", + "Observation", "ObservationOperator", "ObservationError"] + diff --git a/src/daSalome/daYacsSchemaCreator/methods.py b/src/daSalome/daYacsSchemaCreator/methods.py new file mode 100644 index 0000000..29726b7 --- /dev/null +++ b/src/daSalome/daYacsSchemaCreator/methods.py @@ -0,0 +1,103 @@ +#-*-coding:iso-8859-1-*- +# Copyright (C) 2010 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# -- +# Author : André RIBES (EDF R&D) +# -- + +import sys +import traceback +import logging +import pilot +import loader +import SALOMERuntime +import os + +from daYacsSchemaCreator.infos_daComposant import * + +def create_yacs_proc(study_config): + + logging.debug("[create_yacs_proc]") + + # Init part + SALOMERuntime.RuntimeSALOME_setRuntime() + l = loader.YACSLoader() + l.registerProcCataLoader() + runtime = pilot.getRuntime() + try: + catalogAd = runtime.loadCatalog("proc", os.environ["DATASSIM_ROOT_DIR"] + "share/salome/resources/datassim/DATASSIMSchemaCatalog.xml") + except: + logging.fatal("Exception in loading DataAssim YACS catalog") + traceback.print_exc() + sys.exit(1) + + # Starting creating proc + proc = runtime.createProc("proc") + proc.setTypeCode("pyobj", runtime.getTypeCode("pyobj")) + t_pyobj = proc.getTypeCode("pyobj") + t_string = proc.getTypeCode("string") + + # Step 0: create AssimilationStudyObject + factory_CAS_node = catalogAd._nodeMap["CreateAssimilationStudy"] + CAS_node = factory_CAS_node.cloneNode("CreateAssimilationStudy") + CAS_node.getInputPort("Name").edInitPy(study_config["Name"]) + CAS_node.getInputPort("Algorithm").edInitPy(study_config["Algorithm"]) + proc.edAddChild(CAS_node) + + # Step 1: get input data from user configuration + + for key in study_config.keys(): + if key in AssimData: + data_config = study_config[key] + + key_type = key + "Type" + + if data_config["Type"] == "Vector" and data_config["From"] == "string": + # Create node + factory_back_node = catalogAd._nodeMap["CreateNumpyVectorFromString"] + back_node = factory_back_node.cloneNode("Get" + key) + back_node.getInputPort("vector_in_string").edInitPy(data_config["Data"]) + proc.edAddChild(back_node) + # Connect node with CreateAssimilationStudy + CAS_node.edAddInputPort(key, t_pyobj) + CAS_node.edAddInputPort(key_type, t_string) + proc.edAddDFLink(back_node.getOutputPort("vector"), CAS_node.getInputPort(key)) + proc.edAddDFLink(back_node.getOutputPort("type"), CAS_node.getInputPort(key_type)) + + if data_config["Type"] == "Matrix" and data_config["From"] == "string": + # Create node + factory_back_node = catalogAd._nodeMap["CreateNumpyMatrixFromString"] + back_node = factory_back_node.cloneNode("Get" + key) + back_node.getInputPort("matrix_in_string").edInitPy(data_config["Data"]) + proc.edAddChild(back_node) + # Connect node with CreateAssimilationStudy + CAS_node.edAddInputPort(key, t_pyobj) + CAS_node.edAddInputPort(key_type, t_string) + proc.edAddDFLink(back_node.getOutputPort("matrix"), CAS_node.getInputPort(key)) + proc.edAddDFLink(back_node.getOutputPort("type"), CAS_node.getInputPort(key_type)) + + + # Step 3: create optimizer loop + + # Step 4: create post-processing from user configuration + + return proc + +def write_yacs_proc(proc, yacs_schema_filename): + + proc.saveSchema(yacs_schema_filename) +