Skip to content
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

purge influx feature #222

Merged
merged 2 commits into from
Feb 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ Release Notes
* Due to ambiguity, conversion functions (`.pv(...)`, `.wind(...)` etc.) now raise an `ValueError` if shapes and matrix are given.
* Atlite now supports calculating of heat pump coefficients of performance (https://github.com/PyPSA/atlite/pull/145).
* Enabled the GitHub feature "Cite this repository" to generate a BibTeX file (Added a `CITATION.cff` file to the repository).
* The function `SolarPosition` does not return the atmospheric insolation anymore. This data variable was not used by any of the currently supported modules.

**Bug fixes**
* The solar position for ERA5 cutouts is now calculated for half a time step earlier (time-shift by `cutout.dt/2`) to account for the aggregated nature of
4 changes: 1 addition & 3 deletions atlite/convert.py
Original file line number Diff line number Diff line change
@@ -909,9 +909,7 @@ def convert_line_rating(

if isinstance(ds, dict):
Position = namedtuple("solarposition", ["altitude", "azimuth"])
solar_position = Position(
ds["solar_position: altitude"], ds["solar_position: azimuth"]
)
solar_position = Position(ds["solar_altitude"], ds["solar_azimuth"])
else:
solar_position = SolarPosition(ds)
Phi_s = np.arccos(
7 changes: 3 additions & 4 deletions atlite/datasets/era5.py
Original file line number Diff line number Diff line change
@@ -49,9 +49,8 @@ def nullcontext():
"influx_direct",
"influx_diffuse",
"albedo",
"solar_position: altitude",
"solar_position: azimuth",
"solar_position: atmospheric insolation",
"solar_altitude",
"solar_azimuth",
],
"temperature": ["temperature", "soil temperature"],
"runoff": ["runoff"],
@@ -173,7 +172,7 @@ def get_data_influx(retrieval_params):
)
)
sp = SolarPosition(ds, time_shift=time_shift)
sp = sp.rename({v: f"solar_position: {v}" for v in sp.data_vars})
sp = sp.rename({v: f"solar_{v}" for v in sp.data_vars})

ds = xr.merge([ds, sp])

9 changes: 4 additions & 5 deletions atlite/datasets/sarah.py
Original file line number Diff line number Diff line change
@@ -33,10 +33,9 @@
"influx": [
"influx_direct",
"influx_diffuse",
"solar_position: altitude",
"solar_position: azimuth",
"solar_position: atmospheric insolation",
]
"solar_altitude",
"solar_azimuth",
],
}
static_features = {}

@@ -229,7 +228,7 @@ def get_data(cutout, feature, tmpdir, lock=None, **creation_parameters):
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
sp = SolarPosition(ds, time_shift="0H")
sp = sp.rename({v: f"solar_position: {v}" for v in sp.data_vars})
sp = sp.rename({v: f"solar_{v}" for v in sp.data_vars})

ds = xr.merge([ds, sp])

10 changes: 5 additions & 5 deletions atlite/pv/irradiation.py
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ def DiffuseHorizontalIrrad(ds, solar_position, clearsky_model, influx):
# Lauret et al. (2013):http://dx.doi.org/10.1016/j.renene.2012.01.049

sinaltitude = sin(solar_position["altitude"])
atmospheric_insolation = solar_position["atmospheric insolation"]
influx_toa = ds["influx_toa"]

