Commit 5aba1c8e authored by Médéric Boquien's avatar Médéric Boquien
Browse files

Move the backup dir function to the utils file common to all analysis modules...

Move the backup dir function to the utils file common to all analysis modules so it can easily be used by all anlysis modules.
parent 3caa5296
...@@ -34,14 +34,14 @@ import numpy as np ...@@ -34,14 +34,14 @@ import numpy as np
from ...utils import read_table from ...utils import read_table
from .. import AnalysisModule, complete_obs_table from .. import AnalysisModule, complete_obs_table
from .utils import save_table_analysis, save_table_best, backup_dir from .utils import save_table_analysis, save_table_best
from ...warehouse import SedWarehouse from ...warehouse import SedWarehouse
from ...data import Database from ...data import Database
from .workers import sed as worker_sed from .workers import sed as worker_sed
from .workers import init_sed as init_worker_sed from .workers import init_sed as init_worker_sed
from .workers import init_analysis as init_worker_analysis from .workers import init_analysis as init_worker_analysis
from .workers import analysis as worker_analysis from .workers import analysis as worker_analysis
from ..utils import ParametersHandler from ..utils import ParametersHandler, backup_dir
# Tolerance threshold under which any flux or error is considered as 0. # Tolerance threshold under which any flux or error is considered as 0.
TOLERANCE = 1e-12 TOLERANCE = 1e-12
......
...@@ -5,15 +5,11 @@ ...@@ -5,15 +5,11 @@
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt # Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Yannick Roehlly & Médéric Boquien # Author: Yannick Roehlly & Médéric Boquien
from datetime import datetime
import os
from astropy.table import Table, Column from astropy.table import Table, Column
import numpy as np import numpy as np
from scipy.stats import gaussian_kde from scipy.stats import gaussian_kde
from scipy.linalg import LinAlgError from scipy.linalg import LinAlgError
# Directory where the output files are stored
OUT_DIR = "out/"
# Number of points in the PDF # Number of points in the PDF
PDF_NB_POINTS = 1000 PDF_NB_POINTS = 1000
# Name of the file containing the analysis results # Name of the file containing the analysis results
...@@ -234,14 +230,3 @@ def save_table_best(obsid, chi2, chi2_red, variables, fluxes, filters, ...@@ -234,14 +230,3 @@ def save_table_best(obsid, chi2, chi2_red, variables, fluxes, filters,
best_model_table.add_column(column) best_model_table.add_column(column)
best_model_table.write(OUT_DIR + BEST_MODEL_FILE) best_model_table.write(OUT_DIR + BEST_MODEL_FILE)
def backup_dir(directory):
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(
OUT_DIR,
new_name
))
os.mkdir(OUT_DIR)
...@@ -7,11 +7,16 @@ ...@@ -7,11 +7,16 @@
Various utility functions for pcigale analysis modules Various utility functions for pcigale analysis modules
""" """
import itertools from datetime import datetime
import collections import collections
import itertools
import os
import numpy as np import numpy as np
# Directory where the output files are stored
OUT_DIR = "out/"
class ParametersHandler(object): class ParametersHandler(object):
"""Class to handle the parameters to generate a parameter list on-the-fly. """Class to handle the parameters to generate a parameter list on-the-fly.
""" """
...@@ -116,3 +121,14 @@ class ParametersHandler(object): ...@@ -116,3 +121,14 @@ class ParametersHandler(object):
return module_idx return module_idx
return len(self.shape) return len(self.shape)
def backup_dir(directory):
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(
OUT_DIR,
new_name
))
os.mkdir(OUT_DIR)
Supports Markdown
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