Skip to content

feat: generate hazard descriptions programmatically #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 29, 2024

Conversation

ciaransweet
Copy link

What this PR is

  • Undoes some model description changes as we haven't touched those indicators
  • Refactors days_tas_above.py and degree_days.py to have a generate_description function
  • Adds the relevant source datasets description to the indicator description
  • Adds the periods for which an indicator is generated, based on its scenarios and other parameters

How you can test it

You should be able to run the workflow:

$ cwltool hazard_workflow.cwl#produce-hazard-indicator input.yml

Where input.yml contains:

source_dataset: UKCP18
source_dataset_kwargs: "{'resolution':'60km','domain':'uk'}"
scenario_list: "[rcp85]"
gcm_list: "[ukcp18]"
threshold_list: "[20,25,28,30,32,35,40,45,50,55]"
central_year_list: "[2030,2040,2050,2060,2070,2080,2090]"
central_year_historical: 2005
window_years: 20
inventory_format: "all"
write_xarray_compatible_zarr: true
store: "./indicator"
indicator: "days_tas_above_indicator"
ceda_ftp_username: username
ceda_ftp_url: "ftp.ceda.ac.uk"
ceda_ftp_password: "password"

And you should see a description like:

"Days per year for which the average near-surface temperature 'tas' is above a threshold specified in \u00b0C.\n\n$$\nI =  \\frac{365}{n_y} \\sum_{i = 1}^{n_y} \\boldsymbol{\\mathbb{1}}_{\\; \\, T^{avg}_i > T^\\text{ref}} \\nonumber\n$$\n\n$I$ is the indicator, $T^\\text{avg}_i$ is the daily average near-surface temperature for day index $i$ in \u00b0C, $n_y$ is the number of days in the year\nand $T^\\text{ref}$ is the reference temperature.\n\nUK Climate Projections (UKCP) by the [Met Office Hadley Centre](https://www.metoffice.gov.uk/research/approach/collaboration/ukcp), sourced from the [Centre for Environmental Data Analysis (CEDA)](http://catalogue.ceda.ac.uk/?q=ukcp18&record_types=Observation&sort_by=relevance). Projections until 2080 on global (60km), regional (12km) and local (5km and 2.2km) scales, for a high emissions scenario, RCP8.5.\n\nIndicators are generated for periods: 2030 (2020-2040), 2040 (2030-2050), 2050 (2040-2060), 2060 (2050-2070), 2070 (2060-2080), 2080 (2070-2090), and 2090 (2080-2100)."

This was from chronic_heat_osc_v2_days_tas_above_20c_ukcp18_rcp85_2030.json for example

Diff here: https://www.diffchecker.com/l3fUzyxc/ - The degree symbol changes are just because the 'before' was copy and pasted from elsewhere, the degree symbol still renders fine in the 'after'.

@ciaransweet ciaransweet force-pushed the source-data-descriptions branch from 15d67f8 to 9f407fb Compare August 29, 2024 09:52
@ciaransweet ciaransweet requested a review from j08lue August 29, 2024 10:14
@ciaransweet
Copy link
Author

Diff will be slightly out as I had to fix the UKCP18 years, but it's close enough.

@ciaransweet
Copy link
Author

ciaransweet commented Aug 29, 2024

Before

image

After

image

Example of the changes on the frontend

Copy link
Member

@j08lue j08lue left a comment

Choose a reason for hiding this comment

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

Dynamically generating the hazard indicator descriptions based on source and parameters is a great improvement that may make the descriptions even more valuable to downstream applications.

Clean implementation and the generate descriptions read well. 👌

@ciaransweet ciaransweet merged commit 34a6c43 into main Aug 29, 2024
3 checks passed
@ciaransweet ciaransweet deleted the source-data-descriptions branch August 29, 2024 13:22
ciaransweet added a commit that referenced this pull request Aug 29, 2024
ciaransweet added a commit that referenced this pull request Sep 2, 2024
* Modify workflow into `hazard_workflow.cwl` (#9)

Signed-off-by: Ciaran Sweet <[email protected]>

* feat: allow to write inventory for (stac, osc, all) and expose xarray output (#10)

* feat: allow to write inventory for (stac, osc, all) and expose xarray output

* Use latest image

Signed-off-by: Ciaran Sweet <[email protected]>

* Enable more UKCP18 resolutions and expose dataset kwargs (#11)

* feat: support more UKCP18 resolutions

* feat: add source_dataset_kwargs to cwl

* feat: support eur 12km

* feat: fetch crs from .nc file

Signed-off-by: Ciaran Sweet <[email protected]>

* fix: undo change to default threshold value (#12)

Signed-off-by: Ciaran Sweet <[email protected]>

* Separate source data information from model information (#13)

Signed-off-by: Jonas <[email protected]>

* fix: improvements after generating UKCP18 indicators

---------

Signed-off-by: Ciaran Sweet <[email protected]>

* feat: update hazard cwl input example (#15)

Signed-off-by: Ciaran Sweet <[email protected]>

* feat: generate hazard descriptions programmatically (#16)

Signed-off-by: Ciaran Sweet <[email protected]>

---------

Signed-off-by: Ciaran Sweet <[email protected]>
Signed-off-by: Jonas <[email protected]>
Co-authored-by: Jonas <[email protected]>
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