Anyone that reads this blog knows that I use iris a lot. Still, every now and then I get bitten by some iris quirkiness. This post is to explain on of those quirkiness that a lot of my colleagues, myself included, like to rant about: "How to load a cube?!"
import iris
url = ('http://hfrnet.ucsd.edu/thredds/dodsC/HFR/USWC/6km/hourly/GNOME/'
'HFRADAR,_US_West_Coast,_6km_Resolution,_Hourly_RTV_(GNOME)_best.ncd')
It is only natural to use load_cubes
to load your cubes, right?
cubes = iris.load_cubes(url)
Apparently not!
(And you have to love when the error messages are cryptic ;-)
Time to read the docs! From the docstring
(the online docs are better BTW):
iris.load_cubes
:: Loads exactly one Cube for each constraint.iris.load
:: Loads any number of Cubes for each constraint.iris.load_raw
:: Loads non-merged cubes.
OK, I admit. This confusion looks a lot like the PERL TIMTOWTDI philosophy and I do not like. I try to follow the rule:
There should be one -- and preferably only one -- obvious way to do it.
However, I see the appeal for at least load_raw()
and, even though the docs
do not recommend it, I use it a lot. Let's see what is going on with that
dataset using load_raw()
.
cubes = iris.load_raw(url)
print(cubes)
One of those cubes is not OK with the rule "exactly one Cube for each constraint." What constraint? We did not specify anything!
for cube in cubes:
standard_name = cube.standard_name
print(standard_name)
I guess the issue is the None
as standard_name
. Iris is OK loading them using the long_name
though.
print(iris.load_cube(url, 'RTV processing parameters'))
And OK with load
(Any number of Cubes for each constraint).
cubes = iris.load(url)
print(cubes)
In conclusion? Stick with either load
or load_raw
when you do not want to
be strict about loading.
HTML(html)