pythonrainfallhydrologyidfpandasdrainage
Description
Use this when you have daily or sub-daily rainfall records from a station and need a Python script that extracts annual maxima, fits an extreme value distribution and reports return-level estimates for drainage design inputs.
csv_sample is the header and ten to twenty rows of your file, so the script matches your real column names and date format. distribution is Gumbel or GEV. return_periods is the list in years, for example 2, 10, 50, 100. missing_data_rule is how many missing days in a year you will tolerate before excluding that year.
The script is a starting point you read and test, not a design rainfall. It will not decide your design storm, and it warns about short records and trends instead of hiding them. Check the output against your authority's published IDF data.
Prompt
440 words
You are a Python developer helping a civil engineer who works on drainage design. Write a script that estimates return-level rainfall from a station record. The engineer will read, run and check the code, so it must be clear and not clever.
Inputs
CSV header and sample rows: {csv_sample}
Distribution to fit: {distribution}
Return periods in years: {return_periods}
Maximum missing days allowed per year before the year is excluded: {missing_data_rule}
Requirements
1. Use pandas, numpy, scipy and matplotlib only. Python 3.10 or later. One file, with functions and a main block, no classes.
2. Read the CSV using the exact column names and date format visible in the sample. If the sample is ambiguous, for example the date could be day-first or month-first, do not guess: put a clearly named constant at the top and add a comment telling the user to confirm it.
3. Handle missing values and sentinel codes such as -999 or blank cells. List every sentinel you treat as missing in a constant at the top, and print how many values were removed.
4. Define the year. Use a calendar year unless the sample suggests a hydrological year, and make the start month a constant.
5. For each year, count missing days. Exclude years above the allowed limit and print the excluded years. Take the annual maximum from the remaining years.
6. Fit the chosen distribution to the annual maxima. Print the fitted parameters.
7. Compute return levels for each requested return period. Add bootstrap confidence intervals with 1000 resamples and a fixed random seed. Label them clearly as approximate.
8. Print warnings, in plain words, when: fewer than 30 usable years remain, a requested return period is more than twice the record length, or a simple linear trend in the annual maxima has p below 0.05. For the trend warning, say stationarity is questionable and the engineer should consider it. Do not adjust the data for trend.
9. Save two outputs: a CSV of annual maxima with year and value and units, and a PNG with the return level plot, with the annual maxima plotted using Weibull plotting positions.
10. Do not hard-code any rainfall values, and do not add any claim about what design standard applies.
Output format
First, a short list of assumptions you made from the sample. Then the full script in one code block. Then three sample checks the user can run by hand to test it, for example confirming the annual maximum of one named year against the raw file. End with a reminder that the results are estimates to be compared with authority IDF curves before use in design.How to use
Replace {{csv_sample}}, {{distribution}}, {{return_periods}} with your own details before running the prompt. It works best with claude-sonnet-4-6. See more prompts in Coding for related workflows.
Reviews
Loading reviews