guohanghui commited on
Commit
24943cd
·
verified ·
1 Parent(s): dfdb960

Update pyPDAF/mcp_output/mcp_plugin/mcp_service.py

Browse files
pyPDAF/mcp_output/mcp_plugin/mcp_service.py CHANGED
@@ -25,6 +25,125 @@ mcp = FastMCP("pyPDAF_service")
25
  # PDAF Core Module Tools
26
  # ============================================================================
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  @mcp.tool(name="pdaf_correlation_function", description="Calculate the value of a correlation function at a given distance")
29
  def pdaf_correlation_function(ctype: int, length: float, distance: float) -> dict:
30
  """
 
25
  # PDAF Core Module Tools
26
  # ============================================================================
27
 
28
+ @mcp.tool(name="pdaf_gather_dim_obs_f", description="Gather global observation dimension across local domains")
29
+ def pdaf_gather_dim_obs_f(dim_obs_p: int) -> dict:
30
+ """
31
+ Gather total observation dimension and displacements from local dimensions.
32
+
33
+ This allocates the global observation size used by gather_obs_f routines.
34
+
35
+ Args:
36
+ dim_obs_p: Process-local observation dimension.
37
+
38
+ Returns:
39
+ dict: A dictionary containing the full observation dimension.
40
+ """
41
+ try:
42
+ dim_obs_f = PDAF.gather_dim_obs_f(dim_obs_p)
43
+ return {"success": True, "result": {"dim_obs_f": int(dim_obs_f)}, "error": None}
44
+ except Exception as e:
45
+ return {"success": False, "result": None, "error": str(e)}
46
+
47
+
48
+ @mcp.tool(name="pdaf_gather_obs_f", description="Gather full observation vector from process-local pieces")
49
+ def pdaf_gather_obs_f(obs_p: List[float], dimobs_f: int) -> dict:
50
+ """
51
+ Concatenate process-local observation vectors into a full vector (local-filter use).
52
+
53
+ Args:
54
+ obs_p: Process-local observation vector.
55
+ dimobs_f: Full observation dimension.
56
+
57
+ Returns:
58
+ dict: A dictionary containing the gathered observation vector and status.
59
+ """
60
+ try:
61
+ obs_p_np = np.array(obs_p, dtype=np.float64)
62
+ obs_f, status = PDAF.gather_obs_f(obs_p_np, dimobs_f)
63
+ return {
64
+ "success": True,
65
+ "result": {"obs_f": obs_f.tolist(), "status": int(status)},
66
+ "error": None,
67
+ }
68
+ except Exception as e:
69
+ return {"success": False, "result": None, "error": str(e)}
70
+
71
+
72
+ @mcp.tool(name="pdaf_gather_obs_f2", description="Gather observation coordinates from local pieces")
73
+ def pdaf_gather_obs_f2(coords_p: List[List[float]], nrows: int, dimobs_f: int) -> dict:
74
+ """
75
+ Concatenate process-local observation coordinate arrays into a full coordinate array.
76
+
77
+ Args:
78
+ coords_p: Local coordinate array shaped [nrows, dimobs_p].
79
+ nrows: Number of coordinate rows (e.g., spatial dimensions).
80
+ dimobs_f: Full observation dimension.
81
+
82
+ Returns:
83
+ dict: A dictionary containing the gathered coordinates and status.
84
+ """
85
+ try:
86
+ coords_p_np = np.array(coords_p, dtype=np.float64)
87
+ coords_f, status = PDAF.gather_obs_f2(coords_p_np, nrows, dimobs_f)
88
+ return {
89
+ "success": True,
90
+ "result": {"coords_f": coords_f.tolist(), "status": int(status)},
91
+ "error": None,
92
+ }
93
+ except Exception as e:
94
+ return {"success": False, "result": None, "error": str(e)}
95
+
96
+
97
+ @mcp.tool(name="pdaf_gather_obs_f_flex", description="Gather full observation vector without PDAF-internal metadata")
98
+ def pdaf_gather_obs_f_flex(dim_obs_p: int, dim_obs_f: int, obs_p: List[float]) -> dict:
99
+ """
100
+ Flexibly gather observation vectors using explicit local/global sizes.
101
+
102
+ Args:
103
+ dim_obs_p: Process-local observation dimension.
104
+ dim_obs_f: Full observation dimension.
105
+ obs_p: Local observation vector.
106
+
107
+ Returns:
108
+ dict: A dictionary containing the gathered observation vector and status.
109
+ """
110
+ try:
111
+ obs_p_np = np.array(obs_p, dtype=np.float64)
112
+ obs_f, status = PDAF.gather_obs_f_flex(dim_obs_p, dim_obs_f, obs_p_np)
113
+ return {
114
+ "success": True,
115
+ "result": {"obs_f": obs_f.tolist(), "status": int(status)},
116
+ "error": None,
117
+ }
118
+ except Exception as e:
119
+ return {"success": False, "result": None, "error": str(e)}
120
+
121
+
122
+ @mcp.tool(name="pdaf_gather_obs_f2_flex", description="Gather observation coordinates without PDAF-internal metadata")
123
+ def pdaf_gather_obs_f2_flex(dim_obs_p: int, dim_obs_f: int, coords_p: List[List[float]], nrows: int) -> dict:
124
+ """
125
+ Flexibly gather 2D observation coordinate arrays using explicit local/global sizes.
126
+
127
+ Args:
128
+ dim_obs_p: Process-local observation dimension.
129
+ dim_obs_f: Full observation dimension.
130
+ coords_p: Local coordinate array shaped [nrows, dim_obs_p].
131
+ nrows: Number of coordinate rows (e.g., spatial dimensions).
132
+
133
+ Returns:
134
+ dict: A dictionary containing the gathered coordinates and status.
135
+ """
136
+ try:
137
+ coords_p_np = np.array(coords_p, dtype=np.float64)
138
+ coords_f, status = PDAF.gather_obs_f2_flex(dim_obs_p, dim_obs_f, coords_p_np, nrows)
139
+ return {
140
+ "success": True,
141
+ "result": {"coords_f": coords_f.tolist(), "status": int(status)},
142
+ "error": None,
143
+ }
144
+ except Exception as e:
145
+ return {"success": False, "result": None, "error": str(e)}
146
+
147
  @mcp.tool(name="pdaf_correlation_function", description="Calculate the value of a correlation function at a given distance")
148
  def pdaf_correlation_function(ctype: int, length: float, distance: float) -> dict:
149
  """