Skip to content

Add more intuitive unit specification when creating Hazard object via attrs keyword#1287

Open
ChrisFairless wants to merge 8 commits intodevelopfrom
fix-haz-creation-with-attrs
Open

Add more intuitive unit specification when creating Hazard object via attrs keyword#1287
ChrisFairless wants to merge 8 commits intodevelopfrom
fix-haz-creation-with-attrs

Conversation

@ChrisFairless
Copy link
Copy Markdown
Collaborator

The Hazard.from_raster method allows you to specify an attrs dictionary that are passed to the created Hazard's __init__ method. It behaves differently from a normal kwargs argument in that the attributes are processed and "sensible defaults" are provided when they are missing.

The issues

  • The "units" parameter in the __init__ method has to be specified through "unit", and this isn't explained anywhere
  • There's no easy way to see what attributes are accepted

This commit

  • allows you to set the units with either 'unit' or 'units' with 'units' taking priority
  • adds an ATTRS_TO_CHECK constant to the hazard module's io.py so that the user can see what is supported in the source code (and removes a comment that suggests doing this)
  • updates the documentation

PR Author Checklist

PR Reviewer Checklist

climada-jenkins and others added 4 commits September 30, 2025 09:52
* ci: Add job for Mamba installation
* ci: Import CLIMADA in bash and powershell
* ci: Run impact test when testing the installation
… attrs keyword

The Hazard.from_raster method allows you to specify an `attrs` dictionary to set
additional parameters in the created Hazard's `__init__` method.

This commit
- allows you to set both 'unit' and 'units' which will be used as the 'units' parameter
when the Hazard object is created, with 'units' taking priority. Currently only 'unit' is
accepted which is very counterintuitive, since all other attributes are exactly as
specified in the `__init__`
- adds an ATTRS_TO_CHECK constant to the hazard module's io.py so that the user can see
what is supported in the source code (and removes a comment that suggests doing this).
- updates the documentation
- Allow event names that are integers (some test files have integer names)
- even though this is NOT ALLOWED
- Allow core or numpy integers/booleans/strings
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.

3 participants