Skip to content

Standardize country codes iso 3166#159

Open
ram-from-tvl wants to merge 10 commits intoopenclimatefix:mainfrom
ram-from-tvl:standardize-country-codes-iso-3166
Open

Standardize country codes iso 3166#159
ram-from-tvl wants to merge 10 commits intoopenclimatefix:mainfrom
ram-from-tvl:standardize-country-codes-iso-3166

Conversation

@ram-from-tvl
Copy link
Copy Markdown
Contributor

Pull Request

Description

This PR standardizes all country codes in the solar-consumer project to follow the ISO 3166-1 alpha-3 standard, as requested in issue #157.

Changes made:

Old Code New Code Country
gb gbr_gb Great Britain (excluding Northern Ireland)
nl nld Netherlands
de deu Germany
be bel Belgium
ind_rajasthan ind_rj India – Rajasthan

Files updated:

  • fetch_data.py — Updated country code dict keys, default parameter, docstring, and error message
  • app.py — Updated all country conditionals, default parameters, docstring, and os.getenv default
  • save_data_platform.py — Updated default parameter, docstring, and all country comparisons/comments
  • save_site_database.py — Updated all country comparisons, default parameters, docstrings, and error messages
  • test_fetch_data.py — Updated country= argument in GB historic tests
  • test_save_forecast.py — Updated country= argument for NL and India tests
  • test_save_nl_to_data_platform.py — Updated country= argument
  • README.md — Updated COUNTRY environment variable documentation
  • .example.env — Updated default COUNTRY value and available options comment

Only country code parameter strings were changed. No data-level identifiers (e.g. "nl_national" site names, "Belgium" region names from the Elia API) were modified — these are data values, not country code parameters.

Fixes #157

Checklist:

  • My code follows OCF's coding style guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works (updated existing tests with new country codes)
  • I have checked my code and corrected any misspellings

Copilot AI review requested due to automatic review settings February 9, 2026 05:19
@ram-from-tvl
Copy link
Copy Markdown
Contributor Author

Hi @peterdudfield
I have made changes for country codes standardization.
Please review it and let me know if we are good to go.
Thank you!

@ram-from-tvl
Copy link
Copy Markdown
Contributor Author

All tests have passed.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to standardize country code parameters across the solar-consumer project to ISO 3166-1 alpha-3-style codes (with special handling like gbr_gb), updating application defaults, dispatch logic, and tests/docs accordingly.

Changes:

  • Updated country-code parameters/defaults across fetch, save, and app orchestration paths (e.g. gb→gbr_gb, nl→nld, de→deu, be→bel, ind_rajasthan→ind_rj).
  • Updated unit/integration tests to use the new country code strings.
  • Updated user-facing documentation and example environment configuration to reflect the new codes.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
solar_consumer/fetch_data.py Updates default country and dispatch table keys to new codes; updates docstrings/messages.
solar_consumer/app.py Updates default country and country→model_tag mapping to new codes.
solar_consumer/save/save_data_platform.py Updates default country and NL/GB branching comparisons to new codes.
solar_consumer/save/save_site_database.py Updates defaults and country comparisons/docstrings for site-db saving logic.
solar_consumer/data/fetch_gb_data.py Adds fallback logic for missing GSPs (DB-backed) and adjusts handling of empty GSP frames.
tests/unit/test_fetch_data.py Updates GB historic tests to call fetch_data(..., country="gbr_gb").
tests/unit/test_save_forecast.py Updates NL and India country args used in save tests.
tests/integration/test_save_nl_to_data_platform.py Updates NL integration test to use country="nld".
README.md Updates COUNTRY env var docs to new codes.
.example.env Updates default COUNTRY value and comment options list.
Comments suppressed due to low confidence (1)

solar_consumer/save/save_data_platform.py:56

  • save_generation_to_data_platform treats any country other than "nld" as the GB branch. Now that the application supports other country codes (e.g. "deu", "bel", "ind_rj"), calling this with those values (e.g. via app.py when SAVE_METHOD=data-platform) will incorrectly assume GB columns like gsp_id/regime exist and can fail or silently write bad data. Add explicit validation (raise for unsupported countries) or implement dedicated branches per supported country.
    # 0. Create the observers required if they don't exist already
    if country == "nld":
        required_observers = {"nednl"}
        id_key = "region_id"
        capacity_col = "capacity_kw"
        capacity_multiplier = 1000
    else:  # gbr_gb
        required_observers = {"pvlive_in_day", "pvlive_day_after"}
        id_key = "gsp_id"
        capacity_col = "capacity_mwp"
        capacity_multiplier = 1e6


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 69 to 76
If `capacity_override_kw` is provided, that value will be used when creating the site.
For Germany, the TSO’s known capacity is used if no override is given. For NL, default 20GW applied

Parameters:
session (Session): CurrentSQLAlchemy session
pvsite (PVSite): Pydantic model with site metadata
country (str): Country code ('nl' or 'de')
country (str): Country code ('nld' or 'deu')
capacity_override_kw (Optional[int]): Force a specific capacity on creation
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

