Ejemplo n.º 1
0
 def __init__(self, folder, data_format=None):
     r"""
     Initialization of the stack. Reading in the maps and creating a list
     of ``Map`` class objects, depending on the input format.
     """
     self.log = log_tools.init_logger(
         directory="/home/{}/.astrolyze/".format(USER),
         name="astrolyze"
     )
     self.gildas_formats = ['gdf', 'mean', 'velo', 'width', 'lmv',
                            'lmv-clean']
     self.fits_formats = ['fits']
     self.miriad_formats = ['']
     self.folder = folder
     self.get_list(data_format=data_format)
     print self.list
     self.stack = []
     for i in self.list:
         self.stack += [self.get_map_format(i)]
     self.resolutions = []
     self.units = []
     self.dataFormats = []
     for i in self.stack:
         print i
         self.resolutions += [i.resolution]
         self.units += [i.fluxUnit]
         self.dataFormats = [i.dataFormat]
     self.log = log_tools.init_logger(
         directory="/home/{}/.astrolyze/".format(USER),
         name="astrolyze"
     )
Ejemplo n.º 2
0
 def __init__(self, source=None, target=None, exclude_file=None, options=None, delete=False, use_ssh=False):
     self.log = log_tools.init_logger("rsync")
     self.rsync_path = "/usr/bin/rsync"
     if not os.path.isfile(self.rsync_path):
         self.log.error("Can't find rsync under {}".format(self.rsync_path))
         raise SystemExit
     self.source = source
     self.target = target
     self.exclude_file = exclude_file
     self.options = options
     self.delete = delete
     self.use_ssh = use_ssh
     self.command = self.create_rsync_command()
Ejemplo n.º 3
0
 def __init__(self, source_name, coordinate, flux_array,
              number_components=2, init_fit=True, temperature_guess=None,
              mass_guess=None, beta_guess=None):
     self.log = log_tools.init_logger(
         directory="/home/{}/.astrolyze/".format(USER),
         name="astrolyze"
     )
     self.source_name = source_name
     self.coordinate = coordinate
     self.number_components = number_components
     self.temperature_guess = temperature_guess
     self.mass_guess = mass_guess
     self.beta_guess = beta_guess
     self.flux_array = flux_array
     self.fit_temperatures = None
     self.fit_masses = None
     self.fit_beta = None
     self.fit_done = False
     self.set_defaults()
     if init_fit:
         self.grey_body_fit()
         self.log.debug(self.info())
Ejemplo n.º 4
0
import os
import sqlite3
import glob
import datetime
import subprocess
import hashlib

from .tools import get_file_hash
from generaltools import log_tools

LOG = log_tools.init_logger("transfer_inbox")

SOURCE = "/home/buchbend/scratch/DCIM/"
PICTURES = "/home/buchbend/scratch/Pictures/"
INBOX = "INBOX"

DATABASE = ".transfer.db"
EXTERNAL_DATABASES = [".transfer_uta.db", ".transfer_christof.db"]

FILE_TYPES = ["JPG", "MP4", "AVI"]

def connect_to_database(database):
    conn = sqlite3.connect(database)
    c = conn.cursor()
    return conn, c

def check_if_transferred(path, hash_, cursor):
    cursor.execute('''SELECT * FROM transferred
    WHERE file_name=\"{}\" and
    hash=\"{}\"'''.format(path, hash_))
    try:
Ejemplo n.º 5
0
import os
import re
import subprocess
import socket
from generaltools import log_tools

log = log_tools.init_logger("system_tools", log_to_file=False)

def download_file(url, path_to_store):
    cmd = ["wget", url, path_to_store]
    subprocess.call(cmd)

def store_package_list(output_file=None):
    cmd = ["dpkg", "--get-selections"]
    package_list = subprocess.check_output(cmd)
    pattern = r"^.*(deinstall|hold|purge)\n"
    new_list = re.sub(pattern, '', package_list, flags=re.MULTILINE)
    pattern = r"\s*[^de]install$"
    new_list = re.sub(pattern, '', package_list, flags=re.MULTILINE)
    if output_file:
        with open(output_file, "w") as file_:
            log.debug("Storing package list to {}".format(file_))
            file_.write(new_list)
    else:
        return new_list.split("\n")

