Skip to content

Commit

Permalink
Merge branch 'feat/Refactor_idea_Draft' of https://github.com/Freeman…
Browse files Browse the repository at this point in the history
…-kuch/FLINT.Cloud into feat/Refactor_idea_Draft
  • Loading branch information
Freeman-kuch committed Oct 27, 2022
2 parents 44402d9 + 8fa9a81 commit 93002b5
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 6 deletions.
30 changes: 24 additions & 6 deletions local/rest_api_gcbm/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,24 @@ def gcbm_download():
title = request.form.get("title") or "simulation"
# Sanitize title
title = "".join(c for c in title if c.isalnum())

output_dir = f"{os.getcwd()}/output/{title}.zip"
input_dir = f"{os.getcwd()}/input/{title}"

# if the title has an input simulation and there is no output simulation then they should check the status.
if not os.path.exists(f"{output_dir}") and os.path.exists(f"{input_dir}"):
return {
"message": "You simulation is currently running, check the status via /gcbm/status"
}

# if there is no input simulation and no output simulation then the simulation does not exist.
elif not os.path.exists(f"{output_dir}") and not os.path.exists(f"{input_dir}"):
return {
"message": "You don't have a simulation with this title kindly check the title and try again"
}

return send_file(
f"{os.getcwd()}/output/{title}.zip",
attachment_filename="{title}.zip",
f"{os.getcwd()}/output/{title}.zip", attachment_filename="{title}.zip",
)


Expand All @@ -484,10 +499,13 @@ def gcbm_list_simulations():
for file in os.listdir(f"{os.getcwd()}/input"):
list.append(file)

return {
"data": list,
"message": "To create a new simulation, create a request at gcbm/new. To access the results of the existing simulations, create a request at gcbm/download.",
}, 200
return (
{
"data": list,
"message": "To create a new simulation, create a request at gcbm/new. To access the results of the existing simulations, create a request at gcbm/download.",
},
200,
)


@app.route("/gcbm/status", methods=["POST"])
Expand Down
84 changes: 84 additions & 0 deletions local/rest_api_gcbm/curl.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,90 @@ A file named `output.zip` will be obtained. This file contains the outputs gener
curl -d "title=run4" -X POST http://localhost:8080/gcbm/download -L -o run4.zip
```

### Get Config mean annual temperature moja file

| **Method** | **Endpoint** | **Response code** |
| ---------- | ----------------- | ----------------- |
| POST | `/gcbm/getConfig` | 200 OK (Success) |

```
curl -F file_name="mean_annual_temperature_moja" \
-F title="run4" \
http://localhost:8080/gcbm/getConfig
```

Expected response (Success):

```json
{"data":{
"blockLatSize":0.1,"blockLonSize":0.1,"cellLatSize":0.00025,
"cellLonSize":0.00025,"layer_data":"Float32","layer_type":"GridLayer",
"nodata":32767.0,"tileLatSize":1.0,"tileLonSize":1.0
}
}
```

### Get Config internal_variables file

| **Method** | **Endpoint** | **Response code** |
| ---------- | ----------------- | ----------------- |
| POST | `/gcbm/getConfig` | 200 OK (Success) |

```
curl -F file_name="internal_variables" \
-F title="run4" \
http://localhost:8080/gcbm/getConfig
```

Expected response (Success):

```json
{"data":{
"Variables":{
"LandUnitId":-1,"LocalDomainId":1,"age":0,"age_class":0,"blockIndex":0,
"cellIndex":0,"classifier_set":{},"current_land_class":"FL","historic_land_class":"FL",
"is_decaying":true,"is_forest":true,"landUnitArea":0,"landUnitBuildSuccess":true,
"localDomainId":0,"peatlandId":-1,"regen_delay":0,"run_delay":false,"run_moss":false,
"run_peatland":false,"simulateLandUnit":true,
"spatialLocationInfo":{
"flintdata":{"library":"internal.flint","settings":{},"type":"SpatialLocationInfo"}
},
"spinup_moss_only":false,"tileIndex":0,"unfccc_land_class":"UNFCCC_FL_R_FL"
}
}
}
```


### Get Config localdomain file

| **Method** | **Endpoint** | **Response code** |
| ---------- | ----------------- | ----------------- |
| POST | `/gcbm/getConfig` | 200 OK (Success) |

```
curl -F file_name="localdomain" \
-F title="run4" \
http://localhost:8080/gcbm/getConfig
```

Expected response (Success):

```json
{"data":{"Libraries":{"moja.modules.cbm":"external","moja.modules.gdal":"external"},
"LocalDomain":{"end_date":"2021/01/01","landUnitBuildSuccess":"landUnitBuildSuccess",
"landscape":{"num_threads":4,"provider":"RasterTiled",
"tile_size_x":1.0,"tile_size_y":1.0,
"tiles":[{"index":12674,"x":-106,"y":55}],
"x_pixels":4000,"y_pixels":4000},
"sequencer":"CBMSequencer","sequencer_library":"moja.modules.cbm",
"simulateLandUnit":"simulateLandUnit","start_date":"2010/01/01",
"timing":"annual","type":"spatial_tiled"}}}
```

### List all of the simulations

| **Method** | **Endpoint** | **Response code** |
Expand Down

0 comments on commit 93002b5

Please sign in to comment.