1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966 |
+ cd OrgMatt
+ coverage run -m pytest tests
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-8.2.2, pluggy-1.5.0
rootdir: /home/build/OrgMatt
configfile: pyproject.toml
collected 38 items
tests/test_data.py ........... [ 28%]
tests/test_excreta.py F. [ 34%]
tests/test_food.py ... [ 42%]
tests/test_impacts.py .. [ 47%]
tests/test_metabolism.py FF.F..FF [ 68%]
tests/test_nutrients.py ..F [ 76%]
tests/test_plots.py . [ 78%]
tests/test_units.py .... [ 89%]
tests/test_utils.py .F.. [100%]
=================================== FAILURES ===================================
____________________________ test_urine_production _____________________________
def test_urine_production():
'''
Check the urine production function
'''
# check errors
with pytest.raises(AssertionError):
urine_from_population(100, 100)
with pytest.raises(AssertionError):
urine_from_population(100, 100, plop=2)
# check that results are in the right range
assert 0.5*L < urine_from_population(1, 1*day) < 2*L
# check that the CI works
u_ref = urine_from_population(1, 1*day, ci=68)
> assert np.isnan(
urine_from_population(1, 1*day, ci=68, sex="mixed", region="Africa")
).all(), "Expected NaNs (urine production, sex=mixed, region=Africa)"
tests/test_excreta.py:31:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
orgmatt/_utils/decorator.py:208: in fun
return caller(func, *(extras + args), **kw)
orgmatt/_utils/tools.py:331: in auto_format
raise exception
orgmatt/_utils/tools.py:274: in auto_format
res = f(*args, **local_kwargs)
orgmatt/_utils/decorator.py:208: in fun
return caller(func, *(extras + args), **kw)
orgmatt/units.py:148: in check_dim
res = f(*args, **kwargs)
orgmatt/excreta.py:76: in urine_from_population
res = _rval(df_Ur, "amount", pop, ci, q)
orgmatt/_utils/tools.py:160: in return_values
res = _val_from_arr(values, ci_value, q)
orgmatt/_utils/tools.py:57: in _val_from_arr
return np.full(len(q) + (ci > 0), np.NaN) * unit
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
attr = 'NaN'
def __getattr__(attr):
# Warn for expired attributes
import warnings
if attr == "linalg":
import numpy.linalg as linalg
return linalg
elif attr == "fft":
import numpy.fft as fft
return fft
elif attr == "dtypes":
import numpy.dtypes as dtypes
return dtypes
elif attr == "random":
import numpy.random as random
return random
elif attr == "polynomial":
import numpy.polynomial as polynomial
return polynomial
elif attr == "ma":
import numpy.ma as ma
return ma
elif attr == "ctypeslib":
import numpy.ctypeslib as ctypeslib
return ctypeslib
elif attr == "exceptions":
import numpy.exceptions as exceptions
return exceptions
elif attr == "testing":
import numpy.testing as testing
return testing
elif attr == "matlib":
import numpy.matlib as matlib
return matlib
elif attr == "f2py":
import numpy.f2py as f2py
return f2py
elif attr == "typing":
import numpy.typing as typing
return typing
elif attr == "rec":
import numpy.rec as rec
return rec
elif attr == "char":
import numpy.char as char
return char
elif attr == "array_api":
raise AttributeError("`numpy.array_api` is not available from "
"numpy 2.0 onwards")
elif attr == "core":
import numpy.core as core
return core
elif attr == "strings":
import numpy.strings as strings
return strings
elif attr == "distutils":
if 'distutils' in __numpy_submodules__:
import numpy.distutils as distutils
return distutils
else:
raise AttributeError("`numpy.distutils` is not available from "
"Python 3.12 onwards")
if attr in __future_scalars__:
# And future warnings for those that will change, but also give
# the AttributeError
warnings.warn(
f"In the future `np.{attr}` will be defined as the "
"corresponding NumPy scalar.", FutureWarning, stacklevel=2)
if attr in __former_attrs__:
raise AttributeError(__former_attrs__[attr])
if attr in __expired_attributes__:
> raise AttributeError(
f"`np.{attr}` was removed in the NumPy 2.0 release. "
f"{__expired_attributes__[attr]}"
)
E AttributeError: `np.NaN` was removed in the NumPy 2.0 release. Use `np.nan` instead.. Did you mean: 'nan'?
../.local/lib/python3.10/site-packages/numpy/__init__.py:397: AttributeError
____________________________ test_body_composition _____________________________
def test_body_composition():
''' Test results for body composition '''
for nut in "NKP":
default = body_composition(nut)
assert np.isclose(
default, body_composition(nut, group="adult"), rtol=0.05)
if nut != "P":
for g in ("kid", "teenager", "young adult"):
assert 0 < body_composition(nut, group=g) < 1
# test auto-correct
> assert np.isnan(body_composition(nut, age="8", region="Africa"))
tests/test_metabolism.py:41:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
orgmatt/_utils/decorator.py:208: in fun
return caller(func, *(extras + args), **kw)
orgmatt/_utils/tools.py:331: in auto_format
raise exception
orgmatt/_utils/tools.py:274: in auto_format
res = f(*args, **local_kwargs)
orgmatt/metabolism/nutrient_flows.py:56: in body_composition
return 0.01*return_values(df, "content", 1, ci_value=ci, q=q)
orgmatt/_utils/tools.py:160: in return_values
res = _val_from_arr(values, ci_value, q)
orgmatt/_utils/tools.py:55: in _val_from_arr
return np.NaN * unit
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
attr = 'NaN'
def __getattr__(attr):
# Warn for expired attributes
import warnings
if attr == "linalg":
import numpy.linalg as linalg
return linalg
elif attr == "fft":
import numpy.fft as fft
return fft
elif attr == "dtypes":
import numpy.dtypes as dtypes
return dtypes
elif attr == "random":
import numpy.random as random
return random
elif attr == "polynomial":
import numpy.polynomial as polynomial
return polynomial
elif attr == "ma":
import numpy.ma as ma
return ma
elif attr == "ctypeslib":
import numpy.ctypeslib as ctypeslib
return ctypeslib
elif attr == "exceptions":
import numpy.exceptions as exceptions
return exceptions
elif attr == "testing":
import numpy.testing as testing
return testing
elif attr == "matlib":
import numpy.matlib as matlib
return matlib
elif attr == "f2py":
import numpy.f2py as f2py
return f2py
elif attr == "typing":
import numpy.typing as typing
return typing
elif attr == "rec":
import numpy.rec as rec
return rec
elif attr == "char":
import numpy.char as char
return char
elif attr == "array_api":
raise AttributeError("`numpy.array_api` is not available from "
"numpy 2.0 onwards")
elif attr == "core":
import numpy.core as core
return core
elif attr == "strings":
import numpy.strings as strings
return strings
elif attr == "distutils":
if 'distutils' in __numpy_submodules__:
import numpy.distutils as distutils
return distutils
else:
raise AttributeError("`numpy.distutils` is not available from "
"Python 3.12 onwards")
if attr in __future_scalars__:
# And future warnings for those that will change, but also give
# the AttributeError
warnings.warn(
f"In the future `np.{attr}` will be defined as the "
"corresponding NumPy scalar.", FutureWarning, stacklevel=2)
if attr in __former_attrs__:
raise AttributeError(__former_attrs__[attr])
if attr in __expired_attributes__:
> raise AttributeError(
f"`np.{attr}` was removed in the NumPy 2.0 release. "
f"{__expired_attributes__[attr]}"
)
E AttributeError: `np.NaN` was removed in the NumPy 2.0 release. Use `np.nan` instead.. Did you mean: 'nan'?
../.local/lib/python3.10/site-packages/numpy/__init__.py:397: AttributeError
___________________________ test_nutrient_fractions ____________________________
def test_nutrient_fractions():
'''
Check the function to compute the fraction of nutrients that is kept
within the body or excreted in urine and feces.
'''
for nut in "NKP":
> res = fraction_nutrient_excreta(nut, age="8")
tests/test_metabolism.py:56:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
orgmatt/_utils/decorator.py:208: in fun
return caller(func, *(extras + args), **kw)
orgmatt/_utils/tools.py:331: in auto_format
raise exception
orgmatt/_utils/tools.py:274: in auto_format
res = f(*args, **local_kwargs)
orgmatt/metabolism/nutrient_flows.py:177: in fraction_nutrient_excreta
frac -= fraction_nutrient_retention(nutrient, ci=ci, q=q, **kwargs)
orgmatt/_utils/decorator.py:208: in fun
return caller(func, *(extras + args), **kw)
orgmatt/_utils/tools.py:331: in auto_format
raise exception
orgmatt/_utils/tools.py:274: in auto_format
res = f(*args, **local_kwargs)
orgmatt/metabolism/nutrient_flows.py:117: in fraction_nutrient_retention
frac = 0.01*return_values(df, "amount", 1, ci_value=ci, q=q)
orgmatt/_utils/tools.py:160: in return_values
res = _val_from_arr(values, ci_value, q)
orgmatt/_utils/tools.py:55: in _val_from_arr
return np.NaN * unit
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
attr = 'NaN'
def __getattr__(attr):
# Warn for expired attributes
import warnings
if attr == "linalg":
import numpy.linalg as linalg
return linalg
elif attr == "fft":
import numpy.fft as fft
return fft
elif attr == "dtypes":
import numpy.dtypes as dtypes
return dtypes
elif attr == "random":
import numpy.random as random
return random
elif attr == "polynomial":
import numpy.polynomial as polynomial
return polynomial
elif attr == "ma":
import numpy.ma as ma
return ma
elif attr == "ctypeslib":
import numpy.ctypeslib as ctypeslib
return ctypeslib
elif attr == "exceptions":
import numpy.exceptions as exceptions
return exceptions
elif attr == "testing":
import numpy.testing as testing
return testing
elif attr == "matlib":
import numpy.matlib as matlib
return matlib
elif attr == "f2py":
import numpy.f2py as f2py
return f2py
elif attr == "typing":
import numpy.typing as typing
return typing
elif attr == "rec":
import numpy.rec as rec
return rec
elif attr == "char":
import numpy.char as char
return char
elif attr == "array_api":
raise AttributeError("`numpy.array_api` is not available from "
"numpy 2.0 onwards")
elif attr == "core":
import numpy.core as core
return core
elif attr == "strings":
import numpy.strings as strings
return strings
elif attr == "distutils":
if 'distutils' in __numpy_submodules__:
import numpy.distutils as distutils
return distutils
else:
raise AttributeError("`numpy.distutils` is not available from "
"Python 3.12 onwards")
if attr in __future_scalars__:
# And future warnings for those that will change, but also give
# the AttributeError
warnings.warn(
f"In the future `np.{attr}` will be defined as the "
"corresponding NumPy scalar.", FutureWarning, stacklevel=2)
if attr in __former_attrs__:
raise AttributeError(__former_attrs__[attr])
if attr in __expired_attributes__:
> raise AttributeError(
f"`np.{attr}` was removed in the NumPy 2.0 release. "
f"{__expired_attributes__[attr]}"
)
E AttributeError: `np.NaN` was removed in the NumPy 2.0 release. Use `np.nan` instead.. Did you mean: 'nan'?
../.local/lib/python3.10/site-packages/numpy/__init__.py:397: AttributeError
____________________________ test_unavailable_data _____________________________
def test_unavailable_data():
''' Check corrections when data is unavailable '''
kwargs = {"sex": "female", "diet": "vegan", "country": "DEU"}
m = DataBasedMetabolicModel(age_group="senior", **kwargs)
# for intake
> assert np.isnan(nutrient_intake(1, 1*day, "N", group="senior", **kwargs).m)
tests/test_metabolism.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
orgmatt/_utils/decorator.py:208: in fun
return caller(func, *(extras + args), **kw)
orgmatt/_utils/tools.py:331: in auto_format
raise exception
orgmatt/_utils/tools.py:274: in auto_format
res = f(*args, **local_kwargs)
orgmatt/_utils/decorator.py:208: in fun
return caller(func, *(extras + args), **kw)
orgmatt/units.py:148: in check_dim
res = f(*args, **kwargs)
orgmatt/agrifood/human_consumption.py:142: in nutrient_intake
nintake = return_values(df, "intake", pop, ci, q)
orgmatt/_utils/tools.py:160: in return_values
res = _val_from_arr(values, ci_value, q)
orgmatt/_utils/tools.py:55: in _val_from_arr
return np.NaN * unit
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
attr = 'NaN'
def __getattr__(attr):
# Warn for expired attributes
import warnings
if attr == "linalg":
import numpy.linalg as linalg
return linalg
elif attr == "fft":
import numpy.fft as fft
return fft
elif attr == "dtypes":
import numpy.dtypes as dtypes
return dtypes
elif attr == "random":
import numpy.random as random
return random
elif attr == "polynomial":
import numpy.polynomial as polynomial
return polynomial
elif attr == "ma":
import numpy.ma as ma
return ma
elif attr == "ctypeslib":
import numpy.ctypeslib as ctypeslib
return ctypeslib
elif attr == "exceptions":
import numpy.exceptions as exceptions
return exceptions
elif attr == "testing":
import numpy.testing as testing
return testing
elif attr == "matlib":
import numpy.matlib as matlib
return matlib
elif attr == "f2py":
import numpy.f2py as f2py
return f2py
elif attr == "typing":
import numpy.typing as typing
return typing
elif attr == "rec":
import numpy.rec as rec
return rec
elif attr == "char":
import numpy.char as char
return char
elif attr == "array_api":
raise AttributeError("`numpy.array_api` is not available from "
"numpy 2.0 onwards")
elif attr == "core":
import numpy.core as core
return core
elif attr == "strings":
import numpy.strings as strings
return strings
elif attr == "distutils":
if 'distutils' in __numpy_submodules__:
import numpy.distutils as distutils
return distutils
else:
raise AttributeError("`numpy.distutils` is not available from "
"Python 3.12 onwards")
if attr in __future_scalars__:
# And future warnings for those that will change, but also give
# the AttributeError
warnings.warn(
f"In the future `np.{attr}` will be defined as the "
"corresponding NumPy scalar.", FutureWarning, stacklevel=2)
if attr in __former_attrs__:
raise AttributeError(__former_attrs__[attr])
if attr in __expired_attributes__:
> raise AttributeError(
f"`np.{attr}` was removed in the NumPy 2.0 release. "
f"{__expired_attributes__[attr]}"
)
E AttributeError: `np.NaN` was removed in the NumPy 2.0 release. Use `np.nan` instead.. Did you mean: 'nan'?
../.local/lib/python3.10/site-packages/numpy/__init__.py:397: AttributeError
______________________________ test_flow_fraction ______________________________
def test_flow_fraction():
''' Check data and models for flow fractions '''
kwargs = {"sex": "female", "diet": "omnivorous"}
m = DataBasedMetabolicModel(age_group="adult", **kwargs)
# check that results are identical when data is available
res_model = m.flow_fraction("N", flow="urine")
assert m.last_correction_status == 0
res_urine = fraction_nutrient_excreta(
"N", "urine", sex="female", diet="omnivorous", group="adult")
assert np.isclose(res_model, res_urine, rtol=0.05)
res_feces = m.flow_fraction("N", flow="feces")
res_ffunc = fraction_nutrient_excreta(
"N", "feces", sex="female", diet="omnivorous", group="adult")
> res_ffunc2 = fraction_nutrient_excreta(
"N", "feces", sex="female", diet="omnivorous", age="33-34")
tests/test_metabolism.py:419:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
orgmatt/_utils/decorator.py:208: in fun
return caller(func, *(extras + args), **kw)
orgmatt/_utils/tools.py:331: in auto_format
raise exception
orgmatt/_utils/tools.py:274: in auto_format
res = f(*args, **local_kwargs)
orgmatt/metabolism/nutrient_flows.py:193: in fraction_nutrient_excreta
frac = 0.01*return_values(df, "amount", 1, ci, q)
orgmatt/_utils/tools.py:160: in return_values
res = _val_from_arr(values, ci_value, q)
orgmatt/_utils/tools.py:55: in _val_from_arr
return np.NaN * unit
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
attr = 'NaN'
def __getattr__(attr):
# Warn for expired attributes
import warnings
if attr == "linalg":
import numpy.linalg as linalg
return linalg
elif attr == "fft":
import numpy.fft as fft
return fft
elif attr == "dtypes":
import numpy.dtypes as dtypes
return dtypes
elif attr == "random":
import numpy.random as random
return random
elif attr == "polynomial":
import numpy.polynomial as polynomial
return polynomial
elif attr == "ma":
import numpy.ma as ma
return ma
elif attr == "ctypeslib":
import numpy.ctypeslib as ctypeslib
return ctypeslib
elif attr == "exceptions":
import numpy.exceptions as exceptions
return exceptions
elif attr == "testing":
import numpy.testing as testing
return testing
elif attr == "matlib":
import numpy.matlib as matlib
return matlib
elif attr == "f2py":
import numpy.f2py as f2py
return f2py
elif attr == "typing":
import numpy.typing as typing
return typing
elif attr == "rec":
import numpy.rec as rec
return rec
elif attr == "char":
import numpy.char as char
return char
elif attr == "array_api":
raise AttributeError("`numpy.array_api` is not available from "
"numpy 2.0 onwards")
elif attr == "core":
import numpy.core as core
return core
elif attr == "strings":
import numpy.strings as strings
return strings
elif attr == "distutils":
if 'distutils' in __numpy_submodules__:
import numpy.distutils as distutils
return distutils
else:
raise AttributeError("`numpy.distutils` is not available from "
"Python 3.12 onwards")
if attr in __future_scalars__:
# And future warnings for those that will change, but also give
# the AttributeError
warnings.warn(
f"In the future `np.{attr}` will be defined as the "
"corresponding NumPy scalar.", FutureWarning, stacklevel=2)
if attr in __former_attrs__:
raise AttributeError(__former_attrs__[attr])
if attr in __expired_attributes__:
> raise AttributeError(
f"`np.{attr}` was removed in the NumPy 2.0 release. "
f"{__expired_attributes__[attr]}"
)
E AttributeError: `np.NaN` was removed in the NumPy 2.0 release. Use `np.nan` instead.. Did you mean: 'nan'?
../.local/lib/python3.10/site-packages/numpy/__init__.py:397: AttributeError
__________________________ test_consistent_metabolism __________________________
def test_consistent_metabolism():
''' Check the consistent metabolic model '''
kwargs = {"sex": "female", "diet": "vegan", "country": "URY"}
m = ConsistentMetabolicModel(age_group="kid", **kwargs)
for nutrient in ("N", "P", "K"):
> loss = m.flow_fraction(nutrient, flow="loss", ci=90)
tests/test_metabolism.py:474:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
orgmatt/metabolism/metabolic_model.py:456: in flow_fraction
if len(self._get_flow("urine", nutrient)) == 0:
orgmatt/metabolism/metabolic_model.py:310: in _get_flow
unit = ureg("g{nutrient}")
../.local/lib/python3.10/site-packages/pint/facets/plain/registry.py:1398: in parse_expression
return build_eval_tree(gen).evaluate(_define_op)
../.local/lib/python3.10/site-packages/pint/pint_eval.py:384: in evaluate
self.right.evaluate(define_op, bin_op, un_op),
../.local/lib/python3.10/site-packages/pint/pint_eval.py:395: in evaluate
return define_op(self.left)
../.local/lib/python3.10/site-packages/pint/facets/plain/registry.py:1396: in _define_op
return self._eval_token(s, case_sensitive=case_sensitive, **values)
../.local/lib/python3.10/site-packages/pint/facets/plain/registry.py:1305: in _eval_token
{self.get_name(token_text, case_sensitive=case_sensitive): 1}
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pint.registry.UnitRegistry object at 0x7f2790a04100>
name_or_alias = 'nutrient', case_sensitive = None
def get_name(self, name_or_alias: str, case_sensitive: bool | None = None) -> str:
"""Return the canonical name of a unit."""
if name_or_alias == "dimensionless":
return ""
try:
return self._units[name_or_alias].name
except KeyError:
pass
candidates = self.parse_unit_name(name_or_alias, case_sensitive)
if not candidates:
> raise UndefinedUnitError(name_or_alias)
E pint.errors.UndefinedUnitError: 'nutrient' is not defined in the unit registry
../.local/lib/python3.10/site-packages/pint/facets/plain/registry.py:658: UndefinedUnitError
____________________________ test_nutrient_content _____________________________
def test_nutrient_content():
''' Check the nutrient content of urine and feces '''
nitrogen_from_feces(1*kg, wet=False)
# check that results are in the right range
Nf = nitrogen_from_feces(1*kg)
Nu = nitrogen_from_urine(1*L)
Pu = phosphorus_from_urine(1*L)
Pf = phosphorus_from_feces(1*kg)
Nw = nutrient_from_biowaste(1*kg, "N")
Pw = nutrient_from_biowaste(1*kg, "P")
Kw = nutrient_from_biowaste(1*kg, "K")
assert 10*gN < Nf < 30*gN
assert 5*gN < Nu < 15*gN
assert 1*gP < Pu < 2.5*gP
assert 3*gP < Pf < 8*gP
assert 2.9*gN < Nw < 10*gN
assert 0.5*gP < Pw < 2*gP
assert 2*gK < Kw < 10*gK
# check that compound gives the same results
Nf2 = nutrient_from_compound(1*kg, "N", "feces", group="adult")
Pu2 = nutrient_from_compound(1*L, "P", "urine", group="adult")
Pw2 = nutrient_from_compound(1*kg, "P", "biowaste")
assert np.isclose(Nf, Nf2, rtol=0.05)
assert np.isclose(Pu, Pu2, rtol=0.05)
assert np.isclose(Pw, Pw2, rtol=0.05)
# check that the CI works
nitrogen_from_feces(1*kg, ci=68, group=None)
nitrogen_from_urine(1*L, ci=68)
phosphorus_from_urine(1*L, ci=68)
nutrient_from_biowaste(1*kg, "N", waste_type="FoodResidues", ci=68)
# check vector
val = [1, 2, 5, 10]
Nf_vec = nitrogen_from_feces(val*kg)
for v, res in zip(val, Nf_vec):
assert np.isclose(v*Nf, res, rtol=0.05)
Nf_vec = nitrogen_from_feces(val*kg, ci=68)
assert Nf_vec.shape == (len(val), 3)
for v, res in zip(val, Nf_vec):
assert np.isclose(v*Nf, res[1], rtol=0.05)
# check kwargs
> nutrient_from_biowaste(1*kg, "N", location="home", region="Europe")
tests/test_nutrients.py:158:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
orgmatt/_utils/decorator.py:208: in fun
return caller(func, *(extras + args), **kw)
orgmatt/_utils/tools.py:331: in auto_format
raise exception
orgmatt/_utils/tools.py:274: in auto_format
res = f(*args, **local_kwargs)
orgmatt/_utils/decorator.py:208: in fun
return caller(func, *(extras + args), **kw)
orgmatt/units.py:148: in check_dim
res = f(*args, **kwargs)
orgmatt/nutrients/all_nutrients.py:164: in nutrient_from_biowaste
return ureg(unit) * return_values(df, "value", mass, ci, q)
orgmatt/_utils/tools.py:160: in return_values
res = _val_from_arr(values, ci_value, q)
orgmatt/_utils/tools.py:55: in _val_from_arr
return np.NaN * unit
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
attr = 'NaN'
def __getattr__(attr):
# Warn for expired attributes
import warnings
if attr == "linalg":
import numpy.linalg as linalg
return linalg
elif attr == "fft":
import numpy.fft as fft
return fft
elif attr == "dtypes":
import numpy.dtypes as dtypes
return dtypes
elif attr == "random":
import numpy.random as random
return random
elif attr == "polynomial":
import numpy.polynomial as polynomial
return polynomial
elif attr == "ma":
import numpy.ma as ma
return ma
elif attr == "ctypeslib":
import numpy.ctypeslib as ctypeslib
return ctypeslib
elif attr == "exceptions":
import numpy.exceptions as exceptions
return exceptions
elif attr == "testing":
import numpy.testing as testing
return testing
elif attr == "matlib":
import numpy.matlib as matlib
return matlib
elif attr == "f2py":
import numpy.f2py as f2py
return f2py
elif attr == "typing":
import numpy.typing as typing
return typing
elif attr == "rec":
import numpy.rec as rec
return rec
elif attr == "char":
import numpy.char as char
return char
elif attr == "array_api":
raise AttributeError("`numpy.array_api` is not available from "
"numpy 2.0 onwards")
elif attr == "core":
import numpy.core as core
return core
elif attr == "strings":
import numpy.strings as strings
return strings
elif attr == "distutils":
if 'distutils' in __numpy_submodules__:
import numpy.distutils as distutils
return distutils
else:
raise AttributeError("`numpy.distutils` is not available from "
"Python 3.12 onwards")
if attr in __future_scalars__:
# And future warnings for those that will change, but also give
# the AttributeError
warnings.warn(
f"In the future `np.{attr}` will be defined as the "
"corresponding NumPy scalar.", FutureWarning, stacklevel=2)
if attr in __former_attrs__:
raise AttributeError(__former_attrs__[attr])
if attr in __expired_attributes__:
> raise AttributeError(
f"`np.{attr}` was removed in the NumPy 2.0 release. "
f"{__expired_attributes__[attr]}"
)
E AttributeError: `np.NaN` was removed in the NumPy 2.0 release. Use `np.nan` instead.. Did you mean: 'nan'?
../.local/lib/python3.10/site-packages/numpy/__init__.py:397: AttributeError
______________________________ test_auto_correct _______________________________
def test_auto_correct():
''' Test autocorrect features '''
> res_basic = nitrogen_from_population(1, 1*year, age="12")
tests/test_utils.py:45:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
orgmatt/nutrients/nitrogen.py:64: in nitrogen_from_population
return nutrient_from_population(
orgmatt/_utils/decorator.py:208: in fun
return caller(func, *(extras + args), **kw)
orgmatt/_utils/tools.py:331: in auto_format
raise exception
orgmatt/_utils/tools.py:274: in auto_format
res = f(*args, **local_kwargs)
orgmatt/_utils/decorator.py:208: in fun
return caller(func, *(extras + args), **kw)
orgmatt/units.py:148: in check_dim
res = f(*args, **kwargs)
orgmatt/nutrients/all_nutrients.py:83: in nutrient_from_population
return factor * nutrient_intake(
orgmatt/_utils/decorator.py:208: in fun
return caller(func, *(extras + args), **kw)
orgmatt/_utils/tools.py:331: in auto_format
raise exception
orgmatt/_utils/tools.py:274: in auto_format
res = f(*args, **local_kwargs)
orgmatt/_utils/decorator.py:208: in fun
return caller(func, *(extras + args), **kw)
orgmatt/units.py:148: in check_dim
res = f(*args, **kwargs)
orgmatt/agrifood/human_consumption.py:142: in nutrient_intake
nintake = return_values(df, "intake", pop, ci, q)
orgmatt/_utils/tools.py:160: in return_values
res = _val_from_arr(values, ci_value, q)
orgmatt/_utils/tools.py:55: in _val_from_arr
return np.NaN * unit
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
attr = 'NaN'
def __getattr__(attr):
# Warn for expired attributes
import warnings
if attr == "linalg":
import numpy.linalg as linalg
return linalg
elif attr == "fft":
import numpy.fft as fft
return fft
elif attr == "dtypes":
import numpy.dtypes as dtypes
return dtypes
elif attr == "random":
import numpy.random as random
return random
elif attr == "polynomial":
import numpy.polynomial as polynomial
return polynomial
elif attr == "ma":
import numpy.ma as ma
return ma
elif attr == "ctypeslib":
import numpy.ctypeslib as ctypeslib
return ctypeslib
elif attr == "exceptions":
import numpy.exceptions as exceptions
return exceptions
elif attr == "testing":
import numpy.testing as testing
return testing
elif attr == "matlib":
import numpy.matlib as matlib
return matlib
elif attr == "f2py":
import numpy.f2py as f2py
return f2py
elif attr == "typing":
import numpy.typing as typing
return typing
elif attr == "rec":
import numpy.rec as rec
return rec
elif attr == "char":
import numpy.char as char
return char
elif attr == "array_api":
raise AttributeError("`numpy.array_api` is not available from "
"numpy 2.0 onwards")
elif attr == "core":
import numpy.core as core
return core
elif attr == "strings":
import numpy.strings as strings
return strings
elif attr == "distutils":
if 'distutils' in __numpy_submodules__:
import numpy.distutils as distutils
return distutils
else:
raise AttributeError("`numpy.distutils` is not available from "
"Python 3.12 onwards")
if attr in __future_scalars__:
# And future warnings for those that will change, but also give
# the AttributeError
warnings.warn(
f"In the future `np.{attr}` will be defined as the "
"corresponding NumPy scalar.", FutureWarning, stacklevel=2)
if attr in __former_attrs__:
raise AttributeError(__former_attrs__[attr])
if attr in __expired_attributes__:
> raise AttributeError(
f"`np.{attr}` was removed in the NumPy 2.0 release. "
f"{__expired_attributes__[attr]}"
)
E AttributeError: `np.NaN` was removed in the NumPy 2.0 release. Use `np.nan` instead.. Did you mean: 'nan'?
../.local/lib/python3.10/site-packages/numpy/__init__.py:397: AttributeError
----------------------------- Captured stderr call -----------------------------
[INFO @ orgmatt._utils.tools]: from coverage (L8) - Removed {'age': '12'} from `kwargs` in function `fraction_nutrient_excreta`.
Final arguments used were: {'group': 'teenager'}.
------------------------------ Captured log call -------------------------------
INFO orgmatt._utils.tools:logger.py:41 from coverage (L8) - Removed {'age': '12'} from `kwargs` in function `fraction_nutrient_excreta`.
Final arguments used were: {'group': 'teenager'}.
=============================== warnings summary ===============================
orgmatt/units.py:23
/home/build/OrgMatt/orgmatt/units.py:23: DeprecationWarning: This function will be removed in future versions of pint.
Use ureg.formatter.default_format
ureg.default_format = "~" # abbreviated unit names
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/test_excreta.py::test_urine_production - AttributeError: `np.NaN...
FAILED tests/test_metabolism.py::test_body_composition - AttributeError: `np....
FAILED tests/test_metabolism.py::test_nutrient_fractions - AttributeError: `n...
FAILED tests/test_metabolism.py::test_unavailable_data - AttributeError: `np....
FAILED tests/test_metabolism.py::test_flow_fraction - AttributeError: `np.NaN...
FAILED tests/test_metabolism.py::test_consistent_metabolism - pint.errors.Und...
FAILED tests/test_nutrients.py::test_nutrient_content - AttributeError: `np.N...
FAILED tests/test_utils.py::test_auto_correct - AttributeError: `np.NaN` was ...
=================== 8 failed, 30 passed, 1 warning in 11.29s ===================
|