def add_package_to_list(package, list_):
    pattern = r"^{}$".format(package)
    with open(list_, "r") as file_:
        list_string = file_.read()
        package_present = re.search(pattern,
Ejemplo n.º 6
0
 def _init_logger(self, name, directory="."):
     """ Set up a logging file """
     return log_tools.init_logger(name=name, directory=directory, log_level=logging.DEBUG)
Ejemplo n.º 7
0
import scipy

from scipy.optimize import leastsq as least
from numpy import asarray, mean, std, where, exp, log, sqrt, arange
from copy import deepcopy as copy
import random as rnd

from generaltools import log_tools

import astrolyze.functions.constants as const
import astrolyze.functions.units

USER = os.getenv("USER")

log = log_tools.init_logger(
    directory="/home/{}/.astrolyze/".format(USER),
    name="astrolyze"
)

def black_body(x, T, nu_or_lambda='nu'):
    r"""
    Calculation of the flux density of a black body at a temperature T and a
    wavelenght/frequency x.

    Parameters
    ----------
    x : float or numpy array
        wavelength [GHz] or frequency [micron];  specify type in nu_or_lambda
    T : float [Kelvin]
        Temperature of the black_body
    nu_or_lambda : string
        Specify whether x is a frequency :math:`\nu` ``'nu'`` or a wavelenght
Ejemplo n.º 8
0
import sqlite3
import pyinotify
import datetime

from generaltools import log_tools
from .tools import get_file_hash

PICTURES = "/home/buchbend/scratch/Pictures"
INBOX = "INBOX"
LOG = log_tools.init_logger("monitor_inbox", "/var/log/monitor_inbox")

FILE_TYPES = ["JPG", "MP4"]

class MyEventHandler(pyinotify.ProcessEvent):

    def __init__(self, database):
        self.conn = sqlite3.connect(database)

        self.c = self.conn.cursor()
        try:
            self.c.execute('''CREATE TABLE transferred (file_name text,
            hash text, date_transferred date)
            ''')
        except sqlite3.OperationalError:
            LOG.debug("Table exists already")


    def process_IN_ACCESS(self, event):
        print "ACCESS event:", event.pathname

    def process_IN_ATTRIB(self, event):
Ejemplo n.º 9
0
    def __init__(self, map_name, **kwargs):
        '''
        Initialize a map to maps.
        '''
        USER = os.getenv("USER")
        config_path = "/home/{}/.astrolyze/".format(USER)
        config_file = "astrolyze.cfg"
        self.config = ConfigParser.ConfigParser()
        self.config.read("{}{}".format(config_path, config_file))
        # Definition of the unit nomenclatures.
        self.log = log_tools.init_logger(
            directory="/home/{}/.astrolyze/".format(USER),
            name="astrolyze"
        )
        USER = os.getenv("USER")
        self.database_prefix = self.config.get("General", "database_prefix")
        self.database_prefix = self.database_prefix.format(USER)

        # Load configuration from config_file
        self.jansky_beam_names = self.config.get(
            "Units", "jansky_beam_names"
        ).split(',')
        self.jansky_pixel_names = self.config.get(
            "Units", "jansky_pixel_names"
        ).split(',')
        self.tmb_names = self.config.get(
            "Units", "tmb_names"
        ).split(',')
        self.MJy_per_sterad_names = self.config.get(
            "Units", "MJy_per_sterad_names"
        ).split(',')
        self.erg_sec_pixel_names =  self.config.get(
            "Units", "erg_sec_pixel_names"
        ).split(',')
        self.erg_sec_beam_names = self.config.get(
            "Units", "erg_sec_beam_names"
        ).split(',')
        self.erg_sec_sterad_names =  self.config.get(
            "Units", "erg_sec_sterad_names"
        ).split(',')

        self.known_units = (self.jansky_beam_names + self.jansky_pixel_names +
                            self.tmb_names + self.MJy_per_sterad_names +
                            self.erg_sec_beam_names +
                            self.erg_sec_sterad_names +
                            self.erg_sec_pixel_names)
        # Definition of possible data format endings for the different
        # programs.

        self.gildas_formats = self.config.get(
            "Formats", "gildas_formats"
        ).split(',')
        self.fits_formats = self.config.get(
            "Formats", "fits_formats"
        ).split(',')
        self.miriad_formats = ['',None]
        self.class_formats = self.config.get(
            "Formats", "class_formats"
        ).split(',')
        # name_convention is not needed anymore. Only kept for backward
        # compatibality.
        self.map_name = map_name
        # Test if the file exists. Directory for Miriad.
        # File for Fits and GILDAS.
        if ((not os.path.isdir(self.map_name)
             and not os.path.isfile(self.map_name))):
            self.log.critical(
                'Exiting: {} does not exist'.format(self.map_name)
            )
            raise SystemExit
        # Get Informations from the file name.

        self.map_nameList = map_name.split('/')[-1].split('_')
        if len(self.map_nameList) < 5:
            self.log.critical(
                "This map does not follow the Naming Convention for Astrolyze"
            )
            raise SystemExit
        self.map_nameList = map_name.split('/')[-1].split('_')
        self.prefix_list = map_name.split('/')[0:-1]
        self.comments = []
        self.source = self.map_nameList[0].split('/')[-1]
        if len(self.prefix_list) > 0:
            self.prefix = string.join(self.prefix_list, '/') + '/'
        elif len(self.prefix_list) == 0:
            self.prefix = ''
        self.telescope = self.map_nameList[1]
        self.species = self._resolveSpecies()
        self.fluxUnit = self.map_nameList[3]
        # Check dataFormat.
        if self.map_name.endswith('.fits'):
            self.dataFormat = 'fits'
            self.map_nameList[-1] = self.map_nameList[-1].replace(
                '.fits', ''
            )
        for i in self.gildas_formats:
            if self.map_name.endswith('.' + i):
                self.dataFormat = i
                self.map_nameList[-1] = self.map_nameList[-1].replace(
                    '.' + i, ''
                )
        for i in self.class_formats:
            if self.map_name.endswith('.' + i):
                self.dataFormat = i
                self.map_nameList[-1] = self.map_nameList[-1].replace(
                    '.' + i, ''
                )
        if os.path.isdir(self.map_name):
            # Miriad Data Format uses directories
            self.dataFormat = None
        self.resolution = self._resolveResolution()
        # Entries after the fifth are considered comments.
        if len(self.map_nameList) > 5:
            for i in range(len(self.map_nameList) - 6):
                self.comments += [self.map_nameList[i + 5]]
            self.comments += [self.map_nameList[-1]]
        #!!!!!  TODO: Bas implementation. Try should only contain very short
        # parts of the program otherwise errors in the program are camouflaged.
        try:
            self.connection = sqlite.connect(str(self.database_prefix) +
                                             'parameter.db')
            self.cursor = self.connection.cursor()
            self.cursor.execute("SELECT * FROM Galaxies WHERE Name = ?",
                                (self.source.upper(),))
            self.params = self.cursor.fetchall()[0]
            self.type = self.params[2]
            self.distance = self.params[3]
            self.vlsr = self.params[4]
            self.centralPosition = self.params[5]
            self.pa = self.params[6]
            self.inclination = self.params[7]
            self.R25 = self.params[8]
            self.cursor.close()
            self.connection.close()
        except:
            self.params = None
            self.type = None
            self.distance = None
            self.vlsr = None
            self.centralPosition = None
            self.pa = None
            self.inclination = None
            self.R25 = None
        try:
            self.connection = sqlite.connect(str(self.database_prefix) +
                                             'parameter.db')
            self.cursor = self.connection.cursor()
            self.cursor.execute("SELECT * FROM Lines WHERE Name = ?",
                                (self.species.upper(),))
            self.params = self.cursor.fetchall()[0]
            self.frequency = self.params[2]
            self.wavelength = self.params[3]
            self.cursor.close()
            self.connection.close()
        except:
            pass
        try:
            self.connection = sqlite.connect(str(self.database_prefix) +
                                             'parameter.db')
            self.cursor = self.connection.cursor()
            self.cursor.execute("SELECT * FROM cal_error WHERE Telescope = "
                                " ? AND Species = ?", (self.telescope.upper(),
                                                       self.species.upper()))
            self.params = self.cursor.fetchall()[0]
            self.calibrationError = self.params[3]
            self.cursor.close()
            self.connection.close()
        except:
            self.calibrationError = np.nan
        self.get_beam_size()