From b1e5dfe56e551c16f3abae6e74a38b8db746556c Mon Sep 17 00:00:00 2001 From: dsheward-astro <56971042+dsheward-astro@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:36:47 +0200 Subject: [PATCH 1/5] Update nightshade.py to allow user-defined sub-solar coordinates This allows for the specification of the sub solar coordinates directly, rather than calculating them using the date. This increases the usefulness of nightshade to those of us using cartopy for non-Earth bodies. --- lib/cartopy/feature/nightshade.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/cartopy/feature/nightshade.py b/lib/cartopy/feature/nightshade.py index 0285accb6..4bcbf9192 100644 --- a/lib/cartopy/feature/nightshade.py +++ b/lib/cartopy/feature/nightshade.py @@ -14,7 +14,7 @@ class Nightshade(ShapelyFeature): def __init__(self, date=None, delta=0.1, refraction=-0.83, - color="k", alpha=0.5, **kwargs): + color="k", alpha=0.5, sub_solar_coords=None, **kwargs): """ Shade the darkside of the Earth, accounting for refraction. @@ -47,8 +47,12 @@ def __init__(self, date=None, delta=0.1, refraction=-0.83, # Returns the Greenwich hour angle, # need longitude (opposite direction) - lat, lon = _solar_position(date) + if sub_solar_coords is None: #if not specified proceed as usual + lat, lon = _solar_position(date) + else: + lat, lon = sub_solar_coords #if specified, use given coordinates pole_lon = lon + if lat > 0: pole_lat = -90 + lat central_lon = 180 From bee4c459f14c5d94ab914713088b82bea658f9e1 Mon Sep 17 00:00:00 2001 From: dsheward-astro <56971042+dsheward-astro@users.noreply.github.com> Date: Fri, 26 Apr 2024 09:44:01 +0200 Subject: [PATCH 2/5] Replaced sub_solar_coords with sub_solar_point, added description to docstring --- lib/cartopy/feature/nightshade.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/cartopy/feature/nightshade.py b/lib/cartopy/feature/nightshade.py index 4bcbf9192..16a475ef5 100644 --- a/lib/cartopy/feature/nightshade.py +++ b/lib/cartopy/feature/nightshade.py @@ -14,7 +14,7 @@ class Nightshade(ShapelyFeature): def __init__(self, date=None, delta=0.1, refraction=-0.83, - color="k", alpha=0.5, sub_solar_coords=None, **kwargs): + color="k", alpha=0.5, sub_solar_point=None, **kwargs): """ Shade the darkside of the Earth, accounting for refraction. @@ -29,6 +29,11 @@ def __init__(self, date=None, delta=0.1, refraction=-0.83, refraction : float The adjustment in degrees due to refraction, thickness of the solar disc, elevation etc... + sub_solar_point : tuple of latitude, longitude + The coordinates in degrees of the point at which the sun is directly + overhead. If both sub_solar_point and date are provided, sub_solar_point + takes precedence. + Note ---- @@ -47,10 +52,10 @@ def __init__(self, date=None, delta=0.1, refraction=-0.83, # Returns the Greenwich hour angle, # need longitude (opposite direction) - if sub_solar_coords is None: #if not specified proceed as usual + if sub_solar_point is None: #if not specified proceed as usual lat, lon = _solar_position(date) else: - lat, lon = sub_solar_coords #if specified, use given coordinates + lat, lon = sub_solar_point #if specified, use given coordinates pole_lon = lon if lat > 0: From 44fca8a6272a1202de510705e90ed966dd25e579 Mon Sep 17 00:00:00 2001 From: dsheward-astro <56971042+dsheward-astro@users.noreply.github.com> Date: Mon, 29 Apr 2024 09:07:28 +0200 Subject: [PATCH 3/5] Docstring updated to generic body, whitespace cleanup --- lib/cartopy/feature/nightshade.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/cartopy/feature/nightshade.py b/lib/cartopy/feature/nightshade.py index 16a475ef5..3ca12bf64 100644 --- a/lib/cartopy/feature/nightshade.py +++ b/lib/cartopy/feature/nightshade.py @@ -16,7 +16,7 @@ class Nightshade(ShapelyFeature): def __init__(self, date=None, delta=0.1, refraction=-0.83, color="k", alpha=0.5, sub_solar_point=None, **kwargs): """ - Shade the darkside of the Earth, accounting for refraction. + Shade the darkside of a body, accounting for refraction. Parameters ---------- @@ -29,12 +29,11 @@ def __init__(self, date=None, delta=0.1, refraction=-0.83, refraction : float The adjustment in degrees due to refraction, thickness of the solar disc, elevation etc... - sub_solar_point : tuple of latitude, longitude - The coordinates in degrees of the point at which the sun is directly + sub_solar_point : tuple of latitude, longitude, optional + The coordinates in degrees of the point at which the sun is directly overhead. If both sub_solar_point and date are provided, sub_solar_point takes precedence. - Note ---- Matplotlib keyword arguments can be used when drawing the feature. @@ -57,7 +56,6 @@ def __init__(self, date=None, delta=0.1, refraction=-0.83, else: lat, lon = sub_solar_point #if specified, use given coordinates pole_lon = lon - if lat > 0: pole_lat = -90 + lat central_lon = 180 From b62996e1ffff71e1cec072352a186c336918028f Mon Sep 17 00:00:00 2001 From: dsheward-astro <56971042+dsheward-astro@users.noreply.github.com> Date: Mon, 29 Apr 2024 09:10:22 +0200 Subject: [PATCH 4/5] Removed trailing whitespace --- lib/cartopy/feature/nightshade.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/cartopy/feature/nightshade.py b/lib/cartopy/feature/nightshade.py index 3ca12bf64..ad217e73f 100644 --- a/lib/cartopy/feature/nightshade.py +++ b/lib/cartopy/feature/nightshade.py @@ -51,10 +51,12 @@ def __init__(self, date=None, delta=0.1, refraction=-0.83, # Returns the Greenwich hour angle, # need longitude (opposite direction) - if sub_solar_point is None: #if not specified proceed as usual + if sub_solar_point is None: + #If not specified proceed as usual lat, lon = _solar_position(date) else: - lat, lon = sub_solar_point #if specified, use given coordinates + #If specified, use given coordinates + lat, lon = sub_solar_point pole_lon = lon if lat > 0: pole_lat = -90 + lat From 8a21be3735f66ff5daeba7e60409037446728ea3 Mon Sep 17 00:00:00 2001 From: dsheward-astro <56971042+dsheward-astro@users.noreply.github.com> Date: Mon, 29 Apr 2024 09:12:10 +0200 Subject: [PATCH 5/5] Removed whitespace --- lib/cartopy/feature/nightshade.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cartopy/feature/nightshade.py b/lib/cartopy/feature/nightshade.py index ad217e73f..f799e2702 100644 --- a/lib/cartopy/feature/nightshade.py +++ b/lib/cartopy/feature/nightshade.py @@ -33,7 +33,7 @@ def __init__(self, date=None, delta=0.1, refraction=-0.83, The coordinates in degrees of the point at which the sun is directly overhead. If both sub_solar_point and date are provided, sub_solar_point takes precedence. - + Note ---- Matplotlib keyword arguments can be used when drawing the feature.