物理の駅 Physics station by 現役研究者

テクノロジーは共有されてこそ栄える

WSLでEPICS Archiver Appliance(v2.3.1)をインストールする

準備

# パッケージ更新、必要なパッケージのインストール
sudo apt update
sudo apt upgrade -y
sudo apt install openjdk-21-jdk wget curl -y

# Javaバージョンの確認(21系であることを確認)
java -version

作業ディレクトリの作成

mkdir ~/archiver && cd ~/archiver

AA 2.3.1とtomcat11のダウンロード

wget https://github.com/archiver-appliance/epicsarchiverap/releases/download/2.3.1/archappl_v2.3.1.tar.gz
wget https://dlcdn.apache.org/tomcat/tomcat-11/v11.0.21/bin/apache-tomcat-11.0.21.tar.gz

インストールと起動

# Archiver Applianceを展開
tar -xzf archappl_v2.3.1.tar.gz

# quickstart実行(Tomcat 11を使用)
./quickstart.sh apache-tomcat-11.0.21.tar.gz

しばらくしたらブラウザからアクセスできる

http://localhost:17665/mgmt/ui/index.html

Google Apps Script(GAS): Spotifyからプレイリストの最新エピソード12件を取得する

Spotify APIが有料化されたので、無料で取得する方法をメモしておく。何のことはない、愚直にHTMLからパースしているだけである。

function getSpotifyLatestUrls() {

  var playlist = "5vSDpbHdx2YaXQPWzLSFri";

  const res = UrlFetchApp.fetch("https://open.spotify.com/show/" + playlist, {
    headers: { "User-Agent": "Mozilla/5.0" },
    muteHttpExceptions: true
  });

  let html = res.getContentText();

  html = html.replace(/<span[^>]*><\/span>/g, "");

  const pattern = /<a href="\/episode\/([A-Za-z0-9]{22})"><h4[^>]*>(.*?)<\/h4>/gs;

  let titles = [];
  let urls = [];

  let m;
  while ((m = pattern.exec(html)) !== null) {
    urls.push("https://open.spotify.com/episode/" + m[1]);
    titles.push(m[2]);
  }

  var result = {
    titles: titles,
    urls: urls
  };
  Logger.log(result);
}

出力は新しい順である

{urls=[https://open.spotify.com/episode/5PkNLlN9SaaL8WdaSh4xzX, https://open.spotify.com/episode/3M4oAkZTE7uC3ragZJAhgh, https://open.spotify.com/episode/31ZcGvYr1u0jIfULwz8C2t, https://open.spotify.com/episode/4oumqRPcaRLfGR9aqXhKUg, https://open.spotify.com/episode/6Hwksm1YOjY1NEPNIeVx1c, https://open.spotify.com/episode/0e6puBUsZzxR3LdDT8DB69, https://open.spotify.com/episode/0PLSstt3emLgNSBmvMQQpH, https://open.spotify.com/episode/4iKWHpm7amwSW1z0rzzPQH, https://open.spotify.com/episode/2Xv5UR9eai5Eiz9HZEz8fr, https://open.spotify.com/episode/4FsNJjOIrAghNe0GhsKfoS, https://open.spotify.com/episode/3Z9B3Y3OxAN7xS1YZalBnT, https://open.spotify.com/episode/0NxAZMzq5MWQtSPLChFfq0], titles=[【Season2】#20…Podcast Season2も今回でラスト!「●●●みたいだった…最終回のPodcast」, 【Season2】#19…フォージャー家またまた全員登場!「アーニャ…●●●が◆◆◆!」, 【Season2】#18…フォージャー家全員で引き続き「その●●の人間になりたかった…」, 【Season2】#17…フォージャー家そろいました!「(劇場版公開前)●●●禁止令が出てました!」, 【Season2】#16…ボンド&アーニャのつづき「(劇場版で)ボンドが●●●してるところが好き!」, 【Season2】#15…ボンド&アーニャ「(劇場版は)アーニャの●●だけで描いてるところもあって…」, 【Season2】#14…ロイド&ダミアンのつづき「●●になるとそうなのか!変わっちまったな!」, 【Season2】#13…ロイド&ダミアン「劇場版で●●役の方が、たくさんアドリブを…」, 【Season2】#12…ロイド&ボンド&映画監督のつづき 「普通は監督に●●●なんて、やらせないんですよ!!」, 【Season2】#11…ロイド&ボンド&映画監督「スタートから(映画完成まで)●年くらい!」, 【Season2】#10…ロイド&アーニャのつづき!「江口さんのことが、今までで1番●●●…」, 【Season2】#09…ロイド&アーニャ「アーニャの●●●っていうセリフ、大好き!」]}

アーニャ、カッコいい

Python: ディスクを埋め尽くすコード

from pathlib import Path

target_dir = r"D:"
chunk_mb=100

target = Path(target_dir)
target.mkdir(parents=True, exist_ok=True)

chunk = b"\0" * (chunk_mb * 1024 * 1024)
i = 0
written_bytes = 0
next_report = 1 * 1024**3  # 1GB

while True:
    path = target / f"fill_{i:06d}.bin"
    if path.exists():
        i+=1
        continue
    try:
        with path.open("wb") as f:
            f.write(chunk)
            written_bytes += len(chunk)
            if written_bytes >= next_report:
                total, used, free = shutil.disk_usage(path)
                print(f"{written_bytes // 1024**3} GB written free={free/1024**3:.2f} GB")
                next_report += 1 * 1024**3            
    except OSError as e:
        print(f"停止: {e}")
        break
    i += 1

Python+matplotlib で 発表等で使える文字が大きめのグラフを簡単に作る方法

普通にグラフを作ると、スライドやポスターで使うには文字が小さく出力される。

デフォルト

コード

import numpy as np
import matplotlib.pyplot as plt

def gaussian_func(arr, constant, mean, sigma):
    return constant * np.exp(- (arr - mean) ** 2 / (2 * sigma ** 2))/(2*np.pi*sigma**2)**0.5

x = np.linspace(-5, 5, 1000)
y =gaussian_func(x, 1.0, 0, 1)
fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot(x,y,"k-",label="Total")
ax.set_xlim(-5, 5)
ax.set_ylim(0,None)
plt.legend()
plt.ylabel("Probability")
plt.xlabel("Data (cm)")
plt.savefig("test_org.png")
plt.show()

matplotlibは様々な設定が可能で、詳細な設定は他のブログに任せることにするとして、簡単な方法を紹介する。

plt.rcParamsで figsize を小さめ(例えば(4,3))に設定し、出力時は、DPIを大きく(300くらいが適当)、bbox_inchesを tight にするだけで、見栄えの良いグラフになる。

改善後

コード

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [4,3] # 追加行: figsizeを指定

def gaussian_func(arr, constant, mean, sigma):
    return constant * np.exp(- (arr - mean) ** 2 / (2 * sigma ** 2))/(2*np.pi*sigma**2)**0.5

x = np.linspace(-5, 5, 1000)
y =gaussian_func(x, 1.0, 0, 1)
fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot(x,y,"k-",label="Total")
ax.set_xlim(-5, 5)
ax.set_ylim(0,None)
plt.legend()
plt.ylabel("Probability")
plt.xlabel("Data (cm)")
plt.savefig("test.png",dpi=300,bbox_inches="tight") #変更行: dpiとbbox_inchesを指定
plt.show()

グラフの要素をさらに操作したい場合はこの記事へ

phst.hateblo.jp