Skip to content

Commit

Permalink
Merge pull request #10 from ali-ramadhan/ali/night-time-shading
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ramadhan authored Jun 30, 2024
2 parents f370f9e + 3d16e0a commit 1c83dae
Show file tree
Hide file tree
Showing 5 changed files with 283 additions and 19 deletions.
51 changes: 51 additions & 0 deletions examples/night_time_shading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import datetime

import matplotlib.pyplot as plt
import cartopy.crs as ccrs

from cartopy.feature.nightshade import Nightshade
from joblib import Parallel, delayed
from matplotloom import Loom

def plot_frame(day_of_year, loom, frame_number):
date = datetime.datetime(2024, 1, 1, 12) + datetime.timedelta(days=day_of_year-1)

fig = plt.figure(figsize=(15, 5))

proj1 = ccrs.Orthographic(central_longitude=0, central_latitude=30)
proj2 = ccrs.Orthographic(central_longitude=120, central_latitude=0)
proj3 = ccrs.Orthographic(central_longitude=240, central_latitude=-30)

ax1 = fig.add_subplot(1, 3, 1, projection=proj1)
ax2 = fig.add_subplot(1, 3, 2, projection=proj2)
ax3 = fig.add_subplot(1, 3, 3, projection=proj3)

fig.suptitle(f"Night time shading for {date} UTC")

ax1.stock_img()
ax1.add_feature(Nightshade(date, alpha=0.2))

ax2.stock_img()
ax2.add_feature(Nightshade(date, alpha=0.2))

ax3.stock_img()
ax3.add_feature(Nightshade(date, alpha=0.2))

loom.save_frame(fig, frame_number)

loom = Loom(
"night_time_shading.mp4",
fps = 10,
verbose = True,
overwrite = True,
parallel = True
)

with loom:
n_days_2024 = 366
days_of_year = range(1, n_days_2024 + 1)

Parallel(n_jobs=-1)(
delayed(plot_frame)(day_of_year, loom, i)
for i, day_of_year in enumerate(days_of_year)
)
3 changes: 2 additions & 1 deletion examples/parallel_sine_wave.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np
import matplotlib.pyplot as plt
from matplotloom import Loom

from joblib import Parallel, delayed
from matplotloom import Loom

def plot_frame(phase, frame_number, loom):
fig, ax = plt.subplots()
Expand Down
162 changes: 161 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ scipy = [
{version = "^1.14.0", python = "^3.10"}
]
tqdm = "^4.66.4"
cartopy = "^0.23.0"

[build-system]
requires = ["poetry-core"]
Expand Down
Loading

0 comments on commit 1c83dae

Please sign in to comment.