B
    <^L                 @   s   d Z ddlZddlZddlZddlZddlZddlZddlZddl	Z	dej
krfddlZe ejd< nddlZed ddlmZ G dd dZdS )z
.. module:: spectrograph
    :platform: unix
    :synopsis: This module is for communicating with the spectrograph instrument.

.. codeauthor:: Michael Coughlin, Eric Coughlin
    NZTESTENVIRONMENT	seabreezeZpyseabreezec               @   sJ   e Zd ZdZdd Zdd Zddd	Zd
d Zdd Zdd Z	dd Z
dS )SpectrographzC
    This is the class for communicating with the spectrograph
    c             C   s   d | _ |  | _d S )N)statuscreate_connectionspectrometer)self r   !/home/cbp/cbp/cbp/spectrograph.py__init__   s    zSpectrograph.__init__c          
   C   sf   t  }t| y t |d }d| _td |S  tk
r` } zt| d| _W dd}~X Y nX dS )zX
        This method creates a connection to the spectrograph

        :return:
        r   	connectedzSpectrograph connectedznot connectedN)sbZlist_devicesprintZSpectrometerr   	Exception)r   Zdevicesspecer   r   r	   r   !   s    zSpectrograph.create_connection@B test.datc       	      C   s   | j dkr| j}|| t|d  | }| }t|dkd }t|dkd }t	||}|| }|| }||fS dS )z
        This method returns the wavelength and intensities measured during the duration.

        :param duration:
        :param spectrumFile:
        :return:
        znot connectedgư>g     u@r   g     0@N)
r   r   Zintegration_time_microstimesleepwavelengthsintensitiesnpwhereintersect1d)	r   ZdurationZspectrumFiler   r   r   Zidx1Zidx2idxr   r   r	   get_spectrograph3   s    

zSpectrograph.get_spectrographc             C   s   | j dkr| j S dS )z[
        This method returns the temperature of the spectrograph

        :return:
        znot connectedN)r   r   Ztec_get_temperature_C)r   r   r   r	   get_temperatureR   s    
zSpectrograph.get_temperaturec             C   s   | j dkr| j| dS )zx
        This method sets a temperature in c for the spectrograph

        :param temperature:
        :return:
        znot connectedN)r   r   Ztec_set_temperature_C)r   Ztemperaturer   r   r	   set_temperature[   s    
zSpectrograph.set_temperaturec             C   s   | j dkr| jd dS )zk
        This method enables the powered temperature control of the spectrograph

        :return:
        znot connectedTN)r   r   tec_set_enable)r   r   r   r	   enable_temperature_controle   s    
z'Spectrograph.enable_temperature_controlc             C   s   | j dkr| jd dS )zm
        This method turns off the powered temperature control of the spectrograph

        :return:
        znot connectedFN)r   r   r   )r   r   r   r	   disable_temperature_controln   s    
z(Spectrograph.disable_temperature_controlN)r   r   )__name__
__module____qualname____doc__r
   r   r   r   r   r   r    r   r   r   r	   r      s   
	
	r   )r$   serialsysr   globstructosnumpyr   optparseenvironZmockZMockmodulesr   useZseabreeze.spectrometersZspectrometersr   r   r   r   r   r	   <module>   s   0

