diff --git a/src/elli/importer/woollam.py b/src/elli/importer/woollam.py index ce345844..f04ed359 100644 --- a/src/elli/importer/woollam.py +++ b/src/elli/importer/woollam.py @@ -15,6 +15,21 @@ logger = logging.getLogger(__name__) +is_float_regex = re.compile(r"[+-]?(\d+([.]\d*)?([eE][+-]?\d+)?|[.]\d+([eE][+-]?\d+)?)") + + +def is_float(line: str) -> bool: + """Checks whether the given line is a float + + Args: + line (str): The line presumably containing a float + + Returns: + bool: True if it is a float, False otherwise + """ + return bool(is_float_regex.search(line)) + + def _is_wvase_tabular(line: str) -> bool: """ Checks whether the provided line is in wvase tabular layout. @@ -69,7 +84,7 @@ def scale_to_nm(unit: str, dataframe: pd.DataFrame) -> pd.DataFrame: try: scaling = ureg(unit).to("nm").magnitude dataframe.index = dataframe.index.set_levels( - dataframe.index.levels[1] * scaling, level=1 + dataframe.index.levels[1].astype(float) * scaling, level=1 ) return dataframe @@ -107,10 +122,13 @@ def _read_wvase_dataframe(file_object: TextIO) -> pd.DataFrame: file_object, sep="\t", header=None, - names=["Ψ", "Δ", "Ψ_err", "Δ_err"], - index_col=(1, 0), + names=["Wavelength", "Angle of Incidence", "Ψ", "Δ", "Ψ_err", "Δ_err"], + ) + dframe = ( + dframe[dframe.apply(lambda x: is_float(x[0]), axis=1)] + .set_index(["Wavelength", "Angle of Incidence"]) + .swaplevel(0, 1) ) - dframe.index.names = ("Angle of Incidence", "Wavelength") return dframe diff --git a/tests/test_wollam/wvase_example.dat b/tests/test_wollam/wvase_example.dat index 0b13b330..e1b47a1e 100644 --- a/tests/test_wollam/wvase_example.dat +++ b/tests/test_wollam/wvase_example.dat @@ -544,4 +544,288 @@ nm 1185.000000 75.000000 27.723391 0.53614789 0.0530629 0.231586 1190.000000 75.000000 27.723328 0.56788856 0.0544147 0.238278 1195.000000 75.000000 27.721346 0.54666221 0.054403 0.239108 -1200.000000 75.000000 27.725864 0.55148453 0.052391 0.231062 \ No newline at end of file +1200.000000 75.000000 27.725864 0.55148453 0.052391 0.231062 +dpolE 300.000000 55.000000 1.30314 0.978814 +dpolE 310.000000 55.000000 0.335272 0.993879 +dpolE 320.000000 55.000000 -0.397972 0.93948 +dpolE 330.000000 55.000000 -0.000593971 1.74989 +dpolE 340.000000 55.000000 0.452508 3.73242 +dpolE 350.000000 55.000000 -0.0601514 0.16697 +dpolE 360.000000 55.000000 -0.0406235 0.220429 +dpolE 370.000000 55.000000 -0.0114487 0.118743 +dpolE 380.000000 55.000000 0.0350828 0.182224 +dpolE 390.000000 55.000000 0.0686426 0.190422 +dpolE 400.000000 55.000000 -0.103195 0.114732 +dpolE 410.000000 55.000000 -0.0420885 0.17016 +dpolE 420.000000 55.000000 0.011859 0.148827 +dpolE 430.000000 55.000000 -0.0230883 0.139376 +dpolE 440.000000 55.000000 -0.0610514 0.154938 +dpolE 450.000000 55.000000 -0.0218411 0.140038 +dpolE 460.000000 55.000000 -0.0754919 0.144852 +dpolE 470.000000 55.000000 -0.0776394 0.123038 +dpolE 480.000000 55.000000 -0.0485566 0.103501 +dpolE 490.000000 55.000000 -0.0294478 0.142829 +dpolE 500.000000 55.000000 -0.0896237 0.11925 +dpolE 510.000000 55.000000 -0.0873465 0.121785 +dpolE 520.000000 55.000000 -0.0394018 0.117093 +dpolE 530.000000 55.000000 -0.105918 0.105822 +dpolE 540.000000 55.000000 -0.0915824 0.103299 +dpolE 550.000000 55.000000 -0.0873375 0.112895 +dpolE 560.000000 55.000000 -0.0601992 0.109179 +dpolE 570.000000 55.000000 -0.0771828 0.104558 +dpolE 580.000000 55.000000 -0.126173 0.102294 +dpolE 590.000000 55.000000 -0.0666788 0.101632 +dpolE 600.000000 55.000000 -0.0756601 0.0980554 +dpolE 610.000000 55.000000 -0.0930203 0.11632 +dpolE 620.000000 55.000000 -0.0535838 0.0945686 +dpolE 630.000000 55.000000 -0.0435814 0.112439 +dpolE 640.000000 55.000000 -0.0615208 0.0968356 +dpolE 650.000000 55.000000 -0.0575071 0.0874309 +dpolE 660.000000 55.000000 -0.074513 0.0920151 +dpolE 670.000000 55.000000 -0.0585059 0.0997868 +dpolE 680.000000 55.000000 -0.0707498 0.0920214 +dpolE 690.000000 55.000000 -0.0941866 0.0909532 +dpolE 700.000000 55.000000 -0.0833144 0.0922139 +dpolE 710.000000 55.000000 -0.0449577 0.0951966 +dpolE 720.000000 55.000000 -0.0598412 0.0881455 +dpolE 730.000000 55.000000 -0.0550871 0.109735 +dpolE 740.000000 55.000000 -0.0845279 0.101986 +dpolE 750.000000 55.000000 -0.0778644 0.112123 +dpolE 760.000000 55.000000 -0.0760247 0.0972251 +dpolE 770.000000 55.000000 -0.0690794 0.105283 +dpolE 780.000000 55.000000 -0.119659 0.0802262 +dpolE 790.000000 55.000000 -0.0973979 0.113787 +dpolE 800.000000 55.000000 -0.0286105 0.115431 +dpolE 810.000000 55.000000 -0.103019 0.10353 +dpolE 820.000000 55.000000 -0.0582463 0.0964206 +dpolE 830.000000 55.000000 -0.0600957 0.0900893 +dpolE 840.000000 55.000000 -0.0670086 0.0893872 +dpolE 850.000000 55.000000 -0.0511352 0.09491 +dpolE 860.000000 55.000000 -0.0847049 0.102436 +dpolE 870.000000 55.000000 -0.0535053 0.0868086 +dpolE 880.000000 55.000000 -0.0487095 0.0917367 +dpolE 890.000000 55.000000 -0.0512044 0.0810721 +dpolE 900.000000 55.000000 -0.0594912 0.0912225 +dpolE 910.000000 55.000000 -0.0540562 0.0880029 +dpolE 920.000000 55.000000 -0.0743923 0.0879249 +dpolE 930.000000 55.000000 -0.0770263 0.111157 +dpolE 940.000000 55.000000 -0.0417676 0.0931164 +dpolE 950.000000 55.000000 -0.0383727 0.0940979 +dpolE 960.000000 55.000000 -0.0841924 0.107996 +dpolE 970.000000 55.000000 -0.0467836 0.0908613 +dpolE 980.000000 55.000000 -0.0469153 0.0892701 +dpolE 990.000000 55.000000 -0.0465751 0.0834166 +dpolE 1000.000000 55.000000 -0.0802398 0.0976298 +dpolE 300.000000 56.000000 0.124623 0.957846 +dpolE 310.000000 56.000000 -0.192051 0.683013 +dpolE 320.000000 56.000000 -0.325247 0.977804 +dpolE 330.000000 56.000000 0.20315 1.41693 +dpolE 340.000000 56.000000 -1.04341 3.37211 +dpolE 350.000000 56.000000 0.0270028 0.114176 +dpolE 360.000000 56.000000 0.00944627 0.12885 +dpolE 370.000000 56.000000 -0.0322686 0.144539 +dpolE 380.000000 56.000000 -0.0815426 0.138543 +dpolE 390.000000 56.000000 -0.168267 0.164879 +dpolE 400.000000 56.000000 -0.112955 0.113451 +dpolE 410.000000 56.000000 -0.101943 0.111889 +dpolE 420.000000 56.000000 0.00714651 0.108193 +dpolE 430.000000 56.000000 -0.202766 0.134949 +dpolE 440.000000 56.000000 -0.0517197 0.0880416 +dpolE 450.000000 56.000000 -0.0129446 0.106188 +dpolE 460.000000 56.000000 -0.125 0.0883322 +dpolE 470.000000 56.000000 -0.0521324 0.0881632 +dpolE 480.000000 56.000000 -0.0398657 0.0863529 +dpolE 490.000000 56.000000 0.00299915 0.0808046 +dpolE 500.000000 56.000000 -0.0495301 0.0717372 +dpolE 510.000000 56.000000 -0.0527283 0.0780883 +dpolE 520.000000 56.000000 -0.0328532 0.0724175 +dpolE 530.000000 56.000000 -0.0595472 0.0763886 +dpolE 540.000000 56.000000 -0.032738 0.0920542 +dpolE 550.000000 56.000000 -0.0520326 0.0799603 +dpolE 560.000000 56.000000 -0.0449898 0.072897 +dpolE 570.000000 56.000000 -0.0295001 0.0774399 +dpolE 580.000000 56.000000 -0.056407 0.0836775 +dpolE 590.000000 56.000000 -0.0253151 0.0774677 +dpolE 600.000000 56.000000 -0.0425546 0.0763203 +dpolE 610.000000 56.000000 -0.0290175 0.0727699 +dpolE 620.000000 56.000000 -0.0348932 0.0734368 +dpolE 630.000000 56.000000 -0.0507374 0.0687374 +dpolE 640.000000 56.000000 -0.0579771 0.0718604 +dpolE 650.000000 56.000000 -0.0261575 0.0616109 +dpolE 660.000000 56.000000 -0.0384767 0.0708724 +dpolE 670.000000 56.000000 -0.0572926 0.0745851 +dpolE 680.000000 56.000000 -0.0313404 0.0759956 +dpolE 690.000000 56.000000 -0.0537586 0.061923 +dpolE 700.000000 56.000000 -0.00120696 0.072318 +dpolE 710.000000 56.000000 -0.0463371 0.067311 +dpolE 720.000000 56.000000 -0.0502287 0.0744805 +dpolE 730.000000 56.000000 -0.0175719 0.0662916 +dpolE 740.000000 56.000000 -0.0132096 0.0690502 +dpolE 750.000000 56.000000 -0.0520914 0.0647742 +dpolE 760.000000 56.000000 -0.0283671 0.0830285 +dpolE 770.000000 56.000000 -0.0198376 0.0811473 +dpolE 780.000000 56.000000 0.0060187 0.0777515 +dpolE 790.000000 56.000000 -0.0602578 0.0615667 +dpolE 800.000000 56.000000 0.0250954 0.076529 +dpolE 810.000000 56.000000 -0.0318102 0.0786017 +dpolE 820.000000 56.000000 -0.0337664 0.0656641 +dpolE 830.000000 56.000000 -0.00620208 0.0628222 +dpolE 840.000000 56.000000 -0.0330732 0.0686823 +dpolE 850.000000 56.000000 -0.038541 0.0851984 +dpolE 860.000000 56.000000 -0.0517019 0.0805984 +dpolE 870.000000 56.000000 -0.0241661 0.0692862 +dpolE 880.000000 56.000000 -0.024398 0.0628993 +dpolE 890.000000 56.000000 -0.0144839 0.0645675 +dpolE 900.000000 56.000000 -0.0275936 0.0643557 +dpolE 910.000000 56.000000 -0.0184616 0.0619833 +dpolE 920.000000 56.000000 -0.0283622 0.0618685 +dpolE 930.000000 56.000000 -0.0409616 0.0638597 +dpolE 940.000000 56.000000 -0.0296277 0.0689692 +dpolE 950.000000 56.000000 -0.0257706 0.0663065 +dpolE 960.000000 56.000000 -0.0095377 0.0675569 +dpolE 970.000000 56.000000 -0.0274188 0.0670614 +dpolE 980.000000 56.000000 -0.0236127 0.0598707 +dpolE 990.000000 56.000000 -0.0190679 0.0652348 +dpolE 1000.000000 56.000000 -0.0251999 0.0720196 +dpolE 300.000000 57.000000 0.210005 0.77624 +dpolE 310.000000 57.000000 0.894686 0.764974 +dpolE 320.000000 57.000000 -0.0883232 1.00534 +dpolE 330.000000 57.000000 -0.723884 1.12637 +dpolE 340.000000 57.000000 -0.371358 2.97671 +dpolE 350.000000 57.000000 -0.0267147 0.0940255 +dpolE 360.000000 57.000000 0.0174907 0.0585244 +dpolE 370.000000 57.000000 -0.0468935 0.0611836 +dpolE 380.000000 57.000000 0.0571498 0.176367 +dpolE 390.000000 57.000000 -0.0510095 0.104787 +dpolE 400.000000 57.000000 -0.0191099 0.0856199 +dpolE 410.000000 57.000000 -0.112289 0.109187 +dpolE 420.000000 57.000000 0.0396477 0.12051 +dpolE 430.000000 57.000000 -0.0257657 0.124664 +dpolE 440.000000 57.000000 -0.0628995 0.0910965 +dpolE 450.000000 57.000000 -0.0240705 0.133912 +dpolE 460.000000 57.000000 -0.041983 0.133967 +dpolE 470.000000 57.000000 -0.0772669 0.121203 +dpolE 480.000000 57.000000 -0.0170043 0.290416 +dpolE 490.000000 57.000000 -0.0153943 0.344361 +dpolE 500.000000 57.000000 -0.0144569 0.277648 +dpolE 510.000000 57.000000 -0.0124562 0.326759 +dpolE 520.000000 57.000000 -0.0104679 0.347835 +dpolE 530.000000 57.000000 -0.00755243 0.465994 +dpolE 540.000000 57.000000 -0.00707105 0.524015 +dpolE 550.000000 57.000000 -0.00617844 0.554564 +dpolE 560.000000 57.000000 -0.00550175 0.636438 +dpolE 570.000000 57.000000 -0.00612778 0.593992 +dpolE 580.000000 57.000000 -0.0023043 1.66246 +dpolE 590.000000 57.000000 -0.00408402 0.699995 +dpolE 600.000000 57.000000 -0.00459289 0.773068 +dpolE 610.000000 57.000000 -0.00395655 0.93686 +dpolE 620.000000 57.000000 -0.00338397 1.02306 +dpolE 630.000000 57.000000 -0.00592601 0.672511 +dpolE 640.000000 57.000000 -0.00616127 0.522716 +dpolE 650.000000 57.000000 -0.00246015 0.454876 +dpolE 660.000000 57.000000 -0.00371873 0.945272 +dpolE 670.000000 57.000000 -0.00540415 0.69573 +dpolE 680.000000 57.000000 -0.00767478 0.464175 +dpolE 690.000000 57.000000 -0.00897616 0.375517 +dpolE 700.000000 57.000000 -0.00696257 0.539818 +dpolE 710.000000 57.000000 -0.00727238 0.510354 +dpolE 720.000000 57.000000 0.00280621 0.465157 +dpolE 730.000000 57.000000 0.00930274 0.439491 +dpolE 740.000000 57.000000 -0.00950748 0.342676 +dpolE 750.000000 57.000000 -0.00658298 0.482911 +dpolE 760.000000 57.000000 0.0080079 0.329061 +dpolE 770.000000 57.000000 -0.0119837 0.292619 +dpolE 780.000000 57.000000 -0.00882687 0.420547 +dpolE 790.000000 57.000000 0.0160791 0.299384 +dpolE 800.000000 57.000000 -0.0150739 0.174439 +dpolE 810.000000 57.000000 -0.01432 0.28517 +dpolE 820.000000 57.000000 -0.0127776 0.260258 +dpolE 830.000000 57.000000 -0.0124146 0.239806 +dpolE 840.000000 57.000000 -0.0138726 0.273742 +dpolE 850.000000 57.000000 -0.00486392 0.273313 +dpolE 860.000000 57.000000 0.00472699 0.277842 +dpolE 870.000000 57.000000 -0.020304 0.161248 +dpolE 880.000000 57.000000 -0.0142262 0.18569 +dpolE 890.000000 57.000000 -0.0174916 0.182147 +dpolE 900.000000 57.000000 -0.0217695 0.159669 +dpolE 910.000000 57.000000 -0.0199238 0.173936 +dpolE 920.000000 57.000000 -0.0146308 0.177552 +dpolE 930.000000 57.000000 -0.0197314 0.172295 +dpolE 940.000000 57.000000 -0.00941801 0.178292 +dpolE 950.000000 57.000000 -0.0124652 0.134806 +dpolE 960.000000 57.000000 -0.00285857 0.142042 +dpolE 970.000000 57.000000 -0.00445287 0.120579 +dpolE 980.000000 57.000000 -0.0172799 0.139553 +dpolE 990.000000 57.000000 -0.0144572 0.120985 +dpolE 1000.000000 57.000000 -0.0140384 0.14979 +dpolE 300.000000 58.000000 0.561687 0.891027 +dpolE 310.000000 58.000000 0.190337 0.335722 +dpolE 320.000000 58.000000 -0.178998 0.724317 +dpolE 330.000000 58.000000 0.0500972 0.694652 +dpolE 340.000000 58.000000 1.62506 3.0576 +dpolE 350.000000 58.000000 -0.0795499 0.13091 +dpolE 360.000000 58.000000 0.0337711 0.177685 +dpolE 370.000000 58.000000 -0.0757299 0.0638001 +dpolE 380.000000 58.000000 0.0718276 0.159978 +dpolE 390.000000 58.000000 -0.120914 0.125633 +dpolE 400.000000 58.000000 0.00979513 0.0483058 +dpolE 410.000000 58.000000 -0.0444667 0.0454154 +dpolE 420.000000 58.000000 -0.0146552 0.101359 +dpolE 430.000000 58.000000 -0.0805498 0.0606675 +dpolE 440.000000 58.000000 -0.0211248 0.0674016 +dpolE 450.000000 58.000000 -0.0493298 0.0703562 +dpolE 460.000000 58.000000 -0.00330039 0.0641246 +dpolE 470.000000 58.000000 -0.0203143 0.0585686 +dpolE 480.000000 58.000000 -0.0662604 0.0638066 +dpolE 490.000000 58.000000 -0.0121065 0.0753368 +dpolE 500.000000 58.000000 -0.00848383 0.0671708 +dpolE 510.000000 58.000000 -0.0170825 0.0658525 +dpolE 520.000000 58.000000 -0.012711 0.0675222 +dpolE 530.000000 58.000000 -0.0554397 0.0641332 +dpolE 540.000000 58.000000 -0.0573388 0.0768784 +dpolE 550.000000 58.000000 -0.0307432 0.0648677 +dpolE 560.000000 58.000000 -0.00865787 0.0700312 +dpolE 570.000000 58.000000 -0.0290539 0.0688069 +dpolE 580.000000 58.000000 -0.0531497 0.0680289 +dpolE 590.000000 58.000000 -0.0296492 0.0666579 +dpolE 600.000000 58.000000 -0.0515343 0.0736571 +dpolE 610.000000 58.000000 -0.0125774 0.0608474 +dpolE 620.000000 58.000000 -0.0388441 0.0684848 +dpolE 630.000000 58.000000 -0.0339024 0.0689374 +dpolE 640.000000 58.000000 -0.0436583 0.0677698 +dpolE 650.000000 58.000000 -0.0476324 0.0707918 +dpolE 660.000000 58.000000 -0.00707896 0.0706823 +dpolE 670.000000 58.000000 -0.00567341 0.0697922 +dpolE 680.000000 58.000000 -0.0170426 0.0741473 +dpolE 690.000000 58.000000 -0.017786 0.0737488 +dpolE 700.000000 58.000000 -0.0380238 0.0770916 +dpolE 710.000000 58.000000 -0.0074274 0.0702329 +dpolE 720.000000 58.000000 -0.0264891 0.0742188 +dpolE 730.000000 58.000000 -0.0230063 0.0699355 +dpolE 740.000000 58.000000 -0.0240072 0.0858082 +dpolE 750.000000 58.000000 -0.0364167 0.0790147 +dpolE 760.000000 58.000000 -0.0367382 0.0679614 +dpolE 770.000000 58.000000 -0.0347689 0.0749848 +dpolE 780.000000 58.000000 -0.050943 0.0703015 +dpolE 790.000000 58.000000 -0.0290641 0.0810084 +dpolE 800.000000 58.000000 -0.020938 0.0767132 +dpolE 810.000000 58.000000 -0.0383089 0.0753664 +dpolE 820.000000 58.000000 -0.0298303 0.0679526 +dpolE 830.000000 58.000000 -0.0242845 0.0664482 +dpolE 840.000000 58.000000 -0.0221946 0.0792853 +dpolE 850.000000 58.000000 -0.00753182 0.0734105 +dpolE 860.000000 58.000000 0.0333665 0.0975857 +dpolE 870.000000 58.000000 -0.0123538 0.0721228 +dpolE 880.000000 58.000000 -0.0126262 0.0776185 +dpolE 890.000000 58.000000 -0.0244162 0.0735019 +dpolE 900.000000 58.000000 -0.0161363 0.0743216 +dpolE 910.000000 58.000000 -0.0130564 0.0697746 +dpolE 920.000000 58.000000 -0.0176506 0.0627193 +dpolE 930.000000 58.000000 -0.00906618 0.075833 +dpolE 940.000000 58.000000 -0.00577294 0.0759865 +dpolE 950.000000 58.000000 -0.0226446 0.0735196 +dpolE 960.000000 58.000000 -0.00074874 0.0644514 +dpolE 970.000000 58.000000 0.00432517 0.0681364 +dpolE 980.000000 58.000000 -0.0165229 0.0700611 +dpolE 990.000000 58.000000 -0.0211404 0.0716636 +dpolE 1000.000000 58.000000 -0.0295836 0.0770814 \ No newline at end of file