Skip to content

Shamba Upgrade#25

Open
tmaabm wants to merge 118 commits intomasterfrom
cirevo/initial-improvements
Open

Shamba Upgrade#25
tmaabm wants to merge 118 commits intomasterfrom
cirevo/initial-improvements

Conversation

@tmaabm
Copy link
Collaborator

@tmaabm tmaabm commented May 2, 2025

In this upgrade of the SHAMBA model, the following changes were made:

  1. Upgrade Python from v2 to v3
  2. Use a Python package manager: poetry
  3. Remove the old GUI and replace it with a modern client-server application.
  4. Enable interactive prompts when running the model using the command line.
  5. Add type annotations to Python functions,
  6. Vectorise most variables.
  7. Convert all variable names to be snake cased instead of camel case.
  8. Add model input validations using marshmallow.
  9. Add flexibility by removing classes and prioritizing functions.
  10. Break large functions/methods into smaller ones.
  11. Fix bugs reported in the BGD report.
  12. Parameterize some inputs, especially in the command line.
  13. Improve the printing to stdout.
  14. Add tests.
  15. Updated the documentation.

N.B

  1. The client-server application is a proof of concept and is not fully functional; e.g. some of the input cannot be defined in the UI.

@tmaabm tmaabm force-pushed the cirevo/initial-improvements branch from 91d0e2d to c8a0bb6 Compare June 4, 2025 13:51
Copy link
Collaborator

@hhughes92 hhughes92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I have not thoroughly reviewed the test files yet)

I have put the GUI feedback on the Projects.civet file.

Perhaps worth discussing the comments: it will certainly be that some of them are for modellers to resolve and some are better handled by devs.

Pipfile Outdated
[dev-packages]

[requires]
python_version = "3.13"

This comment was marked as resolved.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an artifact from an initial attempt to use pipenv. It is no longer needed. I'll remove it

@@ -75,7 +75,7 @@ Then to enable a smooth debugging experience:
4- choose the appropriate Python interpreter in vscode (bottom left in the status bar)
You should choose something like ```Python 3.7.8 64-bit ('myenv':conda)```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to make sure python versions are consistent, where stated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made corrections to this specific issue but I wonder if this README is still relevant. Should we just remove it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so. Any information that's still important can be moved into one of the remaining three READMEs, which should cover everything.

  1. shamba/README.md: what is SHAMBA, links to model description, explains what's in the other READMEs
  2. shamba/shamba/README.md: explains how to set up the environment, run the command_line script, run the UI version
  3. shamba/shamba/client/README.md: explains how to generate the static files for the UI

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[DOCUMENTATION]


#### Run the Server

From the `./server` directory, run the server in _development_ mode: `poetry run fastapi dev main.py`

This comment was marked as resolved.

@@ -0,0 +1,12 @@
# Small-Holder Agriculture Mitigation Benefit Assessment (SHAMBA) project. version 2.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version number tbc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[DOCUMENTATION]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably clean this up to reflect what has been done in this latest update.

Copy link
Collaborator Author

@tmaabm tmaabm Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR's description could be a template but I'm not sure what exactly we want to include/exclude?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do this at the end after modelling tasks are resolved, too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[DOCUMENTATION]

Comment on lines 16 to 17
freq=int(csv_input_data["base_sf_int"]),
qty=float(csv_input_data["base_sf_qty"]),

This comment was marked as resolved.

Comment on lines 22 to 23
freq=int(csv_input_data["proj_sf_int"]),
qty=float(csv_input_data["proj_sf_qty"]),

This comment was marked as resolved.

Comment on lines 30 to 31
litterFreq=int(csv_input_data["base_lit_int"]),
litterQty=float(csv_input_data["base_lit_qty"]),

This comment was marked as resolved.

Comment on lines 35 to 37
litterFreq=int(csv_input_data["proj_lit_int"]),
litterQty=float(csv_input_data["proj_lit_qty"]),
no_of_years=N_YEARS,

This comment was marked as resolved.

from model.common.calculate_emissions import get_int


def test_crop_model():

This comment was marked as resolved.

Copy link
Collaborator

@hhughes92 hhughes92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed climate.py in previous review

from model.common.data_sources.climate import get_climate_data


def validate_list_length(lst):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest this should either be called validated_monthly_list_length and assume length should be 12 or have the intended length as a separate arg? could be used to make sure yearly lists are the length of NUM YEARS

)

# Account for scaling factor in CRU-TS dataset
climate_data *= 0.1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Modellers] Does this apply to every indicator? We are also not using CRU-TS from the new API

return schema.load(params) # type: ignore


def from_csv(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't called anywhere? Care needed on is_evaporation.

climate_data *= 0.1

# Get the number of days in every month
days_in_months = np.array([calendar.monthrange(2000, i)[1] for i in range(1, 13)])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Modellers] Is it correct to use a leap year here?

@hhughes92
Copy link
Collaborator

hhughes92 commented Aug 15, 2025

Update 15/08/25:

  • resolved comments hidden
  • 🚀reaction = comment resolved on HH local branch (waiting for repo permissions to be granted to push)

@tmaabm
Copy link
Collaborator Author

tmaabm commented Aug 20, 2025

@hhughes92 I've merged the other branch to this one. Hopefully there won't be any conflicts with you branch. I recommend you do git rebase as soon as you can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants