<commit_before>
def transformTopo(src=GetActiveSource(),moveXFunction=''):
    depth = Calculator(src)
    depth.Function = 'iHat*(coordsX'+moveXFunction+') + jHat*coordsY - kHat*abs('+str(depthVar)+')'
    depth.CoordinateResults = 1
    MakeSelectable()
    
    aspect = Calculator(depth)
    aspect.Function = 'iHat*coordsX*'+str(aspRat[0])+' + jHat*coordsY*'+str(aspRat[1])+' + kHat*coordsZ*'+str(aspRat[2])
    aspect.CoordinateResults = 1
    rep = Show(aspect)
    rep.ColorArrayName = depthVar
    # assign a colormap lookup table. Only ParaView > v4.0
    try:
        depthVal = aspect.PointData.GetArray(depthVar)
        lkpD = AssignLookupTable(depthVal,'erdc_blue_BW')
        #invert the colors
        valPts=lkpD.RGBPoints[::4]
        lkpD.RGBPoints[::4]=valPts[::-1]
        rep.LookupTable = lkpD
    except:
        pass

#########

try:
    from atmos_basic import *
    from atmos_grids import *
except:
    pvAtmosPath='../'
    execfile(pvAtmosPath + 'atmos_basic.py')
    execfile(pvAtmosPath + 'atmos_grids.py')

## show me where the files are ##
oceanPath='./'

topoFile = 'ocean_depth.nc'
topoDims = ['rlon','rlat']
depthVar = 'deptho'

dataFile = 'ocean_o2.nc'
dataDims = ['xt_ocean','yt_ocean','st_ocean']
# the values we will be interested in
dataName = 'o2'
dataContours = [8e-5]

## how would you like the transformation to work ##
logCoord = [] #no logarithmic coordinates
aspRat   = [1,1,0.01]


### get the data ###

# topography
(depth_out,depth_coor)=LoadData(oceanPath+topoFile,ncDims=topoDims,logCoords=logCoord )
# get the bounds of the topography
topoBds = depth_out.GetDataInformation().GetBounds()

# data
(o2_out,o2_coor)=LoadData(oceanPath+dataFile,ncDims=dataDims,aspectRatios=aspRat,logCoords=logCoord )
# we want to replace the fill values with NaNs here
o2_out.ReplaceFillValueWithNan = 1
# get the bounds of the data file
dataBds = o2_out.GetDataInformation().GetBounds()
# instead of NaNs, there are -1e10 values in this file that we don't want
o2_thresh = Threshold(o2_coor,ThresholdRange=[0,1])
MakeSelectable()

#the topography file is in cell data, need to convert to point data
c2p=CellDatatoPointData(depth_coor)
MakeSelectable()

### see if we have to move the topography file to align it with the data file
### this is not necessary with the provided files, but might be with other files
swapTopo = False
if topoBds[0] != dataBds[0] or topoBds[1] != dataBds[1]:
    if topoBds[0] < dataBds[0]:
        moveClip = Clip(c2p, ClipType="Plane")
        moveClip.ClipType.Origin=[dataBds[0],0,0]
        moveClip.ClipType.Normal=[-1,0,0]
        MakeSelectable()
        RenameSource('moveRight',moveClip)
        moveXFunction = '+ 360'
        stayClip = Clip(c2p, ClipType="Plane")
        stayClip.ClipType.Origin=[dataBds[0],0,0]
        stayClip.ClipType.Normal=[+1,0,0]
        MakeSelectable()
        RenameSource('stayClip',stayClip)
    elif topoBds[1] > dataBds[1]:
        moveClip = Clip(c2p, ClipType="Plane")
        moveClip.ClipType.Origin=[dataBds[1],0,0]
        moveClip.ClipType.Normal=[1,0,0]
        MakeSelectable()
        RenameSource('moveLeft',moveClip)
        moveXFunction = '- 360'
        stayClip = Clip(c2p, ClipType="Plane")
        stayClip.ClipType.Origin=[dataBds[0],0,0]
        stayClip.ClipType.Normal=[-1,0,0]
        MakeSelectable()
        RenameSource('stayClip',stayClip)
    swapTopo = True


### work on the topography #####

if swapTopo :
    transformTopo(moveClip,moveXFunction)
    transformTopo(stayClip,'')
else:
    transformTopo(c2p,'')


#### now add data to the ocean #######
o2_cont = Contour(o2_thresh, ContourBy=['POINTS',dataName], Isosurfaces=dataContours)
rep=Show()
rep.ColorArrayName = dataName
try:
    dataVal = o2_cont.PointData.GetArray(dataName)
    lkpW = AssignLookupTable(dataVal,'GnYlRd')
    rep.LookupTable = lkpW
except:
    pass

#### finally, add a grid  ####
AddGrid(xlevels=[-270,-225,-180,-135,-90,-45,0,45], ylevels=[-60,-30,0,30,60], zlevels=range(-5000,1000,1000), bounds=[-280,80,-90,90,-5500,0], ratios=aspRat, logCoord=logCoord, AxisNames=["longitude","latitude","depth [m]"], AxisColor=[0,0,0], AxisWidth=1.0,LabelSize=5.0)


Render()<commit_msg>Adding comments<commit_after>#!/usr/bin/python
# Filename: example_ocean.py
#
# Code by <NAME>, distributed under an MIT License
# Any publication benefitting from this piece of code should cite
# <NAME> 2014. Scientific Visualisation of Atmospheric Data with ParaView.
# Journal of Open Research Software 2(1):e4, DOI: http://dx.doi.org/10.5334/jors.al

