Skip to content
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

Bias adjusted precip #3202

Merged
merged 11 commits into from
Nov 1, 2023
Merged

Bias adjusted precip #3202

merged 11 commits into from
Nov 1, 2023

Conversation

dgboss
Copy link
Collaborator

@dgboss dgboss commented Oct 30, 2023

  • Add bias_adjusted_precip_24h to WeatherModelStationPredictions and the materialized view
  • Add crud functions to get actual and predicted 24 hour precip
  • Add PrecipModel class for handling precip specific linear regression (a unique add_samples() function is required

Test Links:

Landing Page
MoreCast 2.0
Percentile Calculator
MoreCast
C-Haines
FireBat
FireBat bookmark
Auto Spatial Advisory (ASA)
HFI Calculator

@dgboss dgboss requested review from conbrad and brettedw October 30, 2023 23:27
stmt = """
SELECT day, station_code, sum(precipitation) actual_precip_24h
FROM
generate_series(\'{}\', \'{}\', '24 hours'::interval) day
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not familiar with this syntax, but is this creating a series of days based on 24 hour intervals, then selecting each weather date based on it's hour being less than the subset of the series, then summing up the precip based on the hourly actuals that fit in that window? (There's probably a better way of expressing this in English)...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have/need an index on hourly_actuals.weather_date for this query?

Copy link
Collaborator Author

@dgboss dgboss Oct 31, 2023

Choose a reason for hiding this comment

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

Haha, you have the gist of it. I'm glad you asked this question, I think I found an off-by-one day logic error.

I'll add to the comment with a description of what this is doing.

generate_series(\'{}\', \'{}\', '24 hours'::interval)
This gives us a one column table of dates separated by 24 hours between the start and end dates. For example, if start and end dates are 2023-10-31 20:00:00 to 2023-11-03 20:00:00 we would have a table like:

day
2023-10-31 20:00:00
2023-11-01 20:00:00
2023-11-02 20:00:00
2023-11-03 20:00:00

We then join the HourlyActuals table so that we can sum hourly precip in a 24 hour period. The join is based on the weather_date field in the HourlyActuals table being in a 24 hour range using this odd looking syntax:

weather_date <@ tstzrange(day, day + '24 hours', '(]')

Using 2023-10-31 20:00:00 as an example, rows with the following dates would match. The (] syntax means the lower bound is excluded but the upper bound is included.

2023-10-31 21:00:00
2023-10-31 22:00:00
2023-10-31 23:00:00
2023-11-01 00:00:00
2023-11-01 01:00:00
....
2023-11-01 19:00:00
2023-11-01 20:00:00

My off by one error is that right now I am attributing this accumulated precipitation to October 31, but it should actually be for Nov 1 (we need the preceding 24 hour precip).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

An index on weather_date is a great idea!

api/app/weather_models/machine_learning.py Show resolved Hide resolved
api/app/weather_models/precip_model.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Oct 31, 2023

Codecov Report

Merging #3202 (d2da018) into main (2b7fd60) will decrease coverage by 0.11%.
Report is 1 commits behind head on main.
The diff coverage is 89.15%.

@@            Coverage Diff             @@
##             main    #3202      +/-   ##
==========================================
- Coverage   82.16%   82.05%   -0.11%     
==========================================
  Files         272      274       +2     
  Lines        9240     9301      +61     
  Branches      413      413              
==========================================
+ Hits         7592     7632      +40     
- Misses       1535     1557      +22     
+ Partials      113      112       -1     
Files Coverage Δ
api/app/db/models/weather_models.py 97.43% <100.00%> (+0.04%) ⬆️
api/app/weather_models/__init__.py 92.06% <100.00%> (-1.59%) ⬇️
api/app/weather_models/fetch/predictions.py 77.77% <100.00%> (ø)
api/app/weather_models/regression_model.py 100.00% <100.00%> (ø)
api/app/weather_models/wind_direction_model.py 100.00% <100.00%> (ø)
.../features/moreCast2/components/MoreCast2Column.tsx 93.47% <100.00%> (ø)
api/app/jobs/common_model_fetchers.py 57.47% <0.00%> (-0.34%) ⬇️
api/app/weather_models/utils.py 90.00% <90.00%> (ø)
api/app/weather_models/weather_models.py 97.95% <94.44%> (-2.05%) ⬇️
api/app/weather_models/machine_learning.py 90.76% <92.00%> (-0.14%) ⬇️
... and 1 more

... and 3 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link

sonarcloud bot commented Oct 31, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@dgboss dgboss temporarily deployed to production November 1, 2023 16:55 Inactive
@dgboss dgboss merged commit b781237 into main Nov 1, 2023
28 checks passed
@dgboss dgboss deleted the story/bias-adjusted-precip-final/2816 branch November 1, 2023 17:22
vanislekahuna pushed a commit to vanislekahuna/wps that referenced this pull request Sep 19, 2024
Co-authored-by: Conor Brady <con.brad@gmail.com>
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