Commit e5444dd8 authored by Médéric Boquien's avatar Médéric Boquien

Move the backup_dir() function to the base class of the analysis modules as it...

Move the backup_dir() function to the base class of the analysis modules as it makes sense for analysers to prepare the output directories.
parent ee7a6c0a
......@@ -4,11 +4,15 @@
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Yannick Roehlly & Denis Burgarella
from datetime import datetime
from importlib import import_module
import os
import shutil
import numpy as np
from astropy.table import Column
OUT_DIR = 'out/'
class AnalysisModule(object):
"""Abstract class, the pCigale analysis modules are based on.
......@@ -49,6 +53,17 @@ class AnalysisModule(object):
"""
raise NotImplementedError()
def prepare_dirs(self, directory=OUT_DIR):
# Create a new out/ directory and move existing one if needed
if os.path.exists(directory):
name = datetime.now().strftime("%Y%m%d%H%M") + '_' + directory
os.rename(directory, name)
print("The {} directory was renamed to {}".format(directory, name))
os.mkdir(directory)
shutil.copy('pcigale.ini', directory)
shutil.copy('pcigale.ini.spec', directory)
def process(self, configuration):
"""Process with the analysis
......
......@@ -41,7 +41,6 @@ from .workers import sed as worker_sed
from .workers import init_sed as init_worker_sed
from .workers import init_analysis as init_worker_analysis
from .workers import analysis as worker_analysis
from ..utils import backup_dir
from ...handlers.parameters_handler import ParametersHandler
......@@ -111,7 +110,7 @@ class PdfAnalysis(AnalysisModule):
print("Initialising the analysis module... ")
# Rename the output directory if it exists
backup_dir()
self.prepare_dirs()
# Initalise variables from input arguments.
variables = conf['analysis_params']["variables"]
......
......@@ -22,7 +22,7 @@ from multiprocessing.sharedctypes import RawArray
import time
from .. import AnalysisModule
from ..utils import backup_dir, save_fluxes
from ..utils import save_fluxes
from .workers import init_fluxes as init_worker_fluxes
from .workers import fluxes as worker_fluxes
from ...handlers.parameters_handler import ParametersHandler
......@@ -65,7 +65,7 @@ class SaveFluxes(AnalysisModule):
"""
# Rename the output directory if it exists
backup_dir()
self.prepare_dirs()
save_sed = conf['analysis_params']['save_sed']
filters = [name for name in conf['bands'] if not
......
......@@ -7,10 +7,6 @@
Various utility functions for pcigale analysis modules
"""
from datetime import datetime
import os
import shutil
import numpy as np
from astropy import log
from astropy.table import Table, Column
......@@ -20,20 +16,6 @@ log.setLevel('ERROR')
# Directory where the output files are stored
OUT_DIR = "out/"
def backup_dir(directory=OUT_DIR):
if os.path.exists(directory):
new_name = datetime.now().strftime("%Y%m%d%H%M") + "_" + directory
os.rename(directory, new_name)
print("The existing {} directory was renamed to {}".format(
directory,
new_name
))
os.mkdir(directory)
shutil.copyfile('pcigale.ini', directory + 'pcigale.ini')
shutil.copyfile('pcigale.ini.spec', directory + 'pcigale.ini.spec')
def save_fluxes(model_fluxes, model_parameters, filters, names,
directory=OUT_DIR):
"""Save fluxes and associated parameters into a table.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment