@@ -509,18 +509,28 @@ def _lambertw_v_from_i(resistance_shunt, resistance_series, nNsVth, current,
509
509
# Ensure that we are working with read-only views of numpy arrays
510
510
# Turns Series into arrays so that we don't have to worry about
511
511
# multidimensional broadcasting failing
512
- Gsh , Rs , a , I , I0 , IL = \
513
- np .broadcast_arrays (conductance_shunt , resistance_series , nNsVth ,
514
- current , saturation_current , photocurrent )
512
+ Gsh , Rs , a , I0 , IL = [
513
+ np .transpose (np .atleast_2d (arr ))
514
+ for arr in np .broadcast_arrays (conductance_shunt , resistance_series ,
515
+ nNsVth , saturation_current ,
516
+ photocurrent )
517
+ ]
518
+
519
+ if np .isscalar (current ):
520
+ I = np .full (Gsh .shape , current )
521
+ elif current .ndim == 1 :
522
+ I = np .tile (current , (Gsh .shape [0 ], 1 ))
523
+ else :
524
+ I = np .asarray (current )
515
525
516
526
# Intitalize output V (I might not be float64)
517
527
V = np .full_like (I , np .nan , dtype = np .float64 )
518
528
519
529
# Determine indices where 0 < Gsh requires implicit model solution
520
- idx_p = 0. < Gsh
530
+ idx_p = ( 0. < Gsh ). squeeze ()
521
531
522
532
# Determine indices where 0 = Gsh allows explicit model solution
523
- idx_z = 0. == Gsh
533
+ idx_z = ( 0. == Gsh ). squeeze ()
524
534
525
535
# Explicit solutions where Gsh=0
526
536
if np .any (idx_z ):
@@ -586,18 +596,28 @@ def _lambertw_i_from_v(resistance_shunt, resistance_series, nNsVth, voltage,
586
596
# Ensure that we are working with read-only views of numpy arrays
587
597
# Turns Series into arrays so that we don't have to worry about
588
598
# multidimensional broadcasting failing
589
- Gsh , Rs , a , V , I0 , IL = \
590
- np .broadcast_arrays (conductance_shunt , resistance_series , nNsVth ,
591
- voltage , saturation_current , photocurrent )
599
+ Gsh , Rs , a , I0 , IL = [
600
+ np .transpose (np .atleast_2d (arr ))
601
+ for arr in np .broadcast_arrays (conductance_shunt , resistance_series ,
602
+ nNsVth , saturation_current ,
603
+ photocurrent )
604
+ ]
605
+
606
+ if np .isscalar (voltage ):
607
+ V = np .full (Gsh .shape , voltage )
608
+ elif voltage .ndim == 1 :
609
+ V = np .tile (voltage , (Gsh .shape [0 ], 1 ))
610
+ else :
611
+ V = np .asarray (voltage )
592
612
593
613
# Intitalize output I (V might not be float64)
594
614
I = np .full_like (V , np .nan , dtype = np .float64 ) # noqa: E741, N806
595
615
596
616
# Determine indices where 0 < Rs requires implicit model solution
597
- idx_p = 0. < Rs
617
+ idx_p = (
E4B9
0. < Rs ). squeeze ()
598
618
599
619
# Determine indices where 0 = Rs allows explicit model solution
600
- idx_z = 0. == Rs
620
+ idx_z = ( 0. == Rs ). squeeze ()
601
621
602
622
# Explicit solutions where Rs=0
603
623
if np .any (idx_z ):
@@ -648,8 +668,8 @@ def _lambertw(photocurrent, saturation_current, resistance_series,
648
668
649
669
# Find the voltage, v_mp, where the power is maximized.
650
670
# Start the golden section search at v_oc * 1.14
651
- p_mp , v_mp = _golden_sect_DataFrame (params , 0. , v_oc * 1.14 ,
652
- _pwr_optfcn )
671
+ p_mp , v_mp = _golden_sect_DataFrame (params , np . zeros_like ( v_oc ) ,
672
+ v_oc * 1.14 , _pwr_optfcn )
653
673
654
674
# Find Imp using Lambert W
655
675
i_mp = _lambertw_i_from_v (resistance_shunt , resistance_series , nNsVth ,
@@ -683,8 +703,9 @@ def _pwr_optfcn(df, loc):
683
703
'''
684
704
Function to find power from ``i_from_v``.
685
705
'''
706
+ V_per_curve = df [loc ]
686
707
687
708
I = _lambertw_i_from_v (df ['r_sh' ], df ['r_s' ], # noqa: E741, N806
688
- df ['nNsVth' ], df [ loc ] , df ['i_0' ], df ['i_l' ])
709
+ df ['nNsVth' ], V_per_curve , df ['i_0' ], df ['i_l' ])
689
710
690
- return I * df [ loc ]
711
+ return I * V_per_curve
0 commit comments