Jupyter Notebooks FAQ

Here is a compilation of questions and issues that arose during the Jupyter Notebooks session of the Python Tutorial Seminar Series.

Q. I installed Miniconda but it doesn’t seem to be working. conda is not a recognized command. What should I do?

A. This is possible if Miniconda is not visible from your workspace, according to the Conda trouble shooting site this happens if you answered “NO” instead of “YES” when asked if you’d like to prepend the conda prompt to your path. You have two options:

  1. Manually edit your (hidden) .baschrc file to include the line:

     export PATH=/Users/your-username/anaconda3/bin:$PATH
  2. Try uninstalling and re-installing Conda, making sure to answer “YES” this time,

Read more…

Numpy Tutorial

The NCAR/UCAR virtual Python Tutorial Seminar Series continues with an introduction to the Python package numpy on Wednesday, March 10th at 1 PM Mountain. This session will be led by Austin Kootz.


  1. Check your conda install if this is the first tutorial in the series you are joining us for with conda --version and if necessary install by following these instructions
  2. Activate your tutorial environment from the last session on Jupyter notebooks with conda activate jupyter_tutorial
  3. Install numpy and matplotlib with conda install numpy matplotlib

Read more…

Your First Package Python Tutorial FAQ

Here is a compilation of questions from the fourth and fifth sessions ("Your First Package") of the Python Tutorial Seminar Series which covered refactoring code into seperate modules and packages, using an external built-in module (math), and how to publish your package

Q. Should we add __init__.py to .gitignore?

A. We do not advise that. __init__.py is a special file that needs to be in that directory for Python to know to treat that directory like a Python package. So you need it even though it is, in this case, an empty file.

Whenever you do an import of a module, that module is executed. So if you’ve defined variables or run code in that file - at import time, that code will be executed. Modules tend to only contain function definitions or the construction of data or classes, so that at import time these definitions are available to us without. __init__.py works much the same way. Whenever you import something from a package its __init__.py will be executed. Since we don’t need anything done, in our situation, it is empty.

Read more…

Python Tutorial FAQ - Part 3

Here is a compilation of questions from the third session of the Python Tutorial Seminar Series which covered writing functions as well as f-string formatting.

Q. Seeing how 2/2 returns 1.0 instead of 1, is the numeric type automatically determined from the inputs or do you have to force it?

A. The numeric type is inferred. / always returns a float for numeric types. // always returns an integer.

One should note that Python 2 does not behave this way. In Python 2, the // operator does not exist and the / operator behaves like it does in other languages (i.e., division of two integers yields an integer and division with a float yields a float).

Read more…

Python Tutorial FAQ - Part 2

Here is a compilation of questions and issues that arose during the second session of the Python Tutorial Seminar Series, on creating a data dictionary. After this first short series, these FAQ sections will be added to the Xdev tutorial website

Q. Why is list[0:10] the first 10 elements, not 11?

A. In Python, "list slicing" uses square brackets with the syntax [start:stop:step]. The start is inclusive, while the step is exclusive. So, you read up to (but excluding) the stop index.

Read more…

Python Tutorial FAQ

Here is a compilation of questions and issues that arose during the first session of the Python Tutorial Seminar Series. Hopefully all attendees feel that their issues are addressed here.

Q. I am having issues running the command: curl -kO https://sundowner.colorado.edu/weather/atoc8/wxobs20170821.txt. What should I do?

A. If that was your case, try running the above command without the “-kO” option, or try using “wget” instead: wget --no-check-certificate https://sundowner.colorado.edu/weather/atoc8/wxobs20170821.txt.

If you are on Windows and have curl, try: curl https://sundowner.colorado.edu/weather/atoc8/wxobs20170821.txt -OutFile wxobs20170821.txt.

Read more…

Tutorial Seminar Series

Because we are unable to host an in-person tutorial for this fall season, the Xdev team has decided to switch to a virtual seminar series. We will be hosting one hour tutorial sessions scheduled for the 2nd and 4th Wednesdays of each month at 1 PM Mountain starting in October. The first tutorial session, covering how to create your first Python script, will be on October 14th. Some tutorials will be 1-off seminars on specific topics, while others will span multiple seminar sessions.

Read more…

Writing multiple netCDF files in parallel with xarray and dask

A typical computation workflow with xarray consists of:

  1. reading one or more netCDF files into an xarray dataset backed by dask using xr.open_mfdataset() or xr.open_dataset(chunks=...),
  2. applying some transformation to the input dataset, and
  3. saving the resulting output to disk in a netCDF file using xr.to_netcdf().

The last step (3) can easily lead to a large netCDF file (>=10GB in size). As a result, this step can take a very long time to complete (since it is run in serial), and sometimes may hang. So, to avoid these issues one can use one of the lesser-used but helpful xarray capabilities: the xr.save_mfdataset() function.

Read more…

Templating isn't just for Web Developers!

Recently, I found myself rambling on in an unprepared attempt to explain templating to a colleague of mine who had no prior experience with frontend design. It didn't take me long to realize that my explanation was convoluted and confusing, not that I stopped talking, mind you. Attribute that to being unprepared, or sleep deprived (i.e., child still not sleeping through the night!), or just a bad teacher.

Read more…