From 895d10aee43af92b2a8de2d54d2c3485f7412ec8 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Mon, 7 Aug 2023 14:36:18 +0200 Subject: [PATCH 1/4] delete unused file --- scripts/cluster.py | 201 --------------------------------------------- 1 file changed, 201 deletions(-) delete mode 100644 scripts/cluster.py diff --git a/scripts/cluster.py b/scripts/cluster.py deleted file mode 100644 index 044e485..0000000 --- a/scripts/cluster.py +++ /dev/null @@ -1,201 +0,0 @@ -import pyvisgen.simulation.utils as ut -import pyvisgen.layouts.layouts as layouts -import astropy.constants as const -from astropy import units as un -import time as t -import numpy as np -import pyvisgen.simulation.scan as scan -import torch -from astropy.io import fits -from pyvisgen.simulation.scan import get_valid_baselines -from astropy.time import Time -import pyvisgen.fits.writer as writer -from dataclasses import dataclass - -import sys - -from PIL import Image - -# jobid = sys.getenv('SLURM_ARRAY_TASK_ID') - - -@dataclass -class Visibilities: - I: [complex] - Q: [complex] - U: [complex] - V: [complex] - num: [int] - scan: [int] - base_num: [int] - u: [float] - v: [float] - w: [float] - date: [float] - _date: [float] - - def __getitem__(self, i): - baseline = Vis( - self.I[i], - self.Q[i], - self.U[i], - self.V[i], - self.num[i], - self.scan[i], - self.base_num[i], - self.u[i], - self.v[i], - self.w[i], - self.date[i], - self._date[i], - ) - return baseline - - def get_values(self): - return np.array([self.I, self.Q, self.U, self.V]) - - def add(self, visibilities): - self.I = np.concatenate([self.I, visibilities.I]) - self.Q = np.concatenate([self.Q, visibilities.Q]) - self.U = np.concatenate([self.U, visibilities.U]) - self.V = np.concatenate([self.V, visibilities.V]) - self.num = np.concatenate([self.num, visibilities.num]) - self.scan = np.concatenate([self.scan, visibilities.scan]) - self.base_num = np.concatenate([self.base_num, visibilities.base_num]) - self.u = np.concatenate([self.u, visibilities.u]) - self.v = np.concatenate([self.v, visibilities.v]) - self.w = np.concatenate([self.w, visibilities.w]) - self.date = np.concatenate([self.date, visibilities.date]) - self._date = np.concatenate([self._date, visibilities._date]) - - -@dataclass -class Vis: - I: complex - Q: complex - U: complex - V: complex - num: int - scan: int - base_num: int - u: float - v: float - w: float - date: float - _date: float - - -# set number of threads - - -def loop(): - torch.set_num_threads(48) - - # read config - rc = ut.read_config("../config/vlba.toml") - array_layout = layouts.get_array_layout("vlba") - src_crd = rc["src_coord"] - - wave1 = ( - const.c - / ( - ( - float(rc["channel"].split(":")[0]) - - float(rc["channel"].split(":")[1]) / 2 - ) - * 10 ** 6 - / un.second - ) - / un.meter - ) - wave2 = ( - const.c - / ( - ( - float(rc["channel"].split(":")[0]) - + float(rc["channel"].split(":")[1]) / 2 - ) - * 10 ** 6 - / un.second - ) - / un.meter - ) - - # calculate rd, lm - rd = scan.rd_grid(rc["fov_size"] * np.pi / (3600 * 180), 256, src_crd) - lm = scan.lm_grid(rd, src_crd) - - # calculate time steps - time = ut.calc_time_steps(rc) - - # open image - img = np.asarray(Image.open("/net/nfshome/home/sfroese/150.jpg")) - norm = np.sum(img) - img = img / norm - img = torch.tensor(img) - I = torch.zeros((img.shape[0], img.shape[1], 4), dtype=torch.cdouble) - I[..., 0] = img - I[..., 1] = img - - stat_num = array_layout.st_num.shape[0] - base_num = int(stat_num * (stat_num - 1) / 2) - - # calculate vis - visibilities = Visibilities([], [], [], [], [], [], [], [], [], [], [], []) - vis_num = np.zeros(1) - # i in total number of scans - for i in range(72): - # i=30 - t = time[i * 31 : (i + 1) * 31] - baselines = scan.get_baselines(src_crd, t, array_layout) - - valid = baselines.valid.reshape(-1, base_num) - mask = np.array(valid[:-1]).astype(bool) & np.array(valid[1:]).astype(bool) - u = baselines.u.reshape(-1, base_num) - v = baselines.v.reshape(-1, base_num) - w = baselines.w.reshape(-1, base_num) - base_valid = np.arange(len(baselines.u)).reshape(-1, base_num)[:-1][mask] - u_valid = u[:-1][mask] - v_valid = v[:-1][mask] - w_valid = w[:-1][mask] - date = np.repeat( - (t[:-1] + rc["corr_int_time"] * un.second / 2).jd.reshape(-1, 1), - base_num, - axis=1, - )[mask] - _date = np.zeros(len(u_valid)) - - X1 = scan.corrupted(lm, baselines, wave1, time, src_crd, array_layout, I, rd) - if X1.shape[0] == 1: - continue - X2 = scan.corrupted(lm, baselines, wave1, time, src_crd, array_layout, I, rd) - - vis_num = np.arange(X1.shape[2] // 2) + 1 + vis_num.max() - - int_values = scan.integrate(X1, X2) - del X1, X2 - int_values = int_values.reshape(-1, 4) - - vis = Visibilities( - int_values[:, 0], - int_values[:, 1], - int_values[:, 2], - int_values[:, 3], - vis_num, - np.repeat(i + 1, len(vis_num)), - np.array([baselines[i].baselineNum() for i in base_valid]), - u_valid, - v_valid, - w_valid, - date, - _date, - ) - - visibilities.add(vis) - # break - return visibilities - - -# save vis -hdu_list = writer.create_hdu_list(loop(), rc) -hdu_list.writeto("test07_vlba.fits", overwrite=True) From 527be85a7ec879709f5c887dfcccadf93bf6cdc5 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Mon, 7 Aug 2023 15:33:54 +0200 Subject: [PATCH 2/4] Add docstrings --- pyvisgen/simulation/data_set.py | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/pyvisgen/simulation/data_set.py b/pyvisgen/simulation/data_set.py index 5c68f54..93b0b39 100644 --- a/pyvisgen/simulation/data_set.py +++ b/pyvisgen/simulation/data_set.py @@ -17,6 +17,22 @@ def simulate_data_set(config, slurm=False, job_id=None, n=None): + """ + Wrapper function for simulating visibilities. + Distinction between slurm and non-threaded simulation. + + Parameters + ---------- + config : toml file + path to config file + slurm : bool + True, if slurm is used + job_id : int + job_id, given by slurm + n : int + running index + + """ conf = read_data_set_conf(config) out_path = Path(conf["out_path_fits"]) out_path.mkdir(parents=True, exist_ok=True) @@ -54,6 +70,20 @@ def simulate_data_set(config, slurm=False, job_id=None, n=None): def create_sampling_rc(conf): + """ + Draw sampling options and test if atleast half of the telescopes can see the source. + If not, then new parameters are drawn. + + Parameters + ---------- + conf : dict + simulation options + + Returns + ------- + dict + contains the observation parameters + """ samp_ops = draw_sampling_opts(conf) array_layout = layouts.get_array_layout(conf["layout"][0]) half_telescopes = array_layout.x.shape[0] // 2 @@ -65,6 +95,19 @@ def create_sampling_rc(conf): def draw_sampling_opts(conf): + """ + Draw observation options from given intervals. + + Parameters + ---------- + conf : dict + simulation options + + Returns + ------- + dict + contains randomly drawn observation options + """ angles_ra = np.arange( conf["fov_center_ra"][0][0], conf["fov_center_ra"][0][1], step=0.1 ) @@ -127,6 +170,19 @@ def draw_sampling_opts(conf): def test_opts(rc): + """ + Compute the number of telescopes that can observe the source given + certain randomly drawn parameters. + + Parameters + ---------- + rc : dict + randomly drawn observational parameters + + Returns + ------- + + """ array_layout = layouts.get_array_layout(rc["layout"]) src_crd = SkyCoord( ra=rc["fov_center_ra"], dec=rc["fov_center_dec"], unit=(un.deg, un.deg) From 6f77cb6cf033dc7aa17c7a84a7f071d1cd0f6266 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Tue, 8 Aug 2023 15:07:30 +0200 Subject: [PATCH 3/4] Small changes --- pyvisgen/simulation/scan.py | 8 ++++---- pyvisgen/simulation/visibility.py | 4 ---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pyvisgen/simulation/scan.py b/pyvisgen/simulation/scan.py index ecf17f8..33b1009 100644 --- a/pyvisgen/simulation/scan.py +++ b/pyvisgen/simulation/scan.py @@ -196,7 +196,7 @@ def uncorrupted(lm, baselines, wave, time, src_crd, array_layout, SI): source position array_layout : dataclass station information - I : 2d array + SI : 2d array source brightness distribution / input img Returns @@ -248,7 +248,7 @@ def corrupted(lm, baselines, wave, time, src_crd, array_layout, SI, rd): source position array_layout : dataclass station information - I : 2d array + SI : 2d array source brightness distribution / input img rd : 3d array RA and dec values for every pixel @@ -328,7 +328,7 @@ def corrupted(lm, baselines, wave, time, src_crd, array_layout, SI, rd): def direction_independent(lm, baselines, wave, time, src_crd, array_layout, SI, rd): - """Calculates direction independet visibility + """Calculates direction independent visibility Parameters ---------- @@ -344,7 +344,7 @@ def direction_independent(lm, baselines, wave, time, src_crd, array_layout, SI, source position array_layout : dataclass station information - I : 2d array + SI : 2d array source brightness distribution / input img rd : 3d array RA and dec values for every pixel diff --git a/pyvisgen/simulation/visibility.py b/pyvisgen/simulation/visibility.py index 930219c..b569cc6 100644 --- a/pyvisgen/simulation/visibility.py +++ b/pyvisgen/simulation/visibility.py @@ -169,10 +169,6 @@ def vis_loop(rc, SI, num_threads=10, noisy=True): ) visibilities.add(vis) - # workaround to guarantee min number of visibilities - # when num vis is below N sampling is redone - # if visibilities.get_values().shape[1] < 3500: - # return 0 del int_values return visibilities From 1d8d44adac9d548b15d8589e362bf111311260fd Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Thu, 9 Nov 2023 14:07:36 +0100 Subject: [PATCH 4/4] Towncrier --- docs/changes/27.maintenance.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 docs/changes/27.maintenance.rst diff --git a/docs/changes/27.maintenance.rst b/docs/changes/27.maintenance.rst new file mode 100644 index 0000000..d0517ac --- /dev/null +++ b/docs/changes/27.maintenance.rst @@ -0,0 +1,2 @@ +- add docstrings +- delete unused files