Example #1
0
def take_photo(gpio_pin_number):
    '''
    :param gpio_pin_number: The Pi's GPIO pin number to signal to the user that the photo is being taken
    :return: The filepath of the new image
    '''

    photo_location = ""

    InOut.led_take_photo(gpio_pin_number)

    try:
        photo_location = actuate_camera_shutter()

    except subprocess.CalledProcessError:
        InOut.script_event_indicator()
        print "Unable to take photo as camera is not turned on or battery is dead"
        logging.error(
            "Unable to take photo as camera is not turned on or battery is dead"
        )
        raise Exception(
            "Camera is not responding, battery is dead or camera is not turned on"
        )

    else:
        return photo_location
Example #2
0
    def test_export_project(self):
        """
        Test if a created project can be exported.
        Result expected : yes
        
        ..codeauthor:: Salomé Attar, Laura Xénard
        """

        # If everything goes well
        path_export_success = os.path.abspath(
            os.path.split(os.path.realpath(__file__))[0] +
            "/Ressources_pour_tests_unitaires/Project_test_open/save/test_save_open"
        )
        project1 = InOut.open_project(path_export_success)[0]
        self.assertEqual(InOut.export_project(project1, True, False, False),
                         "Analysis exported.")

        # Cleaning after the test
        path = os.path.abspath(os.path.join(project1.path + '/export/'))
        shutil.rmtree(path, ignore_errors=True)

        # If the export directory does not exist
        path_export_fail = os.path.abspath(
            os.path.split(os.path.realpath(__file__))[0] +
            "/Ressources_pour_tests_unitaires/Project_test_export_fail/save/test_save_export"
        )
        project2 = InOut.open_project(path_export_fail)[0]
        self.assertEqual(InOut.export_project(project2, True, False, False),
                         "An error occurred during the export.")

        # Cleaning after the test
        os.mkdir(path)
Example #3
0
    def test_total_distance(self):
        s = Seq("A",IUPAC.unambiguous_dna)
        i = 0
        seq = InOut.read('seqT.fasta')
        r = InOut.total_distance(s,seq,1)
        self.assertEqual(0, r)

        s = Seq("AA",IUPAC.unambiguous_dna)
        i = 0
        seq = InOut.read('seqT.fasta')
        r = InOut.total_distance(s,seq,2)
        self.assertEqual(1, r)


        s = Seq("TT",IUPAC.unambiguous_dna)
        i = 0
        seq = InOut.read('seqT.fasta')
        r = InOut.total_distance(s,seq,2)
        self.assertEqual(0, r)

        s = Seq("TAGTT",IUPAC.unambiguous_dna)
        i = 0
        seq = InOut.read('seqT.fasta')
        r = InOut.total_distance(s,seq,5)
        self.assertEqual(0, r)

        s = Seq("TC",IUPAC.unambiguous_dna)
        i = 0
        seq = InOut.read('seqT.fasta')
        r = InOut.total_distance(s,seq,2)
        self.assertEqual(1, r)
Example #4
0
def run(args, noise):
    '''
    Runs the Grover simulation with the input of reg size and target fock in args and
    a value for noise(0 if none). This has print statements to say the current operation and timings.
    There is an option to display the Oracle and Diffusion matrices used for the current run by
    commenting in the lines below the NOTE.
    '''
    # --- Reg size and target value ---
    n = args[0]
    target = args[1]

    # --- Timer Initialise ---
    t1 = t.time()

    # --- Initialised gates ---
    print('\nInitialising gates...')
    I = Identity()
    H = Hadamard(n)  #hadamard all
    X = PauliX(n)  #paulix all
    x = PauliX()
    z = PauliZ()
    cZ = Controlled(z, n)  #controlled z all
    #for noisy use; Initialises all gates with the same noise
    if noise != 0:
        I = Noisy(I, noise[0])
        H = Noisy(H, noise[1])
        x = Noisy(x, noise[2])
        X = Noisy(X, noise[3])
        cZ = Noisy(cZ, noise[4])
    print('Gate initialisation took ' + str(t.time() - t1) + ' s')

    # --- Qreg formation ---
    print('\nForming quantum register...')
    t2 = t.time()
    q = Qubit(n)
    print('Quantum register formation took ' + str(t.time() - t2) + ' s')

    # --- Number of Iterations calculation ---
    its = numits(n)

    # --- Fock to Binary Array Conversion ---
    Binaryform = findBinary(n, target)

    # --- Oracle PauliX application dependent on Fock Target ---
    Search = oracleX(n, Binaryform, x, I)

    # --- Create Superposition and Grover's Iteration ---
    q = grover(q, Search, cZ, H, X, its)

    # --- Measure and Display ---
    q.measure()
    IO.printOut(q, target)
    tf = t.time() - t1
    print('\nThis took ' + str(tf) + ' s to run')
    #NOTE: Comment in to display Oracle and Diffusion matrices, can increase runtime
    #      significantly for higher number of qubits
    #IO.display(formOracle(Search, cZ))
    #IO.display(formDiffusion(H, X, cZ))
    return tf
