Skip to content

Commit

Permalink
Merge branch 'feature/revert' of ssh://git.ecmwf.int/mag/magics into …
Browse files Browse the repository at this point in the history
…feature/revert
  • Loading branch information
sylvielamythepaut committed Dec 4, 2023
2 parents 7d35683 + fbd5204 commit 86fa83a
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 226 deletions.
16 changes: 1 addition & 15 deletions src/attributes/ColourTechniqueAttributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@

using namespace magics;

ColourTechniqueAttributes::ColourTechniqueAttributes():
oob_min_colour_(ParameterManager::getString("contour_out_of_bound_min_colour")),
oob_max_colour_(ParameterManager::getString("contour_out_of_bound_max_colour"))
ColourTechniqueAttributes::ColourTechniqueAttributes()


{
Expand All @@ -45,16 +43,12 @@ void ColourTechniqueAttributes::set(const std::map<string, string>& params)
int i = 0;
prefix[i++] = "";

setAttribute(prefix, "contour_out_of_bound_min_colour", oob_min_colour_, params);
setAttribute(prefix, "contour_out_of_bound_max_colour", oob_max_colour_, params);


}

void ColourTechniqueAttributes::copy(const ColourTechniqueAttributes& other)
{
oob_min_colour_ = other.oob_min_colour_;
oob_max_colour_ = other.oob_max_colour_;

}

Expand Down Expand Up @@ -93,21 +87,13 @@ void ColourTechniqueAttributes::set(const XmlNode& node)
void ColourTechniqueAttributes::print(ostream& out) const
{
out << "Attributes[";
out << " oob_min_colour = " << oob_min_colour_;
out << " oob_max_colour = " << oob_max_colour_;

out << "]" << "\n";
}

void ColourTechniqueAttributes::toxml(ostream& out) const
{
out << "\"\"";
out << ", \"contour_out_of_bound_min_colour\":";
niceprint(out,oob_min_colour_);
out << ", \"contour_out_of_bound_max_colour\":";
niceprint(out,oob_max_colour_);

}

static MagicsParameter<string> contour_out_of_bound_min_colour("contour_out_of_bound_min_colour", "automatic");
static MagicsParameter<string> contour_out_of_bound_max_colour("contour_out_of_bound_max_colour", "automatic");
2 changes: 0 additions & 2 deletions src/attributes/ColourTechniqueAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class ColourTechniqueAttributes
virtual void toxml(std::ostream& out) const;
// -- members:
string tag_;
string oob_min_colour_;
string oob_max_colour_;


private:
Expand Down
8 changes: 0 additions & 8 deletions src/attributes/ColourTechniqueWrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ void ColourTechniqueWrapper::set(const MagRequest& request)



