- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.1k
stream_temperature_function #2104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Closed
      
      
            IoannisSifnaios
  wants to merge
  22
  commits into
  pvlib:main
from
IoannisSifnaios:stream_temperature_stefan
  
      
      
   
      
    
  
     Closed
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            22 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      c92a907
              
                stream_temperature_function
              
              
                IoannisSifnaios ff791e6
              
                format edits
              
              
                IoannisSifnaios 9197a03
              
                degree symbol fix
              
              
                IoannisSifnaios 9eb689c
              
                Echedey's feedback
              
              
                IoannisSifnaios 9f24a1a
              
                fixed toc
              
              
                IoannisSifnaios 05da823
              
                Update pvlib/floating.py
              
              
                IoannisSifnaios 2fff8a6
              
                Update pvlib/floating.py
              
              
                IoannisSifnaios d5c93f9
              
                Update pvlib/floating.py
              
              
                IoannisSifnaios c281c4b
              
                Update pvlib/floating.py
              
              
                IoannisSifnaios d8e6f10
              
                Update pvlib/floating.py
              
              
                IoannisSifnaios 883b2c2
              
                fixed linter
              
              
                IoannisSifnaios 5d0246b
              
                Added text
              
              
                IoannisSifnaios 6b2a2a0
              
                update whatsnew
              
              
                IoannisSifnaios e0a3b71
              
                Merge branch 'main' into stream_temperature_stefan
              
              
                IoannisSifnaios dee6a82
              
                Update pvlib/floating.py
              
              
                IoannisSifnaios 78fedf7
              
                Update pvlib/floating.py
              
              
                IoannisSifnaios 352e4f4
              
                Apply suggestions from code review
              
              
                IoannisSifnaios dc3098b
              
                Update pvlib/floating.py
              
              
                IoannisSifnaios 805c73d
              
                Merge branch 'main' into stream_temperature_stefan
              
              
                IoannisSifnaios 7d1ac3c
              
                fixed linter
              
              
                IoannisSifnaios 7cdfc43
              
                Merge branch 'main' into stream_temperature_stefan
              
              
                IoannisSifnaios ceedb1d
              
                Apply suggestions from code review
              
              
                AdamRJensen File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| .. currentmodule:: pvlib | ||
|  | ||
| Floating | ||
| ======== | ||
|  | ||
| Functions | ||
| --------- | ||
|  | ||
| .. autosummary:: | ||
| :toctree: generated/ | ||
|  | ||
| floating.stream_temperature_stefan | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -21,3 +21,4 @@ API reference | |
| scaling | ||
| location | ||
| transformer | ||
| floating | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -8,6 +8,7 @@ | |
| atmosphere, | ||
| bifacial, | ||
| clearsky, | ||
| floating, | ||
| iam, | ||
| inverter, | ||
| iotools, | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """ | ||
| The ``floating`` module contains functions for calculating parameters related | ||
| to floating PV systems. | ||
| """ | ||
|  | ||
| import numpy as np | ||
| import pandas as pd | ||
|  | ||
|  | ||
| def stream_temperature_stefan(temp_air): | ||
| r""" | ||
| Estimate daily stream water temperature from daily ambient air temperature. | ||
|  | ||
| Parameters | ||
| ---------- | ||
| temp_air : numeric | ||
| Daily average ambient dry bulb temperature. [°C] | ||
|  | ||
| Returns | ||
| ------- | ||
| water_temperature : numeric | ||
| Daily average stream water temperature. [°C] | ||
|  | ||
| Notes | ||
| ----- | ||
| Daily average stream water temperature | ||
| :math:`T_w` is calculated from daily ambient air temperature | ||
| :math:`T_{air}` as provided in [1]_: | ||
|  | ||
| .. math:: | ||
|  | ||
| T_w = 5 + 0.75 \cdot T_{air} | ||
|  | ||
|         
                  IoannisSifnaios marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| The predicted daily stream water temperatures had a | ||
| standard deviation of 2.7 °C compared to measurements. Small, shallow | ||
| streams had smaller deviations than large, deep rivers. | ||
|  | ||
| It should be noted that this equation is limited to streams, i.e., water | ||
| bodies that are well mixed in the vertical and transverse directions of a | ||
| cross section. Also, it is only tested on ice-free streams. Consequently, | ||
| when the mean ambient air temperature is lower than -6.66 °C, the surface | ||
| stream water temperature is returned as ``np.nan``. | ||
|  | ||
| ..warning:: | ||
| This model was developed to estimate stream temperature. A number of | ||
| a number of publications have used it to estimate lakewater and | ||
| seawater temperatures for floating PV without evidence of validity | ||
| for such applications. | ||
|  | ||
| References | ||
| ---------- | ||
| .. [1] Stefan H. G., Preud'homme E. B. (1993). "Stream temperature | ||
| estimation from air temperature." Journal of the American Water | ||
| Resources Association 29-1: 27-45. | ||
| :doi:`10.1111/j.1752-1688.1993.tb01502.x` | ||
| """ | ||
|  | ||
| temp_stream = 5 + 0.75 * temp_air | ||
|  | ||
| temp_stream = np.where(temp_stream < 0, np.nan, temp_stream) | ||
|  | ||
| if isinstance(temp_air, pd.Series): | ||
| temp_stream = pd.Series(temp_stream, index=temp_air.index) | ||
|         
                  IoannisSifnaios marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| return temp_stream | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import numpy as np | ||
| import pandas as pd | ||
| from pvlib import floating | ||
|  | ||
| from .conftest import assert_series_equal | ||
| from numpy.testing import assert_allclose | ||
| import pytest | ||
|  | ||
|  | ||
| @pytest.mark.parametrize('air_temp,water_temp', [ | ||
| (-15, np.nan), | ||
| (-5, 1.25), | ||
| (40, 35), | ||
| ]) | ||
| def test_stream_temperature_stefan(air_temp, water_temp): | ||
| result = floating.stream_temperature_stefan(air_temp) | ||
| assert_allclose(result, water_temp) | ||
|  | ||
|  | ||
| @pytest.fixture | ||
| def times(): | ||
| return pd.date_range(start="2015-01-01 00:00", end="2015-01-07 00:00", | ||
| freq="1d") | ||
|  | ||
|  | ||
| @pytest.fixture | ||
| def air_temps(times): | ||
| return pd.Series([-15, -5, 2.5, 15, 20, 30, 40], index=times) | ||
|  | ||
|  | ||
| @pytest.fixture | ||
| def water_temps_expected(times): | ||
| return pd.Series([np.nan, 1.25, 6.875, 16.25, 20, 27.5, 35], index=times) | ||
|  | ||
|  | ||
| def test_stream_temperature_stefan_ndarray(air_temps, water_temps_expected): | ||
| result = floating.stream_temperature_stefan(temp_air=air_temps.to_numpy()) | ||
| assert_allclose(water_temps_expected.to_numpy(), result) | ||
|  | ||
|  | ||
| def test_stream_temperature_stefan_series(air_temps, water_temps_expected): | ||
| result = floating.stream_temperature_stefan(temp_air=air_temps) | ||
| assert_series_equal(water_temps_expected, result) | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.