diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2b96278..4221ac5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: os: ["ubuntu-latest", "windows-latest"] - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] steps: diff --git a/pycoare/coare_35.py b/pycoare/coare_35.py index 01b5c18..2762ab8 100644 --- a/pycoare/coare_35.py +++ b/pycoare/coare_35.py @@ -14,9 +14,11 @@ from __future__ import annotations from dataclasses import dataclass + import numpy as np from numpy.typing import ArrayLike, NDArray -from .util import _check_size, grv, qsea, qair, psit_26, psiu_26, psiu_40, rhcalc + +from .util import _check_size, grv, psit_26, psiu_26, psiu_40, qair, qsea, rhcalc class coare_35: diff --git a/tests/data/c35_test_input.csv b/tests/data/c35_c36_test_input.csv similarity index 100% rename from tests/data/c35_test_input.csv rename to tests/data/c35_c36_test_input.csv diff --git a/tests/data/c35_test_expected.csv b/tests/data/c35_test_expected.csv index 9618aee..02c7f99 100644 --- a/tests/data/c35_test_expected.csv +++ b/tests/data/c35_test_expected.csv @@ -1,16 +1,16 @@ -tau,ustar,tstar,qstar,sensible,latent,buoyancy,webb,cd -0.010839700299122611,0.0929537802403513,0.0035289594577549185,-5.8191668973998876e-05,-0.4150173752971719,16.955400714681762,0.7461770343390143,0.08888038490726081,0.0009527954787808854 -0.018315073623469603,0.12181259806571534,0.0043481156786216914,-6.563891859896353e-05,-0.6588128592234483,24.523223922626137,1.0590327687052603,0.19074225048503993,0.0009217693595408025 -0.028315449887385553,0.15272945389593492,0.005068413943322712,-6.985101255268265e-05,-0.9464477080296773,32.00884607308208,1.3463238377800446,0.3619101314251821,0.0009283349444582006 -0.21787092715226272,0.4270989073371195,0.004690421987323391,-4.934085866092562e-05,-2.4066331275054127,61.82797253900009,2.1206663593320934,0.9561985438017788,0.0022468002608987646 -0.2234095834055547,0.43635723213796795,0.0049312950732702514,-4.1506517863884125e-05,-2.5384631456603937,51.92827965063115,1.3475600403217147,1.073205627920829,0.001901212762637836 -0.0018574304086998044,0.03942350399437484,-0.016928100519770683,-8.055570715110489e-05,0.8443373584433258,9.95478134123862,1.5260927847593508,0.08893543701631644,0.0013997691524369152 -0.03763814634463486,0.1745265562167727,0.0052292787432463685,-5.820440100628473e-05,-1.1351992176602295,31.155970472302215,1.0472686270483724,0.22749589194731457,0.0012136759075838768 -0.054164075018491235,0.21115691044683293,0.0053829981664504385,-6.104002417071663e-05,-1.3897327076008326,38.67181086464837,1.3803024062224247,0.4195036265224866,0.0012341073406133135 -0.07897245326952188,0.25718634155848036,0.005292719833433635,-5.7082434516050114e-05,-1.6352957925193576,43.07251488379331,1.5186516284023626,0.6703771470595152,0.001345758773188982 -0.2630661209856086,0.47347804763047374,0.0050574660343511366,-4.173333740136162e-05,-2.824883337741888,56.65371858250518,1.4147653751544709,1.1628654086122279,0.0018503601023419824 -0.009672421531772488,0.08806757006817484,0.0002196987401259344,-4.9835878469862954e-05,-0.0244791387603142,13.757461947462694,0.9177037192563257,0.08266489425681092,0.0019016043928476256 -0.020426476922271772,0.1288236138067376,0.0018798653084120044,-5.417298418620115e-05,-0.30122497918760943,21.404356613871855,1.198144783278318,0.18010576541739998,0.0018224801002963596 -0.16138683513237076,0.3644660774764541,0.0041939541221669195,-4.901839564251868e-05,-1.8688848184347708,53.60320021866439,1.9706754064197005,0.5856135783776176,0.0027019000341239907 -0.19804467475656345,0.40726007945108816,0.004349379621473561,-4.7949277065028334e-05,-2.127985527961758,57.29328807583576,2.067265635115754,0.8965577349985705,0.0025841071817240035 -0.23873609027729353,0.4511299473878712,0.004363336717680007,-3.928605322152922e-05,-2.322138295222561,50.814249401305986,1.4805170725323866,1.0735505074796374,0.0025076059987283322 +rnl,tau,hsb,hlb,hbb,hsbb,hlwebb,evap,rf,ut,usr,du,gf,u,u_rf,u_n,u_n_rf,lapse,dt,dter,t_rf,t_n,t_n_rf,dq,dqer,q_rf,q_n,q_n_rf,rh_rf,tsr,tvsr,tssr,qsr,tkt,obukL,zet,zo,zot,zoq,cd,ch,ce,cdn_rf,chn_rf,cen_rf,psi_u,psi_u_rf,psi_t,psi_t_rf,psi_q,psi_q_rf +-10.263173021482334,0.010839700299122611,-0.4150173752971719,16.955400714681762,0.7461770343390143,0.5558172950543936,0.08888038490726081,0.024522203391862417,nan,3.0113914465096823,0.0929537802403513,3.0,1.0037971488365607,2.0,2.0,2.0591391044665737,2.0591391044665737,0.009736413350274321,-0.0882,0.004018441045320441,5.0,5.004277082071795,5.004277082071795,0.0015221478462797279,1.4885017681042802e-06,3.792479871445064,3.722085368100146,3.721951845528082,69.99663155764539,0.0035289594577549185,-0.006344863273747673,-0.0047262038095669204,-5.8191668973998876e-05,0.0018153261003852445,-96.8108840497482,-0.0929647537912697,1.6421953002893476e-05,0.00016,0.00016,0.0009527954787808854,0.0011812144106666152,0.0011812143707750906,0.9163127853690164,1.1070350303409628,1.1070350303409628,0.2554545465275193,0.2554545465275193,0.4847980967756412,0.4847980967756412,0.4847980967756412,0.4847980967756412 +-10.264284180321086,0.018315073623469603,-0.6588128592234483,24.523223922626137,1.0590327687052603,0.7774187313398984,0.19074225048503993,0.03563702665056881,0.0,4.012186130071301,0.12181259806571534,4.0,1.0030465325178253,4.0,4.0,4.0585474641774955,4.0585474641774955,0.00974087820211294,-0.098,0.01801727072896971,10.0,10.004022481545727,10.004022481545727,0.001760404055141435,9.01359901856969e-06,5.713323155465227,5.652692278819221,5.652599992085759,74.99639515298703,0.0043481156786216914,-0.0069895371975726445,-0.005130905578524393,-6.563891859896353e-05,0.001397962934882702,-153.56292268645606,-0.06511988587517278,1.564747107811581e-05,0.00016,0.00016,0.0009217693595408025,0.0011378619605081535,0.0011378619437428356,0.8953668099678077,1.0838682360670933,1.0838682360670933,0.19283992579902806,0.19283992579902806,0.3700436550484408,0.3700436550484408,0.3700436550484408,0.3700436550484408 +-8.938158705453954,0.028315449887385553,-0.9464477080296773,32.00884607308208,1.3463238377800446,0.9704596499423855,0.3619101314251821,0.046738666719298924,2.0460661491350898,5.012685409431049,0.15272945389593492,5.0,1.0025370818862098,6.0,6.0,6.055225785327416,6.055225785327416,0.009747725391552413,-0.10779999999999999,0.029774797961080648,15.0,15.003558128056227,15.003558128056227,0.0019158769157694953,1.9871764073426725e-05,8.459445432216846,8.410470710095229,8.410408623010099,79.99616121410281,0.005068413943322712,-0.007209829400757718,-0.005197002623039616,-6.985101255268265e-05,0.001126097574673096,-237.99486144452337,-0.04621948529995511,1.891826169362864e-05,0.00016,0.00016,0.0009283349444582006,0.0011224979139034203,0.0011224979129507518,0.908162556457221,1.082244848075148,1.082244848075148,0.14500385159432597,0.14500385159432597,0.2808080078711052,0.2808080078711052,0.2808080078711052,0.2808080078711052 +66.25779330301711,0.21787092715226272,-2.4066331275054127,61.82797253900009,2.1206663593320934,1.3784861155882402,0.9561985438017788,0.09071596883778951,1.5651400844687389,9.01044474011033,0.4270989073371195,9.0,1.0011605266789256,8.0,8.0,8.01077059170753,8.01077059170753,0.009756135708904837,-0.0882,0.08550912719222369,20.0,20.000236248969436,20.000236248969436,0.0019026047511468604,7.526924260987121e-05,12.328989172892946,12.326505394471418,12.326503953643765,84.99593081009863,0.004690421987323391,-0.004133085348949152,-0.0026866087364454568,-4.934085866092562e-05,0.0004097498377860196,-3300.0699855001853,-0.002727214889242989,0.0019273346714032825,3.2498730972653586e-06,3.2498730972653586e-06,0.0022468002608987646,0.001279886657502357,0.0012798840958467461,2.2414322968734144,1.276618224467268,1.276618224467268,0.0100989172122069,0.0100989172122069,0.020147353058925413,0.020147353058925413,0.020147353058925413,0.020147353058925413 +70.44412737781893,0.2234095834055547,-2.5384631456603937,51.92827965063115,1.3475600403217147,0.7105070590131726,1.073205627920829,0.07656058431136363,2.0349105787887716,10.007528090362786,0.43635723213796795,10.0,1.0007528090362787,10.0,10.0,10.007335022500117,10.007335022500117,0.00976509912249875,-0.098,0.08037718406022373,25.0,25.00016563449935,25.00016563449935,0.0015937285681765397,9.23337089976236e-05,17.711185161777177,17.70979154713508,17.70979102267092,89.99570538856089,0.0049312950732702514,-0.0026178107801701203,-0.0013802524435405517,-4.1506517863884125e-05,0.0004046944680215499,-5526.309274148111,-0.0018095259428891654,0.0010303611943599143,5.1328354462240456e-06,5.1328354462240456e-06,0.001901212762637836,0.001205416264254755,0.0012054154021110177,1.898426751689655,1.2034145364071747,1.2034145364071747,0.006728931096543187,0.006728931096543187,0.013435375242295575,0.013435375242295575,0.013435375242295575,0.013435375242295575 +-56.54283413572331,0.0018574304086998044,0.8443373584433258,9.95478134123862,1.5260927847593508,1.4143296001173795,0.08893543701631644,0.01439736971595084,2.9780333309631177,1.0537243422807592,0.03942350399437484,1.0,1.0537243422807592,2.0,2.0,2.170002881394951,2.170002881394951,0.009736413350274321,-0.10779999999999999,-0.4637639575563865,5.0,4.884593342414094,4.884593342414094,0.0015221478462797279,-0.00017178638756181435,3.792479871445064,3.2574778266609337,3.2432945153609403,69.99663155764539,-0.016928100519770683,-0.030596599575472998,-0.028355862025357864,-8.055570715110489e-05,0.004335676956216247,-3.6135166100715126,-3.0441260375948036,4.0641562833476365e-05,0.00016,0.00016,0.0013997691524369152,0.0017792231140918362,0.0017792131453177882,1.0225900461168884,1.148403510979627,1.148403510979627,1.8175571041000176,1.8175571041000176,2.7269842225031766,2.7269842225031766,2.7269842225031766,2.7269842225031766 +13.74141400972347,0.03763814634463486,-1.1351992176602295,31.155970472302215,1.0472686270483724,0.6894870131617166,0.22749589194731457,0.04527570084377668,4.509082555898388,5.009681939357663,0.1745265562167727,5.0,1.0019363878715326,4.0,4.0,4.029580128816665,4.029580128816665,0.00974087820211294,-0.0882,0.06695137922221574,10.0,10.001747778194947,10.001747778194947,0.001760404055141435,3.34941343296205e-05,5.713323155465227,5.693888346589088,5.693869539025273,74.99639515298703,0.0052292787432463685,-0.004824227752006779,-0.003176111933112821,-5.820440100628473e-05,0.0009772818561882416,-456.71526180304164,-0.01970593223547946,8.675121838036307e-05,5.521000328311624e-05,5.521000328311624e-05,0.0012136759075838768,0.0011741876740427003,0.0011741876418648904,1.1994420679903852,1.154279035812945,1.154279035812945,0.06792641317584328,0.06792641317584328,0.1336917216129693,0.1336917216129693,0.1336917216129693,0.1336917216129693 +15.115917203529483,0.054164075018491235,-1.3897327076008326,38.67181086464837,1.3803024062224247,0.9261982892022188,0.4195036265224866,0.05646779253796839,6.007776965524837,6.010752298753567,0.21115691044683293,6.0,1.0017920497922612,6.0,6.0,6.030011821854772,6.030011821854772,0.009747725391552413,-0.098,0.0670131792348533,15.0,15.001512262654048,15.001512262654048,0.0019158769157694953,4.4724739670976826e-05,8.459445432216846,8.442312610256595,8.442297265693057,79.99616121410281,0.0053829981664504385,-0.005346470786220121,-0.0035875414497167513,-6.104002417071663e-05,0.0008165762183463996,-613.465684102056,-0.016300830281382784,0.00010721304911321213,4.226323080346712e-05,4.226323080346712e-05,0.0012341073406133135,0.0011459932719712555,0.0011459932396469745,1.2218534215369694,1.1299342691361052,1.1299342691361052,0.05695405273788028,0.05695405273788028,0.11237326168697663,0.11237326168697663,0.11237326168697663,0.11237326168697663 +17.880060956650244,0.07897245326952188,-1.6352957925193576,43.07251488379331,1.5186516284023626,1.0016110675955234,0.6703771470595152,0.06319736451811865,6.360010336081718,7.010746935982562,0.25718634155848036,7.0,1.0015352765689374,8.0,8.0,8.025069418088789,8.025069418088789,0.009756135708904837,-0.10779999999999999,0.06343346871086246,20.0,20.001023697384156,20.001023697384156,0.0019026047511468604,5.583718724260103e-05,12.328989172892946,12.317956974842012,12.317948509352398,84.99593081009863,0.005292719833433635,-0.004915194933228769,-0.0032417662829562445,-5.7082434516050114e-05,0.0006779763821280847,-1006.2328246293706,-0.01093186361123895,0.00019453133172261022,2.4409749331564134e-05,2.4409749331564134e-05,0.001345758773188982,0.0011338976651285762,0.0011338976594936633,1.336171055267645,1.1231367429670558,1.1231367429670558,0.03905013995195939,0.03905013995195939,0.07736645175807806,0.07736645175807806,0.07736645175807806,0.07736645175807806 +94.62575119905541,0.2630661209856086,-2.824883337741888,56.65371858250518,1.4147653751544709,0.7197409959911341,1.1628654086122279,0.08352754659445832,5.0238360970318165,11.00706979634261,0.47347804763047374,11.0,1.000642708758419,10.0,10.0,10.005900059182787,10.005900059182787,0.00976509912249875,-0.0882,0.09211314962286467,25.0,25.00012596774955,25.00012596774955,0.0015937285681765397,0.0001058154605884121,17.711185161777177,17.7101460315103,17.710145697634875,89.99570538856089,0.0050574660343511366,-0.0025328932121987512,-0.0012885720242397543,-4.173333740136162e-05,0.0003730402306001676,-6724.689005956732,-0.0013383518541939703,0.0008196204481694474,5.70661329404535e-06,5.70661329404535e-06,0.0018503601023419824,0.001206517715317733,0.001206517636340926,1.848376747636397,1.2050290147919487,1.2050290147919487,0.004987645135434927,0.004987645135434927,0.009962914130782255,0.009962914130782255,0.009962914130782255,0.009962914130782255 +-34.06240463026949,0.009672421531772488,-0.0244791387603142,13.757461947462694,0.9177037192563257,0.7632475130240896,0.08266489425681092,0.019897098612323763,2.521423460928721,2.0195561276116174,0.08806757006817484,2.0,1.0097780638058087,2.0,2.0,2.0789461787584216,2.0789461787584216,0.009736413350274321,-0.098,-0.09114071968029015,5.0,5.000371101429145,5.000371101429145,0.0015221478462797279,-3.376013754099765e-05,3.792479871445064,3.708708772540669,3.7083002092754325,69.99663155764539,0.0002196987401259344,-0.008236333512532085,-0.0068500987170143765,-4.9835878469862954e-05,0.0019408685588735077,-66.94320345215584,-0.14938036252099854,0.000722892749482637,1.9186068724169583e-05,1.9186068724169583e-05,0.0019016043928476256,0.0013967191922322616,0.001396748760956172,1.759922884998002,1.274740740166412,1.274740740166412,0.3620770709119598,0.3620770709119598,0.6756550882957711,0.6756550882957711,0.6756550882957711,0.6756550882957711 +-34.194914425341985,0.020426476922271772,-0.30122497918760943,21.404356613871855,1.198144783278318,0.9523464615625923,0.18010576541739998,0.0311047042384607,4.780295176984809,3.017616741566341,0.1288236138067376,3.0,1.0058722471887804,4.0,4.0,4.064335531708734,4.064335531708734,0.00974087820211294,-0.10779999999999999,-0.045914849005346134,10.0,10.001809402479687,10.001809402479687,0.001760404055141435,-2.297007377854e-05,5.713323155465227,5.661333158173716,5.6611807325586705,74.99639515298703,0.0018798653084120044,-0.007477304234908475,-0.005943342014692004,-5.417298418620115e-05,0.0013381615641621417,-160.5448227857584,-0.06851669090992192,0.0007671688136168741,1.4302048167140393e-05,1.4302048167140393e-05,0.0018224801002963596,0.0012967960407734881,0.0012967960985317878,1.746757718096934,1.233504646827489,1.233504646827489,0.20093622261220592,0.20093622261220592,0.38500683460475704,0.38500683460475704,0.38500683460475704,0.38500683460475704 +39.3416328571334,0.16138683513237076,-1.8688848184347708,53.60320021866439,1.9706754064197005,1.3412393039845412,0.5856135783776176,0.07827030391498177,5.99160799566485,7.011686246170311,0.3644660774764541,7.0,1.0016694637386159,6.0,6.0,6.013636993882747,6.013636993882747,0.009747725391552413,-0.0882,0.07162979802931188,15.0,15.00031320820597,15.00031320820597,0.0019158769157694953,4.78058809643735e-05,8.459445432216846,8.455787746956618,8.455784695043397,79.99616121410281,0.0041939541221669195,-0.004422381819725474,-0.0030098677308906547,-4.901839564251868e-05,0.000475866063913311,-2209.549889691561,-0.004073227783626258,0.004033731739056449,2.0938962990514935e-06,2.0938962990514935e-06,0.0027019000341239907,0.0013639566360997145,0.0013639559498813758,2.691403364244796,1.358641536246692,1.358641536246692,0.014991530014664238,0.014991530014664238,0.02987235404557869,0.02987235404557869,0.02987235404557869,0.02987235404557869 +42.09885870181392,0.19804467475656345,-2.127985527961758,57.29328807583576,2.067265635115754,1.3795195428079652,0.8965577349985705,0.08406253548785815,6.334633198427033,8.011550602593475,0.40726007945108816,8.0,1.0014438253241844,8.0,8.0,8.01278697001373,8.01278697001373,0.009756135708904837,-0.098,0.06906662139262114,20.0,20.00027266482136,20.00027266482136,0.0019026047511468604,6.0795758915407205e-05,12.328989172892946,12.325985376014813,12.325983208317977,84.99593081009863,0.004349379621473561,-0.004225274517800501,-0.0028195935113621293,-4.7949277065028334e-05,0.0004297503951754295,-2935.156800131672,-0.0034069730106246446,0.0037773838691294065,2.0717120151890714e-06,2.0717120151890714e-06,0.0025841071817240035,0.0013234053528196144,0.001323404893554481,2.5758662303850626,1.3191400820150554,1.3191400820150554,0.012577154315852003,0.012577154315852003,0.02507620351309682,0.02507620351309682,0.02507620351309682,0.02507620351309682 +46.3048396401697,0.23873609027729353,-2.322138295222561,50.814249401305986,1.4805170725323866,0.8571309466709206,1.0735505074796374,0.07491811112714304,5.189980905645842,9.008905011441426,0.4511299473878712,9.0,1.000989445715714,10.0,10.0,10.008285137367917,10.008285137367917,0.00976509912249875,-0.10779999999999999,0.061377667328923864,25.0,25.000160133809423,25.000160133809423,0.0015937285681765397,7.05079151548225e-05,17.711185161777177,17.70974408221811,17.70974336945937,89.99570538856089,0.004363336717680007,-0.002781916355723995,-0.0016105633928708814,-3.928605322152922e-05,0.000391660389294002,-5558.376680424108,-0.001978995061407154,0.0037078013558022233,1.993126315774109e-06,1.993126315774109e-06,0.0025076059987283322,0.0012915325209761023,0.0012915321786026346,2.502995515935845,1.2891241557508168,1.2891241557508168,0.0073533890708077955,0.0073533890708077955,0.01467994058524065,0.01467994058524065,0.01467994058524065,0.01467994058524065 diff --git a/tests/data/c35_test_expected_old.csv b/tests/data/c35_test_expected_old.csv new file mode 100644 index 0000000..9618aee --- /dev/null +++ b/tests/data/c35_test_expected_old.csv @@ -0,0 +1,16 @@ +tau,ustar,tstar,qstar,sensible,latent,buoyancy,webb,cd +0.010839700299122611,0.0929537802403513,0.0035289594577549185,-5.8191668973998876e-05,-0.4150173752971719,16.955400714681762,0.7461770343390143,0.08888038490726081,0.0009527954787808854 +0.018315073623469603,0.12181259806571534,0.0043481156786216914,-6.563891859896353e-05,-0.6588128592234483,24.523223922626137,1.0590327687052603,0.19074225048503993,0.0009217693595408025 +0.028315449887385553,0.15272945389593492,0.005068413943322712,-6.985101255268265e-05,-0.9464477080296773,32.00884607308208,1.3463238377800446,0.3619101314251821,0.0009283349444582006 +0.21787092715226272,0.4270989073371195,0.004690421987323391,-4.934085866092562e-05,-2.4066331275054127,61.82797253900009,2.1206663593320934,0.9561985438017788,0.0022468002608987646 +0.2234095834055547,0.43635723213796795,0.0049312950732702514,-4.1506517863884125e-05,-2.5384631456603937,51.92827965063115,1.3475600403217147,1.073205627920829,0.001901212762637836 +0.0018574304086998044,0.03942350399437484,-0.016928100519770683,-8.055570715110489e-05,0.8443373584433258,9.95478134123862,1.5260927847593508,0.08893543701631644,0.0013997691524369152 +0.03763814634463486,0.1745265562167727,0.0052292787432463685,-5.820440100628473e-05,-1.1351992176602295,31.155970472302215,1.0472686270483724,0.22749589194731457,0.0012136759075838768 +0.054164075018491235,0.21115691044683293,0.0053829981664504385,-6.104002417071663e-05,-1.3897327076008326,38.67181086464837,1.3803024062224247,0.4195036265224866,0.0012341073406133135 +0.07897245326952188,0.25718634155848036,0.005292719833433635,-5.7082434516050114e-05,-1.6352957925193576,43.07251488379331,1.5186516284023626,0.6703771470595152,0.001345758773188982 +0.2630661209856086,0.47347804763047374,0.0050574660343511366,-4.173333740136162e-05,-2.824883337741888,56.65371858250518,1.4147653751544709,1.1628654086122279,0.0018503601023419824 +0.009672421531772488,0.08806757006817484,0.0002196987401259344,-4.9835878469862954e-05,-0.0244791387603142,13.757461947462694,0.9177037192563257,0.08266489425681092,0.0019016043928476256 +0.020426476922271772,0.1288236138067376,0.0018798653084120044,-5.417298418620115e-05,-0.30122497918760943,21.404356613871855,1.198144783278318,0.18010576541739998,0.0018224801002963596 +0.16138683513237076,0.3644660774764541,0.0041939541221669195,-4.901839564251868e-05,-1.8688848184347708,53.60320021866439,1.9706754064197005,0.5856135783776176,0.0027019000341239907 +0.19804467475656345,0.40726007945108816,0.004349379621473561,-4.7949277065028334e-05,-2.127985527961758,57.29328807583576,2.067265635115754,0.8965577349985705,0.0025841071817240035 +0.23873609027729353,0.4511299473878712,0.004363336717680007,-3.928605322152922e-05,-2.322138295222561,50.814249401305986,1.4805170725323866,1.0735505074796374,0.0025076059987283322 diff --git a/tests/data/c36_test_expected.csv b/tests/data/c36_test_expected.csv new file mode 100644 index 0000000..98205be --- /dev/null +++ b/tests/data/c36_test_expected.csv @@ -0,0 +1,16 @@ +rnl,tau,hsb,hlb,hbb,hsbb,hlwebb,evap,rf,ut,usr,du,gf,u,u_rf,u_n,u_n_rf,lapse,dt,dter,t_rf,t_n,t_n_rf,dq,dqer,q_rf,q_n,q_n_rf,rh_rf,tsr,tvsr,tssr,qsr,tkt,obukL,zet,zo,zot,zoq,cd,ch,ce,cdn_rf,chn_rf,cen_rf,psi_u,psi_u_rf,psi_t,psi_t_rf,psi_q,psi_q_rf +-10.25995140293192,0.010842299379885898,-0.40954116036997484,16.964901391313077,0.7513564674995068,0.5610453809635262,0.08912302805475439,0.024535944000452795,nan,3.011443999908579,0.09296573471954066,3.0,1.003814666636193,2.0,2.0,2.0595000478272008,2.0595000478272008,0.009736413350274321,-0.08762772015246889,0.0033379968267240757,5.0,5.004244288368128,5.004244288368128,0.0015221478462797279,1.2364531723792038e-06,3.792479871445064,3.721651988047094,3.721517024253196,69.99663155764539,0.0034819465202455386,-0.006388083276197337,-0.004770045604649324,-5.8216788638091754e-05,0.0018155960179213435,-96.05949486370403,-0.09369193553193084,1.642046996001826e-05,0.00016,0.00016,0.0009530073031416409,0.0011816598076117202,0.0011816597598293317,0.9163002603127819,1.1070274642982247,1.1070274642982247,0.25698509608807457,0.25698509608807457,0.4875765142801865,0.4875765142801865,0.4875765142801865,0.4875765142801865 +-10.262290471187306,0.018317627302622486,-0.6533337789715669,24.531476528151796,1.0628129906104713,0.7814774546134158,0.19109006591445035,0.03564901929574394,0.0,4.012215067691023,0.12182152927542438,4.0,1.0030537669227557,4.0,4.0,4.058812470857097,4.058812470857097,0.00974087820211294,-0.0974087820211294,0.017618031426032087,10.0,10.004005889219004,10.004005889219004,0.001760404055141435,8.813869378977446e-06,5.713323155465227,5.6524157309345755,5.65232280328615,74.99639515298703,0.004311638031955799,-0.007013972120630576,-0.005157314718567236,-6.565619367862465e-05,0.0013980156381209437,-152.7231967403271,-0.06547793795203781,1.5647640581413066e-05,0.00016,0.00016,0.0009218912331894019,0.0011381068775117803,0.0011381068595165884,0.8953682610889198,1.0838691143794372,1.0838691143794372,0.19369998320041207,0.19369998320041207,0.371635020316061,0.371635020316061,0.371635020316061,0.371635020316061 +-8.935996546639492,0.028318659361886836,-0.9398259088353045,32.01894885099928,1.3488195443269657,0.9736317651200362,0.3625229218406633,0.04675341859035771,2.046545819074698,5.012701061529601,0.1527383478340267,5.0,1.0025402123059202,6.0,6.0,6.055476677989154,6.055476677989154,0.009747725391552413,-0.10722497930707654,0.029363927025423658,15.0,15.003548425842386,15.003548425842386,0.0019158769157694953,1.9597547928998942e-05,8.459445432216846,8.41024468203896,8.410182231497682,79.99616121410281,0.005032659835702499,-0.007222773795156593,-0.00521368631468789,-6.986899054673123e-05,0.0011261222778624013,-236.74477682598967,-0.04646353827727796,1.8919637799919425e-05,0.00016,0.00016,0.0009284372695009403,0.001122686323229045,0.001122686322468099,0.9081725099136334,1.0822507787575635,1.0822507787575635,0.14565458201685136,0.14565458201685136,0.28203184464909586,0.28203184464909586,0.28203184464909586,0.28203184464909586 +66.43616156543015,1.0952153901668995,-3.4601869277229933,111.08035244914738,4.647552248537002,3.318414678658314,1.8066058478308247,0.16298062798212037,1.6014084748121455,9.017615408491448,0.9579687218355412,9.0,1.001957267610161,8.0,8.0,8.004782490300865,8.004782490300865,0.009756135708904837,-0.08780522138014353,0.05330606582161848,20.0,20.000030063796796,20.000030063796796,0.0019026047511468604,4.69225605809955e-05,12.328989172892946,12.328594373399586,12.328593987224325,84.99593081009863,0.003006621222025476,-0.004038345185622358,-0.002883432659778451,-3.95217419120358e-05,0.00018305667698262674,-16825.80632166534,-0.0005348926421678449,0.20803025654545465,6.252776999557067e-08,6.252776999557067e-08,0.011285459339932141,0.0022634796031808287,0.0022625182876086477,11.273542832787475,2.26090224073015,2.26090224073015,0.0020008381505588102,0.0020008381505588102,0.003999678652845679,0.003999678652845679,0.003999678652845679,0.003999678652845679 +70.50298984181812,0.32614225836557087,-2.6529352436215645,58.093039942442964,1.6657624195410268,0.9577791960717507,1.227593886976428,0.08564961351194621,2.056753536590195,10.008670350484664,0.5272536559616683,10.0,1.0008670350484663,10.0,10.0,10.006331605242698,10.006331605242698,0.00976509912249875,-0.0976509912249875,0.07027524575180848,25.0,25.00010240477072,25.00010240477072,0.0015937285681765397,8.07290547292894e-05,17.711185161777177,17.71026290535411,17.710262505626414,89.99570538856089,0.00426519955643905,-0.002678093688883388,-0.0015398488945682362,-3.8428996787790314e-05,0.000335252063293316,-7753.40103427508,-0.001289756579827806,0.005015202228884857,1.4332930305470831e-06,1.4332930305470831e-06,0.0027751497867714746,0.001338024339857605,0.0013380226744338797,2.7716389211568435,1.3363612839669419,1.3363612839669419,0.004807625244285097,0.004807625244285097,0.009603749542136664,0.009603749542136664,0.009603749542136664,0.009603749542136664 +-56.662349664681564,0.0020785808209409493,0.8162528025753593,10.283046468037762,1.5223778691267862,1.4066196614954047,0.08997893567815836,0.014872131966709896,2.947251873414272,1.0536393407245477,0.04170276846702928,1.0,1.0536393407245477,2.0,2.0,2.168010331321434,2.168010331321434,0.009736413350274321,-0.10710054685301754,-0.43864429385412707,5.0,4.899814675411936,4.899814675411936,0.0015221478462797279,-0.00016248161901766953,3.792479871445064,3.296198928100266,3.2830626906713185,69.99663155764539,-0.015470603102087907,-0.028853933132423668,-0.02665994460286043,-7.866412620351096e-05,0.004098710567305564,-4.2959905628391715,-2.5605270400617974,8.22145085410092e-05,0.00015717352461159197,0.00015717352461159197,0.0015665556161722197,0.0018468826947473857,0.0018481841411238861,1.148302030407642,1.2150031281541975,1.2150031281541975,1.6979428583345457,1.6979428583345457,2.5903405039081644,2.5903405039081644,2.5903405039081644,2.5903405039081644 +13.76700696122914,0.04746901835027838,-1.13035291154877,32.2452844549455,1.124481678300498,0.75483666357111,0.23766567831962504,0.04685868648843652,4.52140372896778,5.010151685875676,0.19600759129350212,5.0,1.0020303371751351,4.0,4.0,4.025747235717587,4.025747235717587,0.00974087820211294,-0.08766790381901647,0.06182387325988069,10.0,10.001205244819552,10.001205244819552,0.001760404055141435,3.0928968750157824e-05,5.713323155465227,5.699393774224312,5.699379640724336,74.99639515298703,0.004636309222133001,-0.004612227492810997,-0.0030960739329841122,-5.3637605350697685e-05,0.0008727095941632648,-600.4356235586636,-0.01498911731229199,0.0003097240554416815,2.0313187618417096e-05,2.0313187618417096e-05,0.001530537709280804,0.0012133248889048976,0.0012133248358902379,1.5148957884960725,1.1974546784865598,1.1974546784865598,0.05265002465907352,0.05265002465907352,0.10398312638846939,0.10398312638846939,0.10398312638846939,0.10398312638846939 +15.12558513461602,0.05852528807590402,-1.384272849977184,39.10454883769816,1.4096157759111365,0.9516012470769859,0.42571153294001646,0.05709966773437441,6.014213837678045,6.010903857829348,0.21949614076574298,6.0,1.0018173096382246,6.0,6.0,6.028670317620831,6.028670317620831,0.009747725391552413,-0.09747725391552413,0.06517530179322605,15.0,15.001333159325442,15.001333159325442,0.0019158769157694953,4.3498136321270525e-05,8.459445432216846,8.444112662865642,8.444098736994913,79.99616121410281,0.005158139274716067,-0.005252573216404872,-0.003545899037532588,-5.937804270699988e-05,0.0007862214234717015,-671.3258423941298,-0.014895896103652573,0.0001659604435132582,3.0007245561585632e-05,3.0007245561585632e-05,0.0013334422581925886,0.0011580285853214538,0.0011580285709162292,1.3207896149316511,1.1431516937790185,1.1431516937790185,0.052342460993022435,0.052342460993022435,0.10338296462656567,0.10338296462656567,0.10338296462656567,0.10338296462656567 +17.88663424306581,0.08328090376391957,-1.6338370295294633,43.482298476488715,1.5378288673572764,1.0178836383594503,0.6785027273125632,0.06379861204571216,6.365356275761051,7.010837150335665,0.2641104559255906,7.0,1.0015481643336666,8.0,8.0,8.024329015718463,8.024329015718463,0.009756135708904837,-0.1073174927979532,0.062246790573598686,20.0,20.000941700640485,20.000941700640485,0.0019026047511468604,5.479261612433028e-05,12.328989172892946,12.31873500614457,12.318727071646743,84.99593081009863,0.0051493644059129534,-0.0048467754670951345,-0.003208064012503645,-5.611475304926551e-05,0.0006604809899153351,-1067.5920627819723,-0.010303561054337345,0.0002594240670899911,1.9464412305318375e-05,1.9464412305318375e-05,0.0014191602269265351,0.0011440235472010174,0.001144023529222737,1.4093466267879442,1.1337646325343635,1.1337646325343635,0.03690377338144698,0.03690377338144698,0.07315082532534525,0.07315082532534525,0.07315082532534525,0.07315082532534525 +94.64422304266319,0.28818635935212744,-2.833581227496765,58.0898966650404,1.4829295430682603,0.7753048265821911,1.201426937746082,0.08564497921332873,5.040975263871693,11.007295020590751,0.49557403176182235,11.0,1.0006631836900683,10.0,10.0,10.005763954196917,10.005763954196917,0.00976509912249875,-0.08788589210248875,0.08894253861591034,25.0,25.000112690145276,25.000112690145276,0.0015937285681765397,0.00010217320467358143,17.711185161777177,17.71023493086807,17.71023461583147,89.99570538856089,0.004846848348408299,-0.002536554991570107,-0.0013261610014097137,-4.088336238983652e-05,0.00035650128376343816,-7207.555577663166,-0.0012486896428369936,0.001240908233214699,4.096613361168504e-06,4.096613361168504e-06,0.002027009895440287,0.001234057151305733,0.0012340568378527567,2.024887278625445,1.2326250411434332,1.2326250411434332,0.004655430985215135,0.004655430985215135,0.009300076022528464,0.009300076022528464,0.009300076022528464,0.009300076022528464 +-34.07871499171798,0.01045454493770887,-0.03487561446580434,13.899191712223617,0.91693295649496,0.7608987645341788,0.08317383889008922,0.020102079088847608,2.5172062885103346,2.0195452291802716,0.09155873865472262,2.0,1.0097726145901358,2.0,2.0,2.0755014657144972,2.0755014657144972,0.009736413350274321,-0.09736413350274321,-0.08769923375467409,5.0,5.000469860919635,5.000469860919635,0.0015221478462797279,-3.248535017260986e-05,3.792479871445064,3.7172660641810147,3.7168994399474724,69.99663155764539,0.00030107140753826017,-0.007915625288862966,-0.0065686258304365345,-4.842945208339538e-05,0.0018668625224982133,-75.28106183666155,-0.1328355333469811,0.0010558206620305457,1.4202933609632276e-05,1.4202933609632276e-05,0.0020553814572341076,0.001412272090102625,0.0014123028503761775,1.9085622295400642,1.2978311029643639,1.2978311029643639,0.3330727948423223,0.3330727948423223,0.6242517992352459,0.6242517992352459,0.6242517992352459,0.6242517992352459 +-34.20432172750513,0.02175065129384705,-0.310728458575489,21.637165184295565,1.2038665571356166,0.9555722922649436,0.18175490598926444,0.03144302049144796,4.775771479389477,3.017672619079543,0.1329348647210749,3.0,1.0058908730265144,4.0,4.0,4.061784969178849,4.061784969178849,0.00974087820211294,-0.10714966022324235,-0.04403229397091546,10.0,10.001687695901298,10.001687695901298,0.001760404055141435,-2.202827762827934e-05,5.713323155465227,5.665802445177672,5.665662681472771,74.99639515298703,0.0018792015456825955,-0.007280658827763038,-0.00577904237309982,-5.306858677898333e-05,0.0012967764996364738,-175.41515072269942,-0.06270838040317891,0.0010392412172855103,1.1237265808950062e-05,1.1237265808950062e-05,0.0019405889373721589,0.0013115693774422002,0.0013115693122100639,1.8630593403312727,1.2516351549013098,1.2516351549013098,0.18700567896203743,0.18700567896203743,0.35923680569034083,0.35923680569034083,0.35923680569034083,0.35923680569034083 +39.357264822390256,0.18544918013835848,-1.9068551893019547,55.95534751080688,2.0913478503762613,1.4359047291175373,0.6144832521485772,0.08170486160291421,6.002016138244694,7.012158160028828,0.390706047523347,7.0,1.0017368800041182,6.0,6.0,6.012683268953303,6.012683268953303,0.009747725391552413,-0.08772952852397171,0.06865803006477209,15.0,15.000258782119065,15.000258782119065,0.0019158769157694953,4.5822516645680437e-05,8.459445432216846,8.456353652438722,8.456350968578365,79.99616121410281,0.003991772956569182,-0.004377986246017498,-0.003005894573462305,-4.773280438317542e-05,0.00044409736252947705,-2552.8691301279314,-0.0035254451134159722,0.0067734595355334725,1.3713350707954184e-06,1.3713350707954184e-06,0.003104537147420949,0.0014222045448995142,0.0014222015278803366,3.093317532892074,1.417284240090454,1.417284240090454,0.013007526604794836,0.013007526604794836,0.02593154689709456,0.02593154689709456,0.02593154689709456,0.02593154689709456 +42.112656922313164,0.22351946321559787,-2.167509924610022,59.46974359239906,2.1708091438297865,1.459609296544572,0.934859350225992,0.08725590028229403,6.3458556236524215,8.01193285907618,0.43267150129639753,8.0,1.0014916073845226,8.0,8.0,8.012007207246617,8.012007207246617,0.009756135708904837,-0.09756135708904837,0.06657549589161087,20.0,20.00023115271203,20.00023115271203,0.0019026047511468604,5.86029505467091e-05,12.328989172892946,12.32639421701084,12.326392282404312,84.99593081009863,0.004169973461441278,-0.004176320678786717,-0.002808075737765734,-4.684766328239591e-05,0.0004046454673751169,-3326.6957521138334,-0.0030059857423528577,0.006003126110320717,1.4208568433319095e-06,1.4208568433319095e-06,0.0029163656792657667,0.0013719812557551826,0.001371979373259014,2.907631042473358,1.3679968640562261,1.3679968640562261,0.011117087443552536,0.011117087443552536,0.02217306313001223,0.02217306313001223,0.02217306313001223,0.02217306313001223 +46.31675954428996,0.2663875597225963,-2.364681931350448,52.58000785808766,1.5445653583522696,0.903705146925595,1.116363169971572,0.0775214613654615,5.20103747372626,9.009159889801854,0.47654699174289783,9.0,1.0010177655335393,10.0,10.0,10.0078812509062,10.0078812509062,0.00976509912249875,-0.10741609034748625,0.05933228923193565,25.0,25.0001390419032,25.0001390419032,0.0015937285681765397,6.815827640838521e-05,17.711185161777177,17.709913724434475,17.709913077586467,89.99570538856089,0.004206290919368914,-0.002747469397501012,-0.0016075086898174181,-3.848304760582636e-05,0.00037086391439098836,-6177.897455361899,-0.0017805410464450035,0.005680253252641416,1.4093409908047415e-06,1.4093409908047415e-06,0.002797968852163109,0.0013343173156383995,0.0013343159358703172,2.793074980440007,1.3320379572275927,1.3320379572275927,0.006622030824603695,0.006622030824603695,0.013222281184575605,0.013222281184575605,0.013222281184575605,0.013222281184575605 diff --git a/tests/test_coare.py b/tests/test_coare.py deleted file mode 100644 index 956e3ea..0000000 --- a/tests/test_coare.py +++ /dev/null @@ -1,357 +0,0 @@ -""" -Tests for the COARE functions in pycoare.util and pycoare.coare -""" - -import csv -import numpy as np -import os -from pycoare.util import rhcalc, psit_26, psiu_26, psiu_40, qsat, qsea, qair -from pycoare import coare_35 -import pytest - -# required or tests fail since numpy doesn't save enough precision -np.set_printoptions(precision=12) - - -@pytest.fixture -def load_input(): - path = os.path.join(os.path.dirname(__file__), "data/c35_test_input.csv") - data = list(csv.reader(open(path))) - input_data = {i[0]: np.array(i[1:], dtype=float) for i in zip(*data)} - input_data.update({"jcool": 1, "nits": 10}) - return input_data - - -@pytest.fixture -def load_expected(): - path = os.path.join(os.path.dirname(__file__), "data/c35_test_expected.csv") - data = list(csv.reader(open(path))) - expected = {i[0]: np.array(i[1:], dtype=float) for i in zip(*data)} - return expected - - -class TestOutputC35: - def test_tau(self, load_input, load_expected): - expected = load_expected["tau"] - actual = coare_35.tau(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_ustar(self, load_input, load_expected): - expected = load_expected["ustar"] - actual = coare_35.ustar(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_tstar(self, load_input, load_expected): - expected = load_expected["tstar"] - actual = coare_35.tstar(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_qstar(self, load_input, load_expected): - expected = load_expected["qstar"] - actual = coare_35.qstar(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_sensible(self, load_input, load_expected): - expected = load_expected["sensible"] - actual = coare_35.sensible(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_latent(self, load_input, load_expected): - expected = load_expected["latent"] - actual = coare_35.latent(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_buoyancy(self, load_input, load_expected): - expected = load_expected["buoyancy"] - actual = coare_35.buoyancy(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_webb(self, load_input, load_expected): - expected = load_expected["webb"] - actual = coare_35.webb(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_cd(self, load_input, load_expected): - expected = load_expected["cd"] - actual = coare_35.cd(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - -class TestC35Attributes: - def test_fluxes(self, load_input): - c35 = coare_35(**load_input) - assert hasattr(c35, "fluxes") - - def test_velocities(self, load_input): - c35 = coare_35(**load_input) - assert hasattr(c35, "velocities") - - def test_temperatures(self, load_input): - c35 = coare_35(**load_input) - assert hasattr(c35, "temperatures") - - def test_humidities(self, load_input): - c35 = coare_35(**load_input) - assert hasattr(c35, "humidities") - - def test_stability_parameters(self, load_input): - c35 = coare_35(**load_input) - assert hasattr(c35, "stability_parameters") - - def test_transfer_coefficients(self, load_input): - c35 = coare_35(**load_input) - assert hasattr(c35, "transfer_coefficients") - - def test_stability_functions(self, load_input): - c35 = coare_35(**load_input) - assert hasattr(c35, "stability_functions") - - -class TestSubclassAttributes: - def test_fluxes(self, load_input): - c35 = coare_35(**load_input) - assert hasattr(c35.fluxes, "rnl") - assert hasattr(c35.fluxes, "tau") - assert hasattr(c35.fluxes, "hsb") - assert hasattr(c35.fluxes, "hlb") - assert hasattr(c35.fluxes, "hbb") - assert hasattr(c35.fluxes, "hsbb") - assert hasattr(c35.fluxes, "hlwebb") - assert hasattr(c35.fluxes, "evap") - assert hasattr(c35.fluxes, "rf") - - def test_velocities(self, load_input): - c35 = coare_35(**load_input) - assert hasattr(c35.velocities, "ut") - assert hasattr(c35.velocities, "usr") - assert hasattr(c35.velocities, "du") - assert hasattr(c35.velocities, "gf") - assert hasattr(c35.velocities, "u") - assert hasattr(c35.velocities, "u_rf") - assert hasattr(c35.velocities, "u_n") - assert hasattr(c35.velocities, "u_n_rf") - - def test_temperatures(self, load_input): - c35 = coare_35(**load_input) - assert hasattr(c35.temperatures, "lapse") - assert hasattr(c35.temperatures, "dt") - assert hasattr(c35.temperatures, "dter") - assert hasattr(c35.temperatures, "t_rf") - assert hasattr(c35.temperatures, "t_n") - assert hasattr(c35.temperatures, "t_n_rf") - - def test_humidities(self, load_input): - c35 = coare_35(**load_input) - assert hasattr(c35.humidities, "dq") - assert hasattr(c35.humidities, "dqer") - assert hasattr(c35.humidities, "q_rf") - assert hasattr(c35.humidities, "q_n") - assert hasattr(c35.humidities, "q_n_rf") - assert hasattr(c35.humidities, "rh_rf") - - def test_stability_parameters(self, load_input): - c35 = coare_35(**load_input) - assert hasattr(c35.stability_parameters, "tsr") - assert hasattr(c35.stability_parameters, "tvsr") - assert hasattr(c35.stability_parameters, "tssr") - assert hasattr(c35.stability_parameters, "qsr") - assert hasattr(c35.stability_parameters, "tkt") - assert hasattr(c35.stability_parameters, "obukL") - assert hasattr(c35.stability_parameters, "zet") - assert hasattr(c35.stability_parameters, "zo") - assert hasattr(c35.stability_parameters, "zot") - assert hasattr(c35.stability_parameters, "zoq") - - def test_transfer_coefficients(self, load_input): - c35 = coare_35(**load_input) - assert hasattr(c35.transfer_coefficients, "cd") - assert hasattr(c35.transfer_coefficients, "ch") - assert hasattr(c35.transfer_coefficients, "ce") - assert hasattr(c35.transfer_coefficients, "cdn_rf") - assert hasattr(c35.transfer_coefficients, "chn_rf") - assert hasattr(c35.transfer_coefficients, "cen_rf") - - def test_stability_functions(self, load_input): - c35 = coare_35(**load_input) - assert hasattr(c35.stability_functions, "psi_u") - assert hasattr(c35.stability_functions, "psi_u_rf") - assert hasattr(c35.stability_functions, "psi_t") - assert hasattr(c35.stability_functions, "psi_t_rf") - assert hasattr(c35.stability_functions, "psi_q") - assert hasattr(c35.stability_functions, "psi_q_rf") - - -class TestUtil: - @pytest.fixture - def input_zet(self): - return dict(z_L=[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]) - - def test_psit_26(self, input_zet): - expected = np.array( - [ - 3.12724961201, - 2.94563937069, - 2.7153981664, - 2.39730604321, - 1.86548667371, - -0.0, - -4.43410797233, - -8.02103778406, - -11.0874415242, - -13.8543826804, - -16.469041132, - ] - ) - actual = psit_26(**input_zet) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_psiu_26(self, input_zet): - expected = np.array( - [ - 2.17508663882, - 2.0118078783, - 1.80735371734, - 1.53234530616, - 1.11049402203, - -0.0, - -4.39257224887, - -7.53860684364, - -9.85231262359, - -11.6119662782, - -13.0040743224, - ] - ) - actual = psiu_26(**input_zet) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_psiu_40(self, input_zet): - expected = np.array( - [ - 2.16931171714, - 2.0088210855, - 1.80959461827, - 1.54608872607, - 1.15293343263, - -0.0, - -4.69257224887, - -8.13860684364, - -10.7523126236, - -12.8119662782, - -14.5040743224, - ] - ) - actual = psiu_40(**input_zet) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - @pytest.fixture() - def input_rhcalc(self): - return dict( - t=[0, 1, 2, 3, 4], - p=[1006, 1008, 1010, 1012, 1014], - q=[0.001, 0.002, 0.003, 0.004, 0.005], - ) - - def test_rhcalc(self, input_rhcalc): - expected = np.array( - [26.335489852, 49.0630103047, 68.5938644747, 85.2938428107, 99.4883206669] - ) - actual = rhcalc(**input_rhcalc) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - @pytest.fixture() - def input_qsea(self): - return dict( - t=[0, 1, 2, 3, 4], - p=[1006, 1008, 1010, 1012, 1014], - ) - - def test_qsat(self, input_qsea): - expected = np.array( - [6.1376532232, 6.59809274866, 7.08885199804, 7.61163590591, 8.1682276771] - ) - actual = qsat(**input_qsea) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_qsea(self, input_qsea): - expected = np.array( - [3.72737831642, 3.99971180693, 4.28945019389, 4.59754176056, 4.92497736469] - ) - actual = qsea(**input_qsea) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - @pytest.fixture() - def input_qair(self): - return dict( - t=[0, 1, 2, 3, 4], - p=[1006, 1008, 1010, 1012, 1014], - rh=[65, 70, 75, 80, 85], - ) - - def test_qair(self, input_qair): - expected = np.array( - [2.47023726098, 2.85481658691, 3.28057712818, 3.7509893477, 4.26976278961] - ) - actual = qair(**input_qair) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - -class Testcoare_35: - @pytest.fixture - def load_input(self): - path = os.path.join(os.path.dirname(__file__), "data/c35_test_input.csv") - data = list(csv.reader(open(path))) - input_data = {i[0]: np.array(i[1:], dtype=float) for i in zip(*data)} - input_data.update({"jcool": 1, "nits": 10}) - return input_data - - @pytest.fixture - def load_expected(self): - path = os.path.join(os.path.dirname(__file__), "data/c35_test_expected.csv") - data = list(csv.reader(open(path))) - expected = {i[0]: np.array(i[1:], dtype=float) for i in zip(*data)} - return expected - - def test_tau(self, load_input, load_expected): - expected = load_expected["tau"] - actual = coare_35.tau(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_ustar(self, load_input, load_expected): - expected = load_expected["ustar"] - actual = coare_35.ustar(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_tstar(self, load_input, load_expected): - expected = load_expected["tstar"] - actual = coare_35.tstar(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_qstar(self, load_input, load_expected): - expected = load_expected["qstar"] - actual = coare_35.qstar(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_sensible(self, load_input, load_expected): - expected = load_expected["sensible"] - actual = coare_35.sensible(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_latent(self, load_input, load_expected): - expected = load_expected["latent"] - actual = coare_35.latent(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_buoyancy(self, load_input, load_expected): - expected = load_expected["buoyancy"] - actual = coare_35.buoyancy(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_webb(self, load_input, load_expected): - expected = load_expected["webb"] - actual = coare_35.webb(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) - - def test_cd(self, load_input, load_expected): - expected = load_expected["cd"] - actual = coare_35.cd(**load_input) - np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) diff --git a/tests/test_coare_35.py b/tests/test_coare_35.py new file mode 100644 index 0000000..b03c8c0 --- /dev/null +++ b/tests/test_coare_35.py @@ -0,0 +1,236 @@ +""" +Tests for the COARE functions in pycoare.coare_35 +""" + +import csv +import os + +import numpy as np +import pytest + +from pycoare import coare_35 + +# required or tests fail since numpy doesn't save enough precision +np.set_printoptions(precision=12) + + +@pytest.fixture +def load_input(): + path = os.path.join(os.path.dirname(__file__), "data/c35_c36_test_input.csv") + data = list(csv.reader(open(path))) + input_data = {i[0]: np.array(i[1:], dtype=float) for i in zip(*data)} + input_data.update({"jcool": 1, "nits": 10}) + return input_data + + +@pytest.fixture +def load_expected(): + path = os.path.join(os.path.dirname(__file__), "data/c35_test_expected.csv") + data = list(csv.reader(open(path))) + expected = {i[0]: np.array(i[1:], dtype=float) for i in zip(*data)} + return expected + + +class TestOutputC35: + def test_fluxes(self, load_input, load_expected): + expected = load_expected + actual = coare_35(**load_input).fluxes + np.testing.assert_allclose(actual.rnl, expected["rnl"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.tau, expected["tau"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.hsb, expected["hsb"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.hlb, expected["hlb"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.hbb, expected["hbb"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.hsbb, expected["hsbb"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.hlwebb, expected["hlwebb"], atol=1e-10, rtol=0 + ) + np.testing.assert_allclose(actual.evap, expected["evap"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.rf, expected["rf"], atol=1e-10, rtol=0) + + def test_velocities(self, load_input, load_expected): + expected = load_expected + actual = coare_35(**load_input).velocities + np.testing.assert_allclose(actual.ut, expected["ut"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.usr, expected["usr"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.du, expected["du"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.gf, expected["gf"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.u, expected["u"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.u_rf, expected["u_rf"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.u_n, expected["u_n"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.u_n_rf, expected["u_n_rf"], atol=1e-10, rtol=0 + ) + + def test_temperatures(self, load_input, load_expected): + expected = load_expected + actual = coare_35(**load_input).temperatures + np.testing.assert_allclose(actual.lapse, expected["lapse"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.dt, expected["dt"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.dter, expected["dter"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.t_rf, expected["t_rf"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.t_n, expected["t_n"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.t_n_rf, expected["t_n_rf"], atol=1e-10, rtol=0 + ) + + def test_humidities(self, load_input, load_expected): + expected = load_expected + actual = coare_35(**load_input).humidities + np.testing.assert_allclose(actual.dq, expected["dq"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.dqer, expected["dqer"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.q_rf, expected["q_rf"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.q_n, expected["q_n"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.q_n_rf, expected["q_n_rf"], atol=1e-10, rtol=0 + ) + np.testing.assert_allclose(actual.rh_rf, expected["rh_rf"], atol=1e-10, rtol=0) + + def test_stability_parameters(self, load_input, load_expected): + expected = load_expected + actual = coare_35(**load_input).stability_parameters + np.testing.assert_allclose(actual.tsr, expected["tsr"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.tvsr, expected["tvsr"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.tssr, expected["tssr"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.qsr, expected["qsr"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.tkt, expected["tkt"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.obukL, expected["obukL"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.zet, expected["zet"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.zo, expected["zo"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.zot, expected["zot"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.zoq, expected["zoq"], atol=1e-10, rtol=0) + + def test_transfer_coefficients(self, load_input, load_expected): + expected = load_expected + actual = coare_35(**load_input).transfer_coefficients + np.testing.assert_allclose(actual.cd, expected["cd"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.ch, expected["ch"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.ce, expected["ce"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.cdn_rf, expected["cdn_rf"], atol=1e-10, rtol=0 + ) + np.testing.assert_allclose( + actual.chn_rf, expected["chn_rf"], atol=1e-10, rtol=0 + ) + np.testing.assert_allclose( + actual.cen_rf, expected["cen_rf"], atol=1e-10, rtol=0 + ) + + def test_stability_functions(self, load_input, load_expected): + expected = load_expected + actual = coare_35(**load_input).stability_functions + np.testing.assert_allclose(actual.psi_u, expected["psi_u"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.psi_u_rf, expected["psi_u_rf"], atol=1e-10, rtol=0 + ) + np.testing.assert_allclose(actual.psi_t, expected["psi_t"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.psi_t_rf, expected["psi_t_rf"], atol=1e-10, rtol=0 + ) + np.testing.assert_allclose(actual.psi_q, expected["psi_q"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.psi_q_rf, expected["psi_q_rf"], atol=1e-10, rtol=0 + ) + + +class TestC35Attributes: + def test_fluxes(self, load_input): + c35 = coare_35(**load_input) + assert hasattr(c35, "fluxes") + + def test_velocities(self, load_input): + c35 = coare_35(**load_input) + assert hasattr(c35, "velocities") + + def test_temperatures(self, load_input): + c35 = coare_35(**load_input) + assert hasattr(c35, "temperatures") + + def test_humidities(self, load_input): + c35 = coare_35(**load_input) + assert hasattr(c35, "humidities") + + def test_stability_parameters(self, load_input): + c35 = coare_35(**load_input) + assert hasattr(c35, "stability_parameters") + + def test_transfer_coefficients(self, load_input): + c35 = coare_35(**load_input) + assert hasattr(c35, "transfer_coefficients") + + def test_stability_functions(self, load_input): + c35 = coare_35(**load_input) + assert hasattr(c35, "stability_functions") + + +class TestSubclassAttributes: + def test_fluxes(self, load_input): + c35 = coare_35(**load_input) + assert hasattr(c35.fluxes, "rnl") + assert hasattr(c35.fluxes, "tau") + assert hasattr(c35.fluxes, "hsb") + assert hasattr(c35.fluxes, "hlb") + assert hasattr(c35.fluxes, "hbb") + assert hasattr(c35.fluxes, "hsbb") + assert hasattr(c35.fluxes, "hlwebb") + assert hasattr(c35.fluxes, "evap") + assert hasattr(c35.fluxes, "rf") + + def test_velocities(self, load_input): + c35 = coare_35(**load_input) + assert hasattr(c35.velocities, "ut") + assert hasattr(c35.velocities, "usr") + assert hasattr(c35.velocities, "du") + assert hasattr(c35.velocities, "gf") + assert hasattr(c35.velocities, "u") + assert hasattr(c35.velocities, "u_rf") + assert hasattr(c35.velocities, "u_n") + assert hasattr(c35.velocities, "u_n_rf") + + def test_temperatures(self, load_input): + c35 = coare_35(**load_input) + assert hasattr(c35.temperatures, "lapse") + assert hasattr(c35.temperatures, "dt") + assert hasattr(c35.temperatures, "dter") + assert hasattr(c35.temperatures, "t_rf") + assert hasattr(c35.temperatures, "t_n") + assert hasattr(c35.temperatures, "t_n_rf") + + def test_humidities(self, load_input): + c35 = coare_35(**load_input) + assert hasattr(c35.humidities, "dq") + assert hasattr(c35.humidities, "dqer") + assert hasattr(c35.humidities, "q_rf") + assert hasattr(c35.humidities, "q_n") + assert hasattr(c35.humidities, "q_n_rf") + assert hasattr(c35.humidities, "rh_rf") + + def test_stability_parameters(self, load_input): + c35 = coare_35(**load_input) + assert hasattr(c35.stability_parameters, "tsr") + assert hasattr(c35.stability_parameters, "tvsr") + assert hasattr(c35.stability_parameters, "tssr") + assert hasattr(c35.stability_parameters, "qsr") + assert hasattr(c35.stability_parameters, "tkt") + assert hasattr(c35.stability_parameters, "obukL") + assert hasattr(c35.stability_parameters, "zet") + assert hasattr(c35.stability_parameters, "zo") + assert hasattr(c35.stability_parameters, "zot") + assert hasattr(c35.stability_parameters, "zoq") + + def test_transfer_coefficients(self, load_input): + c35 = coare_35(**load_input) + assert hasattr(c35.transfer_coefficients, "cd") + assert hasattr(c35.transfer_coefficients, "ch") + assert hasattr(c35.transfer_coefficients, "ce") + assert hasattr(c35.transfer_coefficients, "cdn_rf") + assert hasattr(c35.transfer_coefficients, "chn_rf") + assert hasattr(c35.transfer_coefficients, "cen_rf") + + def test_stability_functions(self, load_input): + c35 = coare_35(**load_input) + assert hasattr(c35.stability_functions, "psi_u") + assert hasattr(c35.stability_functions, "psi_u_rf") + assert hasattr(c35.stability_functions, "psi_t") + assert hasattr(c35.stability_functions, "psi_t_rf") + assert hasattr(c35.stability_functions, "psi_q") + assert hasattr(c35.stability_functions, "psi_q_rf") diff --git a/tests/test_coare_36.py b/tests/test_coare_36.py new file mode 100644 index 0000000..fa68abc --- /dev/null +++ b/tests/test_coare_36.py @@ -0,0 +1,236 @@ +""" +Tests for the COARE functions in pycoare.coare_36 +""" + +import csv +import os + +import numpy as np +import pytest + +from pycoare import coare_36 + +# required or tests fail since numpy doesn't save enough precision +np.set_printoptions(precision=12) + + +@pytest.fixture +def load_input(): + path = os.path.join(os.path.dirname(__file__), "data/c35_c36_test_input.csv") + data = list(csv.reader(open(path))) + input_data = {i[0]: np.array(i[1:], dtype=float) for i in zip(*data)} + input_data.update({"jcool": 1, "nits": 10}) + return input_data + + +@pytest.fixture +def load_expected(): + path = os.path.join(os.path.dirname(__file__), "data/c36_test_expected.csv") + data = list(csv.reader(open(path))) + expected = {i[0]: np.array(i[1:], dtype=float) for i in zip(*data)} + return expected + + +class TestOutputC35: + def test_fluxes(self, load_input, load_expected): + expected = load_expected + actual = coare_36(**load_input).fluxes + np.testing.assert_allclose(actual.rnl, expected["rnl"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.tau, expected["tau"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.hsb, expected["hsb"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.hlb, expected["hlb"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.hbb, expected["hbb"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.hsbb, expected["hsbb"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.hlwebb, expected["hlwebb"], atol=1e-10, rtol=0 + ) + np.testing.assert_allclose(actual.evap, expected["evap"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.rf, expected["rf"], atol=1e-10, rtol=0) + + def test_velocities(self, load_input, load_expected): + expected = load_expected + actual = coare_36(**load_input).velocities + np.testing.assert_allclose(actual.ut, expected["ut"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.usr, expected["usr"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.du, expected["du"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.gf, expected["gf"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.u, expected["u"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.u_rf, expected["u_rf"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.u_n, expected["u_n"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.u_n_rf, expected["u_n_rf"], atol=1e-10, rtol=0 + ) + + def test_temperatures(self, load_input, load_expected): + expected = load_expected + actual = coare_36(**load_input).temperatures + np.testing.assert_allclose(actual.lapse, expected["lapse"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.dt, expected["dt"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.dter, expected["dter"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.t_rf, expected["t_rf"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.t_n, expected["t_n"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.t_n_rf, expected["t_n_rf"], atol=1e-10, rtol=0 + ) + + def test_humidities(self, load_input, load_expected): + expected = load_expected + actual = coare_36(**load_input).humidities + np.testing.assert_allclose(actual.dq, expected["dq"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.dqer, expected["dqer"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.q_rf, expected["q_rf"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.q_n, expected["q_n"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.q_n_rf, expected["q_n_rf"], atol=1e-10, rtol=0 + ) + np.testing.assert_allclose(actual.rh_rf, expected["rh_rf"], atol=1e-10, rtol=0) + + def test_stability_parameters(self, load_input, load_expected): + expected = load_expected + actual = coare_36(**load_input).stability_parameters + np.testing.assert_allclose(actual.tsr, expected["tsr"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.tvsr, expected["tvsr"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.tssr, expected["tssr"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.qsr, expected["qsr"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.tkt, expected["tkt"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.obukL, expected["obukL"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.zet, expected["zet"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.zo, expected["zo"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.zot, expected["zot"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.zoq, expected["zoq"], atol=1e-10, rtol=0) + + def test_transfer_coefficients(self, load_input, load_expected): + expected = load_expected + actual = coare_36(**load_input).transfer_coefficients + np.testing.assert_allclose(actual.cd, expected["cd"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.ch, expected["ch"], atol=1e-10, rtol=0) + np.testing.assert_allclose(actual.ce, expected["ce"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.cdn_rf, expected["cdn_rf"], atol=1e-10, rtol=0 + ) + np.testing.assert_allclose( + actual.chn_rf, expected["chn_rf"], atol=1e-10, rtol=0 + ) + np.testing.assert_allclose( + actual.cen_rf, expected["cen_rf"], atol=1e-10, rtol=0 + ) + + def test_stability_functions(self, load_input, load_expected): + expected = load_expected + actual = coare_36(**load_input).stability_functions + np.testing.assert_allclose(actual.psi_u, expected["psi_u"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.psi_u_rf, expected["psi_u_rf"], atol=1e-10, rtol=0 + ) + np.testing.assert_allclose(actual.psi_t, expected["psi_t"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.psi_t_rf, expected["psi_t_rf"], atol=1e-10, rtol=0 + ) + np.testing.assert_allclose(actual.psi_q, expected["psi_q"], atol=1e-10, rtol=0) + np.testing.assert_allclose( + actual.psi_q_rf, expected["psi_q_rf"], atol=1e-10, rtol=0 + ) + + +class TestC35Attributes: + def test_fluxes(self, load_input): + c35 = coare_36(**load_input) + assert hasattr(c35, "fluxes") + + def test_velocities(self, load_input): + c35 = coare_36(**load_input) + assert hasattr(c35, "velocities") + + def test_temperatures(self, load_input): + c35 = coare_36(**load_input) + assert hasattr(c35, "temperatures") + + def test_humidities(self, load_input): + c35 = coare_36(**load_input) + assert hasattr(c35, "humidities") + + def test_stability_parameters(self, load_input): + c35 = coare_36(**load_input) + assert hasattr(c35, "stability_parameters") + + def test_transfer_coefficients(self, load_input): + c35 = coare_36(**load_input) + assert hasattr(c35, "transfer_coefficients") + + def test_stability_functions(self, load_input): + c35 = coare_36(**load_input) + assert hasattr(c35, "stability_functions") + + +class TestSubclassAttributes: + def test_fluxes(self, load_input): + c35 = coare_36(**load_input) + assert hasattr(c35.fluxes, "rnl") + assert hasattr(c35.fluxes, "tau") + assert hasattr(c35.fluxes, "hsb") + assert hasattr(c35.fluxes, "hlb") + assert hasattr(c35.fluxes, "hbb") + assert hasattr(c35.fluxes, "hsbb") + assert hasattr(c35.fluxes, "hlwebb") + assert hasattr(c35.fluxes, "evap") + assert hasattr(c35.fluxes, "rf") + + def test_velocities(self, load_input): + c35 = coare_36(**load_input) + assert hasattr(c35.velocities, "ut") + assert hasattr(c35.velocities, "usr") + assert hasattr(c35.velocities, "du") + assert hasattr(c35.velocities, "gf") + assert hasattr(c35.velocities, "u") + assert hasattr(c35.velocities, "u_rf") + assert hasattr(c35.velocities, "u_n") + assert hasattr(c35.velocities, "u_n_rf") + + def test_temperatures(self, load_input): + c35 = coare_36(**load_input) + assert hasattr(c35.temperatures, "lapse") + assert hasattr(c35.temperatures, "dt") + assert hasattr(c35.temperatures, "dter") + assert hasattr(c35.temperatures, "t_rf") + assert hasattr(c35.temperatures, "t_n") + assert hasattr(c35.temperatures, "t_n_rf") + + def test_humidities(self, load_input): + c35 = coare_36(**load_input) + assert hasattr(c35.humidities, "dq") + assert hasattr(c35.humidities, "dqer") + assert hasattr(c35.humidities, "q_rf") + assert hasattr(c35.humidities, "q_n") + assert hasattr(c35.humidities, "q_n_rf") + assert hasattr(c35.humidities, "rh_rf") + + def test_stability_parameters(self, load_input): + c35 = coare_36(**load_input) + assert hasattr(c35.stability_parameters, "tsr") + assert hasattr(c35.stability_parameters, "tvsr") + assert hasattr(c35.stability_parameters, "tssr") + assert hasattr(c35.stability_parameters, "qsr") + assert hasattr(c35.stability_parameters, "tkt") + assert hasattr(c35.stability_parameters, "obukL") + assert hasattr(c35.stability_parameters, "zet") + assert hasattr(c35.stability_parameters, "zo") + assert hasattr(c35.stability_parameters, "zot") + assert hasattr(c35.stability_parameters, "zoq") + + def test_transfer_coefficients(self, load_input): + c35 = coare_36(**load_input) + assert hasattr(c35.transfer_coefficients, "cd") + assert hasattr(c35.transfer_coefficients, "ch") + assert hasattr(c35.transfer_coefficients, "ce") + assert hasattr(c35.transfer_coefficients, "cdn_rf") + assert hasattr(c35.transfer_coefficients, "chn_rf") + assert hasattr(c35.transfer_coefficients, "cen_rf") + + def test_stability_functions(self, load_input): + c35 = coare_36(**load_input) + assert hasattr(c35.stability_functions, "psi_u") + assert hasattr(c35.stability_functions, "psi_u_rf") + assert hasattr(c35.stability_functions, "psi_t") + assert hasattr(c35.stability_functions, "psi_t_rf") + assert hasattr(c35.stability_functions, "psi_q") + assert hasattr(c35.stability_functions, "psi_q_rf") diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..7b7fd89 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,125 @@ +""" +Tests for the COARE functions in pycoare.utils +""" + +import numpy as np +import pytest + +from pycoare.util import psit_26, psiu_26, psiu_40, qair, qsat, qsea, rhcalc + +# required or tests fail since numpy doesn't save enough precision +np.set_printoptions(precision=12) + + +class TestUtil: + @pytest.fixture + def input_zet(self): + return dict(z_L=[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]) + + def test_psit_26(self, input_zet): + expected = np.array( + [ + 3.12724961201, + 2.94563937069, + 2.7153981664, + 2.39730604321, + 1.86548667371, + -0.0, + -4.43410797233, + -8.02103778406, + -11.0874415242, + -13.8543826804, + -16.469041132, + ] + ) + actual = psit_26(**input_zet) + np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) + + def test_psiu_26(self, input_zet): + expected = np.array( + [ + 2.17508663882, + 2.0118078783, + 1.80735371734, + 1.53234530616, + 1.11049402203, + -0.0, + -4.39257224887, + -7.53860684364, + -9.85231262359, + -11.6119662782, + -13.0040743224, + ] + ) + actual = psiu_26(**input_zet) + np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) + + def test_psiu_40(self, input_zet): + expected = np.array( + [ + 2.16931171714, + 2.0088210855, + 1.80959461827, + 1.54608872607, + 1.15293343263, + -0.0, + -4.69257224887, + -8.13860684364, + -10.7523126236, + -12.8119662782, + -14.5040743224, + ] + ) + actual = psiu_40(**input_zet) + np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) + + @pytest.fixture() + def input_rhcalc(self): + return dict( + t=[0, 1, 2, 3, 4], + p=[1006, 1008, 1010, 1012, 1014], + q=[0.001, 0.002, 0.003, 0.004, 0.005], + ) + + def test_rhcalc(self, input_rhcalc): + expected = np.array( + [26.335489852, 49.0630103047, 68.5938644747, 85.2938428107, 99.4883206669] + ) + actual = rhcalc(**input_rhcalc) + np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) + + @pytest.fixture() + def input_qsea(self): + return dict( + t=[0, 1, 2, 3, 4], + p=[1006, 1008, 1010, 1012, 1014], + ) + + def test_qsat(self, input_qsea): + expected = np.array( + [6.1376532232, 6.59809274866, 7.08885199804, 7.61163590591, 8.1682276771] + ) + actual = qsat(**input_qsea) + np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) + + def test_qsea(self, input_qsea): + expected = np.array( + [3.72737831642, 3.99971180693, 4.28945019389, 4.59754176056, 4.92497736469] + ) + actual = qsea(**input_qsea) + np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0) + + @pytest.fixture() + def input_qair(self): + return dict( + t=[0, 1, 2, 3, 4], + p=[1006, 1008, 1010, 1012, 1014], + rh=[65, 70, 75, 80, 85], + ) + + def test_qair(self, input_qair): + expected = np.array( + [2.47023726098, 2.85481658691, 3.28057712818, 3.7509893477, 4.26976278961] + ) + actual = qair(**input_qair) + np.testing.assert_allclose(actual, expected, atol=1e-10, rtol=0)