Example #5
0
def photobooth_main():
    '''
    Takes 4 photos in a series, tweets each one and then saves the individual files plus a vertical montage onto the pi
    :return: True/False on whether the process was successful
    '''

    process_success = False
    photo_file_locations_original = []
    photo_file_locations_converted = []

    # Take photo 1
    photo_location = take_photo(r.PIN_LED_PHOTO_1)
    photo_file_locations_original.append(photo_location)

    # Take photo 2
    photo_location = take_photo(r.PIN_LED_PHOTO_2)
    photo_file_locations_original.append(photo_location)

    # Take photo 3
    photo_location = take_photo(r.PIN_LED_PHOTO_3)
    photo_file_locations_original.append(photo_location)

    # Take photo 4
    photo_location = take_photo(r.PIN_LED_PHOTO_4)
    photo_file_locations_original.append(photo_location)

    print photo_file_locations_original

    try:

        # Turn on the "waiting" LED
        InOut.turn_off_all_leds([
            r.PIN_LED_PHOTO_1, r.PIN_LED_PHOTO_2, r.PIN_LED_PHOTO_3,
            r.PIN_LED_PHOTO_4
        ])
        GPIO.output(r.PIN_LED_PHOTO_WAIT, True)

        # Convert each of the captured photos into a standardised format
        for photo in photo_file_locations_original:
            mono_photo_filepath = convert_image(photo)
            photo_file_locations_converted.append(mono_photo_filepath)

        #Turn off the "waiting" light
        GPIO.output(r.PIN_LED_PHOTO_WAIT, False)

        # Create a montage of the captured photos and save them down
        montage_image_name = "photobooth_" + strftime("%Y-%m-%d_%H%M%S",
                                                      gmtime()) + ".jpg"
        montage_filepath = r.FOLDER_PHOTOS_MONTAGE + montage_image_name

        montage = create_image_montage(photo_file_locations_converted)
        montage.save(montage_filepath, 'JPEG')

        process_success = True

    except Exception, e:
        raise Exception(e)
Example #6
0
def photobooth_main():
    '''
    Takes 4 photos in a series, tweets each one and then saves the individual files plus a vertical montage onto the pi
    :return: True/False on whether the process was successful
    '''

    process_success = False
    photo_file_locations_original = []
    photo_file_locations_converted = []

    # Take photo 1
    photo_location = take_photo(r.PIN_LED_PHOTO_1)
    photo_file_locations_original.append(photo_location)

    # Take photo 2
    photo_location = take_photo(r.PIN_LED_PHOTO_2)
    photo_file_locations_original.append(photo_location)

    # Take photo 3
    photo_location = take_photo(r.PIN_LED_PHOTO_3)
    photo_file_locations_original.append(photo_location)

    # Take photo 4
    photo_location = take_photo(r.PIN_LED_PHOTO_4)
    photo_file_locations_original.append(photo_location)

    print photo_file_locations_original

    try:

        # Turn on the "waiting" LED
        InOut.turn_off_all_leds([r.PIN_LED_PHOTO_1, r.PIN_LED_PHOTO_2, r.PIN_LED_PHOTO_3, r.PIN_LED_PHOTO_4])
        GPIO.output(r.PIN_LED_PHOTO_WAIT, True)

        # Convert each of the captured photos into a standardised format
        for photo in photo_file_locations_original:
            mono_photo_filepath = convert_image(photo)
            photo_file_locations_converted.append(mono_photo_filepath)

        #Turn off the "waiting" light
        GPIO.output(r.PIN_LED_PHOTO_WAIT,False)
        
        # Create a montage of the captured photos and save them down
        montage_image_name = "photobooth_" + strftime("%Y-%m-%d_%H%M%S", gmtime()) + ".jpg"
        montage_filepath = r.FOLDER_PHOTOS_MONTAGE + montage_image_name

        montage = create_image_montage(photo_file_locations_converted)
        montage.save(montage_filepath, 'JPEG')

        process_success = True

    except Exception, e:
        raise Exception(e)
Example #7
0
    def test_bypass(self):
        s = Seq("AAAA",IUPAC.unambiguous_dna)
        i = 0

        (s,i) = InOut.bypass(s,i,'T')
        self.assertEqual("CAAA", str(s))
        self.assertEqual(0, i)

        s = Seq("CTAA",IUPAC.unambiguous_dna)
        (s,i) = InOut.bypass(s,1,'T')
        self.assertEqual("GTAA", str(s))
        self.assertEqual(0, i)

        (s,i) = InOut.bypass(s,2,'T')
        self.assertEqual("GTCA", str(s))
        self.assertEqual(2, i)
Example #8
0
    def test_is_img_with_dir(self):
        """
        Tests is_img() with a directory.
        
        ..codeauthor:: Laura Xénard
        """

        self.assertFalse(InOut.is_img(self.path_img + "dossier_vide"))
Example #9
0
    def test_is_img_with_jpg(self):
        """
        Tests is_img() with a jpg image.
        
        ..codeauthor:: Laura Xénard
        """

        self.assertTrue(InOut.is_img(self.path_img + "Logo_Paris_Diderot.jpg"))
def test_wps_inout():
    client = client_for(Service(processes=[InOut()]))
    datainputs = "string=onetwothree;int=7;float=2.0;boolean=0"
    resp = client.get(
        service='WPS', request='Execute', version='1.0.0', identifier='inout',
        datainputs=datainputs)
    print(resp.data)
    assert_response_success(resp)
Example #11
0
    def test_is_img_with_file_not_img(self):
        """
        Tests is_img() with a file a file that is not an image.
        
        ..codeauthor:: Laura Xénard
        """

        self.assertFalse(InOut.is_img(self.path_img + "blabla.txt"))
Example #12
0
    def test_is_img_with_tif(self):
        """
        Tests is_img() with a jpg tif.
        
        ..codeauthor:: Laura Xénard
        """

        self.assertTrue(InOut.is_img(self.path_img + "mycelium.tif"))
Example #13
0
    def test_is_img_with_png(self):
        """
        Tests is_img() with a png image.
        
        ..codeauthor:: Laura Xénard
        """

        self.assertTrue(
            InOut.is_img(self.path_img + "Logo_Paris_Descartes.png"))
