From 9171ad33947cd4061d918553430ba900c24d6b61 Mon Sep 17 00:00:00 2001 From: yusuke-takase Date: Tue, 23 Apr 2024 16:09:16 +0900 Subject: [PATCH] add warnings for BeamGrid depends on its beam solid angle. --- README.md | 6 ------ grasp2alm/beam_grid.py | 10 ++++++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 93782c4..220a37d 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,6 @@ cd grasp2alm pip install -e . ``` -## Dependency - -- `numpy` -- `healpy` -- `matplotlib` - ## Class Descriptions ### Class: BeamGrid diff --git a/grasp2alm/beam_grid.py b/grasp2alm/beam_grid.py index 33413e2..5ef36cc 100644 --- a/grasp2alm/beam_grid.py +++ b/grasp2alm/beam_grid.py @@ -3,6 +3,7 @@ from dataclasses import dataclass import numpy as np import matplotlib.pyplot as plt +import warnings from .beam_polar import BeamPolar @dataclass @@ -77,8 +78,10 @@ def __post_init__(self): self.freq = float(fi.readline().strip()) else: self.header += "\n" + line + self.ktype = int(fi.readline()) assert self.ktype == 1, "Unknown Grasp grid format, ktype != 1" + line = fi.readline().split() self.nset = int(line[0]) self.icomp = int(line[1]) @@ -86,7 +89,7 @@ def __post_init__(self): self.igrid = int(line[3]) if self.nset > 1: - print("Warning: nset > 1, only reading first beam in file") + warnings.warn("Warning: nset > 1, only reading first beam in file") line = fi.readline().split() self.ix = int(line[0]) @@ -102,6 +105,10 @@ def __post_init__(self): self.xe = float(line[2]) self.ye = float(line[3]) + beam_solid_angle_rad = (np.cos(np.deg2rad(self.ys)) - np.cos(np.deg2rad(self.ye))) * (np.deg2rad(self.xe) - np.deg2rad(self.xs)) + if not np.isclose(beam_solid_angle_rad, 2.0*np.pi) and not np.isclose(beam_solid_angle_rad, 4.0*np.pi): + warnings.warn("Warning: beam solid angle is not 2pi or 4pi because BeamGrid has xs={xs}, xe={xe}, ys={ys} and ye={ye}. The header should be checked.") + line = fi.readline().split() self.nx = int(line[0]) self.ny = int(line[1]) @@ -157,7 +164,6 @@ def to_polar(self, copol_axis="x"): if swaptheta: print("Warning: swapping theta direction") theta_rad_min = np.deg2rad(self.ye) - theta_rad_max = np.deg2rad(self.ys) beam_polar = BeamPolar(nphi, ntheta, theta_rad_min, theta_rad_max, self.filename)