Commit a7ff6274 authored by Ambra Di Piano's avatar Ambra Di Piano
Browse files

plotting

parent 628d53d6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ mapper:
  smooth: 1
  pixelsize: 0.02
  center: pointing
  plot: false
  plot: true
  region: false
  output: /data01/homes/dipiano/astroRT/astrort/testing/tmp

+8 −4
Original line number Diff line number Diff line
@@ -9,8 +9,7 @@
import argparse
from time import time
from os import makedirs
from os.path import join
from astrort.utils.wrap import load_yaml_conf, write_mapping_info, execute_mapper_no_visibility
from astrort.utils.wrap import load_yaml_conf, write_mapping_info, execute_mapper_no_visibility, plot_map
from astrort.utils.utils import get_all_seeds
from astrort.configure.logging import set_logger, get_log_level, get_logfile
from astrort.configure.slurmjobs import slurm_submission
@@ -34,9 +33,14 @@ def base_mapper(configuration_file, seeds=None):
    log.info(f"\n {'-'*15} \n| START MAPPER | \n {'-'*15} \n")
    for seed in seeds:
        clock_map = time()
        # check pointing option
        execute_mapper_no_visibility(configuration, log)
        # make map
        fitsmap = execute_mapper_no_visibility(configuration, log)
        log.info(f"Mapping (seed = {seed}) complete, took {time() - clock_map} s")
        # make plot
        if configuration['mapper']['plot']:
            clock_plot = time()
            plotmap = plot_map(fitsmap, log)
            log.info(f"Plotting (seed = {seed}) complete, took {time() - clock_plot} s")
        # timing simulation
        clock_map = time() - clock_map
        # save simulation data
+4 −1
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
# *****************************************************************************

import pytest
import numpy as np
from shutil import rmtree
from os import listdir
from os.path import isfile, join
@@ -15,7 +16,7 @@ from astrort.simulator.base_mapper import base_mapper
from astrort.utils.wrap import load_yaml_conf

@pytest.mark.test_conf_file
@pytest.mark.parametrize('seeds', [None, list([1,2])])
@pytest.mark.parametrize('seeds', [None, list()])
def test_base_mapper(test_conf_file, seeds):

    # clean output
@@ -24,6 +25,8 @@ def test_base_mapper(test_conf_file, seeds):

    # run simulator
    base_simulator(test_conf_file)
    if type(seeds) == list:
        seeds = np.arange(conf['simulator']['samples'])
    base_mapper(test_conf_file, seeds)

    # check output
+17 −4
Original line number Diff line number Diff line
@@ -107,11 +107,24 @@ def test_execute_mapper_no_visibility(test_conf_file):
    # clean output
    conf = load_yaml_conf(test_conf_file)
    rmtree(conf['mapper']['output'], ignore_errors=True)
    conf['simulator']['samples']
    conf['simulator']['samples'] = 1
    log = set_logger(logging.CRITICAL)

    # run simulator
    base_simulator(test_conf_file)
    execute_mapper_no_visibility(conf, log)
    mapfile = seeds_to_string_formatter_files(conf['simulator']['samples'], conf['simulator']['output'], conf['simulator']['name'], conf['simulator']['seed'], 'fits', suffix='map')
    assert isfile(mapfile)
    fitsmap = execute_mapper_no_visibility(conf, log)
    assert isfile(fitsmap)

@pytest.mark.test_conf_file
def test_plot_map(test_conf_file):
    # clean output
    conf = load_yaml_conf(test_conf_file)
    rmtree(conf['mapper']['output'], ignore_errors=True)
    conf['simulator']['samples'] = 1
    log = set_logger(logging.CRITICAL)

    # run simulator
    base_simulator(test_conf_file)
    fitsmap = execute_mapper_no_visibility(conf, log)
    plotmap = plot_map(fitsmap, log)
    assert isfile(plotmap)
 No newline at end of file
+4 −5
Original line number Diff line number Diff line
@@ -102,7 +102,6 @@ class Plotter():
        return ra, dec

    def counts_map(self, file, trange=None, erange=None, roi=5, name='skymap.png', title=None, xlabel='right ascension (deg)', ylabel='declination (deg)', figsize=(10, 10), fontsize=20, cmap='CMRmap', pixelsize=0.02, sigma=1):
        self.__check_pointing()
        extent = self.get_extent(roi)
        # counts map
        data = self.get_phlist_data(file=file)
@@ -129,6 +128,7 @@ class Plotter():
        ax.set_ylabel(ylabel, fontsize=fontsize)
        ax.set_title(title, fontsize=fontsize)
        # pointing
        if isinstance(self.pointing, dict):
            ax.plot([self.pointing['ra']], [self.pointing['dec']], 'k+', markersize=fontsize)
        ax.set_xlim((extent[0], extent[1]))
        ax.set_ylim((extent[2], extent[3]))
@@ -141,7 +141,6 @@ class Plotter():
        return self

    def counts_map_with_wcs(self, file, trange=None, erange=None, roi=5, name='skymap.png', title=None, xlabel='right ascension (deg)', ylabel='declination (deg)', figsize=(10, 10), fontsize=20, cmap='CMRmap', pixelsize=0.02, sigma=1):
        self.__check_pointing()
        extent = self.get_extent(roi=roi)
        # counts map
        data = self.get_phlist_data(file=file)
@@ -172,6 +171,7 @@ class Plotter():
        ax.set_ylabel(ylabel, fontsize=fontsize)
        ax.set_title(title, fontsize=fontsize)
        # pointing
        if isinstance(self.pointing, dict):
            ax.plot([self.pointing['ra']], [self.pointing['dec']], 'k+', markersize=fontsize)
        ax.set_aspect('equal')
        #ax.invert_xaxis()
@@ -214,7 +214,6 @@ class Plotter():
        with fits.open(file) as h:
            try:
                w = WCS(h['SKYMAP'].header)
                print(h['SKYMAP'].header)
                data = h['SKYMAP'].data
            except KeyError as e:
                self.log.error(f'Missing "SKYMAP" extention, the input file may not be a compatible counts map. {e}')
Loading