if clearsky_model is None:
clearsky_model = (
@@ -29,7 +29,7 @@ def DiffuseHorizontalIrrad(ds, solar_position, clearsky_model, influx):

# Reindl 1990 clearsky model

k = influx / atmospheric_insolation # clearsky index
k = influx / influx_toa # clearsky index
# k.values[k.values > 1.0] = 1.0
# k = k.rename('clearsky index')

@@ -82,7 +82,7 @@ def TiltedDiffuseIrrad(ds, solar_position, surface_orientation, direct, diffuse)
# Hay-Davies Model

sinaltitude = sin(solar_position["altitude"])
atmospheric_insolation = solar_position["atmospheric insolation"]
influx_toa = ds["influx_toa"]

cosincidence = surface_orientation["cosincidence"]
surface_slope = surface_orientation["slope"]
@@ -94,7 +94,7 @@ def TiltedDiffuseIrrad(ds, solar_position, surface_orientation, direct, diffuse)
f = sqrt(direct / influx).fillna(0.0)

# anisotropy factor
A = direct / atmospheric_insolation
A = direct / influx_toa

# geometric factor
R_b = cosincidence / sinaltitude
@@ -159,7 +159,7 @@ def TiltedIrradiation(
altitude_threshold=1.0,
):

influx_toa = solar_position["atmospheric insolation"]
influx_toa = ds["influx_toa"]

def clip(influx, influx_max):
# use .data in clip due to dask-xarray incompatibilities
19 changes: 4 additions & 15 deletions atlite/pv/solar_position.py
Original file line number Diff line number Diff line change
@@ -54,15 +54,14 @@ def SolarPosition(ds, time_shift="0H"):

# Act like a getter if these return variables are already in ds
rvs = {
"solar_position: azimuth",
"solar_position: altitude",
"solar_position: atmospheric insolation",
"solar_azimuth",
"solar_altitude",
}

if rvs.issubset(set(ds.data_vars)):
solar_position = ds[rvs]
solar_position = solar_position.rename(
{v: v.replace("solar_position: ", "") for v in rvs}
{v: v.replace("solar_", "") for v in rvs}
)
return solar_position

@@ -120,17 +119,7 @@ def SolarPosition(ds, time_shift="0H"):
az.attrs["time shift"] = f"{time_shift}"
az.attrs["units"] = "rad"

if "influx_toa" in ds:
atmospheric_insolation = ds["influx_toa"].rename("atmospheric insolation")
else:
# [3]
atmospheric_insolation = (1366.1 * (1 + 0.033 * cos(g)) * sin(alt)).rename(
"atmospheric insolation"
)
atmospheric_insolation.attrs["time shift"] = f"{time_shift}"
atmospheric_insolation.attrs["units"] = "W m**-2"

vars = {da.name: da for da in [alt, az, atmospheric_insolation]}
vars = {da.name: da for da in [alt, az]}
solar_position = xr.Dataset(vars)

return solar_position
20 changes: 10 additions & 10 deletions test/test_dynamic_line_rating.py
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@ def test_ieee_sample_case():
"height": 0,
"wnd_azimuth": 0,
"influx_direct": 1027,
"solar_position: altitude": np.pi / 2,
"solar_position: azimuth": np.pi,
"solar_altitude": np.pi / 2,
"solar_azimuth": np.pi,
}

psi = 90 # line azimuth
@@ -60,8 +60,8 @@ def test_oeding_and_oswald_sample_case():
"height": 0,
"wnd_azimuth": 0,
"influx_direct": 0,
"solar_position: altitude": np.pi / 2,
"solar_position: azimuth": np.pi,
"solar_altitude": np.pi / 2,
"solar_azimuth": np.pi,
}
psi = 90 # line azimuth
D = 0.0218 # line diameter
@@ -89,8 +89,8 @@ def test_suedkabel_sample_case():
"height": 0,
"wnd_azimuth": 0,
"influx_direct": 0,
"solar_position: altitude": np.pi / 2,
"solar_position: azimuth": np.pi,
"solar_altitude": np.pi / 2,
"solar_azimuth": np.pi,
}
R = 0.0136 * 1e-3
psi = 0 # line azimuth
@@ -113,8 +113,8 @@ def test_right_angle_in_different_configuration():
"height": 0,
"wnd_azimuth": 0,
"influx_direct": 1027,
"solar_position: altitude": np.pi / 2,
"solar_position: azimuth": np.pi,
"solar_altitude": np.pi / 2,
"solar_azimuth": np.pi,
}
psi = 90 # line azimuth
D = 0.02814 # line diameter
@@ -159,8 +159,8 @@ def test_angle_increase():
"height": 0,
"wnd_azimuth": 0,
"influx_direct": 1027,
"solar_position: altitude": np.pi / 2,
"solar_position: azimuth": np.pi,
"solar_altitude": np.pi / 2,
"solar_azimuth": np.pi,
}
D = 0.02814 # line diameter
Ts = 273 + 100 # max allowed line surface temp