Skip to content

Commit 2d6afb2

Browse files
committed
MIR-643 HEALPix orderingConvention=nested unit tests fixes
1 parent 2c50af4 commit 2d6afb2

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

src/mir/key/grid/HEALPixPattern.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
#include <ostream>
1616

17+
#include "eckit/utils/StringTools.h"
1718
#include "eckit/utils/Translator.h"
19+
1820
#include "mir/key/grid/NamedHEALPix.h"
1921
#include "mir/util/Exceptions.h"
2022

21-
2223
namespace mir::key::grid {
2324

2425

@@ -34,7 +35,13 @@ void HEALPixPattern::print(std::ostream& out) const {
3435

3536

3637
const Grid* HEALPixPattern::make(const std::string& name) const {
37-
return new NamedHEALPix(name, eckit::Translator<std::string, size_t>()(name.substr(1)));
38+
auto nested = eckit::StringTools::endsWith(name, "_nested");
39+
ASSERT(!nested || name.size() > 8);
40+
41+
auto Nside = eckit::Translator<std::string, size_t>()(nested ? name.substr(1, name.size() - 8) : name.substr(1));
42+
43+
return new NamedHEALPix(name, Nside,
44+
nested ? NamedHEALPix::Ordering::healpix_nested : NamedHEALPix::Ordering::healpix_ring);
3845
}
3946

4047

@@ -45,6 +52,7 @@ std::string HEALPixPattern::canonical(const std::string& name, const param::MIRP
4552

4653

4754
static const HEALPixPattern __pattern1("^[hH][1-9][0-9]*$");
55+
static const HEALPixPattern __pattern2("^[hH][1-9][0-9]*_nested$");
4856

4957

5058
} // namespace mir::key::grid

src/mir/key/grid/HEALPixPattern.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ class HEALPixPattern : public GridPattern {
2626

2727
// -- Constructors
2828

29-
HEALPixPattern(const std::string& name);
29+
explicit HEALPixPattern(const std::string& name);
30+
3031
HEALPixPattern(const HEALPixPattern&) = delete;
32+
HEALPixPattern(HEALPixPattern&&) = delete;
3133

3234
// -- Destructor
3335

@@ -39,6 +41,7 @@ class HEALPixPattern : public GridPattern {
3941
// -- Operators
4042

4143
HEALPixPattern& operator=(const HEALPixPattern&) = delete;
44+
HEALPixPattern& operator=(HEALPixPattern&&) = delete;
4245

4346
// -- Methods
4447
// None

src/mir/key/grid/NamedHEALPix.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414

1515
#include <ostream>
1616

17-
#include "mir/repres/proxy/HEALPix.h"
17+
#include "mir/repres/unsupported/HEALPixNested.h"
1818
#include "mir/util/Exceptions.h"
1919

2020

2121
namespace mir::key::grid {
2222

2323

24-
NamedHEALPix::NamedHEALPix(const std::string& name, size_t Nside) : NamedGrid(name), Nside_(Nside) {}
24+
NamedHEALPix::NamedHEALPix(const std::string& name, size_t Nside, Ordering ordering) :
25+
NamedGrid(name), Nside_(Nside), ordering_(ordering) {}
2526

2627

2728
void NamedHEALPix::print(std::ostream& out) const {
@@ -30,6 +31,10 @@ void NamedHEALPix::print(std::ostream& out) const {
3031

3132

3233
const repres::Representation* NamedHEALPix::representation() const {
34+
if (ordering_ == Ordering::healpix_nested) {
35+
return new repres::unsupported::HEALPixNested(Nside_);
36+
}
37+
3338
return new repres::proxy::HEALPix(Nside_);
3439
}
3540

src/mir/key/grid/NamedHEALPix.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,27 @@
1414

1515

1616
#include "mir/key/grid/NamedGrid.h"
17+
#include "mir/repres/proxy/HEALPix.h"
1718

1819

1920
namespace mir::key::grid {
2021

2122

2223
class NamedHEALPix : public NamedGrid {
2324
public:
25+
// -- Types
26+
27+
using Ordering = repres::proxy::HEALPix::Ordering;
28+
2429
// -- Exceptions
2530
// None
2631

2732
// -- Constructors
2833

29-
NamedHEALPix(const std::string& name, size_t Nside);
34+
NamedHEALPix(const std::string& name, size_t Nside, Ordering);
35+
3036
NamedHEALPix(const NamedHEALPix&) = delete;
37+
NamedHEALPix(NamedHEALPix&&) = delete;
3138

3239
// -- Destructor
3340
// None
@@ -38,6 +45,7 @@ class NamedHEALPix : public NamedGrid {
3845
// -- Operators
3946

4047
NamedHEALPix& operator=(const NamedHEALPix&) = delete;
48+
NamedHEALPix& operator=(NamedHEALPix&&) = delete;
4149

4250
// -- Methods
4351
// None
@@ -73,9 +81,9 @@ class NamedHEALPix : public NamedGrid {
7381

7482
private:
7583
// -- Members
76-
// None
7784

78-
size_t Nside_;
85+
const size_t Nside_;
86+
const Ordering ordering_;
7987

8088
// -- Methods
8189
// None

src/mir/repres/proxy/HEALPix.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ class HEALPix final : public ProxyGrid {
3131
public:
3232
// -- Types
3333

34+
enum Ordering
35+
{
36+
healpix_ring,
37+
healpix_nested,
38+
};
39+
3440
class Reorder {
3541
public:
3642
explicit Reorder(int Nside);

0 commit comments

Comments
 (0)