Skip to content

Commit

Permalink
Merge pull request #222 from PyPSA/influx_feature_reduction
Browse files Browse the repository at this point in the history
purge influx feature
  • Loading branch information
FabianHofmann authored Feb 25, 2022
2 parents ff17dd9 + 5f5efe3 commit fa17b15
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 42 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Version 0.2.6
* 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
Expand Down
4 changes: 1 addition & 3 deletions atlite/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 3 additions & 4 deletions atlite/datasets/era5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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])

Expand Down
9 changes: 4 additions & 5 deletions atlite/datasets/sarah.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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])

Expand Down
10 changes: 5 additions & 5 deletions atlite/pv/irradiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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')

Expand Down Expand Up @@ -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"]
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 4 additions & 15 deletions atlite/pv/solar_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fa17b15

Please sign in to comment.