The get_or_create_pvsite docstring says country is ('nld' or 'deu'), but the function is also used for India Rajasthan via save_generation_to_site_db(... country="ind_rj"). Update the docstring (and/or the capacity-selection comment) to include the supported ind_rj code so callers know it’s valid.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ram-from-tvl check can we please check this i think we can update the doc string here

README.md Outdated

- `DB_URL=postgresql://postgres:postgres@localhost:5432/neso_solar` : Database Configuration
- `COUNTRY="gb"` : Country code for fetching data. Currently, other options are ["be", "ind_rajasthan", "nl"]
- `COUNTRY="gbr_gb"` : Country code for fetching data. Currently, other options are ["bel", "ind_rj", "nld"]
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

README COUNTRY documentation lists other options as ["bel", "ind_rj", "nld"], but the application also supports Germany ("deu") (see app.py country→model_tag mapping and fetch_data dispatch table). Update the README options list to include "deu" (and any other supported codes) to avoid misconfiguration.

Suggested change
- `COUNTRY="gbr_gb"` : Country code for fetching data. Currently, other options are ["bel", "ind_rj", "nld"]
- `COUNTRY="gbr_gb"` : Country code for fetching data. Currently, other options are ["bel", "deu", "ind_rj", "nld"]

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ram-from-tvl can we update the README as wel?

@peterdudfield
Copy link
Copy Markdown
Contributor

@katyalmohit and @pavankulkarni007 could you review this?

@ram-from-tvl
Copy link
Copy Markdown
Contributor Author

Hi @peterdudfield
Should i be commiting all the Copilot generated comments before review.
Thank you!

@peterdudfield
Copy link
Copy Markdown
Contributor

Hi @peterdudfield Should i be commiting all the Copilot generated comments before review. Thank you!

Up to you, if you think they are good, use them. If you dont think they are good, perhaps reject them

ram-from-tvl and others added 2 commits February 16, 2026 22:05
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Reverts fetch_gb_data.py to upstream state. The backup GSP data logic
(DB_URL lookup, LocationSQL queries, national->GSP data synthesis) falls
outside the scope of the country-code standardization issue (openclimatefix#157).
This will be addressed in a separate PR.
@ram-from-tvl
Copy link
Copy Markdown
Contributor Author

ram-from-tvl commented Feb 17, 2026

Hey @PavanRaghavendraKulkarni,

You're right. the backup GSP data logic was out of scope for this PR. I've now:

  1. Removed the out-of-scope fetch_gb_data.py changes from this PR (commit 8e53981). This PR now only contains the country-code standardization changes as described.

  2. Moved the backup GSP data feature to a separate branch: feature/backup-gsp-data-from-national in a separate PR Add backup GSP data synthesis from national data when GSPs are missing #163

Thanks for the review feedback!

Comment on lines 69 to 76
If `capacity_override_kw` is provided, that value will be used when creating the site.
For Germany, the TSO’s known capacity is used if no override is given. For NL, default 20GW applied

Parameters:
session (Session): CurrentSQLAlchemy session
pvsite (PVSite): Pydantic model with site metadata
country (str): Country code ('nl' or 'de')
country (str): Country code ('nld' or 'deu')
capacity_override_kw (Optional[int]): Force a specific capacity on creation
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ram-from-tvl check can we please check this i think we can update the doc string here

README.md Outdated

- `DB_URL=postgresql://postgres:postgres@localhost:5432/neso_solar` : Database Configuration
- `COUNTRY="gb"` : Country code for fetching data. Currently, other options are ["be", "ind_rajasthan", "nl"]
- `COUNTRY="gbr_gb"` : Country code for fetching data. Currently, other options are ["bel", "ind_rj", "nld"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ram-from-tvl can we update the README as wel?

@ram-from-tvl
Copy link
Copy Markdown
Contributor Author

ram-from-tvl commented Feb 18, 2026

@PavanRaghavendraKulkarni Thanks for the review! I've addressed both unresolved comments:

  1. save_site_database.py - Updated the get_or_create_pvsite docstring to include 'ind_rj' alongside 'nld' and 'deu' as supported country codes.
  2. README.md - Added "deu" to the COUNTRY environment variable options list.

ram-from-tvl added 2 commits February 18, 2026 17:09
- Updated get_or_create_pvsite docstring to include 'ind_rj' as supported country code
- Added 'deu' to README COUNTRY environment variable options list
- Resolved conflicts in save_data_platform.py: accepted upstream's refactored
  config-driven structure, applied ISO 3166 country codes (nl→nld, be→bel, gb→gbr_gb)
- Accepted upstream deletion of test_save_nl_to_data_platform.py (replaced by
  test_save_nl_and_be_to_data_platform.py)
- Updated locations.csv country_code column: nl→nld, be→bel
- Updated test_save_nl_and_be_to_data_platform.py with new country codes
- Updated test_save_be_generation_unit.py with new country codes
@PavanRaghavendraKulkarni
Copy link
Copy Markdown
Contributor

@ram-from-tvl PR lGTM! please resolve the merge conflicts

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.

Standardise countries ISO_3166-1_alpha-3

4 participants