@@ -39,15 +39,16 @@ void compute(const functionspace::FunctionSpaceImpl& _fs, idx_t _halo, std::vect
3939 throw_Exception (" halo must zero or matching the one of the StructuredColumns" , Here ());
4040 }
4141
42- bool north_pole_included = 90 . - grid.y (0 ) == 0 .;
43- bool south_pole_included = 90 . + grid.y (grid.ny () - 1 ) == 0 ;
42+ const int y_numbering = (grid.y ().front () < grid.y ().back ()) ? +1 : -1 ;
43+ bool jfirst_at_pole = y_numbering * 90 . + grid.y (0 ) == 0 .;
44+ bool jlast_at_pole = y_numbering * 90 . - grid.y (grid.ny () - 1 ) == 0 ;
4445
4546 auto compute_j = [&](const idx_t j) {
4647 if (j < 0 ) {
47- return -j - 1 + north_pole_included ;
48+ return -j - 1 + jfirst_at_pole ;
4849 }
4950 else if (j >= grid.ny ()) {
50- return 2 * grid.ny () - j - 1 - south_pole_included ;
51+ return 2 * grid.ny () - j - 1 - jlast_at_pole ;
5152 }
5253 return j;
5354 };
@@ -107,14 +108,17 @@ void compute(const functionspace::FunctionSpaceImpl& _fs, idx_t _halo, std::vect
107108 };
108109
109110 double ymax, ymin, xmax, xmin;
111+ if (fs.j_begin () >= fs.j_end ()) {
112+ return ;
113+ }
110114
111115 // Top
112116 // Top left point
113117 {
114118 idx_t j = _halo ? fs.j_begin_halo () : fs.j_begin ();
115119 idx_t i = _halo ? fs.i_begin_halo (j) : fs.i_begin (j);
116120 if (j == 0 && _halo == 0 ) {
117- p[YY] = dom.ymax ();
121+ p[YY] = y_numbering < 0 ? dom.ymax () : dom. ymin ();
118122 }
119123 else {
120124 p[YY] = 0.5 * (compute_y (j - 1 ) + compute_y (j));
@@ -133,7 +137,7 @@ void compute(const functionspace::FunctionSpaceImpl& _fs, idx_t _halo, std::vect
133137 idx_t j = _halo ? fs.j_begin_halo () : fs.j_begin ();
134138 idx_t i = _halo ? fs.i_end_halo (j) - 1 : fs.i_end (j) - 1 ;
135139 if (j == 0 && _halo == 0 ) {
136- p[YY] = dom.ymax ();
140+ p[YY] = y_numbering < 0 ? dom.ymax () : dom. ymin ();
137141 }
138142 else {
139143 p[YY] = 0.5 * (compute_y (j - 1 ) + compute_y (j));
@@ -194,7 +198,7 @@ void compute(const functionspace::FunctionSpaceImpl& _fs, idx_t _halo, std::vect
194198 idx_t i = _halo ? fs.i_end_halo (j) - 1 : fs.i_end (j) - 1 ;
195199
196200 if (j == grid.ny () - 1 && _halo == 0 ) {
197- p[YY] = dom.ymin ();
201+ p[YY] = y_numbering < 0 ? dom.ymin () : dom. ymax ();
198202 }
199203 else {
200204 p[YY] = 0.5 * (compute_y (j) + compute_y (j + 1 ));
@@ -243,7 +247,7 @@ void compute(const functionspace::FunctionSpaceImpl& _fs, idx_t _halo, std::vect
243247 idx_t j = _halo ? fs.j_end_halo () - 1 : fs.j_end () - 1 ;
244248 idx_t i = _halo ? fs.i_begin_halo (j) : fs.i_begin (j);
245249 if (j == grid.ny () - 1 && _halo == 0 ) {
246- p[YY] = dom.ymin ();
250+ p[YY] = y_numbering < 0 ? dom.ymin () : dom. ymax ();
247251 }
248252 else {
249253 p[YY] = 0.5 * (compute_y (j) + compute_y (j + 1 ));
@@ -325,7 +329,7 @@ StructuredPartitionPolygon::StructuredPartitionPolygon(const functionspace::Func
325329 compute (fs, halo, points_, inner_bounding_box_);
326330 auto min = Point2 (std::numeric_limits<double >::max (), std::numeric_limits<double >::max ());
327331 auto max = Point2 (std::numeric_limits<double >::lowest (), std::numeric_limits<double >::lowest ());
328- for (size_t i = 0 ; i < inner_bounding_box_.size () - 1 ; ++i) {
332+ for (int i = 0 ; i < static_cast < int >( inner_bounding_box_.size () ) - 1 ; ++i) {
329333 min = Point2::componentsMin (min, inner_bounding_box_[i]);
330334 max = Point2::componentsMax (max, inner_bounding_box_[i]);
331335 }
@@ -390,45 +394,52 @@ void StructuredPartitionPolygon::outputPythonScript(const eckit::PathName& filep
390394 " \n " " ax = fig.add_subplot(111,aspect='equal')"
391395 " \n " ;
392396 }
393- f << " \n " " verts_" << r << " = [" ;
394- for ( size_t i=0 ; i<points.size (); ++i ) {
395- f << " \n (" << points[i][XX] << " , " << points[i][YY] << " ), " ;
396- }
397- f << " \n ]"
398- " \n "
399- " \n " " codes_" << r << " = [Path.MOVETO]"
400- " \n " " codes_" << r << " .extend([Path.LINETO] * " << ( points.size () - 2 ) << " )"
401- " \n " " codes_" << r << " .extend([Path.CLOSEPOLY])"
402- " \n "
403- " \n " " count_" << r << " = " << count <<
404- " \n " " count_all_" << r << " = " << count_all <<
405- " \n " ;
406- if ( plot_nodes ) {
407- f << " \n " " x_" << r << " = [" ;
408- for ( idx_t i = 0 ; i < count; ++i ) {
409- f << xy ( i, XX ) << " , " ;
397+ if (points.size () > 0 ) {
398+ f << " \n " " verts_" << r << " = [" ;
399+ for ( size_t i=0 ; i<points.size (); ++i ) {
400+ f << " \n (" << points[i][XX] << " , " << points[i][YY] << " ), " ;
410401 }
411- f << " ]"
412- " \n " " y_" << r << " = [" ;
413- for ( idx_t i = 0 ; i < count; ++i ) {
414- f << xy ( i, YY ) << " , " ;
402+ f << " \n ]"
403+ " \n "
404+ " \n " " codes_" << r << " = [Path.MOVETO]"
405+ " \n " " codes_" << r << " .extend([Path.LINETO] * " << ( points.size () - 2 ) << " )"
406+ " \n " " codes_" << r << " .extend([Path.CLOSEPOLY])"
407+ " \n "
408+ " \n " " count_" << r << " = " << count <<
409+ " \n " " count_all_" << r << " = " << count_all <<
410+ " \n " ;
411+ if ( plot_nodes ) {
412+ f << " \n " " x_" << r << " = [" ;
413+ for ( idx_t i = 0 ; i < count; ++i ) {
414+ f << xy ( i, XX ) << " , " ;
415+ }
416+ f << " ]"
417+ " \n " " y_" << r << " = [" ;
418+ for ( idx_t i = 0 ; i < count; ++i ) {
419+ f << xy ( i, YY ) << " , " ;
420+ }
421+ f << " ]" ;
415422 }
416- f << " ] " ;
417- }
418- f << " \n "
419- " \n " " c = next(colours) "
420- " \n " " ax.add_patch(patches.PathPatch(Path(verts_ " << r << " , codes_ " << r << " ), edgecolor=c, facecolor=c, alpha=0.3, lw=1)) " ;
421- if ( plot_nodes ) {
422- f << " \n " " if plot_nodes: "
423- " \n " " ax.scatter(x_ " << r << " , y_ " << r << " , color=c, marker='o') " ;
423+ f << " \n "
424+ " \n " " c = next(colours) "
425+ " \n " " ax.add_patch(patches.PathPatch(Path(verts_ " << r << " , codes_ " << r << " ), edgecolor=c, facecolor=c, alpha=0.3, lw=1)) " ;
426+ if ( plot_nodes ) {
427+ f << " \n " " if plot_nodes: "
428+ " \n " " ax.scatter(x_ " << r << " , y_ " << r << " , color=c, marker='o') " ;
429+ }
430+ f << " \n " ;
424431 }
425- f << " \n " ;
426432 if ( mpi_rank == mpi_size - 1 ) {
427- f << " \n " " ax.set_xlim( " << xmin << " -5, " << xmax << " +5)"
428- " \n " " ax.set_ylim(-90-5, 90+5)"
429- " \n " " ax.set_xticks([0,45,90,135,180,225,270,315,360])"
430- " \n " " ax.set_yticks([-90,-45,0,45,90])"
431- " \n " " plt.grid()"
433+ if (fs_.projection ().units () == " degrees" ) {
434+ f << " \n " " ax.set_xlim( " << xmin << " -5, " << xmax << " +5)"
435+ " \n " " ax.set_ylim(-90-5, 90+5)"
436+ " \n " " ax.set_xticks([0,45,90,135,180,225,270,315,360])"
437+ " \n " " ax.set_yticks([-90,-45,0,45,90])" ;
438+ }
439+ else {
440+ f << " \n " " ax.autoscale()" ;
441+ }
442+ f << " \n " " plt.grid()"
432443 " \n " " plt.show()" ;
433444 }
434445 }
@@ -463,7 +474,6 @@ void StructuredPartitionPolygon::allGather(util::PartitionPolygons& polygons_) c
463474 mypolygon.push_back (p[XX]);
464475 mypolygon.push_back (p[YY]);
465476 }
466- ATLAS_ASSERT (mypolygon.size () >= 4 );
467477
468478 eckit::mpi::Buffer<double > recv_polygons (mpi_size);
469479
0 commit comments