Skip to content

Commit b3c586c

Browse files
authored
Merge pull request #99 from UoMResearchIT/92-remove-use-of-conda-in-units-and-quantities
Move conda instructions in units chapter into callouts
2 parents 8346c2d + 58e6687 commit b3c586c

1 file changed

Lines changed: 30 additions & 8 deletions

File tree

episodes/05-units_and_quantities.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ One of the most common problems in physics and the development of physical model
2424

2525
In this lesson we will look at one of the available libraries in python for helping to avoid such problems. This is the [units](https://docs.astropy.org/en/stable/units/index.html) module in the [astropy](https://docs.astropy.org/en/stable/index.html) library.
2626

27-
## Installing a new python library
28-
29-
Following the conda lesson, we install the astropy library using:
30-
31-
```bash
32-
conda install astropy
33-
```
27+
## Importing a module from a python library
3428

3529
The `units` module can then be imported in your scripts using:
3630

@@ -40,6 +34,24 @@ from astropy import units as u
4034

4135
Importing as `u` is not necessary, but it is a common shorthand for this module, and so we'll use it below.
4236

37+
::::::::::::::::::::::::::::::::::::::::: callout
38+
39+
As you are likely using the Jupyter interface to follow this lesson, it is likely that the `astropy` library will already be installed there. If not, then you may encounter an error when running this command. We will go into more detail on installing packages in a later lesson; for now, installing the library will depend on how you set your environment up initially; if you used `pip` (or are in Jupyter and `astropy` doesn't work), then you need to use
40+
41+
```bash
42+
pip install astropy
43+
```
44+
45+
Alternatively, if you installed some form of `conda`, then you can use
46+
47+
```bash
48+
conda install astropy
49+
```
50+
51+
We will go into more detail about `conda` in a later lesson.
52+
53+
::::::::::::::::::::::::::::::::::::::::::::::::::
54+
4355
## Basics
4456

4557
Units can be added to a python variable by multiplying that variable by the unit:
@@ -421,12 +433,22 @@ This is verging on unreadable (as is demonstrated by us having to split a simple
421433

422434
Fortunately there is support for cleaner temperature conversions in the [pint](https://pint.readthedocs.io/en/latest/index.html) package. This has similar functionality to the `astropy.unit` package, but has been built from the ground up with a focus on different aspects. These include unit parsing and standalone unit definitions, uncertainties integration, and (important for our example here), cleaner treatment of temperature units.
423435

424-
Pint can be installed using conda (and the conda-forge channel):
436+
::::::::::::::::::::::::::::::::::::::::: callout
437+
438+
Pint should already be installed if you are using Jupyter; however, as before, if you need to install it yourself, it can be installed using conda (and the conda-forge channel) with:
425439

426440
```bash
427441
conda install -c conda-forge pint
428442
```
429443

444+
or using pip with
445+
446+
```bash
447+
pip install pint
448+
```
449+
450+
::::::::::::::::::::::::::::::::::::::::::::::::::
451+
430452
The unit registry is loaded using:
431453

432454
```python

0 commit comments

Comments
 (0)