Example #14
0
    def test_new_environment_1_good(self):
        """
        Test if the creation of a new environment works when everything is ok.
        Result expected: yes.
        
        ..codeauthor:: Salomé Attar, Laura Xénard
        """

        self.assertEqual(
            InOut.new_environment(self.project_test_new_environment),
            (True, "The new environment was successfully created."))
Example #15
0
def take_photo(gpio_pin_number):
    '''
    :param gpio_pin_number: The Pi's GPIO pin number to signal to the user that the photo is being taken
    :return: The filepath of the new image
    '''

    photo_location = ""

    InOut.led_take_photo(gpio_pin_number)

    try:
        photo_location = actuate_camera_shutter()

    except subprocess.CalledProcessError:
        InOut.script_event_indicator()
        print "Unable to take photo as camera is not turned on or battery is dead"
        logging.error("Unable to take photo as camera is not turned on or battery is dead")
        raise Exception("Camera is not responding, battery is dead or camera is not turned on")

    else:
        return photo_location
Example #16
0
def send():
    global entry_today
    try:
        mood = int(e1.get())
    except ValueError:
        print("Mood needs to be a real number from 0-100.")
        e1.delete(0, END)

    if int(mood) > 100:
        mood = "100"
    if int(mood) < 0:
        mood = "00"
    if int(mood) < 10 and not 0:
        mood = "0" + str(mood)

    today = InOut.Day(
        mood,
        datetime.date.today().strftime('%d-%m-%y').replace(",", ""),
        t1.get("0.0",
               END).replace('\n',
                            " "))  # remove \n in textArea for storage in file.

    if entry_today:
        list_of_days[len(list_of_days) - 1] = today
        InOut.write_list("daysGUI.txt", list_of_days)
    else:
        InOut.add_today_to_file("daysGUI.txt", today)

    entry_today = TRUE
    e1.config(state="readonly")
    t1.config(state="disabled")
    b1.config(state="disabled")
    b2.config(state="normal")
    l3.config(
        text=
        "\t\tSaved today's entry correctly.\n \t\t   If you wish to edit it  press EDIT."
    )
    global current_day
    current_day = today
Example #17
0
    def test_open_project_no_directory(self):
        """
        Test if a project not saved can be open.
        Result expected : no.
        
        ..codeauthor:: Salomé Attar, Laura Xénard
        """

        path_open_fail = os.path.abspath(
            os.path.split(os.path.realpath(__file__))[0] +
            "/Ressources_pour_tests_unitaires/Project_test_fail/save/test_save"
        )
        self.assertEqual(
            InOut.open_project(path_open_fail)[1:],
            (False, "No file has been found at the specified path."))
Example #18
0
    def test_open_project_good(self):
        """
        Test if a project already saved can be open.
        Result expected: yes.
        
        ..codeauthor:: Salomé Attar, Laura Xénard
        """

        path_open_success = os.path.abspath(
            os.path.split(os.path.realpath(__file__))[0] +
            "/Ressources_pour_tests_unitaires/Project_test_open/save/test_save_open"
        )
        self.assertEqual(
            InOut.open_project(path_open_success)[1:],
            (True, "Project loaded."))
Example #19
0
    def test_save_project_null(self):
        """
        Test if a project can be saved if the environment doesn't exist.
        Result expected : no.
        
        ..codeauthor:: Salomé Attar, Laura Xénard
        """

        path = os.path.abspath(
            os.path.split(os.path.realpath(__file__))[0] +
            "/Ressources_pour_tests_unitaires/Project_test_fail/")
        project_save_fail = msh.Project(path)
        self.assertEqual(
            InOut.save_project(project_save_fail),
            "An error occurred during the save. Directory not found.")
Example #20
0
    def new_project(self, path):
        """ 
        Initializes the :class:`Project` attribute of :mod:`Management` from the path obtained by the :mod:`Ui` module 
        by filling the images lists *skelPics* and *greyPics* and loading those images.
        
        :param str path: the path to the project environment given by the user
        :return: a tuple of a boolean and a string indicating the success or failure of the project creation 
        :rtype: (bool, str)
        
        .. codeauthor:: Laura Xénard
        """

        self.project = msh.Project(
            path)  # updates the 'project' attribute of 'Management'
        return InOut.new_environment(self.project)
Example #21
0
    def save_project(self):
        """ 
        Asks InOut to save the current :class:`Project`.
        
        :return: a string indicating the success or failure of the saving
        :rtype: str
        :raise AttributeError: if no :class:`Project` instance exists
        
        .. codeauthor:: Sébastien Maillos
        """

        try:
            message = InOut.save_project(self.project)
        except AttributeError:
            message = "Please create or open a project before trying to save it."
        return message
Example #22
0
    def load_project(self, path):
        """ 
        Initializes the :class:`Project` attribute of :mod:`Management` from the path of a pre-existing project.
        
        :param str path: the path to the project environment given by the user
        :return: a tuple of a boolean and a string indicating the success or failure of the project creation 
        :rtype: (bool, str)
        
        .. codeauthor:: Laura Xénard
        """

        project, loadingOK, message = InOut.open_project(
            path
        )  # we directly gives the path to InOut which opens the save and extracts the project
        self.project = project  # the object 'project'
        return (loadingOK, message)
Example #23
0
    def export_project(self, notes, txtOk, imgOk, imgstepsOk):
        """ 
        Asks InOut to export the data obtained during the analysis of the current :class:`Project`.

        :param str notes: a string representing the notes written by the user about the current project
        :param bool txtOk: a boolean representing if the text data should be exported
        :param bool imgOk: a boolean representing if the final img should be exported
        :param bool imgstepsOk: a boolean representing if the steps pictures should be exported
        :return: a string indicating the success or failure of the export
        :rtype: str
        
        .. codeauthor:: Sébastien Maillos
        .. codeauthor:: Laura Xénard
        """

        self.project.notes = notes  # update of the 'notes' attribute of the project
        return InOut.export_project(self.project, txtOk, imgOk, imgstepsOk)
