7from libc.stdint cimport SIZE_MAX
8from cython cimport view
9from libc.stdlib cimport malloc, free
10from warnings
import warn
11from collections
import namedtuple
12from types
import coroutine
15logger = logging.getLogger(
"yac.core")
16logger.addHandler(logging.NullHandler())
18cdef extern
from "Python.h":
19 int Py_AtExit(void (*)())
21cdef extern
from "<mpi.h>" nogil:
22 ctypedef void* MPI_Comm
23 MPI_Comm MPI_Comm_f2c(int)
24 MPI_Comm MPI_COMM_WORLD
25 MPI_Comm MPI_COMM_NULL
33cdef extern
from "yac_core.h" nogil:
37 ctypedef double(*yac_coordinate_pointer)[3];
39 cpdef enum yac_location:
45 cpdef enum yac_interp_avg_weight_type:
46 YAC_INTERP_AVG_ARITHMETIC
49 cdef yac_interp_avg_weight_type YAC_INTERP_AVG_WEIGHT_TYPE_DEFAULT
50 cdef int YAC_INTERP_AVG_PARTIAL_COVERAGE_DEFAULT
52 cpdef enum yac_interp_ncc_weight_type:
55 cdef yac_interp_ncc_weight_type YAC_INTERP_NCC_WEIGHT_TYPE_DEFAULT
56 cdef int YAC_INTERP_NCC_PARTIAL_COVERAGE_DEFAULT
58 cpdef enum yac_interp_dnn_weight_type:
59 YAC_INTERP_DNN_WEIGHT_AVG
60 YAC_INTERP_DNN_WEIGHT_DIST
61 YAC_INTERP_DNN_WEIGHT_GAUSS
62 YAC_INTERP_DNN_WEIGHT_RBF
63 cpdef enum yac_interp_dnn_search_distance_type:
64 YAC_INTERP_DNN_SEARCH_DISTANCE_FIXED
65 YAC_INTERP_DNN_SEARCH_DISTANCE_CELL_AREA
66 cdef yac_interp_dnn_weight_type YAC_INTERP_DNN_WEIGHT_DEFAULT
67 cdef yac_interp_dnn_search_distance_type YAC_INTERP_DNN_SEARCH_DISTANCE_TYPE_DEFAULT
68 cdef double YAC_INTERP_DNN_SEARCH_DISTANCE_DEFAULT
69 cdef double YAC_INTERP_DNN_SCALE_DEFAULT
71 cpdef enum yac_interp_method_conserv_normalisation:
72 YAC_INTERP_CONSERV_DESTAREA
73 YAC_INTERP_CONSERV_FRACAREA
74 cdef int YAC_INTERP_CONSERV_ORDER_DEFAULT
75 cdef int YAC_INTERP_CONSERV_ENFORCED_CONSERV_DEFAULT
76 cdef int YAC_INTERP_CONSERV_PARTIAL_COVERAGE_DEFAULT
77 cdef yac_interp_method_conserv_normalisation YAC_INTERP_CONSERV_NORMALISATION_DEFAULT
79 cpdef enum yac_interp_spmap_weight_type:
82 cpdef enum yac_interp_spmap_scale_type:
84 YAC_INTERP_SPMAP_SRCAREA
85 YAC_INTERP_SPMAP_INVTGTAREA
86 YAC_INTERP_SPMAP_FRACAREA
87 cpdef enum yac_interp_spmap_cell_area_provider:
88 YAC_INTERP_SPMAP_CELL_AREA_FILE
89 YAC_INTERP_SPMAP_CELL_AREA_YAC
90 cdef double YAC_INTERP_SPMAP_SPREAD_DISTANCE_DEFAULT
91 cdef double YAC_INTERP_SPMAP_MAX_SEARCH_DISTANCE_DEFAULT
92 cdef yac_interp_spmap_weight_type YAC_INTERP_SPMAP_WEIGHTED_DEFAULT
93 cdef yac_interp_spmap_scale_type YAC_INTERP_SPMAP_SCALE_TYPE_DEFAULT
94 cdef double YAC_INTERP_SPMAP_SPHERE_RADIUS_DEFAULT
95 cdef const char* YAC_INTERP_SPMAP_FILENAME_DEFAULT
96 cdef const char* YAC_INTERP_SPMAP_VARNAME_DEFAULT
97 cdef int YAC_INTERP_SPMAP_MIN_GLOBAL_ID_DEFAULT
99 cpdef enum yac_interp_nnn_weight_type:
105 cdef yac_interp_nnn_weight_type YAC_INTERP_NNN_WEIGHTED_DEFAULT
106 cdef int YAC_INTERP_NNN_N_DEFAULT
107 cdef double YAC_INTERP_NNN_MAX_SEARCH_DISTANCE_DEFAULT
108 cdef double YAC_INTERP_NNN_GAUSS_SCALE_DEFAULT
109 cdef int YAC_INTERP_RBF_N_DEFAULT
110 cdef double YAC_INTERP_RBF_MAX_SEARCH_DISTANCE_DEFAULT
111 cdef double YAC_INTERP_RBF_SCALE_DEFAULT
112 cdef int YAC_INTERP_RBF_KERNEL_DEFAULT
114 cpdef enum yac_interp_file_on_missing_file:
115 YAC_INTERP_FILE_MISSING_ERROR
116 YAC_INTERP_FILE_MISSING_CONT
117 cpdef enum yac_interp_file_on_success:
118 YAC_INTERP_FILE_SUCCESS_STOP
119 YAC_INTERP_FILE_SUCCESS_CONT
120 cdef yac_interp_file_on_missing_file YAC_INTERP_FILE_ON_MISSING_FILE_DEFAULT
121 cdef yac_interp_file_on_success YAC_INTERP_FILE_ON_SUCCESS_DEFAULT
123 cdef const char* YAC_INTERP_CHECK_CONSTRUCTOR_KEY_DEFAULT
124 cdef const char* YAC_INTERP_CHECK_DO_SEARCH_KEY_DEFAULT
126 cdef int YAC_INTERP_CREEP_DISTANCE_DEFAULT
128 struct yac_basic_grid_data:
130 yac_int * vertex_ids;
132 int * core_cell_mask;
133 int * core_vertex_mask;
134 int * core_edge_mask;
136 struct yac_basic_grid:
139 yac_basic_grid * grid);
140 struct yac_interp_field:
141 yac_location location
142 size_t coordinates_idx
145 yac_basic_grid * grid,
146 const char * filename,
152 yac_basic_grid * grid, yac_location location,
153 yac_coordinate_pointer coordinates, size_t count);
155 yac_basic_grid * grid, yac_location location,
156 const int * mask, size_t count, const char * mask_name);
158 const char * name, size_t nbr_vertices[2], int cyclic[2],
159 double *lon_vertices, double *lat_vertices)
162 const char * name, size_t nbr_vertices, size_t nbr_cells,
163 int *num_vertices_per_cell, double *x_vertices, double *y_vertices,
164 int *cell_to_vertex);
166 const char * name, size_t nbr_vertices, size_t nbr_cells,
167 int *num_vertices_per_cell, double *x_vertices, double *y_vertices,
168 int *cell_to_vertex);
170 const char * name, size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges,
171 int *num_edges_per_cell, double *x_vertices, double *y_vertices,
172 int *cell_to_edge, int *edge_to_vertex);
174 const char * name, size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges,
175 int *num_edges_per_cell, double *x_vertices, double *y_vertices,
176 int *cell_to_edge, int *edge_to_vertex);
178 yac_basic_grid * grid, int is_fatal);
180 struct yac_dist_grid_pair:
183 yac_basic_grid * grid_a, yac_basic_grid * grid_b,
187 struct yac_interp_grid:
190 yac_dist_grid_pair * grid_pair,
191 const char * src_grid_name, const char * tgt_grid_name,
192 size_t num_src_fields, const yac_interp_field * src_fields,
193 const yac_interp_field tgt_field);
196 struct interp_method:
199 interp_method ** method, yac_interp_grid * grid);
202 struct yac_interp_stack_config:
204 struct yac_interp_method:
208 yac_interp_stack_config * interp_stack_config);
210 yac_interp_stack_config * interp_stack);
213 yac_interp_stack_config * interp_stack_config,
214 yac_interp_avg_weight_type reduction_type, int partial_coverage);
216 yac_interp_stack_config * interp_stack_config,
217 yac_interp_ncc_weight_type type, int partial_coverage);
219 yac_interp_stack_config * interp_stack_config,
220 yac_interp_dnn_weight_type type,
221 yac_interp_dnn_search_distance_type search_distance_type,
222 double search_distance, double scale);
224 yac_interp_stack_config * interp_stack_config,
225 yac_interp_nnn_weight_type type, size_t n,
226 double max_search_distance, double scale);
228 yac_interp_stack_config * interp_stack_config,
229 int order, int enforced_conserv, int partial_coverage,
230 yac_interp_method_conserv_normalisation normalisation);
232 yac_interp_stack_config * interp_stack_config,
233 double spread_distance, double max_search_distance,
234 yac_interp_spmap_weight_type weight_type,
235 yac_interp_spmap_scale_type scale_type,
236 double src_sphere_radius, const char * src_filename,
237 const char * src_varname, int src_min_global_id,
238 double tgt_sphere_radius, const char * tgt_filename,
239 const char * tgt_varname, int tgt_min_global_id);
241 yac_interp_stack_config * interp_stack_config, double value);
243 yac_interp_stack_config * interp_stack_config,
244 const char * filename, yac_interp_file_on_missing_file on_missing_file,
245 yac_interp_file_on_success on_success);
247 yac_interp_stack_config * interp_stack_config,
248 const char * constructor_key, const char * do_search_key);
250 yac_interp_stack_config * interp_stack_config);
252 yac_interp_stack_config * interp_stack_config,
253 size_t n, double max_search_distance, double scale);
255 yac_interp_stack_config * interp_stack_config, int creep_distance);
257 struct yac_interp_method_config:
260 const char * method_name);
262 yac_interp_method_config * config);
264 yac_interp_stack_config * interp_stack_config,
265 yac_interp_method_config * method_config);
267 yac_interp_method_config * config,
268 const char * path, const char * value);
270 yac_interp_method_config * config,
271 const char * path, int value);
273 yac_interp_method_config * config,
274 const char * path, double value);
276 const yac_interp_method_config * config,
279 const yac_interp_method_config * config,
282 const yac_interp_method_config * config,
285 const yac_interp_method_config * config,
288 yac_interp_method_config * config,
291 struct yac_interpolation:
294 yac_interpolation * interp, double *** src_fields,
295 double *** src_frac_masks, double ** tgt_field);
297 yac_interpolation * interp, double *** src_fields, double *** src_frac_masks);
300 yac_interpolation * interp, double ** tgt_field);
303 struct yac_collection_selection:
306 size_t collection_size, const size_t * selection_indices);
308 yac_collection_selection * collection_selection);
310 cpdef enum yac_interp_weights_reorder_type:
313 struct yac_interpolation_gen_config:
320 yac_interpolation_gen_config * config,
321 const yac_collection_selection * collection_selection);
323 yac_interpolation_gen_config * config,
324 double frac_mask_fallback_value);
326 yac_interpolation_gen_config * config, double scaling_factor);
328 yac_interpolation_gen_config * config, double scaling_summand);
330 yac_interpolation_gen_config * config, const char * name);
332 struct yac_interp_weights:
334 cpdef enum yac_weight_file_on_existing:
335 YAC_WEIGHT_FILE_ERROR
337 YAC_WEIGHT_FILE_OVERWRITE
338 YAC_WEIGHT_FILE_UNDEFINED
340 yac_interp_weights * weights, const char * filename,
341 const char * src_grid_name, const char * tgt_grid_name,
342 size_t src_grid_size, size_t tgt_grid_size,
343 yac_weight_file_on_existing on_existing);
345 const yac_interp_weights * weights,
346 const yac_interpolation_gen_config * interp_gen_config,
347 int is_source, int is_target);
354 MPI_Comm comm, int * local_is_io, int ** io_ranks, int * num_io_ranks);
358 Returns the YAC core library version string.
360 @see yac_get_core_version
364cdef extern
from * nogil:
366#ifndef YAC_UTILS_ENABLED
367// we cannot link libyac_utils.a so we define the function here
368#include "yac_assert.h"
369void yac_read_icon_basic_grid_parallel_2(
370 const char * filename, const char * gridname, MPI_Comm comm,
371 struct yac_basic_grid ** basic_grid, size_t * cell_coordinate_idx,
373 die("To read an ICON grid YAC must be configured with --enable-utils.");
375struct yac_basic_grid * yac_read_scrip_basic_grid(
376 const char * grid_filename, const char * mask_filename,
377 const char * grid_name, int valid_mask_value, const char * name,
378 int use_ll_edges, size_t * cell_coord_idx,
379 size_t ** duplicated_cell_idx, yac_int ** orig_cell_global_ids,
380 size_t * nbr_duplicated_cells) {
381 die("To read a SCRIP grid YAC must be configured with --enable-utils.");
385 #include "yac_utils.h"
389 const char * filename, const char * gridname, MPI_Comm comm,
390 yac_basic_grid ** basic_grid, size_t * cell_coordinate_idx,
394 const char * grid_filename, const char * mask_filename,
395 const char * grid_name, int valid_mask_value, const char * name,
396 int use_ll_edges, size_t * cell_coord_idx,
397 size_t ** duplicated_cell_idx, yac_int ** orig_cell_global_ids,
398 size_t * nbr_duplicated_cells);
404 return clat * _np.cos(lon), clat * _np.sin(lon), slat
406cdef _decode(const char* c_str):
409 return bytes.decode(c_str)
411cdef int get_c_comm(comm, MPI_Comm* c_comm)
except -1:
413 Convert comm into an MPI_Comm.
414 Comm can be given as an fortran comm (int) or as an mpi4py.Comm
417 from mpi4py
import MPI
418 if isinstance(comm, MPI.Comm):
423 c_comm[0] = MPI_COMM_WORLD
424 elif isinstance(comm, int):
425 c_comm[0] = MPI_Comm_f2c(comm)
427 raise ValueError(
"Invalid communicator")
433 dtype = _np.asarray(<yac_int[:1]>&tmp).dtype
434 assert dtype.itemsize == sizeof(yac_int),
"dtype detected did not work"
435 info = _np.iinfo(dtype)
436 assert _np.min(arr) >= info.min
and _np.max(arr) <= info.max, \
437 f
"Indices must be within the valid range for yac_int ({info.min:_} to {info.max:_})"
438 return _np.ascontiguousarray(arr, dtype=dtype)
441logger.info(
"Initializing MPI")
443logger.info(
"Initializing yaxt")
446Coordinates = namedtuple(
"Coordinates", [
"basic_grid",
"location",
"coord_idx"])
447Mask = namedtuple(
"Mask", [
"basic_grid",
"location",
"mask_idx"])
450 cdef yac_basic_grid* _ptr;
453 raise TypeError(
"This class cannot be instantiated directly.")
456 logger.info(
"calling yac_basic_grid_delete")
460 cdef BasicGrid from_ptr(yac_basic_grid* basic_grid_ptr):
461 cdef BasicGrid basic_grid = BasicGrid.__new__(BasicGrid)
462 basic_grid._ptr = basic_grid_ptr
466 filename_bytes = filename.encode()
467 cdef const char* _filename = filename_bytes
468 cdef MPI_Comm c_comm = MPI_COMM_NULL
469 get_c_comm(comm, &c_comm)
470 logger.info(
"calling yac_basic_grid_to_file_parallel")
479 return _decode(_name)
482 return f
"yac_basic_grid(name={self.name})"
485 logger.info(
"calling yac_basic_grid_get_data_size")
489 location : yac_location,
491 cdef yac_basic_grid_data* data
492 cdef yac_int** grid_global_ids;
496 assert indices.shape == (count,),
"Wrong indices shape"
497 if location == YAC_LOC_CELL:
498 grid_global_ids = &(data.cell_ids)
499 elif location == YAC_LOC_CORNER:
500 grid_global_ids = &(data.vertex_ids)
501 elif location == YAC_LOC_EDGE:
502 grid_global_ids = &(data.edge_ids)
504 raise RuntimeError(
"Invalid location")
505 if grid_global_ids[0] == NULL:
506 grid_global_ids[0] = <yac_int*>malloc(count * sizeof(yac_int));
507 logger.info(
"setting global index")
508 (<yac_int[:count]>(grid_global_ids[0]))[:] = indices
511 cdef yac_basic_grid_data* data
512 cdef int** grid_core_mask;
515 mask = _np.ascontiguousarray(mask, dtype=_np.intc)
516 assert mask.shape == (count,),
"Wrong mask shape"
517 if location == YAC_LOC_CELL:
518 grid_core_mask = &(data.core_cell_mask)
519 elif location == YAC_LOC_CORNER:
520 grid_core_mask = &(data.core_vertex_mask)
521 elif location == YAC_LOC_EDGE:
522 grid_core_mask = &(data.core_edge_mask)
524 raise RuntimeError(
"Invalid location")
525 if grid_core_mask[0] == NULL:
526 grid_core_mask[0] = <int*>malloc(count * sizeof(int));
527 logger.info(
"setting core mask")
528 (<int[:count]>(grid_core_mask[0]))[:] = mask
531 location : yac_location,
534 assert (lon
is None) == (lat
is None),
"lon and lat must both be either set or unset."
535 cdef double[:,::1] coords_view
536 cdef size_t coords_len = 0
537 cdef yac_coordinate_pointer coords_ptr = NULL
538 cdef size_t idx = SIZE_MAX
540 coords_xyz = _np.stack(lonlat2xyz(lon, lat), axis=-1)
541 coords_view = _np.ascontiguousarray(coords_xyz, dtype=_np.double)
542 coords_ptr = <yac_coordinate_pointer>&coords_view[0,0]
543 coords_len = len(coords_view)
544 logger.info(
"calling yac_basic_grid_add_coordinates")
550 return Coordinates(basic_grid=self, location=location, coord_idx=idx)
553 location : yac_location,
555 mask_name : str |
None =
None
557 cdef int[:] mask_view = _np.ascontiguousarray(_np.asarray(mask), dtype=_np.intc)
558 cdef const char* _mask_name = NULL
559 if mask_name
is not None:
560 mask_name_bytes = mask_name.encode()
561 _mask_name = mask_name_bytes
562 logger.info(
"calling yac_basic_grid_add_mask")
566 <int*>&mask_view[0], len(mask), _mask_name)
567 return Mask(basic_grid=self, location=location, mask_idx=idx)
570 logger.info(
"calling yac_basic_grid_check_coordinates")
578 mask_valid_values=
None):
580 filename_bytes = filename.encode()
581 cdef const char* _filename = filename_bytes
582 gridname_bytes = gridname.encode()
583 cdef const char* _gridname = gridname_bytes
584 cdef MPI_Comm c_comm = MPI_COMM_NULL
585 get_c_comm(comm, &c_comm)
586 cdef yac_basic_grid * _yac_basic_grid
587 cdef size_t cell_coordinate_idx
588 cdef int * cell_mask;
590 logger.info(
"calling yac_read_icon_basic_grid_parallel_2")
592 _filename, _gridname, c_comm,
594 &cell_coordinate_idx, &cell_mask)
596 basic_grid = BasicGrid.from_ptr(_yac_basic_grid)
598 location=YAC_LOC_CELL,
599 coord_idx=cell_coordinate_idx)
602 if cell_mask != NULL
and mask_valid_values
is not None:
603 num_cells = basic_grid.get_data_size(YAC_LOC_CELL)
604 _cell_mask = basic_grid.add_mask(YAC_LOC_CELL,
605 _np.isin(<int[:num_cells]>cell_mask, mask_valid_values))
607 return basic_grid,
InterpField(cell_coords, _cell_mask)
615 valid_mask_value = 1,
616 use_ll_edges = False,
618 cdef size_t cell_coord_idx;
619 cdef size_t* duplicated_cell_idx;
620 cdef yac_int* orig_cell_global_ids;
621 cdef size_t nbr_duplicated_cells;
622 cdef yac_basic_grid * yac_basic_grid;
623 grid_filename_bytes = grid_filename.encode()
624 cdef const char* _grid_filename = grid_filename_bytes
625 mask_filename_bytes = mask_filename.encode()
626 cdef const char* _mask_filename = mask_filename_bytes
627 grid_name_bytes = grid_name.encode()
628 cdef const char* _grid_name = grid_name_bytes
629 name_bytes = name.encode()
630 cdef const char* _name = name_bytes
631 cdef int _valid_mask_value = valid_mask_value
632 cdef int _use_ll_edges = use_ll_edges
633 logger.info(
"calling yac_read_scrip_basic_grid")
643 &duplicated_cell_idx,
644 &orig_cell_global_ids,
645 &nbr_duplicated_cells);
646 basic_grid = BasicGrid.from_ptr(yac_basic_grid)
649 location=YAC_LOC_CELL,
650 coord_idx=cell_coord_idx)),
654 @cython.boundscheck(False)
655 def reg_2d_new(cls, name, lon_vertices, lat_vertices, cyclic = [False, False]):
656 cdef const double[::1] x = _np.ascontiguousarray(lon_vertices, dtype=_np.double)
657 cdef const double[::1] y = _np.ascontiguousarray(lat_vertices, dtype=_np.double)
658 cdef int[2] cyclic_view = cyclic
659 name_bytes = name.encode()
660 cdef const char* _name = name_bytes
661 cdef size_t[2] _len = [len(x), len(y)]
662 cdef int[2] _cyclic = cyclic
663 logger.info(
"calling yac_basic_grid_reg_2d_new")
666 _name, _len, _cyclic,
667 <double*>&x[0], <double*>&y[0])
668 return BasicGrid.from_ptr(yac_basic_grid)
671 @cython.boundscheck(False)
674 num_vertices_per_cell,
678 lonlat_edges =
False):
679 assert len(x_vertices) == len(y_vertices)
680 cdef int[:] _num_vertices_per_cell = _np.ascontiguousarray(num_vertices_per_cell, dtype=_np.intc)
681 cdef double[:] _x_vertices = _np.ascontiguousarray(x_vertices, dtype=_np.double)
682 cdef double[:] _y_vertices = _np.ascontiguousarray(y_vertices, dtype=_np.double)
683 cdef int[:] _cell_to_vertex = _np.ascontiguousarray(cell_to_vertex, dtype=_np.intc)
684 cdef int[:] _num_edges_per_cell
685 cdef int[:] _edge_to_vertex
686 cdef yac_basic_grid * ptr
687 name_bytes = name.encode()
688 cdef const char* _name = name_bytes
689 cdef size_t nbr_vertices = len(x_vertices)
690 cdef size_t nbr_cells = len(num_vertices_per_cell)
692 logger.info(
"calling yac_basic_grid_unstruct_ll_new")
698 <int*>&_num_vertices_per_cell[0],
699 <double *>&_x_vertices[0],
700 <double *>&_y_vertices[0],
701 <int *>&_cell_to_vertex[0]);
703 logger.info(
"calling yac_basic_grid_unstruct_new")
709 <int*>&_num_vertices_per_cell[0],
710 <double *>&_x_vertices[0],
711 <double *>&_y_vertices[0],
712 <int *>&_cell_to_vertex[0]);
713 return BasicGrid.from_ptr(ptr)
716 @cython.boundscheck(False)
724 lonlat_edges : bool =
False):
725 assert len(x_vertices) == len(y_vertices)
726 cdef int[:] _num_edges_per_cell = _np.ascontiguousarray(num_edges_per_cell, dtype=_np.intc)
727 cdef double[:] _x_vertices = _np.ascontiguousarray(x_vertices, dtype=_np.double)
728 cdef double[:] _y_vertices = _np.ascontiguousarray(y_vertices, dtype=_np.double)
729 cdef int[:] _cell_to_edge = _np.ascontiguousarray(cell_to_edge, dtype=_np.intc)
730 cdef int[:] _edge_to_vertex = _np.ascontiguousarray(edge_to_vertex, dtype=_np.intc)
731 name_bytes = name.encode()
732 cdef const char* _name = name_bytes
733 cdef size_t nbr_vertices = len(x_vertices)
734 cdef size_t nbr_cells = len(num_edges_per_cell)
735 cdef size_t nbr_edges = _np.max(_cell_to_edge)+1
737 logger.info(
"calling yac_basic_grid_unstruct_edge_ll_new")
744 <int*>&_num_edges_per_cell[0],
745 <double*>&_x_vertices[0],
746 <double*>&_y_vertices[0],
747 <int*>&_cell_to_edge[0],
748 <int*>&_edge_to_vertex[0]);
750 logger.info(
"calling yac_basic_grid_unstruct_edge_new")
757 <int*>&_num_edges_per_cell[0],
758 <double*>&_x_vertices[0],
759 <double*>&_y_vertices[0],
760 <int*>&_cell_to_edge[0],
761 <int*>&_edge_to_vertex[0]);
763 return BasicGrid.from_ptr(ptr)
767 logger.info(
"calling yac_basic_grid_empty_new")
769 return BasicGrid.from_ptr(ptr)
775 def_edges : bool =
False,
776 lonlat_edges : bool =
False):
777 from uxarray
import INT_FILL_VALUE
779 cell_to_edge = _np.asarray(uxgrid.face_edge_connectivity).reshape((-1,), order=
"C")
780 cell_to_edge = cell_to_edge[cell_to_edge!=INT_FILL_VALUE]
781 edge_to_vertex = _np.asarray(uxgrid.edge_node_connectivity).reshape((-1,), order=
"C")
782 edge_to_vertex = edge_to_vertex[edge_to_vertex!=INT_FILL_VALUE]
785 uxgrid.n_nodes_per_face,
786 _np.deg2rad(uxgrid.node_lon),
787 _np.deg2rad(uxgrid.node_lat),
790 lonlat_edges = lonlat_edges)
792 cell_to_vertex = _np.asarray(uxgrid.face_node_connectivity).reshape((-1,), order=
"C")
793 cell_to_vertex = cell_to_vertex[cell_to_vertex!=INT_FILL_VALUE]
796 uxgrid.n_nodes_per_face,
797 _np.deg2rad(uxgrid.node_lon),
798 _np.deg2rad(uxgrid.node_lat),
800 lonlat_edges = lonlat_edges)
801 grid.set_global_index(YAC_LOC_CELL,
802 range(uxgrid.n_face))
803 grid.set_global_index(YAC_LOC_EDGE,
804 range(uxgrid.n_edge))
805 grid.set_global_index(YAC_LOC_CORNER,
806 range(uxgrid.n_node))
811 cdef yac_interp_field _interp_field
812 cdef BasicGrid _basic_grid
815 coordinates : Coordinates,
818 self._interp_field.location = coordinates.location
819 self._interp_field.coordinates_idx = coordinates.coord_idx
820 cdef masks_idx = SIZE_MAX
822 assert mask.location == coordinates.location, \
823 "coordinates and mask have different location"
824 masks_idx = mask.mask_idx
825 self._interp_field.masks_idx = masks_idx
828 return f
"yac_interp_field(grid={self._basic_grid}, location={self.location}, coord_idx={self._interp_field.coordinates_idx}, mask_idx={self._interp_field.masks_idx})"
832 return self._interp_field.location
839 cdef yac_dist_grid_pair* _ptr
845 cdef MPI_Comm c_comm = MPI_COMM_NULL
846 get_c_comm(comm, &c_comm)
847 logger.info(
"calling yac_dist_grid_pair_new")
849 grid_a._ptr, grid_b._ptr,
851 self.
_str = f
"yac_dist_grid_pair(grid_a={grid_a}, grid_b={grid_b}"
857 logger.info(
"calling yac_dist_grid_pair_delete")
861 cdef yac_interp_grid* _ptr
862 cdef InterpField _src_field
863 cdef InterpField _tgt_field
866 grid_pair : DistGridPair,
867 src_field : InterpField,
868 tgt_field : InterpField):
869 src_grid_name = src_field._basic_grid.name
870 tgt_grid_name = tgt_field._basic_grid.name
871 logger.info(
"calling yac_interp_grid_new")
873 src_grid_name.encode(), tgt_grid_name.encode(),
874 1, &src_field._interp_field,
875 tgt_field._interp_field);
880 return f
"yac_interp_grid(src_field={self._src_field}, tgt_field={self._tgt_field})"
883 logger.info(
"calling yac_interp_grid_delete")
887 cdef yac_interp_stack_config* _ptr
888 interpolation_register = {}
891 logger.info(
"calling yac_interp_stack_config_new")
897 interp_list = [(t, {})
if type(t)
is str
else t
for t
in interp_list]
898 for name, kwargs
in interp_list:
899 interp_stack.add(name, **kwargs)
903 logger.info(
"calling yac_interp_stack_config_delete")
907 def _register(method):
908 InterpolationStack.interpolation_register[name] = method
912 def add(self, name, *args, **kwargs):
915 @register_interpolation("average")
917 weight_type : yac_interp_avg_weight_type | str = YAC_INTERP_AVG_WEIGHT_TYPE_DEFAULT,
918 partial_coverage : bool = YAC_INTERP_AVG_PARTIAL_COVERAGE_DEFAULT):
919 if isinstance(weight_type, str):
920 weight_type = getattr(yac_interp_avg_weight_type, weight_type)
921 logger.info(
"calling yac_interp_stack_config_add_average")
923 self.
_ptr, weight_type, partial_coverage);
925 @register_interpolation("ncc")
927 weight_type : yac_interp_ncc_weight_type | str = YAC_INTERP_NCC_WEIGHT_TYPE_DEFAULT,
928 partial_coverage : bool = YAC_INTERP_NCC_PARTIAL_COVERAGE_DEFAULT):
929 if isinstance(weight_type, str):
930 weight_type = getattr(yac_interp_ncc_weight_type, weight_type)
931 logger.info(
"calling yac_interp_stack_config_add_ncc")
934 @register_interpolation("dnn")
936 weight_type : yac_interp_dnn_weight_type | str = YAC_INTERP_DNN_WEIGHT_DEFAULT,
937 search_distance_type : yac_interp_dnn_search_distance_type | str = YAC_INTERP_DNN_SEARCH_DISTANCE_TYPE_DEFAULT,
938 search_distance : float = YAC_INTERP_DNN_SEARCH_DISTANCE_DEFAULT,
939 scale : float = YAC_INTERP_DNN_SCALE_DEFAULT):
940 if isinstance(weight_type, str):
941 weight_type = getattr(yac_interp_dnn_weight_type, weight_type)
942 if isinstance(search_distance_type, str):
943 search_distance_type = getattr(yac_interp_dnn_search_distance_type, search_distance_type)
944 logger.info(
"calling yac_interp_stack_config_add_dnn")
946 self.
_ptr, weight_type, search_distance_type, search_distance, scale);
948 @register_interpolation("nnn")
950 nnn_type : yac_interp_nnn_weight_type | str = YAC_INTERP_NNN_WEIGHTED_DEFAULT,
951 n : int = YAC_INTERP_NNN_N_DEFAULT,
952 max_search_distance: float = YAC_INTERP_NNN_MAX_SEARCH_DISTANCE_DEFAULT,
953 scale : float = YAC_INTERP_NNN_GAUSS_SCALE_DEFAULT,
955 if isinstance(nnn_type, str):
956 nnn_type = getattr(yac_interp_nnn_weight_type, nnn_type)
957 logger.info(
"calling yac_interp_stack_config_add_nnn")
959 self.
_ptr, nnn_type, n, max_search_distance, scale);
961 @register_interpolation("conservative")
963 order : int = YAC_INTERP_CONSERV_ORDER_DEFAULT,
964 enforced_conserv : bool = YAC_INTERP_CONSERV_ENFORCED_CONSERV_DEFAULT,
965 partial_coverage : bool = YAC_INTERP_CONSERV_PARTIAL_COVERAGE_DEFAULT,
966 normalisation : yac_interp_method_conserv_normalisation | str = YAC_INTERP_CONSERV_NORMALISATION_DEFAULT
968 assert order
in {1,2},
"Invalid order"
969 if isinstance(normalisation, str):
970 normalisation = getattr(yac_interp_method_conserv_normalisation, normalisation)
971 logger.info(
"calling yac_interp_stack_config_add_conservative")
973 self.
_ptr, order, enforced_conserv, partial_coverage, normalisation);
975 @register_interpolation("source_to_target_map")
977 spread_distance : float = YAC_INTERP_SPMAP_SPREAD_DISTANCE_DEFAULT,
978 max_search_distance : float = YAC_INTERP_SPMAP_MAX_SEARCH_DISTANCE_DEFAULT,
979 weight_type : yac_interp_spmap_weight_type | str = YAC_INTERP_SPMAP_WEIGHTED_DEFAULT,
980 scale_type : yac_interp_spmap_scale_type | str = YAC_INTERP_SPMAP_SCALE_TYPE_DEFAULT,
981 src_sphere_radius : float = 0.0,
982 src_filename : str |
None =
None,
983 src_varname : str |
None =
None,
984 src_min_global_id : int = YAC_INTERP_SPMAP_MIN_GLOBAL_ID_DEFAULT,
985 tgt_sphere_radius : float = 0.0,
986 tgt_filename : str |
None =
None,
987 tgt_varname : str |
None =
None,
988 tgt_min_global_id : int = YAC_INTERP_SPMAP_MIN_GLOBAL_ID_DEFAULT,
990 cdef const char* _src_filename = NULL
991 cdef const char* _src_varname = NULL
992 cdef const char* _tgt_filename = NULL
993 cdef const char* _tgt_varname = NULL
994 if src_filename
is not None:
995 src_filename_bytes = bytes(src_filename)
996 _src_filename = src_filename_bytes
997 if src_varname
is not None:
998 src_varname_bytes = bytes(src_varname)
999 _src_varname = src_varname_bytes
1000 if tgt_filename
is not None:
1001 tgt_filename_bytes = bytes(tgt_filename)
1002 _tgt_filename = tgt_filename_bytes
1003 if src_varname
is not None:
1004 src_varname_bytes = bytes(src_varname)
1005 _src_varname = src_varname_bytes
1006 if isinstance(weight_type, str):
1007 weight_type = getattr(yac_interp_spmap_weight_type, weight_type)
1008 if isinstance(scale_type, str):
1009 scale_type = getattr(yac_interp_spmap_scale_type, scale_type)
1010 logger.info(
"calling yac_interp_stack_config_add_spmap")
1012 self.
_ptr, spread_distance, max_search_distance, weight_type,
1013 scale_type, src_sphere_radius, _src_filename, _src_varname,
1014 src_min_global_id, tgt_sphere_radius, _tgt_filename, _tgt_varname,
1017 @register_interpolation("fixed")
1019 logger.info(
"calling yac_interp_stack_config_add_fixed")
1023 @register_interpolation("user_file")
1025 filename : str |
None =
None,
1026 on_missing_file : yac_interp_file_on_missing_file | str = YAC_INTERP_FILE_ON_MISSING_FILE_DEFAULT,
1027 on_success : yac_interp_file_on_success | str = YAC_INTERP_FILE_ON_SUCCESS_DEFAULT):
1028 cdef const char* _filename = NULL
1029 if filename
is not None:
1030 filename_bytes = filename.encode()
1031 _filename = filename_bytes
1032 if isinstance(on_missing_file, str):
1033 on_missing_file = getattr(yac_interp_file_on_missing_file, on_missing_file)
1034 if isinstance(on_success, str):
1035 on_success = getattr(yac_interp_file_on_success, on_success)
1036 logger.info(
"calling yac_interp_stack_config_add_user_file")
1038 self.
_ptr, _filename, on_missing_file, on_success);
1040 @register_interpolation("check")
1042 constructor_key : str = _decode(YAC_INTERP_CHECK_CONSTRUCTOR_KEY_DEFAULT),
1043 do_search_key : str = _decode(YAC_INTERP_CHECK_DO_SEARCH_KEY_DEFAULT)):
1044 logger.info(
"calling yac_interp_stack_config_add_check")
1046 constructor_key.encode(), do_search_key.encode());
1048 @register_interpolation("bernstein_bezier")
1050 logger.info(
"calling yac_interp_stack_config_add_hcsbb")
1053 @register_interpolation("rbf")
1055 n : int = YAC_INTERP_RBF_N_DEFAULT,
1056 max_search_distance : float = YAC_INTERP_RBF_MAX_SEARCH_DISTANCE_DEFAULT,
1057 scale : float = YAC_INTERP_RBF_SCALE_DEFAULT,
1058 rbf_kernel : int = YAC_INTERP_RBF_KERNEL_DEFAULT
1060 logger.info(
"calling yac_interp_stack_config_add_rbf")
1063 @register_interpolation("creep")
1065 creep_distance : int = YAC_INTERP_CREEP_DISTANCE_DEFAULT):
1066 logger.info(
"calling yac_interp_stack_config_add_creep")
1070 """Add a method config object to this interpolation stack.
1072 The stack takes ownership of the config; it must not be used
1073 (or deleted) after this call.
1075 logger.info(
"calling yac_interp_stack_config_add")
1085 """User-oriented wrapper around a YAC interpolation method configuration.
1089 cfg = InterpMethodConfig("nnn")
1090 cfg.set_param_int("n", 8)
1091 cfg.set_param_str("weighted", "gauss_weighted")
1092 stack = InterpolationStack()
1093 stack.add_from_config(cfg)
1095 cdef yac_interp_method_config* _ptr
1098 method_name_bytes = method_name.encode()
1099 logger.info(
"calling yac_interp_method_config_default_from_name_new")
1102 for k,v
in kwargs.items():
1106 if self.
_ptr != NULL:
1107 logger.info(
"calling yac_interp_method_config_delete")
1112 """Set a parameter by dot-separated path from a string value."""
1113 logger.info(
"calling yac_interp_method_config_set_param_str")
1115 self.
_ptr, path.encode(), value.encode())
1118 """Set a scalar integer parameter by dot-separated path."""
1119 logger.info(
"calling yac_interp_method_config_set_param_int")
1121 self.
_ptr, path.encode(), value)
1124 """Set a scalar double parameter by dot-separated path."""
1125 logger.info(
"calling yac_interp_method_config_set_param_dble")
1127 self.
_ptr, path.encode(), value)
1129 def set_param(self, path : str, value : str | int | float | dict | list):
1130 """Set a parameter by dot-separated path, dispatching on type."""
1131 if isinstance(value, str):
1133 elif isinstance(value, int):
1135 elif isinstance(value, float):
1137 elif isinstance(value, dict):
1138 for k,v
in value.items():
1140 elif isinstance(value, list):
1145 raise TypeError(f
"Unsupported type {type(value)} for set_param")
1148 """Get the integer value of a parameter by dot-separated path."""
1149 logger.info(
"calling yac_interp_method_config_get_param_int")
1151 self.
_ptr, path.encode())
1154 """Get the double value of a parameter by dot-separated path."""
1155 logger.info(
"calling yac_interp_method_config_get_param_dble")
1157 self.
_ptr, path.encode())
1160 """Get the string value of a parameter by dot-separated path."""
1162 logger.info(
"calling yac_interp_method_config_get_param_str")
1164 self.
_ptr, path.encode())
1165 result = raw.decode()
1170 """Return the number of elements in the list parameter at *path*."""
1171 logger.info(
"calling yac_interp_method_config_get_list_size")
1173 self.
_ptr, path.encode())
1176 """Append a default element to the list parameter at *path*.
1178 Returns the zero-based index of the newly appended element so that its
1179 sub-parameters can be set with paths like ``"listname.<index>.subparam"``.
1181 logger.info(
"calling yac_interp_method_config_append_list_element")
1183 self.
_ptr, path.encode())
1186 cdef yac_interp_weights* _ptr;
1187 cdef _num_src_points, _num_tgt_points;
1190 raise TypeError(
"This class cannot be instantiated directly.")
1193 cdef InterpWeights from_ptr(yac_interp_weights* interp_weights_ptr,
1194 num_src_points : int,
1195 num_tgt_points : int):
1196 cdef InterpWeights interp_weights = InterpWeights.__new__(InterpWeights)
1197 interp_weights._ptr = interp_weights_ptr
1198 interp_weights._num_src_points = num_src_points
1199 interp_weights._num_tgt_points = num_tgt_points
1200 return interp_weights
1204 src_grid_name : str =
"src_grid",
1205 tgt_grid_name : str =
"tgt_grid",
1206 num_global_src_points : int = 0,
1207 num_global_tgt_points : int = 0,
1208 on_existing = YAC_WEIGHT_FILE_ERROR,
1210 filename_bytes = filename.encode()
1211 src_grid_name_bytes = src_grid_name.encode()
1212 tgt_grid_name_bytes = tgt_grid_name.encode()
1213 cdef const char* filename_cstr = filename_bytes
1214 cdef const char* src_grid_name_cstr = src_grid_name_bytes
1215 cdef const char* tgt_grid_name_cstr = tgt_grid_name_bytes
1216 cdef yac_interp_weights* _ptr = self.
_ptr;
1217 cdef int num_global_src_points_c = num_global_src_points
1218 cdef int num_global_tgt_points_c = num_global_tgt_points
1219 cdef yac_weight_file_on_existing on_existing_c = on_existing
1220 logger.info(
"calling yac_interp_weights_write_to_file")
1227 num_global_src_points_c,
1228 num_global_tgt_points_c,
1232 reorder : yac_interp_weights_reorder_type = YAC_MAPPING_ON_SRC,
1233 collection_size : int |
None =
None,
1234 frac_mask_fallback_value : float |
None =
None,
1235 scaling_factor : float = 1.0,
1236 scaling_summand : float = 0.0,
1237 yaxt_exchanger_name : str |
None =
None,
1238 is_source : bool =
True,
1239 is_target : bool =
True,
1240 collection_selection : List[int] |
None =
None):
1241 assert (collection_size
is not None) ^ (collection_selection
is not None), \
1242 "Either collection_size or collection_selection must be provided"
1243 if collection_size
is not None:
1244 collection_selection = list(range(collection_size))
1245 collection_size = len(collection_selection)
1247 cdef yac_collection_selection* coll_sel;
1249 cdef size_t[:] coll_sel_np = _np.ascontiguousarray(collection_selection, dtype=_np.uintp)
1256 if frac_mask_fallback_value
is not None:
1260 if yaxt_exchanger_name
is not None:
1263 logger.info(
"calling yac_interp_weights_get_interpolation_ext")
1265 self.
_ptr, config, is_source, is_target);
1268 return Interpolation.from_ptr(interp_ptr,
1274def do_search(interpolation_stack : InterpolationStack, interp_grid : InterpGrid):
1276 cdef yac_interp_weights * w
1279 interpstack, interp_grid._ptr);
1280 logger.info(
"calling yac_interp_method_delete")
1284 src_loc = interp_grid._src_field.location
1285 num_src_points = interp_grid._src_field._basic_grid.get_data_size(src_loc)
1287 tgt_loc = interp_grid._tgt_field.location
1288 num_tgt_points = interp_grid._tgt_field._basic_grid.get_data_size(tgt_loc)
1290 return InterpWeights.from_ptr(w, num_src_points, num_tgt_points)
1293 src_field : InterpField |
None,
1294 tgt_field : InterpField |
None,
1296 dgp =
DistGridPair(src_field.basic_grid, tgt_field.basic_grid)
1303cdef void* fill_pointer_array(array):
1304 cdef double[::1] view1d
1305 if len(array.shape) == 1:
1308 cdef void** ptr = <void**> malloc(array.shape[0] * sizeof(ptr[0]))
1310 for i
in range(array.shape[0]):
1311 slic = array[i, ...]
1312 assert slic.base
is not None
1313 ptr[i] = fill_pointer_array(slic)
1316cdef void free_pointer_array(void* ptr, shape):
1319 for i
in range(shape[0]):
1320 free_pointer_array((<void**>ptr)[i], shape[1:])
1324 cdef yac_interpolation* _ptr;
1325 cdef int _collection_size;
1326 cdef _num_src_points, _num_tgt_points
1329 raise TypeError(
"This class cannot be instantiated directly.")
1332 cdef Interpolation from_ptr(yac_interpolation* interpolation_ptr,
1333 num_src_points, num_tgt_points,
1335 cdef Interpolation interp = Interpolation.__new__(Interpolation)
1336 interp._ptr = interpolation_ptr
1337 interp._num_src_points = num_src_points
1338 interp._num_tgt_points = num_tgt_points
1339 interp._collection_size = collection_size
1342 def __call__(self, src = None, *, tgt = None, frac_mask = None):
1343 cdef double*** _src = NULL
1344 cdef double*** _frac_masks = NULL
1345 cdef double** _tgt = NULL
1347 src = src.reshape((-1, 1, self._num_src_points))
1348 _src = <double***>fill_pointer_array(src)
1349 if frac_mask
is not None:
1350 frac_mask = frac_mask.reshape((-1, 1, self._num_src_points))
1351 _frac_masks = <double***>fill_pointer_array(frac_mask)
1353 if tgt
is None and self._num_tgt_points > 0:
1354 tgt = _np.empty((self._collection_size, self._num_tgt_points), dtype=_np.double)
1357 tgt = tgt.reshape(self._collection_size, self._num_tgt_points)
1358 _tgt = <double**>fill_pointer_array(tgt)
1360 logger.info(
"calling yac_interpolation_execute_frac")
1363 self._ptr, _src, _frac_masks, _tgt);
1365 free_pointer_array(_src, src.shape)
1366 if frac_mask
is not None:
1367 free_pointer_array(_frac_masks, frac_mask.shape)
1369 free_pointer_array(_tgt, tgt.shape)
1374 cdef double*** _src = NULL
1375 cdef double*** _frac_masks = NULL
1376 cdef double** _tgt = NULL
1378 src = src.reshape((-1, 1, self._num_src_points))
1379 _src = <double***>fill_pointer_array(src)
1380 if frac_mask
is not None:
1381 frac_mask = frac_mask.reshape((-1, 1, self._num_src_points))
1382 _frac_masks = <double***>fill_pointer_array(frac_mask)
1384 if tgt
is None and self._num_tgt_points > 0:
1385 tgt = _np.empty((self._collection_size, self._num_tgt_points), dtype=_np.double)
1387 tgt = tgt.reshape(self._collection_size, self._num_tgt_points)
1388 _tgt = <double**>fill_pointer_array(tgt)
1403 free_pointer_array(_src, src.shape)
1404 if frac_mask
is not None:
1405 free_pointer_array(_frac_masks, frac_mask.shape)
1407 free_pointer_array(_tgt, tgt.shape)
1412 Returns a list of ranks designated for I/O operations in the given
1415 cdef MPI_Comm c_comm = MPI_COMM_NULL
1416 get_c_comm(comm, &c_comm)
1417 cdef int local_is_io
1418 cdef int *io_ranks_ptr
1419 cdef int num_io_ranks
1420 logger.info(
"calling yac_get_io_ranks")
1423 io_ranks = [io_ranks_ptr[i]
for i
in range(num_io_ranks)]
1425 return bool(local_is_io), io_ranks
1427if Py_AtExit(yac_mpi_finalize) < 0:
1428 warn(
"could not register yac_mpi_finalize with Py_AtExit()")
struct yac_basic_grid * yac_basic_grid_unstruct_edge_new(char const *name, size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges, int *num_edges_per_cell, double *x_vertices, double *y_vertices, int *cell_to_edge, int *edge_to_vertex)
struct yac_basic_grid * yac_basic_grid_unstruct_edge_ll_new(char const *name, size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges, int *num_edges_per_cell, double *x_vertices, double *y_vertices, int *cell_to_edge, int *edge_to_vertex)
void yac_basic_grid_to_file_parallel(struct yac_basic_grid *grid, char const *filename, MPI_Comm comm)
struct yac_basic_grid * yac_basic_grid_unstruct_new(char const *name, size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell, double *x_vertices, double *y_vertices, int *cell_to_vertex)
struct yac_basic_grid_data * yac_basic_grid_get_data(struct yac_basic_grid *grid)
size_t yac_basic_grid_add_mask(struct yac_basic_grid *grid, enum yac_location location, int const *mask, size_t count, char const *mask_name)
struct yac_basic_grid * yac_basic_grid_reg_2d_new(char const *name, size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices)
struct yac_basic_grid * yac_basic_grid_unstruct_ll_new(char const *name, size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell, double *x_vertices, double *y_vertices, int *cell_to_vertex)
char const * yac_basic_grid_get_name(struct yac_basic_grid *grid)
size_t yac_basic_grid_add_coordinates(struct yac_basic_grid *grid, enum yac_location location, yac_coordinate_pointer coordinates, size_t count)
int yac_basic_grid_check_coordinates(struct yac_basic_grid *grid, int fatal)
size_t yac_basic_grid_get_data_size(struct yac_basic_grid *grid, enum yac_location location)
struct yac_basic_grid * yac_basic_grid_empty_new(char const *name)
void yac_basic_grid_delete(struct yac_basic_grid *grid)
from_uxgrid(cls, str name, uxgrid, bool def_edges=False, bool lonlat_edges=False)
check_coordinates(self, bool is_fatal=True)
set_global_index(self, yac_location location, indices)
__init__(self, yac_basic_grid_ptr)
reg_2d_new(cls, name, lon_vertices, lat_vertices, cyclic=[False, False])
unstruct_new(cls, str name, num_vertices_per_cell, x_vertices, y_vertices, cell_to_vertex, lonlat_edges=False)
to_file(self, filename, comm=None)
read_scrip(cls, grid_filename, mask_filename, grid_name, name, valid_mask_value=1, use_ll_edges=False)
unstruct_edge_new(cls, str name, num_edges_per_cell, x_vertices, y_vertices, cell_to_edge, edge_to_vertex, bool lonlat_edges=False)
read_icon(cls, str filename, str gridname, comm=None, mask_valid_values=None)
get_data_size(self, yac_location location)
add_coordinates(self, yac_location location, lon=None, lat=None)
add_mask(self, yac_location location, mask, str|None mask_name=None)
set_core_mask(self, yac_location location, mask)
__init__(self, BasicGrid grid_a, BasicGrid grid_b, comm=None)
__init__(self, Coordinates coordinates, Mask mask=None)
__init__(self, DistGridPair grid_pair, InterpField src_field, InterpField tgt_field)
User-oriented wrapper around a YAC interpolation method configuration.
set_param_dble(self, str path, float value)
Set a scalar double parameter by dot-separated path.
int append_list_element(self, str path)
Append a default element to the list parameter at path.
set_param_str(self, str path, str value)
Set a parameter by dot-separated path from a string value.
__init__(self, str method_name, **kwargs)
int get_param_int(self, str path)
Get the integer value of a parameter by dot-separated path.
set_param_int(self, str path, int value)
Set a scalar integer parameter by dot-separated path.
int get_list_size(self, str path)
Return the number of elements in the list parameter at path.
float get_param_dble(self, str path)
Get the double value of a parameter by dot-separated path.
str get_param_str(self, str path)
Get the string value of a parameter by dot-separated path.
set_param(self, str path, str|int|float|dict|list value)
Set a parameter by dot-separated path, dispatching on type.
get_interpolation(self, yac_interp_weights_reorder_type reorder=YAC_MAPPING_ON_SRC, int|None collection_size=None, float|None frac_mask_fallback_value=None, float scaling_factor=1.0, float scaling_summand=0.0, str|None yaxt_exchanger_name=None, bool is_source=True, bool is_target=True, List[int]|None collection_selection=None)
write_to_file(self, str filename, str src_grid_name="src_grid", str tgt_grid_name="tgt_grid", int num_global_src_points=0, int num_global_tgt_points=0, on_existing=YAC_WEIGHT_FILE_ERROR)
add_user_file(self, str|None filename=None, yac_interp_file_on_missing_file|str on_missing_file=YAC_INTERP_FILE_ON_MISSING_FILE_DEFAULT, yac_interp_file_on_success|str on_success=YAC_INTERP_FILE_ON_SUCCESS_DEFAULT)
add_bernstein_bezier(self)
add_method(self, method, **kwargs)
add_conservative(self, int order=YAC_INTERP_CONSERV_ORDER_DEFAULT, bool enforced_conserv=YAC_INTERP_CONSERV_ENFORCED_CONSERV_DEFAULT, bool partial_coverage=YAC_INTERP_CONSERV_PARTIAL_COVERAGE_DEFAULT, yac_interp_method_conserv_normalisation|str normalisation=YAC_INTERP_CONSERV_NORMALISATION_DEFAULT)
dict interpolation_register
register_interpolation(name)
add_check(self, str constructor_key=_decode(YAC_INTERP_CHECK_CONSTRUCTOR_KEY_DEFAULT), str do_search_key=_decode(YAC_INTERP_CHECK_DO_SEARCH_KEY_DEFAULT))
add(self, name, *args, **kwargs)
add_fixed(self, float value)
add_average(self, yac_interp_avg_weight_type|str weight_type=YAC_INTERP_AVG_WEIGHT_TYPE_DEFAULT, bool partial_coverage=YAC_INTERP_AVG_PARTIAL_COVERAGE_DEFAULT)
add_rbf(self, int n=YAC_INTERP_RBF_N_DEFAULT, float max_search_distance=YAC_INTERP_RBF_MAX_SEARCH_DISTANCE_DEFAULT, float scale=YAC_INTERP_RBF_SCALE_DEFAULT, int rbf_kernel=YAC_INTERP_RBF_KERNEL_DEFAULT)
add_creep(self, int creep_distance=YAC_INTERP_CREEP_DISTANCE_DEFAULT)
add_source_to_target_map(self, float spread_distance=YAC_INTERP_SPMAP_SPREAD_DISTANCE_DEFAULT, float max_search_distance=YAC_INTERP_SPMAP_MAX_SEARCH_DISTANCE_DEFAULT, yac_interp_spmap_weight_type|str weight_type=YAC_INTERP_SPMAP_WEIGHTED_DEFAULT, yac_interp_spmap_scale_type|str scale_type=YAC_INTERP_SPMAP_SCALE_TYPE_DEFAULT, float src_sphere_radius=0.0, str|None src_filename=None, str|None src_varname=None, int src_min_global_id=YAC_INTERP_SPMAP_MIN_GLOBAL_ID_DEFAULT, float tgt_sphere_radius=0.0, str|None tgt_filename=None, str|None tgt_varname=None, int tgt_min_global_id=YAC_INTERP_SPMAP_MIN_GLOBAL_ID_DEFAULT)
add_nnn(self, yac_interp_nnn_weight_type|str nnn_type=YAC_INTERP_NNN_WEIGHTED_DEFAULT, int n=YAC_INTERP_NNN_N_DEFAULT, float max_search_distance=YAC_INTERP_NNN_MAX_SEARCH_DISTANCE_DEFAULT, float scale=YAC_INTERP_NNN_GAUSS_SCALE_DEFAULT)
add_dnn(self, yac_interp_dnn_weight_type|str weight_type=YAC_INTERP_DNN_WEIGHT_DEFAULT, yac_interp_dnn_search_distance_type|str search_distance_type=YAC_INTERP_DNN_SEARCH_DISTANCE_TYPE_DEFAULT, float search_distance=YAC_INTERP_DNN_SEARCH_DISTANCE_DEFAULT, float scale=YAC_INTERP_DNN_SCALE_DEFAULT)
add_from_config(self, InterpMethodConfig config)
Add a method config object to this interpolation stack.
from_list(cls, interp_list)
add_ncc(self, yac_interp_ncc_weight_type|str weight_type=YAC_INTERP_NCC_WEIGHT_TYPE_DEFAULT, bool partial_coverage=YAC_INTERP_NCC_PARTIAL_COVERAGE_DEFAULT)
char * yac_get_core_version(void)
void yac_dist_grid_pair_delete(struct yac_dist_grid_pair *grid_pair)
struct yac_dist_grid_pair * yac_dist_grid_pair_new(struct yac_basic_grid *grid_a, struct yac_basic_grid *grid_b, MPI_Comm comm)
void yac_collection_selection_delete(struct yac_collection_selection *collection_selection)
Delete a collection selection object.
struct yac_collection_selection * yac_collection_selection_new(size_t collection_size, size_t const *selection_indices)
Create a new collection selection.
void yac_interp_grid_delete(struct yac_interp_grid *interp_grid)
struct yac_interp_grid * yac_interp_grid_new(struct yac_dist_grid_pair *grid_pair, char const *src_grid_name, char const *tgt_grid_name, size_t num_src_fields, struct yac_interp_field const *src_fields, struct yac_interp_field const tgt_field)
void yac_interp_method_delete(struct interp_method **method)
Delete an interpolation stack and free its resources (but not the pointer array).
struct yac_interp_weights * yac_interp_method_do_search(struct interp_method **method, struct yac_interp_grid *interp_grid)
Perform weight computation using given interpolation stack and grid.
void yac_interp_method_config_set_param_int(struct yac_interp_method_config *config, char const *path, int value)
double yac_interp_method_config_get_param_dble(struct yac_interp_method_config const *config, char const *path)
size_t yac_interp_method_config_append_list_element(struct yac_interp_method_config *config, char const *path)
int yac_interp_method_config_get_param_int(struct yac_interp_method_config const *config, char const *path)
void yac_interp_method_config_set_param_dble(struct yac_interp_method_config *config, char const *path, double value)
char * yac_interp_method_config_get_param_str(struct yac_interp_method_config const *config, char const *path)
struct yac_interp_method_config * yac_interp_method_config_default_from_name_new(char const *method_name)
void yac_interp_method_config_set_param_str(struct yac_interp_method_config *config, char const *path, char const *value)
size_t yac_interp_method_config_get_list_size(struct yac_interp_method_config const *config, char const *path)
void yac_interp_method_config_delete(struct yac_interp_method_config *config)
void yac_interp_stack_config_add_check(struct yac_interp_stack_config *interp_stack_config, char const *constructor_key, char const *do_search_key)
void yac_interp_stack_config_add_spmap(struct yac_interp_stack_config *interp_stack_config, double spread_distance, double max_search_distance, enum yac_interp_spmap_weight_type weight_type, enum yac_interp_spmap_scale_type scale_type, double src_sphere_radius, char const *src_filename, char const *src_varname, int src_min_global_id, double tgt_sphere_radius, char const *tgt_filename, char const *tgt_varname, int tgt_min_global_id)
void yac_interp_stack_config_add_fixed(struct yac_interp_stack_config *interp_stack_config, double value)
void yac_interp_stack_config_add_hcsbb(struct yac_interp_stack_config *interp_stack_config)
void yac_interp_stack_config_add_rbf(struct yac_interp_stack_config *interp_stack_config, size_t n, double max_search_distance, double scale)
void yac_interp_stack_config_add_average(struct yac_interp_stack_config *interp_stack_config, enum yac_interp_avg_weight_type reduction_type, int partial_coverage)
void yac_interp_stack_config_add_creep(struct yac_interp_stack_config *interp_stack_config, int creep_distance)
void yac_interp_stack_config_add_nnn(struct yac_interp_stack_config *interp_stack_config, enum yac_interp_nnn_weight_type type, size_t n, double max_search_distance, double scale)
void yac_interp_stack_config_delete(struct yac_interp_stack_config *interp_stack_config)
Free an interpolation stack configuration object.
void yac_interp_stack_config_add_conservative(struct yac_interp_stack_config *interp_stack_config, int order, int enforced_conserv, int partial_coverage, enum yac_interp_method_conserv_normalisation normalisation)
struct interp_method ** yac_interp_stack_config_generate(struct yac_interp_stack_config *interp_stack)
Generate a NULL-terminated array of interpolation methods from the stack configuration.
void yac_interp_stack_config_add_dnn(struct yac_interp_stack_config *interp_stack_config, enum yac_interp_dnn_weight_type type, enum yac_interp_dnn_search_distance_type search_distance_type, double search_distance, double scale)
void yac_interp_stack_config_add(struct yac_interp_stack_config *interp_stack_config, struct yac_interp_method_config *method_config)
Add an interpolation method configuration to the end of the stack.
void yac_interp_stack_config_add_ncc(struct yac_interp_stack_config *interp_stack_config, enum yac_interp_ncc_weight_type weight_type, int partial_coverage)
void yac_interp_stack_config_add_user_file(struct yac_interp_stack_config *interp_stack_config, char const *filename, enum yac_interp_file_on_missing_file on_missing_file, enum yac_interp_file_on_success on_success)
struct yac_interp_stack_config * yac_interp_stack_config_new()
Allocate a new empty interpolation stack configuration object.
struct yac_interpolation * yac_interp_weights_get_interpolation_ext(struct yac_interp_weights const *weights, struct yac_interpolation_gen_config const *config, int is_source, int is_target)
void yac_interp_weights_write_to_file(struct yac_interp_weights *weights, char const *filename, char const *src_grid_name, char const *tgt_grid_name, size_t src_grid_size, size_t tgt_grid_size, enum yac_weight_file_on_existing on_existing)
int yac_interpolation_execute_put_test(struct yac_interpolation *interp)
Test whether the asynchronous put phase has completed.
void yac_interpolation_execute_frac(struct yac_interpolation *interp, double ***src_fields, double ***src_frac_masks, double **tgt_field)
Execute interpolation with fractional masks and write results to the target field.
void yac_interpolation_execute_get_async(struct yac_interpolation *interp, double **tgt_field)
Complete interpolation asynchronously and write results to the target field (get phase).
void yac_interpolation_execute_put_frac(struct yac_interpolation *interp, double ***src_fields, double ***src_frac_masks)
Provide source field data with fractional masks and start asynchronous execution of interpolation (pu...
int yac_interpolation_execute_get_test(struct yac_interpolation *interp)
Test whether the asynchronous get phase has completed.
void yac_interpolation_gen_config_set_reorder(struct yac_interpolation_gen_config *config, enum yac_interp_weights_reorder_type reorder)
Set the reordering strategy for interpolation weights.
void yac_interpolation_gen_config_set_collection_size(struct yac_interpolation_gen_config *config, size_t collection_size)
Set the number of contiguous fields (starting at "0") in the field collection.
void yac_interpolation_gen_config_set_collection_selection(struct yac_interpolation_gen_config *config, struct yac_collection_selection const *collection_selection)
Set the collection selection of source field in the source field collection.
void yac_interpolation_gen_config_set_scaling_factor(struct yac_interpolation_gen_config *config, double scaling_factor)
Set the multiplicative scaling factor.
void yac_interpolation_gen_config_set_yaxt_exchanger_name(struct yac_interpolation_gen_config *config, char const *name)
Set the name of the Yaxt exchanger.
void yac_interpolation_gen_config_delete(struct yac_interpolation_gen_config *config)
Release a interpolation generation configuration structure allocated by yac_interpolation_gen_config_...
void yac_interpolation_gen_config_set_frac_mask_fallback_value(struct yac_interpolation_gen_config *config, double frac_mask_fallback_value)
Set the fractional mask fallback value.
struct yac_interpolation_gen_config * yac_interpolation_gen_config_new(void)
Allocate and initialise an interpolation generation configuration structure.
void yac_interpolation_gen_config_set_scaling_summand(struct yac_interpolation_gen_config *config, double scaling_summand)
Set the additive scaling summand.
void yac_get_io_ranks(MPI_Comm comm, int *local_is_io_, int **io_ranks_, int *num_io_ranks_)
execute_async(self, src=None, *, tgt=None, frac_mask=None)
_to_yac_int_np_array(arr)
compute_weights(InterpolationStack interpolation_stack, InterpField|None src_field, InterpField|None tgt_field, comm=None)
get_io_ranks(comm=None)
Returns a list of ranks designated for I/O operations in the given communicator.
version()
using int here is ok.
do_search(InterpolationStack interpolation_stack, InterpGrid interp_grid)
Coordinates
Initialization.
__call__(self, src=None, *, tgt=None, frac_mask=None)
void yac_read_icon_basic_grid_parallel_2(char const *filename, char const *gridname, MPI_Comm comm, struct yac_basic_grid **basic_grid, size_t *cell_coordinate_idx, int **cell_mask)
struct yac_basic_grid * yac_read_scrip_basic_grid(char const *grid_filename, char const *mask_filename, char const *grid_name, int valid_mask_value, char const *name, int use_ll_edges, size_t *cell_coord_idx, size_t **duplicated_cell_idx, yac_int **orig_cell_global_ids, size_t *nbr_duplicated_cells)
void yac_yaxt_init(MPI_Comm comm)