Skip to content

Commit d4c5803

Browse files
authored
Merge pull request #881 from SlideRuleEarth/carlos-dev4
Carlos dev4
2 parents f29fadb + 8f8202b commit d4c5803

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed

web-client/src/components/SrReqParmsDisplayDlg.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ watch([modelValue, parsedData], () => {
210210
<Tabs v-model:value="activeTab">
211211
<TabList>
212212
<Tab value="0">JSON</Tab>
213-
<Tab value="1">Python Snippet</Tab>
213+
<Tab value="1">Python</Tab>
214214
<Tab value="2">Lua</Tab>
215-
<Tab value="3">Python Example</Tab>
215+
<Tab value="3">Python Code</Tab>
216216
</TabList>
217217

218218
<TabPanels>
@@ -231,12 +231,12 @@ watch([modelValue, parsedData], () => {
231231
</div>
232232
</TabPanel>
233233

234-
<!-- Python Snippet Tab -->
234+
<!-- Python Tab -->
235235
<TabPanel value="1">
236236
<div class="tab-content">
237237
<div class="button-row">
238238
<Button
239-
label="Copy Snippet"
239+
label="Copy"
240240
size="small"
241241
icon="pi pi-copy"
242242
@click="copyPythonSnippetToClipboard"

web-client/src/utils/reqParmsConverters.ts

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,30 @@ export function jsonToPythonDict(data: unknown, indent: number = 0): string {
6464
}
6565

6666
/**
67-
* Maps API endpoints to SlideRule Python client functions
67+
* Maps web client endpoints to SlideRule run() API names (for non-GEDI endpoints)
6868
*/
69-
const apiToFunctionMap: Record<string, { module: string; func: string }> = {
70-
atl06: { module: 'icesat2', func: 'atl06p' },
71-
atl06p: { module: 'icesat2', func: 'atl06p' },
72-
atl06sp: { module: 'icesat2', func: 'atl06sp' },
73-
atl03x: { module: 'icesat2', func: 'atl03sp' },
74-
'atl03x-surface': { module: 'icesat2', func: 'atl03sp' },
75-
'atl03x-phoreal': { module: 'icesat2', func: 'atl03sp' },
76-
atl03sp: { module: 'icesat2', func: 'atl03sp' },
77-
atl03vp: { module: 'icesat2', func: 'atl03vp' },
78-
atl08: { module: 'icesat2', func: 'atl08p' },
79-
atl08p: { module: 'icesat2', func: 'atl08p' },
80-
atl24x: { module: 'icesat2', func: 'atl24x' },
81-
atl13x: { module: 'icesat2', func: 'atl13sp' },
82-
gedi01bp: { module: 'gedi', func: 'gedi01bp' },
83-
gedi02ap: { module: 'gedi', func: 'gedi02ap' },
84-
gedi04ap: { module: 'gedi', func: 'gedi04ap' }
69+
const endpointToRunName: Record<string, string> = {
70+
atl06: 'atl06',
71+
atl06p: 'atl06',
72+
atl06sp: 'atl06',
73+
atl03x: 'atl03x',
74+
'atl03x-surface': 'atl03x',
75+
'atl03x-phoreal': 'atl03x',
76+
atl03sp: 'atl03x',
77+
atl03vp: 'atl03x',
78+
atl08: 'atl08',
79+
atl08p: 'atl08',
80+
atl24x: 'atl24x',
81+
atl13x: 'atl13x'
82+
}
83+
84+
/**
85+
* Maps GEDI endpoints to their gedi module function names
86+
*/
87+
const gediEndpointToFunc: Record<string, string> = {
88+
gedi01bp: 'gedi01bp',
89+
gedi02ap: 'gedi02ap',
90+
gedi04ap: 'gedi04ap'
8591
}
8692

8793
/**
@@ -107,24 +113,26 @@ function getOutputFormat(jsonData: unknown): string | null {
107113
*/
108114
export function generatePythonClientCode(jsonData: unknown, endpoint: string): string {
109115
const normalizedEndpoint = endpoint.toLowerCase().trim()
110-
const mapping = apiToFunctionMap[normalizedEndpoint] || {
111-
module: 'icesat2',
112-
func: normalizedEndpoint
113-
}
114-
115116
const parmsDict = jsonToPythonDict(jsonData, 0)
116117

117-
// Determine which modules to import
118-
const modules = new Set<string>(['sliderule'])
119-
modules.add(mapping.module)
120-
121-
const importModules = Array.from(modules).join(', ')
118+
// Check if this is a GEDI endpoint
119+
const gediFunc = gediEndpointToFunc[normalizedEndpoint]
120+
const isGedi = !!gediFunc
122121

123122
// Check if output format is specified (returns file path instead of GeoDataFrame)
124123
const outputFormat = getOutputFormat(jsonData)
125124
const hasFileOutput =
126125
outputFormat === 'parquet' || outputFormat === 'geoparquet' || outputFormat === 'csv'
127126

127+
// Determine import and execute statements based on endpoint type
128+
const importStatement = isGedi
129+
? 'from sliderule import sliderule, gedi'
130+
: 'from sliderule import sliderule'
131+
132+
const executeStatement = isGedi
133+
? `gedi.${gediFunc}(parms)`
134+
: `sliderule.run("${endpointToRunName[normalizedEndpoint] || normalizedEndpoint}", parms)`
135+
128136
if (hasFileOutput) {
129137
// When output format is specified, the API returns a file path
130138
const geopandasImport =
@@ -137,17 +145,17 @@ SlideRule request generated from web client
137145
Endpoint: ${endpoint}
138146
"""
139147
140-
from sliderule import ${importModules}
148+
${importStatement}
141149
${geopandasImport}
142150
143-
# Initialize SlideRule connection
151+
# Initialize SlideRule client
144152
sliderule.init("slideruleearth.io")
145153
146154
# Request parameters
147155
parms = ${parmsDict}
148156
149157
# Execute request (returns file path when output format is specified)
150-
output_file = ${mapping.module}.${mapping.func}(parms)
158+
output_file = ${executeStatement}
151159
print(f"Data saved to: {output_file}")
152160
153161
# Read the output file into a GeoDataFrame
@@ -165,16 +173,16 @@ SlideRule request generated from web client
165173
Endpoint: ${endpoint}
166174
"""
167175
168-
from sliderule import ${importModules}
176+
${importStatement}
169177
170-
# Initialize SlideRule connection
178+
# Initialize SlideRule client
171179
sliderule.init("slideruleearth.io")
172180
173181
# Request parameters
174182
parms = ${parmsDict}
175183
176184
# Execute request
177-
gdf = ${mapping.module}.${mapping.func}(parms)
185+
gdf = ${executeStatement}
178186
179187
# Display results
180188
print(f"Retrieved {len(gdf)} records")

0 commit comments

Comments
 (0)