Automatic commit at Wed Jul 25 15:50:05 WST 2012
[matches/honours.git] / research / transmission_spectroscopy / Bulk-loss / process.py
1 import os\r
2 import sys\r
3 import re\r
4 \r
5 def electric_loss_function(infile,outfile):\r
6     """\r
7        Converts data of the form: wavelength Re(eps) Im(eps) => wavelength Im(1/eps)\r
8     """\r
9     file1 = open(infile, "r")\r
10     file2 = open(outfile, "w")\r
11     for line in file1:\r
12         data = str.split(line)\r
13         elf = -float(data[2]) / ((float(data[1])**2.0) + (float(data[2])** 2.0))\r
14         file2.write(str(data[0]) + " " + str(elf) + "\n")\r
15     file1.close()\r
16     file2.close()\r
17 \r
18 \r
19 def split_into_angles(infile, angleStep=5.0, start=0.0):\r
20     """\r
21         Splits data as output by VASE (into sequential curves, single file) into multiple files based on angle\r
22     """\r
23     file = open(infile, "r")\r
24     angleStep = float(angleStep)\r
25     currentAngle = start\r
26 \r
27     outputFile = open(infile + "["+str(currentAngle)+"]", "w")\r
28     lastWavelength = 0.0\r
29     for line in file:\r
30         wavelength = float(str.split(line)[0])\r
31         if wavelength < lastWavelength:\r
32             currentAngle += angleStep\r
33             outputFile.close()\r
34             outputFile = open(infile + "["+str(currentAngle)+"]", "w")  \r
35         outputFile.write(str(line))\r
36         lastWavelength = wavelength\r
37         \r
38 \r
39 if __name__ == "__main__":\r
40     """\r
41         TODO: Overwrite with particular task\r
42     """\r
43     split_into_angles("black-au_si",2.5,60.0)\r
44     angle = 60.0\r
45     while angle <= 80.0:\r
46         electric_loss_function("black-au_si["+str(angle)+"]", "black-au_si["+str(angle)+"].dat")\r
47         angle += 2.5\r
48     \r
49 \r

UCC git Repository :: git.ucc.asn.au