Example #24
0
    def test_new_environment_2_already_existing(self):
        """
        Test if an already existing environment can be created again.
        Result expected: yes.
        
        ..codeauthor:: Salomé Attar, Laura Xénard
        """

        self.assertEqual(
            InOut.new_environment(self.project_test_new_environment),
            (True, "The environment already exists."))

        # Cleaning after the test
        path = os.path.abspath(
            os.path.join(self.project_test_new_environment.path + '/save'))
        shutil.rmtree(path, ignore_errors=True)
        path = os.path.abspath(
            os.path.join(self.project_test_new_environment.path + '/export'))
        shutil.rmtree(path, ignore_errors=True)
Example #25
0
    def test_save_project_good(self):
        """
        Test if an existing project (whose environment was created) can be saved.
        Result expected : yes
        
        ..codeauthor:: Salomé Attar, Laura Xénard
        """

        path = os.path.abspath(
            os.path.split(os.path.realpath(__file__))[0] +
            "/Ressources_pour_tests_unitaires/Project_test_success/")
        project_save_success = msh.Project(path)
        self.assertEqual(InOut.save_project(project_save_success),
                         "Project saved.")

        # Cleaning after the test
        path = os.path.abspath(
            os.path.join(project_save_success.path + '/save/'))
        shutil.rmtree(path, ignore_errors=True)
        os.mkdir(path)
def run_analysis(configfile, resultsdir):
    """ master function that runs line profile analysis of the dataset """

    # Header
    InOut.print_head()

    #reading config from configfile
    listname, filetype, selected_indicators, RVext = InOut.read_config(
        configfile)

    #read observations from obslist
    file_names, dataset, BJDs, RVextvalues = InOut.read_obslist(
        listname, filetype, RVext)

    #fit Gaussian function to the data
    Gauss_params = Gaussfitting.dataset_gaussfit(dataset)

    # Identify selected indicators
    IndicatorList = ["BIS", "BIS-", "BIS+", "biGauss", "Vasy", "Vspan", "FWHM"]
    IndSelected = [
        ind for ind, selected in zip(IndicatorList, selected_indicators)
        if selected == 1
    ]

    #Apply indicators
    output_ASCII_list = [
        Indicators.run_indicator_analysis(ind, dataset, Gauss_params,
                                          file_names, resultsdir, RVextvalues)
        for ind in IndSelected
    ]

    #Wrap the results in one single file
    InOut.wrapRes(output_ASCII_list, BJDs, resultsdir)

    # The End
    InOut.print_foot()
Example #27
0
def main():
    '''
    Main to run Grover's Simulation
    '''
    check = 'run'  #is altered for testing purposes

    #runs grover
    if check == 'run':
        args = IO.start()
        noise = IO.gnoise()
        G.run(args, noise)

    #runs test for varying qubit reg size but constant fock target
    elif check == 'test1':
        # --- Time for n qubits ---
        args = np.zeros(2)
        nlist = [i for i in range(2, 14)]  #varying reg size array
        time1 = np.zeros(len(nlist))
        target = 1  #constant target
        for i in range(len(nlist)):
            print('Running Grovers for ' + str(nlist[i]) +
                  ' qubits for Fock value |1>')
            args[0] = nlist[i]
            args[1] = target
            time1[i] = G.run(args, 0)
        IO.timeplotn(nlist, time1)

    #runs test for varying fock target but constant qubit reg size
    elif check == 'test2':
        # --- Time for different Fock value targets ---
        args = [0, 0]
        n = 10  #constant reg size
        tarlist = [i for i in range(0, 200)]  #varying target
        time2 = np.zeros(len(tarlist))
        for i in range(len(tarlist)):
            print('Running Grovers for 10 qubits for Fock value |' +
                  str(tarlist[i]) + '>')
            args[0] = n
            args[1] = tarlist[i]
            time2[i] = G.run(args, 0)
        IO.timeplottar(tarlist, time2)

    #invalid entry quits programme
    else:
        print('\nThis is not a valid option.')
        sys.exit()
Example #28
0
    def test_next_vertex(self):
        s = Seq("AAAA",IUPAC.unambiguous_dna)
        i = 0
        L = 4
    
        (s,i) = InOut.next_vertex(s,i,L,'T')
        self.assertEqual("AAAA", str(s))
        self.assertEqual(1, i)

        (s,i) = InOut.next_vertex(s,i,L,'T')
        self.assertEqual("AAAA", str(s))
        self.assertEqual(2, i)

        (s,i) = InOut.next_vertex(s,i,L,'T')
        self.assertEqual("AAAA", str(s))
        self.assertEqual(3, i)

        (s,i) = InOut.next_vertex(s,i,L,'T')
        self.assertEqual("AAAC", str(s))
        self.assertEqual(3, i)

        (s,i) = InOut.next_vertex(s,i,L,'T')
        self.assertEqual("AAAG", str(s))
        self.assertEqual(3, i)

        (s,i) = InOut.next_vertex(s,i,L,'T')
        self.assertEqual("AAAT", str(s))
        self.assertEqual(3, i)

        (s,i) = InOut.next_vertex(s,i,L,'T')
        self.assertEqual("AACT", str(s))
        self.assertEqual(2, i)

        (s,i) = InOut.next_vertex(s,i,L,'T')
        self.assertEqual("AACA", str(s))
        self.assertEqual(3, i)

        (s,i) = InOut.next_vertex(s,i,L,'T')
        self.assertEqual("AACC", str(s))
        self.assertEqual(3, i)

        (s,i) = InOut.next_vertex(s,i,L,'T')
        self.assertEqual("AACG", str(s))
        self.assertEqual(3, i)

        (s,i) = InOut.next_vertex(s,i,L,'T')
        self.assertEqual("AACT", str(s))
        self.assertEqual(3, i)

        (s,i) = InOut.next_vertex(s,i,L,'T')
        self.assertEqual("AAGT", str(s))
        self.assertEqual(2, i)

        (s,i) = InOut.next_vertex(s,i,L,'T')
        self.assertEqual("AAGA", str(s))
        self.assertEqual(3, i)

        (s,i) = InOut.next_vertex(s,i,L,'T')
        self.assertEqual("AAGC", str(s))
        self.assertEqual(3, i)
