Comments (5)
Honestly, 95% of my use of assert
is when writing tests. I used to use them to sanity check conditions in I/O code, but I've replaced that with logging and trying to continue--it's not helpful to users when your assert needlessly causes reading a file to completely crash out a script.
I think assert
does have it's place, but I don't think it's something critically important for scientist programmers to know. Much more important, IMO, is error handling with try...except
and raise
. Also provides an opportunity to introduce them to reading tracebacks... 😉
from python-aos-lesson.
Good point, @dopplershift. From what you've seen of the plot_precipitation_climatology.py
script, are there more authentic/appropriate places we could use assertions? (There's currently three assertions in the final version of the script.)
If we can't think of an appropriate use case for assertions in plot_precipitation_climatology.py
, we could also consider using the example in the Software Carpentry defensive programming lesson. There are some nice post-conditions in that example where assertions check that the calculated result is within sensible bounds.
We could also introduce catching and handling errors using try/except in the defensive programming section?
Note to self: We should also get rid of the rainfall observations loop at the beginning of the defensive programming chapter and just use assert np.min(rainfall_obs) >=0.0
, because we literally just finished the vectorisation chapter where we talk about avoiding loops.
from python-aos-lesson.
For quality controlling code, I believe that assertions can be helpful. Though, I have some suggestions on some of the wording and would also like to suggest another objective.
Oftentimes, meteorologists and oceanographers operationalize their code (run it every day at the same time, for example) to analyze data as it comes in. The assertions can be directed to a log file that tracks the code accuracy (I suggest "accuracy" rather than "reliability" in this context) each time it runs.
Failure to generate a new log file (that may, or may not, include the output from the assertions), or a new entry in the log file, indicates a failure of the code to run. This is oftentimes referred to as "reliable" code.
I would suggest "How can I check my programs' accuracy?" for the lesson question rather than "How can I make my programs more reliable?"
That being said, I would leave both questions and introduce the Objective "Create log files to verify my program's reliability."
As an operational oceanographer who is new to Python, this would be very beneficial to me and my colleagues.
from python-aos-lesson.
"Assert is removed with compiling to optimised byte code (python -o producing *.pyo files)."
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
from python-aos-lesson.
Just FYI to anyone on this thread who might be interested - I've done a re-write of the defensive programming lesson taking on board all your feedback. See #55 for details.
from python-aos-lesson.
Related Issues (20)
- Update 06-github HOT 1
- Finish large data lesson HOT 1
- Add metadata to images HOT 5
- JupyterLab
- Pangeo Binder as a backup
- Use shorter file names?
- Add example of zoomed in lat/lon in addition to the global plot
- Add a map_blocks example
- Add content on Dask task graph and debugging HOT 1
- Create a synthetic large dataset?
- Other options for parallel processing
- New EOS book on Earth Observation Using Python: A Practical Programming Guide HOT 2
- Dead link in the Large Data section HOT 1
- xarray.compute() should return an xarray instance
- conda-forge channel needs full path or can't be added HOT 3
- Expand the vectorisation lesson to "xarray thinking" HOT 1
- Helper script references non-existent data file
- Capturing small changes HOT 2
- Transition to new lesson infrastructure?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-aos-lesson.