Skip to content

Commit d427339

Browse files
authored
v0.5.2 (#38)
* relative buffer * hide milky way in minimal style * adjust star sizing * styles and star sizes * sizing * format * styles * update tests * examples * version
1 parent 805736f commit d427339

File tree

13 files changed

+101
-35
lines changed

13 files changed

+101
-35
lines changed

docs/images/example_3.png

30.4 KB
Loading

docs/images/example_4.png

-21 KB
Loading

examples/03_map_orion.png

30.4 KB
Loading

examples/04_map_m45_scope.png

-21 KB
Loading

scripts/scratchpad.py

+34-13
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def create_map_orion():
2020
style = PlotStyle().extend(
2121
# extensions.GRAYSCALE,
2222
# extensions.BLUE_LIGHT,
23-
# extensions.BLUE_MEDIUM,
24-
extensions.BLUE_DARK,
23+
extensions.BLUE_MEDIUM,
24+
# extensions.BLUE_DARK,
2525
extensions.MAP,
2626
{
2727
"star": {
@@ -47,7 +47,7 @@ def create_map_orion():
4747
dec_max=23.6,
4848
limiting_magnitude=7.2,
4949
style=style,
50-
resolution=3000,
50+
resolution=2600,
5151
)
5252
# marker for M42
5353
p.plot_object(
@@ -239,8 +239,8 @@ def create_galaxy_test():
239239
style = PlotStyle().extend(
240240
# sp.styles.extensions.HIDE_LABELS,
241241
# extensions.GRAYSCALE,
242-
extensions.BLUE_LIGHT,
243-
# extensions.BLUE_MEDIUM,
242+
# extensions.BLUE_LIGHT,
243+
extensions.BLUE_MEDIUM,
244244
# extensions.BLUE_DARK,
245245
extensions.MAP,
246246
{
@@ -314,11 +314,11 @@ def create_scope_view_m11():
314314

315315
p = sp.MapPlot(
316316
projection=Projection.MERCATOR,
317-
ra_min=18.7,
318-
ra_max=19,
317+
ra_min=18.6,
318+
ra_max=19.16,
319319
dec_min=-8,
320-
dec_max=-4,
321-
limiting_magnitude=14,
320+
dec_max=-3,
321+
limiting_magnitude=11,
322322
style=style,
323323
resolution=2000,
324324
star_catalog="tycho-1",
@@ -334,6 +334,27 @@ def create_scope_view_m11():
334334
p.export("temp/map-m11.svg", format="svg", padding=0.3)
335335

336336

337+
def create_startest():
338+
style = PlotStyle().extend(
339+
# extensions.MINIMAL,
340+
extensions.BLUE_LIGHT,
341+
extensions.MAP,
342+
)
343+
344+
p = sp.MapPlot(
345+
projection=Projection.STEREO_NORTH,
346+
ra_min=2,
347+
ra_max=6,
348+
dec_min=60,
349+
dec_max=85,
350+
limiting_magnitude=8,
351+
style=style,
352+
resolution=3000,
353+
star_catalog="tycho-1",
354+
)
355+
p.export("temp/stars.png", format="png", padding=0.3)
356+
357+
337358
def dump_extensions():
338359
import yaml
339360

@@ -354,16 +375,16 @@ def dump_extensions():
354375

355376
# ------------------------------------------
356377

357-
358-
# create_scope_view_m45()
378+
create_startest()
379+
create_scope_view_m45()
359380
create_scope_view_m11()
360-
# create_galaxy_test()
381+
create_galaxy_test()
361382

362383
# create_zenith()
363384
# create_map_mercator()
364385
# create_map_stereo_north()
365386
# create_map_stereo_south()
366-
# create_map_orion()
387+
create_map_orion()
367388
# create_map_sgr()
368389

369390
# create_map_with_planets()

src/starplot/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Star charts and maps"""
22

3-
__version__ = "0.5.1"
3+
__version__ = "0.5.2"
44

55
from .base import StarPlot # noqa: F401
66
from .zenith import ZenithPlot # noqa: F401

src/starplot/map.py

+28-7
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class MapPlot(StarPlot):
6868
hide_colliding_labels: If True, then labels will not be plotted if they collide with another existing label
6969
adjust_text: If True, then the labels will be adjusted to avoid overlapping
7070
star_catalog: The catalog of stars to use: "hipparcos" or "tycho-1" -- Hipparcos is the default and has about 10x less stars than Tycho-1 but will also plot much faster
71+
rasterize_stars: If True, then the stars will be rasterized when plotted, which can speed up exporting to SVG and reduce the file size but with a loss of image quality
7172
7273
Returns:
7374
MapPlot: A new instance of a MapPlot
@@ -90,6 +91,7 @@ def __init__(
9091
hide_colliding_labels: bool = True,
9192
adjust_text: bool = False,
9293
star_catalog: stars.StarCatalog = stars.StarCatalog.HIPPARCOS,
94+
rasterize_stars: bool = False,
9395
*args,
9496
**kwargs,
9597
) -> "MapPlot":
@@ -111,6 +113,7 @@ def __init__(
111113
self.dec_min = dec_min
112114
self.dec_max = dec_max
113115
self.star_catalog = star_catalog
116+
self.rasterize_stars = rasterize_stars
114117

115118
self._init_plot()
116119

@@ -204,23 +207,36 @@ def _plot_stars(self):
204207
)
205208
eph = load(self.ephemeris)
206209
earth = eph["earth"]
210+
211+
ra_buffer = (self.ra_max - self.ra_min) / 4
212+
dec_buffer = (self.dec_max - self.dec_min) / 4
213+
207214
nearby_stars_df = stardata[
208215
(stardata["magnitude"] <= self.limiting_magnitude)
209-
& (stardata["ra_hours"] < self.ra_max + 5)
210-
& (stardata["ra_hours"] > self.ra_min - 5)
211-
& (stardata["dec_degrees"] < self.dec_max + 10)
212-
& (stardata["dec_degrees"] > self.dec_min - 10)
216+
& (stardata["ra_hours"] < self.ra_max + ra_buffer)
217+
& (stardata["ra_hours"] > self.ra_min - ra_buffer)
218+
& (stardata["dec_degrees"] < self.dec_max + dec_buffer)
219+
& (stardata["dec_degrees"] > self.dec_min - dec_buffer)
213220
]
214221
nearby_stars = Star.from_dataframe(nearby_stars_df)
215222
astrometric = earth.at(self.timescale).observe(nearby_stars)
216223
stars_ra, stars_dec, _ = astrometric.radec()
217224

218225
sizes = []
226+
alphas = []
219227
for m in nearby_stars_df["magnitude"]:
220-
if m < 4.6:
221-
sizes.append((8 - m) ** 2.36 * self._size_multiplier)
228+
if m < 1.6:
229+
sizes.append((9 - m) ** 2.85 * self._size_multiplier)
230+
alphas.append(1)
231+
elif m < 4.6:
232+
sizes.append((8 - m) ** 2.92 * self._size_multiplier)
233+
alphas.append(1)
234+
elif m < 5.8:
235+
sizes.append((9 - m) ** 2.46 * self._size_multiplier)
236+
alphas.append(0.9)
222237
else:
223-
sizes.append(0.75 * self._size_multiplier)
238+
sizes.append(2.23 * self._size_multiplier)
239+
alphas.append((16 - m) * 0.09)
224240

225241
# Plot Stars
226242
if self.style.star.marker.visible:
@@ -229,6 +245,11 @@ def _plot_stars(self):
229245
sizes,
230246
zorder=self.style.star.marker.zorder,
231247
color=self.style.star.marker.color.as_hex(),
248+
edgecolors=self.style.star.marker.edge_color.as_hex()
249+
if self.style.star.marker.edge_color
250+
else "none",
251+
rasterized=self.rasterize_stars,
252+
alpha=alphas,
232253
**self._plot_kwargs(),
233254
)
234255
self._add_legend_handle_marker("Star", self.style.star.marker)

src/starplot/styles/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class MarkerStyle(BaseStyle):
141141
color: ColorStr = ColorStr("#000")
142142
"""Fill color of marker. Can be a hex, rgb, hsl, or word string."""
143143

144-
edge_color: ColorStr = ColorStr("#000")
144+
edge_color: Optional[ColorStr] = ColorStr("#000")
145145
"""Edge color of marker. Can be a hex, rgb, hsl, or word string."""
146146

147147
symbol: MarkerSymbolEnum = MarkerSymbolEnum.POINT
@@ -165,7 +165,7 @@ class MarkerStyle(BaseStyle):
165165
def matplot_kwargs(self, size_multiplier: float = 1.0) -> dict:
166166
return dict(
167167
color=self.color.as_hex(),
168-
markeredgecolor=self.edge_color.as_hex(),
168+
markeredgecolor=self.edge_color.as_hex() if self.edge_color else "none",
169169
marker=self.symbol,
170170
markersize=self.size * size_multiplier * FONT_SCALE,
171171
fillstyle=self.fill,
@@ -421,7 +421,7 @@ class PlotStyle(BaseStyle):
421421

422422
# Stars
423423
star: ObjectStyle = ObjectStyle(
424-
marker=MarkerStyle(fill=FillStyleEnum.FULL, zorder=1, size=10),
424+
marker=MarkerStyle(fill=FillStyleEnum.FULL, zorder=1, size=10, edge_color=None),
425425
label=LabelStyle(font_size=9, font_weight=FontWeightEnum.BOLD, zorder=1),
426426
)
427427
"""Styling for stars *(see [`ObjectStyle`][starplot.styles.ObjectStyle])*"""

src/starplot/styles/ext/blue_dark.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ dso:
3030
marker:
3131
alpha: 0.46
3232
color: rgb(230, 204, 147)
33+
edge_color: '#d2a441'
3334
fill: full
3435
size: 4
3536
dso_double_star:
@@ -41,16 +42,24 @@ dso_galaxy:
4142
marker:
4243
alpha: 0.6
4344
color: '#D99CBA'
45+
edge_color: '#bd5187'
4446
dso_nebula:
4547
marker:
4648
alpha: 0.45
4749
color: '#9CD9BB'
50+
edge_color: '#52896e'
4851
dso_open_cluster:
4952
label:
5053
visible: false
5154
marker:
5255
alpha: 0.45
5356
color: '#d8d99c'
57+
edge_color: '#9d9f3c'
58+
dso_globular_cluster:
59+
marker:
60+
alpha: 0.5
61+
color: '#c7c7c7'
62+
edge_color: '#444'
5463

5564
ecliptic:
5665
label:
@@ -99,4 +108,4 @@ star:
99108

100109
legend:
101110
background_color: '#a0abbf'
102-
background_alpha: 0.6
111+
background_alpha: 1.0

src/starplot/styles/ext/blue_light.yml

+3
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@ dso_galaxy:
2121
marker:
2222
alpha: 0.5
2323
color: hsl(18, 68%, 75%)
24+
edge_color: hsl(18, 68%, 40%)
2425
dso_nebula:
2526
marker:
2627
alpha: 0.5
2728
color: hsl(91, 53%, 75%)
29+
edge_color: hsl(91, 53%, 40%)
2830
dso_open_cluster:
2931
label:
3032
visible: false
3133
marker:
3234
alpha: 0.3
3335
color: '#fffb68'
36+
edge_color: '#989400'
3437
ecliptic:
3538
label:
3639
font_color: '#e33b3b'

src/starplot/styles/ext/blue_medium.yml

+12-4
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,24 @@ dso_galaxy:
5353
marker:
5454
alpha: 0.45
5555
color: '#D99CBA'
56+
edge_color: '#b15d87'
5657
dso_nebula:
5758
marker:
58-
alpha: 0.45
59-
color: '#a8f5b0'
59+
alpha: 0.56
60+
color: hsl(91, 62%, 82%)
61+
edge_color: hsl(91, 53%, 40%)
6062
dso_open_cluster:
6163
label:
6264
visible: false
6365
marker:
64-
alpha: 0.5
65-
color: '#EDF5A8'
66+
alpha: 0.4
67+
color: '#fffb68'
68+
edge_color: '#989400'
69+
dso_globular_cluster:
70+
marker:
71+
alpha: 0.8
72+
color: '#c7c7c7'
73+
edge_color: '#444'
6674

6775
legend:
6876
background_color: '#f1f6ff'

src/starplot/styles/ext/minimal.yml

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ bayer_labels:
33
constellation:
44
label:
55
visible: false
6+
line:
7+
visible: false
68
constellation_borders:
79
visible: false
810
dso:
@@ -31,3 +33,5 @@ legend:
3133
visible: false
3234
tick_marks:
3335
visible: false
36+
milky_way:
37+
visible: false

tests/test_map.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def map_plot_stereo_north():
4747
def test_map_plot_mercator_base(map_plot_mercator):
4848
filename = DATA_PATH / "actual-mercator-base.png"
4949
map_plot_mercator.export(filename)
50-
assert dhash(filename) == "183b1a3e3636644c"
50+
assert dhash(filename) == "193b1a3e2e26644c"
5151
assert colorhash(filename) == "07406040000"
5252

5353

@@ -77,14 +77,14 @@ def test_map_plot_mercator_with_extra_object(map_plot_mercator):
7777
)
7878
)
7979
map_plot_mercator.export(filename)
80-
assert dhash(filename) == "183b1a3e362c644c"
80+
assert dhash(filename) == "193b1a3e2e2e644c"
8181
assert colorhash(filename) == "07403040000"
8282

8383

8484
def test_map_plot_stereo_base(map_plot_stereo_north):
8585
filename = DATA_PATH / "actual-stereo-north-base.png"
8686
map_plot_stereo_north.export(filename)
87-
assert dhash(filename) == "56f6647468787267"
87+
assert dhash(filename) == "57f66464686c7467"
8888
assert colorhash(filename) == "07000000000"
8989

9090

@@ -108,7 +108,7 @@ def test_map_plot_stereo_with_extra_object(map_plot_stereo_north):
108108
)
109109
)
110110
map_plot_stereo_north.export(filename)
111-
assert dhash(filename) == "56f6647468787267"
111+
assert dhash(filename) == "57f66464686c7467"
112112
assert colorhash(filename) == "07e00000000"
113113

114114

@@ -139,7 +139,7 @@ def test_map_plot_with_planets():
139139
)
140140
p.export(filename)
141141

142-
assert dhash(filename) == "cccc716333b68c0e"
142+
assert dhash(filename) == "ccc871633bb68e0c"
143143
assert colorhash(filename) == "07603000000"
144144

145145

@@ -176,5 +176,5 @@ def test_map_plot_scope_bino_fov():
176176
p.ax.set_title("M45 :: TV-85 / 14mm @ 82deg, 10x binos @ 65deg")
177177
p.export(filename, padding=0.3)
178178

179-
assert dhash(filename) == "86a4c29a9ad2a4ca"
179+
assert dhash(filename) == "0aa4d29a9ad2a480"
180180
assert colorhash(filename) == "07200030000"

0 commit comments

Comments
 (0)