File: facetreader.cpp

package info (click to toggle)
wsclean 3.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,296 kB
  • sloc: cpp: 129,246; python: 22,066; sh: 360; ansic: 230; makefile: 185
file content (55 lines) | stat: -rw-r--r-- 1,763 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "facetreader.h"

#include <algorithm>

#include <schaapcommon/facets/ds9facetfile.h>

#include <aocommon/logger.h>

#include "../structures/facetutil.h"

using schaapcommon::facets::DS9FacetFile;
using schaapcommon::facets::Facet;

namespace wsclean {

std::vector<std::shared_ptr<Facet>> FacetReader::ReadFacets(
    std::string filename, double width, double height, double pixelScaleX,
    double pixelScaleY, double phaseCentreRA, double phaseCentreDec,
    double l_shift, double m_shift, double imagePadding, bool make_square,
    size_t feather_size) {
  const Facet::InitializationData data = CreateFacetInitializationData(
      width, height, pixelScaleX, pixelScaleY, phaseCentreRA, phaseCentreDec,
      l_shift, m_shift, imagePadding, make_square, feather_size);

  std::vector<std::shared_ptr<Facet>> facets;
  if (!filename.empty()) {
    facets = DS9FacetFile(filename).ReadShared(data);

    if (facets.empty()) {
      throw std::runtime_error("No facets found in " + filename);
    }

    std::vector<std::shared_ptr<Facet>>::const_iterator to_remove =
        std::remove_if(
            facets.begin(), facets.end(),
            [](std::shared_ptr<Facet> facet) { return facet->Empty(); });
    if (to_remove != facets.end()) {
      const size_t n = facets.end() - to_remove;
      aocommon::Logger::Warn << n
                             << " facets fall outside the image boundaries.\n";
      facets.erase(to_remove, facets.end());
      if (facets.empty()) {
        throw std::runtime_error("All facets fall outside the image");
      }
    }
  }

  return facets;
}

std::size_t FacetReader::CountFacets(const std::string& filename) {
  return filename.empty() ? 0 : DS9FacetFile(filename).Count();
}

}  // namespace wsclean