# define a helper function for adjusting ocean bathymetry (topography) aspect ratio and color scheme
def transformTopo(src=GetActiveSource(),moveXFunction=''):
    depth = Calculator(src)
    depth.Function = 'iHat*(coordsX'+moveXFunction+') + jHat*coordsY - kHat*abs('+str(depthVar)+')'
    depth.CoordinateResults = 1
    MakeSelectable()
    
    aspect = Calculator(depth)
    aspect.Function = 'iHat*coordsX*'+str(aspRat[0])+' + jHat*coordsY*'+str(aspRat[1])+' + kHat*coordsZ*'+str(aspRat[2])
    aspect.CoordinateResults = 1
    rep = Show(aspect)
    rep.ColorArrayName = depthVar
    # assign a colormap lookup table. Only ParaView > v4.0
    try:
        depthVal = aspect.PointData.GetArray(depthVar)
        lkpD = AssignLookupTable(depthVal,'erdc_blue_BW')
        #invert the colors
        valPts=lkpD.RGBPoints[::4]
        lkpD.RGBPoints[::4]=valPts[::-1]
        rep.LookupTable = lkpD
    except:
        pass

#########

#import pv_atmos
try:
    from atmos_basic import *
    from atmos_grids import *
except:
    pvAtmosPath='../'
    execfile(pvAtmosPath + 'atmos_basic.py')
    execfile(pvAtmosPath + 'atmos_grids.py')

## show me where the files are ##
# path to ocean files
oceanPath='./'

# file containing bathymetry
topoFile = 'ocean_depth.nc'
topoDims = ['rlon','rlat']
depthVar = 'deptho'

# file containing oxygen data
dataFile = 'ocean_o2.nc'
dataDims = ['xt_ocean','yt_ocean','st_ocean']
# the values we will be interested in
dataName = 'o2'
dataContours = [8e-5]

## how would you like the transformation to work ##
logCoord = [] #no logarithmic coordinates
aspRat   = [1,1,0.01] # divide bathymetry by 100


### get the data ###

# bathymetry
(depth_out,depth_coor)=LoadData(oceanPath+topoFile,ncDims=topoDims,logCoords=logCoord )
# get the bounds of the topography. This is important if bathymetry and data files have different origins
topoBds = depth_out.GetDataInformation().GetBounds()

# data
(o2_out,o2_coor)=LoadData(oceanPath+dataFile,ncDims=dataDims,aspectRatios=aspRat,logCoords=logCoord )
# we want to replace the fill values with NaNs here
o2_out.ReplaceFillValueWithNan = 1
# get the bounds of the data file. Again important if different from bathymetry files
dataBds = o2_out.GetDataInformation().GetBounds()
# instead of NaNs, there are -1e10 values in this file that we don't want
o2_thresh = Threshold(o2_coor,ThresholdRange=[0,1])
MakeSelectable()

#the topography file is in cell data, need to convert to point data
c2p=CellDatatoPointData(depth_coor)
MakeSelectable()

### see if we have to move the bathymetry file to align it with the data file
### this is not necessary with the provided files, but might be with other files
swapTopo = False
if topoBds[0] != dataBds[0] or topoBds[1] != dataBds[1]:
    if topoBds[0] < dataBds[0]:
        moveClip = Clip(c2p, ClipType="Plane")
        moveClip.ClipType.Origin=[dataBds[0],0,0]
        moveClip.ClipType.Normal=[-1,0,0]
        MakeSelectable()
        RenameSource('moveRight',moveClip)
        moveXFunction = '+ 360'
        stayClip = Clip(c2p, ClipType="Plane")
        stayClip.ClipType.Origin=[dataBds[0],0,0]
        stayClip.ClipType.Normal=[+1,0,0]
        MakeSelectable()
        RenameSource('stayClip',stayClip)
    elif topoBds[1] > dataBds[1]:
        moveClip = Clip(c2p, ClipType="Plane")
        moveClip.ClipType.Origin=[dataBds[1],0,0]
        moveClip.ClipType.Normal=[1,0,0]
        MakeSelectable()
        RenameSource('moveLeft',moveClip)
        moveXFunction = '- 360'
        stayClip = Clip(c2p, ClipType="Plane")
        stayClip.ClipType.Origin=[dataBds[0],0,0]
        stayClip.ClipType.Normal=[-1,0,0]
        MakeSelectable()
        RenameSource('stayClip',stayClip)
    swapTopo = True


### work on the bathymetry #####

if swapTopo :
    transformTopo(moveClip,moveXFunction)
    transformTopo(stayClip,'')
else:
    transformTopo(c2p,'')


#### now add data to the ocean #######
o2_cont = Contour(o2_thresh, ContourBy=['POINTS',dataName], Isosurfaces=dataContours)
rep=Show()
rep.ColorArrayName = dataName
try:
    dataVal = o2_cont.PointData.GetArray(dataName)
    lkpW = AssignLookupTable(dataVal,'GnYlRd')
    rep.LookupTable = lkpW
except:
    pass

#### finally, add a grid  ####
AddGrid(xlevels=[-270,-225,-180,-135,-90,-45,0,45], ylevels=[-60,-30,0,30,60], zlevels=range(-5000,1000,1000), bounds=[-280,80,-90,90,-5500,0], ratios=aspRat, logCoord=logCoord, AxisNames=["longitude","latitude","depth [m]"], AxisColor=[0,0,0], AxisWidth=1.0,LabelSize=5.0)


Render()
{'fraction_non_alphanumeric': 0.13850904278782533, 'fraction_numerical': 0.03242170269078077, 'mean_word_length': 4.236143187066975, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7556358', 'n_tokens_mistral': 3419, 'n_tokens_neox': 3260, 'n_words': 674}