... | ... | @@ -344,6 +344,39 @@ my\_cube.collapsed(\[\'latitude\', \'longitude\'\],MEAN, |
|
|
weights=grid\_areas) \#This does the clever maths to work out the grid
|
|
|
box areas
|
|
|
|
|
|
Example below:
|
|
|
|
|
|
```
|
|
|
import iris
|
|
|
import iris.quickplot as qplt
|
|
|
import matplotlib.pyplot as plt
|
|
|
from iris import *
|
|
|
from iris.analysis import *
|
|
|
from iris.analysis.cartography import *
|
|
|
|
|
|
|
|
|
my_cube = iris.load_cube('/data/local_ssd/cj362/S2P3Rv2.0/dhw/MIROC6_ssp245_1970_2100_surfacetemperature_all.nc')
|
|
|
|
|
|
#plot the 1st (0th) day of data as a map
|
|
|
qplt.pcolormesh(my_cube[0])
|
|
|
plt.savefig('test.png')
|
|
|
plt.show()
|
|
|
|
|
|
#note, I've just sepected a subset of the time steps here (1st 1000 days) otherwise it takes for ever.
|
|
|
my_cube = my_cube[0:1000]
|
|
|
|
|
|
#averaging the data over an area, based on the example script on the wiki
|
|
|
my_cube.coord('latitude').guess_bounds()
|
|
|
my_cube.coord('longitude').guess_bounds()
|
|
|
grid_areas = area_weights(my_cube)
|
|
|
average_variable = my_cube[0:1000].collapsed(['latitude', 'longitude'],MEAN,weights=grid_areas)
|
|
|
|
|
|
#plot the timeseries:
|
|
|
qplt.plot(average_variable)
|
|
|
plt.savefig('test2.png')
|
|
|
plt.show()
|
|
|
```
|
|
|
|
|
|
### Writing a script
|
|
|
|
|
|
see week 1 practical: [Week 1 An introduction to scientific
|
... | ... | @@ -535,36 +568,7 @@ results\_array = seawater.dens(salinity\_data,temperature\_data,1) |
|
|
|
|
|
e.g.
|
|
|
|
|
|
```
|
|
|
import iris
|
|
|
import iris.quickplot as qplt
|
|
|
import matplotlib.pyplot as plt
|
|
|
from iris import *
|
|
|
from iris.analysis import *
|
|
|
from iris.analysis.cartography import *
|
|
|
|
|
|
|
|
|
my_cube = iris.load_cube('/data/local_ssd/cj362/S2P3Rv2.0/dhw/MIROC6_ssp245_1970_2100_surfacetemperature_all.nc')
|
|
|
|
|
|
#plot the 1st (0th) day of data as a map
|
|
|
qplt.pcolormesh(my_cube[0])
|
|
|
plt.savefig('test.png')
|
|
|
plt.show()
|
|
|
|
|
|
#note, I've just sepected a subset of the time steps here (1st 1000 days) otherwise it takes for ever.
|
|
|
my_cube = my_cube[0:1000]
|
|
|
|
|
|
#averaging the data over an area, based on the example script on the wiki
|
|
|
my_cube.coord('latitude').guess_bounds()
|
|
|
my_cube.coord('longitude').guess_bounds()
|
|
|
grid_areas = area_weights(my_cube)
|
|
|
average_variable = my_cube[0:1000].collapsed(['latitude', 'longitude'],MEAN,weights=grid_areas)
|
|
|
|
|
|
#plot the timeseries:
|
|
|
qplt.plot(average_variable)
|
|
|
plt.savefig('test2.png')
|
|
|
plt.show()
|
|
|
```
|
|
|
|
|
|
##### Extracting horizontal slices from a cube (e.g. at a given depth)
|
|
|
|
... | ... | |