1
-
1
+ #!/usr/bin/python
2
+ # Filename: example_ocean.py
3
+ #
4
+ # Code by Martin Jucker, distributed under an MIT License
5
+ # Any publication benefitting from this piece of code should cite
6
+ # Jucker, M 2014. Scientific Visualisation of Atmospheric Data with ParaView.
7
+ # Journal of Open Research Software 2(1):e4, DOI: http://dx.doi.org/10.5334/jors.al
8
+
9
+ # define a helper function for adjusting ocean bathymetry (topography) aspect ratio and color scheme
2
10
def transformTopo (src = GetActiveSource (),moveXFunction = '' ):
3
11
depth = Calculator (src )
4
12
depth .Function = 'iHat*(coordsX' + moveXFunction + ') + jHat*coordsY - kHat*abs(' + str (depthVar )+ ')'
@@ -23,6 +31,7 @@ def transformTopo(src=GetActiveSource(),moveXFunction=''):
23
31
24
32
#########
25
33
34
+ #import pv_atmos
26
35
try :
27
36
from atmos_basic import *
28
37
from atmos_grids import *
@@ -32,12 +41,15 @@ def transformTopo(src=GetActiveSource(),moveXFunction=''):
32
41
execfile (pvAtmosPath + 'atmos_grids.py' )
33
42
34
43
## show me where the files are ##
44
+ # path to ocean files
35
45
oceanPath = './'
36
46
47
+ # file containing bathymetry
37
48
topoFile = 'ocean_depth.nc'
38
49
topoDims = ['rlon' ,'rlat' ]
39
50
depthVar = 'deptho'
40
51
52
+ # file containing oxygen data
41
53
dataFile = 'ocean_o2.nc'
42
54
dataDims = ['xt_ocean' ,'yt_ocean' ,'st_ocean' ]
43
55
# the values we will be interested in
@@ -46,21 +58,21 @@ def transformTopo(src=GetActiveSource(),moveXFunction=''):
46
58
47
59
## how would you like the transformation to work ##
48
60
logCoord = [] #no logarithmic coordinates
49
- aspRat = [1 ,1 ,0.01 ]
61
+ aspRat = [1 ,1 ,0.01 ] # divide bathymetry by 100
50
62
51
63
52
64
### get the data ###
53
65
54
- # topography
66
+ # bathymetry
55
67
(depth_out ,depth_coor )= LoadData (oceanPath + topoFile ,ncDims = topoDims ,logCoords = logCoord )
56
- # get the bounds of the topography
68
+ # get the bounds of the topography. This is important if bathymetry and data files have different origins
57
69
topoBds = depth_out .GetDataInformation ().GetBounds ()
58
70
59
71
# data
60
72
(o2_out ,o2_coor )= LoadData (oceanPath + dataFile ,ncDims = dataDims ,aspectRatios = aspRat ,logCoords = logCoord )
61
73
# we want to replace the fill values with NaNs here
62
74
o2_out .ReplaceFillValueWithNan = 1
63
- # get the bounds of the data file
75
+ # get the bounds of the data file. Again important if different from bathymetry files
64
76
dataBds = o2_out .GetDataInformation ().GetBounds ()
65
77
# instead of NaNs, there are -1e10 values in this file that we don't want
66
78
o2_thresh = Threshold (o2_coor ,ThresholdRange = [0 ,1 ])
@@ -70,7 +82,7 @@ def transformTopo(src=GetActiveSource(),moveXFunction=''):
70
82
c2p = CellDatatoPointData (depth_coor )
71
83
MakeSelectable ()
72
84
73
- ### see if we have to move the topography file to align it with the data file
85
+ ### see if we have to move the bathymetry file to align it with the data file
74
86
### this is not necessary with the provided files, but might be with other files
75
87
swapTopo = False
76
88
if topoBds [0 ] != dataBds [0 ] or topoBds [1 ] != dataBds [1 ]:
@@ -101,7 +113,7 @@ def transformTopo(src=GetActiveSource(),moveXFunction=''):
101
113
swapTopo = True
102
114
103
115
104
- ### work on the topography #####
116
+ ### work on the bathymetry #####
105
117
106
118
if swapTopo :
107
119
transformTopo (moveClip ,moveXFunction )
0 commit comments