if (request.countValues("CONTOUR_OUT_OF_BOUND_MIN_COLOUR") ) {
string oob_min_colour_value = request("CONTOUR_OUT_OF_BOUND_MIN_COLOUR");
colourtechnique_->oob_min_colour_ = oob_min_colour_value;
}
if (request.countValues("CONTOUR_OUT_OF_BOUND_MAX_COLOUR") ) {
string oob_max_colour_value = request("CONTOUR_OUT_OF_BOUND_MAX_COLOUR");
colourtechnique_->oob_max_colour_ = oob_max_colour_value;
}


}
Expand Down
9 changes: 5 additions & 4 deletions src/common/ColourTableDefinitionCompute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,6 @@ void ColourTableDefinitionCompute::hcl(ColourTable& table, int nb) {
void ColourTableDefinitionCompute::set(ColourTable& table, int nb) {
prepare();

MagLog::dev() << "ColourTableDefinitionCompute::set->min-->" << minColour_ << endl;
MagLog::dev() << "ColourTableDefinitionCompute::set->max-->" << maxColour_ << endl;
MagLog::dev() << "nb interval-->" << nb << endl;

if (nb == 1) {
table.push_back(minColour_);
return;
Expand All @@ -292,6 +288,8 @@ void ColourTableDefinitionCompute::set(ColourTable& table, int nb) {
table.push_back(maxColour_);
return;
}


std::map<string, ComputeFunction>::iterator method = methods_.find(lowerCase(method_));
if (method == methods_.end())
hsl(table, nb);
Expand Down Expand Up @@ -394,6 +392,8 @@ void ColourTableDefinitionCompute::set(const stringarray& from, ColourTable& to,
int nb, ColourListPolicy policy, const string& method)
{


cout << "SET" << policy << endl;
auto colour = from.begin();
if (policy == ColourListPolicy::DYNAMIC) {
auto helper = dynamicMethods_.find(method);
Expand All @@ -409,6 +409,7 @@ void ColourTableDefinitionCompute::set(const stringarray& from, ColourTable& to,
}

for (int i = 0; i < nb - 1; i++) {
cout << i << "->" << *colour << endl;
if (colour == from.end()) {
if (policy == ColourListPolicy::LASTONE) {
to.push_back(Colour(from.back()));
Expand Down
16 changes: 0 additions & 16 deletions src/params/ColourTechnique.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,7 @@ does it submit to any jurisdiction.
<magics>
<class directory="visualisers" name="ColourTechnique" python="mcont">

<parameter from="string"
name="contour_out_of_bound_min_colour"
default="automatic"
member="oob_min_colour"
to="string"
inherit_parent_reqs="no">
<documentation>Colour to use below the out of bound minimum value</documentation>
</parameter>

<parameter from="string"
name="contour_out_of_bound_max_colour"
default="automatic"
member="oob_max_colour"
to="string"
inherit_parent_reqs="no">
<documentation>Colour to use below the out of bound maximum value</documentation>
</parameter>
</class>

</magics>
50 changes: 4 additions & 46 deletions src/visualisers/ColourTechnique.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@

using namespace magics;

ColourTechnique::ColourTechnique() : policy_(ListPolicy::LASTONE),
minOutOfBound_(false), maxOutOfBound_(false)
{}
ColourTechnique::ColourTechnique() : policy_(ListPolicy::LASTONE) {}


ColourTechnique::~ColourTechnique() {}
Expand All @@ -45,53 +43,15 @@ void ColourTechnique::print(ostream& out) const {
}

void ColourTechnique::prepare(LevelSelection& out, LevelSelection& levels, bool rainbow) {
if (levels.empty())
if (levels.empty())
return;


clear();
bands_.clear();
ColourTable table;



minOutOfBound_ = out.minOutOfBond();
maxOutOfBound_ = out.maxOutOfBond();



if (rainbow)
set(out, levels, table, levels.size() + 1);
else {

LevelSelection newlevels;
int count = levels.size();
if (out.minOutOfBond()) count--;

if (out.maxOutOfBond()) count--;



set(out, levels, table, count);
if (out.minOutOfBond()) {
Colour min_colour = magCompare(oob_min_colour_, "automatic") ?
table.front().colour() : Colour(oob_min_colour_);
table.insert(table.begin(), min_colour);
}
if (out.maxOutOfBond()) {
Colour max_colour = magCompare(oob_max_colour_, "automatic") ?
table.back().colour() : Colour(oob_max_colour_);
table.push_back(max_colour);
}
}


// cout << "ColourTechnique::after(" << endl;
// for (auto l = levels.begin(); l != levels.end(); ++l)
// cout << *l << endl;

// cout << "-------------------" << endl;

else
set(out, levels, table, levels.size());

if (table.empty())
table.push_back(Colour("none"));
Expand Down Expand Up @@ -131,8 +91,6 @@ void ColourTechnique::prepare(LevelSelection& out, LevelSelection& levels, bool
if (!rainbow)
bands_.insert(make_pair(Interval(levels.back(), levels.back() + EPSILON), left));



MagLog::dev() << levels.back() << "<<" << left << "<<" << levels.back() + EPSILON << endl;
}

Expand Down
6 changes: 1 addition & 5 deletions src/visualisers/ColourTechnique.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ class ColourTechnique : public map<double, ColourInfo>,
void visit(LegendVisitor&);
ListPolicy getPolicy() const { return policy_; }

bool minOutOfBound() const { return minOutOfBound_; }
bool maxOutOfBound() const { return maxOutOfBound_; }

protected:
//! Method to print string about this class on to a stream of type ostream (virtual).
Expand All @@ -98,9 +96,7 @@ class ColourTechnique : public map<double, ColourInfo>,
map<double, pair<double, double> > ranges_;
double maxLevel_;

bool minOutOfBound_;
bool maxOutOfBound_;


ListPolicy policy_;


Expand Down
96 changes: 24 additions & 72 deletions src/visualisers/CountSelectionType.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,67 +34,29 @@ CountSelectionType::CountSelectionType() {}
#define MAXSET(v) !same(v, +1.0e+21)

void CountSelectionType::calculate(double min, double max, bool shading) {


clear();


double min_limit=min;
double max_limit=max;


if ( MINSET(min_) )
min_limit = min_;

if ( MAXSET(max_) )
max_limit = max_;

if ( shading && MINSET(shade_min_) )
min_limit = shade_min_;

if ( shading && MAXSET(shade_max_) )
max_limit = shade_max_;

minOutOfBond_ = oob_min_ > min_limit;
maxOutOfBond_ = oob_max_ < max_limit;

clear();
double maxi = (max_ > 1000000000) ? max : max_;
double mini = (min_ < -1000000000) ? min : min_;
int i = 0;
if ( minOutOfBond_ || !MINSET(min_)) {
i++;
}

if ( maxOutOfBond_ || !MAXSET(max_) ) {
i++;
}

i += (max_ > 1000000000) ? 1 : 0;
i += (min_ < -1000000000) ? 1 : 0;


// Commented for now, may have to be revisited soon.
// i += ( MINSET(min_limit) ) ? 1 : 0;
// i += ( MAXSET(max_limit) ) ? 1 : 0;

double nb = levelCount_ - 1;
if (same(max_limit, min_limit)) {
push_back(min_limit);
if (same(maxi, mini)) {
push_back(mini);
return;
}

if (min_limit > max_limit) {
push_back(max_limit);
push_back(min_limit);
return;
}


double step = (max_limit - min_limit) / nb;
double step = (maxi - mini) / nb;
double toleranceProportion =
(double)tolerance_ /
(double)(levelCount_ + 1 + i); // tolerance as a proportion of the number of levels
// we add 'i' here because it will be subtracted at the end (because this is the
// number of levels we will not actually plot, ie the min/max contours).
if (same(step, 0)) {
// Only one isoline!
push_back(min_limit);
push_back(mini);
return;
}

Expand Down Expand Up @@ -145,12 +107,13 @@ void CountSelectionType::calculate(double min, double max, bool shading) {

inc *= istep; // convert back into proper range

double first = floor(min_limit / inc) * inc;

while (first > min_limit)
double first = floor(mini / inc) * inc;

while (first > mini)
first -= inc;

push_back(min_limit);
push_back(mini);
first += inc;
double epsilon = inc / 10000.0;
while (same(epsilon, 0)) {
Expand All @@ -159,58 +122,47 @@ void CountSelectionType::calculate(double min, double max, bool shading) {
}



for (double val = first; val < max_limit; val += inc) {
for (double val = first; val < maxi; val += inc) {
// special case - if the value is close to zero then set it to precisely zero to avoid later formatting issues
if (fabs(val) < epsilon)
push_back(0.0);
else if (same(val, max_limit))
push_back(max_limit);
else if (same(val, maxi))
push_back(maxi);
else
push_back(val);
}

if (max_limit != back())
push_back(max_limit);

if (maxi != back())
push_back(maxi);
int si = static_cast<int>(size());


// last resort - if we have too many/few contours, then just do a 'blind' division
// so as to ensure the correct number, even if they are not nice

if (si - i < levelCount_ - tolerance_ || si - i > levelCount_ + tolerance_) {
MagLog::debug() << "Not using nice levels[" << levelCount_ << ", " << tolerance_ << "]-->" << size() << endl;
MagLog::debug() << "Not using nice levels[" << levelCount_ << ", " << tolerance_ << "]-->" << size() << endl;
clear();
step = (max_limit - min_limit) / (levelCount_ - 1);
double val = min_limit;
step = (maxi - mini) / (levelCount_ - 1);
double val = mini;
while (1) {
if ( val >= min_limit && val <= max_limit )
push_back(val);
if (same(val, max_limit) || val > max_limit)
if (same(val, maxi) || val > maxi)
break;
val += step;
}
MagLog::debug() << "New size-->" << size() << endl;
}

if ( minOutOfBond_ ) {
insert(begin(), std::max(min, min_));
}
MagLog::debug() << "count=" << levelCount_ << ", tolerance=" << tolerance_ << ", result=" << size() << endl;

if ( maxOutOfBond_ ) {
push_back(std::min(max, max_));
}


ostringstream level;
for (const_iterator l = begin(); l != end(); ++l)
level << *l << " ";

MagLog::debug() << level.str() << endl;
MagLog::debug() << level.str() << endl;
}


CountSelectionType::~CountSelectionType() {}

/*!
Expand Down
Loading

0 comments on commit 86fa83a

Please sign in to comment.