Example #29
0
                                                      gmtime()) + ".jpg"
        montage_filepath = r.FOLDER_PHOTOS_MONTAGE + montage_image_name

        montage = create_image_montage(photo_file_locations_converted)
        montage.save(montage_filepath, 'JPEG')

        process_success = True

    except Exception, e:
        raise Exception(e)

    finally:

        # Turn off all photo LEDs and reset the 'wait' LED
        InOut.turn_off_all_leds([
            r.PIN_LED_PHOTO_1, r.PIN_LED_PHOTO_2, r.PIN_LED_PHOTO_3,
            r.PIN_LED_PHOTO_4
        ])

        # Upload the montage into a public space where people can view the photos
        return process_success


# MAIN ENTRY POINT OF PROGRAM
# Switch logic taken from http://razzpisampler.oreilly.com/ch07.html

# Set up logging for the process
logging.basicConfig(filename="Photobooth_Log.txt",
                    level=logging.DEBUG,
                    format='%(levelname)s: %(asctime)s %(message)s',
                    datefmt='%m/%d/%Y %I:%M:%S')
Example #30
0
        # Create a montage of the captured photos and save them down
        montage_image_name = "photobooth_" + strftime("%Y-%m-%d_%H%M%S", gmtime()) + ".jpg"
        montage_filepath = r.FOLDER_PHOTOS_MONTAGE + montage_image_name

        montage = create_image_montage(photo_file_locations_converted)
        montage.save(montage_filepath, 'JPEG')

        process_success = True

    except Exception, e:
        raise Exception(e)

    finally:

        # Turn off all photo LEDs and reset the 'wait' LED
        InOut.turn_off_all_leds([r.PIN_LED_PHOTO_1, r.PIN_LED_PHOTO_2, r.PIN_LED_PHOTO_3, r.PIN_LED_PHOTO_4])

        # Upload the montage into a public space where people can view the photos
        return process_success


# MAIN ENTRY POINT OF PROGRAM
# Switch logic taken from http://razzpisampler.oreilly.com/ch07.html

# Set up logging for the process
logging.basicConfig(filename="Photobooth_Log.txt",
                    level=logging.DEBUG,
                    format = '%(levelname)s: %(asctime)s %(message)s',
                    datefmt='%m/%d/%Y %I:%M:%S')

logging.info("Photobooth main.py started")
		return fracs
	while(y):
		fracs.append(x//y)
		x,y = y,x%y
	return np.array(fracs)



def main():
	
<<<<<<< Updated upstream
	H = Hadamard(6)
	N = Noisy(H,0)
	#IO.display(Noisy(H,1))
	#IO.display(Noisy(H,0.1)*Noisy(H,0.1))
	IO.display(N)
=======
	
	#q1 = Qubit([1,1j])
	#q1.normalise()
	#IO.Hist(q1)
	#print(q1.measure())
	IO.Display(Hadamard())
	#H = Hadamard(4)
	#N = Noisy(H,0)
	#IO.Display(Noisy(H,1))
	#IO.Display(Noisy(H,0.1)*Noisy(H,0.1))
	#q = Qubit(4)
	#IO.Hist(q)
	#IO.Hist(H*q)
>>>>>>> Stashed changes
Example #32
0
        draw.line(lin, fill=0, width=3)
    x_start = 0
    x_end = image.width

    for y in range(0, image.height, 180):
        lin = ((x_start, y), (x_end, y))
        draw.line(lin, fill=0, width=10)

    for y in range(0, image.height, 45):
        lin = ((x_start, y), (x_end, y))
        draw.line(lin, fill=0, width=3)


if __name__ == '__main__':

    days = InOut.read_from_file("test.txt")
    image = Image.new('RGB', [945, 720], color=(255, 255, 255))

    # Draw some lines
    draw = ImageDraw.Draw(image)

    xi = 2
    yi = 2
    xf = 43
    yf = 43
    for i in range(0, 17):
        for z in range(0, 21):
            if (i * 17) + z < len(days):
                draw.rectangle([(xi, yi), (xf, yf)], days[(i * 17) + z].color)
            xi += 45
            xf += 45
Example #33
0
from tkinter import *
from tkinter.messagebox import showinfo
import datetime
import InOut
import Calculations

# check if today has already been registered
entry_today = FALSE
current_day = InOut.Day(50, datetime.date.today().strftime('%d-%m-%y'), "")
try:
    list_of_days = InOut.read_from_file("daysGUI.txt")
    if list_of_days[len(list_of_days) -
                    1].date == datetime.date.today().strftime('%d-%m-%y'):
        entry_today = TRUE
        current_day = list_of_days[len(list_of_days) - 1]
except FileNotFoundError:
    print("There's no file for days.")

# window params
window = Tk()
window.title("Mood GUI")
window.minsize(500, 470)
window.maxsize(500, 470)

# frames
f1 = Frame(window)
f2 = Frame(window)
f3 = Frame(window)
f4 = Frame(window)
# elements such as labels and entries
l1 = Label(f1, text="   Mood(1-100):\t")
Example #34
0
def calc():
    global list_of_days
    list_of_days = InOut.read_from_file("daysGUI.txt")
    string = Calculations.calculate_max_and_average(list_of_days)
    showinfo("Stats", string)
Example #35
0
def rel():
    global list_of_days
    list_of_days = InOut.read_from_file("daysGUI.txt")
    string = Calculations.relevant_days(list_of_days)
    showinfo("Relevant days", string)
Example #36
0
def invert(station_block, cfgfile):
  config = SafeConfigParser()
  config.read(cfgfile)

  #Read parameters from an external file (integer case)
  block      = station_block
  wz         = config.getint(block, "wz")
  wsmooth    = config.getint(block, "wsmooth")

  #Read parameters from an external file (float case)
  s1         = config.getfloat(block, "s1")
  depol      = config.getfloat(block, "depol")
  leakrate   = config.getfloat(block, "leakrate")
  mdr        = config.getfloat(block, "mdr")
  dep_s      = config.getfloat(block, "dep_s")
  dep_d      = config.getfloat(block, "dep_d")
  maxint     = config.getfloat(block, "maxint")
  clgrad     = config.getfloat(block, "clgrad")
  clth       = config.getfloat(block, "clth")
  rth1       = config.getfloat(block, "rth1")
  rth4       = config.getfloat(block, "rth4")
  rth6       = config.getfloat(block, "rth6")
  pblth      = config.getfloat(block, "pblth")

  #Read parameters from an external file (string case)
  station    = config.get(block, "prefix")
  ncpath_raw = config.get("Paths", "ncpath_raw")
  ncpath_out = config.get("Paths", "ncpath_out")
  ncfile_raw = config.get("Paths", "ncfile_raw")
  ncfile_out = config.get("Paths", "ncfile_out")
  yrfile_vis = config.get("Paths", "yrfile_vis")
  yrfile_ir  = config.get("Paths", "yrfile_ir")
  power_file = config.get("Paths", "power_file")

  ncpath_out = ncpath_out + block + '/'

  #Read parameters from an external file (boolean case)
  PlotRaw    = config.getboolean("Output", "PlotRaw")
  PlotCal    = config.getboolean("Output", "PlotCal")
  PlotBeta   = config.getboolean("Output", "PlotBeta")
  PlotDep    = config.getboolean("Output", "PlotDep")
  PlotAlpha  = config.getboolean("Output", "PlotAlpha")
  NCDout     = config.getboolean("Output", "NCDout")
  NCDmonth   = config.getboolean("Output", "NCDmonth")

  if os.path.isfile(ncpath_raw+station+ncfile_raw):
    print "Opening file: ", ncpath_raw+station+ncfile_raw
    ### Read Time, Data (mV), Heigth (km)
    ds       = Dataset(ncpath_raw+station+ncfile_raw)
    ch1      = ds.variables["ch1"][:]
    ch2      = ds.variables["ch2"][:]
    ch3      = ds.variables["ch3"][:]
    z        = ds.variables["alt"][:]
    times    = ds.variables["time"]
    day_0    = datetime(year=ds.YEAR, month=ds.MONTH, day=ds.DAY)
    height   = ds.HEIGHT
    x        = num2date(times[:],units=times.units)
    ds.close()
  else:
    print "Unable to open file: ", ncpath_raw+station+ncfile_raw
    exit()
    
  ch1      = ch1.T
  ch2      = ch2.T
  ch3      = ch3.T

  ### Number of profiles and vertical levels
  NX = len(x)
  NZ = len(z)

  ### Background removed and range-corrected signal intensity
  for it in range(NX):
    coeff = np.polyfit(z[-1000:], ch1[-1000:,it], 1)
    pol   = np.poly1d(coeff)
    ch1[:,it] = (ch1[:,it] - pol(z))*z**2
    ###
    coeff = np.polyfit(z[-1000:], ch2[-1000:,it], 1)
    pol   = np.poly1d(coeff)
    ch2[:,it] = (ch2[:,it] - pol(z))*z**2
    ###
    coeff = np.polyfit(z[-2000:], ch3[-2000:,it], 1)
    pol   = np.poly1d(coeff)
    ch3[:,it] = (ch3[:,it] - pol(z))*z**2
    
  ### Smoothing for IR channel
  if wsmooth>1:
    for it in range(NX):
      ch3[:,it] = np.convolve(ch3[:,it],np.ones(wsmooth)/wsmooth,mode='same')

  if Debug:
    print "Max Value for channel 1: {} mV km2".format(np.nanmax(ch1))
    print "Max Value for channel 2: {} mV km2".format(np.nanmax(ch2))
    print "Max Value for channel 3: {} mV km2".format(np.nanmax(ch3))

  ### Power Correction
  if Debug: print "Performing power corrections..."
  c1, c2, c3 = Calibration.power(x,ncpath_out+power_file)
  for ix in range(NX):
    ch1[:,ix] = ch1[:,ix] * c1[ix]
    ch2[:,ix] = ch2[:,ix] * c2[ix]
    ch3[:,ix] = ch3[:,ix] * c3[ix]
  
  ### Polarization correction (Experimental!)
  depol_estimated = Calibration.depol(ch1, ch2, z)
  if depol_estimated>1.0:
    if Debug: print "Using depol={} instead of depol={}".format(depol_estimated, depol)
    depol = depol_estimated
    
  para   = ch1                                       # Parallel component - Visible channel
  perp   = (ch2 - ch1 * leakrate) / depol            # Perpendicular component - Visible channel
  intvis = para + perp                               # Visible channel (total)
  intir  = ch3                                       # Infrared channel
  with np.errstate(divide='ignore', invalid='ignore'):
    dep  = np.where(para == 0, np.nan, perp / para)  # Volume linear depolarization ratio

  if PlotRaw:
    print "Plotting raw data..."
    Plots.show_raw(x,intvis,z, ncpath_out+"raw_vis.png", zmax=16)
    Plots.show_raw(x,intir, z, ncpath_out+"raw_ir.png", zmax=16)

  ### Overlap Correction
  if Debug: print "Performing overlap corrections..."
  yrvis = Calibration.overlap(ncpath_out + yrfile_vis,z)
  yrir  = Calibration.overlap(ncpath_out + yrfile_ir,z)
  for ix in range(NX):
    intvis[:,ix] = intvis[:,ix] * yrvis
    intir[:,ix]  = intir[:,ix]  * yrir

  ### Calibration
  factor  = Calibration.vis_factor(intvis,z)
  intvis  = intvis * factor       # Attenuated Backscatter Coefficient at 532 nm
  color_r = Calibration.color_ratio(intvis, intir, z, maxint)
  intir   = intir / color_r       # Attenuated Backscatter Coefficient at 1064 nm
  if Debug: 
    print "Calibration factor - Visible channel: {}".format(factor)
    print "Calibration factor - IR channel: {}".format(1.0/color_r)
    print "Vis. channel: min={}, max={}".format(np.nanmin(intvis), np.nanmax(intvis))
    print "IR channel: min={}, max={}".format(np.nanmin(intir), np.nanmax(intir))
    
  ### REBIN function: resizes a vector
  if NZ%wz==0:
    NZ   = NZ/wz
    lvis = np.full((NZ,NX),np.nan)
    lir  = np.full((NZ,NX),np.nan)
    ldep = np.full((NZ,NX),np.nan)
    lz   = np.mean(z.reshape(-1, wz), axis=1)
    DZ = lz[1]-lz[0]
    DZinv = 1.0/DZ
    with warnings.catch_warnings():
      # I expect to see RuntimeWarnings in this block
      warnings.simplefilter("ignore", category=RuntimeWarning)
      for it in range(NX):
        if not np.all(np.isnan(intvis[:,it])) and not np.all(np.isnan(intir[:,it])):
          lvis[:,it] = np.nanmean(intvis[:,it].reshape(-1, wz), axis=1)
          lir[:,it]  = np.nanmean(intir[:,it].reshape(-1, wz), axis=1)
          ldep[:,it] = np.nanmean(dep[:,it].reshape(-1, wz), axis=1)
    if Debug: print "REBIN successful. Vertical resolution: {} m".format(1000*DZ)
  else:
    raise SystemExit("STOP: Rebin not performed: verify your configuration")
    
  ### Molecular profiles
  alpha_m, beta_m = Physics.rayleigh(1000.0*lz, 532.0, height)

  ### Cloud Detection
  zb, zt          = CloudDetect.cloud_height(lvis,lir,lz,clgrad,clth)           # Detect Cloud Base above 240 m
  rf, pbl, invtop = CloudDetect.phenomena(lvis,lir,ldep,lz,zb,rth1,rth4,pblth)

  if PlotCal:
    print "Plotting calibrated signal..."
    Plots.show_cal(x,intvis,z,zb,zt,ncpath_out+"cal_vis.png")
    Plots.show_cal(x,intir,z,zb,zt,ncpath_out+"cal_ir.png")
    #Plots.show_cal(x,intvis,z,pbl,invtop,ncpath_out+"cloud_vis.png")
    #Plots.show_cloud(x,intvis,z,pbl,5*rf,ncpath_out+"cloud_vis.png")
    
  ### Inversion
  ### Vertical indexes
  iz_100 = int(round(0.10 * DZinv))-1
  iz_120 = int(round(0.12 * DZinv))-1
  iz_150 = int(round(0.15 * DZinv))-1
  iz_450 = int(round(0.45 * DZinv))-1
  iz_600 = int(round(0.60 * DZinv))-1
  iz_9km = int(round(9.00 * DZinv))-1
  iz_18km = int(round(18. * DZinv))-1

  ### Optical properties for aerosols
  ext_vis = np.full((NZ,NX), np.nan)       # Extinction coefficient - Visible
  adr     = np.full((NZ,NX), np.nan)       # Particulate depolarization ratio

  ### Use the Fernald's algorithm - High clouds caseext
  for ix in range(NX):
    if rf[ix]>0 or invtop[ix] < 0.21: continue
#    profile_ir  = lir [:,ix]
    profile_vis = 1.0*lvis[:,ix]
    if np.all(np.isnan(profile_vis)): continue
    ### In order to increase the signal-to-noise ratio at inversion height.
    ### This is the boundary condition for the inversion method and 
    ### the whole profiles depend on this boundary condition
    iz_inv = int(round(invtop[ix] * DZinv))-1
    profile_vis[iz_inv-1] = np.nanmean(profile_vis[iz_inv-2:iz_inv+1])
    ### We assume that the molecular contribution 
    ### is dominant at the inversion height
    if zb[ix]<3.0: continue
    else: bsc_ini = beta_m[iz_inv-1] * 1E-4 #Here I made a little modification to the Shimitzu code
    alpha, beta = Physics.fernald(profile_vis, lz, alpha_m, beta_m, s1, invtop[ix], bsc_ini)
    extmin = min(alpha[iz_150:1+max(iz_inv-iz_150, iz_150+1)])
    ###
    for itc in range(1,16):
      if extmin > -1E-5: break
      alpha, beta = Physics.fernald(profile_vis, lz, alpha_m, beta_m, s1, invtop[ix], bsc_ini*2**itc)
      extmin = min(alpha[iz_150:1+max(iz_inv-iz_150, iz_150+1)])
    ###
    sr1  = (beta + beta_m) / beta_m    # Backscatter ratio
    adr1 = (ldep[:,ix] * (sr1 + sr1*mdr - mdr) - mdr) / (sr1 - 1 + sr1*mdr - ldep[:,ix])   # Aerosols depolarization ratio
    ext_vis[iz_100:iz_inv,ix] = alpha[iz_100:iz_inv]
    adr[iz_100:iz_inv,ix]     = adr1[iz_100:iz_inv]
    ### Is this necessary?
    if zb[ix] < 9: 
      iz_zb = int(round(zb[ix] * DZinv))-1
      zmax  = min(zt[ix],9)
      iz_zt = int(round(zmax * DZinv))-1
      ext_vis[iz_zb:iz_zt,ix] = np.nan
      
  ### Verify variability?
  for ix in range(NX):
    profile = ext_vis[iz_120:iz_450,ix]
    if np.all(np.isnan(profile)): 
      continue
    else:
      extstd = np.nanstd(profile)
      if extstd>rth6:
        rf[ix]=6
        ext_vis[:,ix] = np.nan

  time_series = lvis[iz_600,:] / (ext_vis[iz_600,:]/s1 + beta_m[iz_600])
  with np.errstate(invalid='ignore'): mask = ext_vis[iz_600,:]>=0
  if mask.sum()>0:
    ext_int_r = np.median( time_series[mask] )
  else: 
    ext_int_r = 1e11
    
  if Debug: print "Calibration constant: {}".format(ext_int_r)

  ### Use the Fernald's algorithm - Low clouds case
  for ix in range(NX):
    if np.isnan(zb[ix]) or zb[ix]>=3 or invtop[ix] < 0.21: continue
    profile_vis = 1.0*lvis[:,ix]
    if np.all(np.isnan(profile_vis)): continue
    iz_inv      = int(round(invtop[ix] * DZinv))-1
    profile_vis[iz_inv-1] = np.nanmean(profile_vis[iz_inv-2:iz_inv+1])
    ### This boundary condition assumes a transmitance = 1 below of 1km
    ### Above 1km, we follow the same criterion as Shimitzu
    ### This is a very poor estimate
    if invtop[ix]<1.0: 
      bsc_ini = profile_vis[iz_inv] / ext_int_r - beta_m[iz_inv]
    else: 
      bsc_ini = profile_vis[iz_inv] / ext_int_r * 0.8 * np.exp(invtop[ix]/4.5) - beta_m[iz_inv]
    if bsc_ini<0:
      if Debug: print "Changing boundary condition bsc_ini = {}".format(bsc_ini)
      bsc_ini = beta_m[iz_inv-1] * 1E-4
    alpha, beta = Physics.fernald(profile_vis, lz, alpha_m, beta_m, s1, invtop[ix], bsc_ini)
    ###
    sr1  = (beta + beta_m) / beta_m
    adr1 = (ldep[:,ix] * (sr1 + sr1*mdr - mdr) - mdr) / (sr1 - 1 + sr1*mdr - ldep[:,ix])
    ###
    ext_vis[iz_100:iz_inv,ix] = alpha[iz_100:iz_inv]
    adr[iz_100:iz_inv,ix]     = adr1[iz_100:iz_inv]
    ###
    iz_zb = int(round(zb[ix] * DZinv))-1
    zmax  = min(zt[ix],9)
    iz_zt = int(round(zmax * DZinv))-1
    ext_vis[iz_zb:iz_zt,ix] = np.nan

  absc532  = lvis / ext_int_r
  absc1064 = lir  / ext_int_r
  ###
  dr = (adr - dep_s) * (1 + dep_d) / (1 + adr) / (dep_d - dep_s)
  with np.errstate(invalid='ignore'): 
    dr[dr<0]=0.0
    dr[dr>1]=1.0
  dust    = ext_vis * dr
  sphere  = ext_vis * (1.0-dr)
  bsc     = ext_vis / s1

  if Debug: print "Max. Att. Backscatter: {}".format(np.nanmax(absc532))

  if PlotBeta:
    print "Plotting attenuated backscatter coefficients..."
    Plots.show_beta(x,1000.0*absc532,lz,ncpath_out+'absc_vis.png',zmax=18)
    Plots.show_beta(x,1000.0*absc1064,lz,ncpath_out+'absc_ir.png',zmax=18)

  if PlotAlpha:
    print "Plotting extinction coefficients..."
    Plots.show_alpha(x,1000.0*dust,lz,zb,zt,invtop,ncpath_out+'dust.png',zmax=9)
    Plots.show_alpha(x,1000.0*sphere,lz,zb,zt,invtop,ncpath_out+'sphere.png',zmax=9)

  if PlotDep:
    print "Plotting depolarization ratio..."
    with np.errstate(invalid='ignore'):
      ldep[absc532<1E-7]=np.nan
    Plots.show_dep(x,ldep,lz,ncpath_out+'dep.png',zmax=18)
    
  if NCDout:
    print "Creating NetCDF file: {}".format(ncpath_out+ncfile_out)
    NZ1 = iz_18km+1
    NZ2 = iz_9km+1
    InOut.save_ncd(ncpath_out+ncfile_out, station, x, lz, absc532, absc1064, ldep, dust, sphere, zb, zt, invtop, NZ1, NZ2)
    
  if NCDmonth:
    print "Creating monthly NetCDF files"
    NZ1 = iz_18km+1
    NZ2 = iz_9km+1
    InOut.monthly_ncd(ncpath_out, station, x, lz, absc532, absc1064, ldep, dust, sphere, zb, zt, invtop, NZ1, NZ2)