Skip to content

Commit

Permalink
Added in extra modules from Craig
Browse files Browse the repository at this point in the history
  • Loading branch information
captainceramic committed Jul 10, 2015
2 parents 760aec8 + 8738e95 commit 5cda4d0
Show file tree
Hide file tree
Showing 6 changed files with 712 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cwsl/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
from cwsl.vt_modules.mv_output import MoveOutput
from cwsl.vt_modules.dataset_summary import DatasetSummary
from cwsl.vt_modules.open_dataset import OpenDataSet
from cwsl.vt_modules.vt_plot_gridded_seas import PlotGriddedSeas
from cwsl.vt_modules.vt_cdo_histogram import Histogram
from cwsl.vt_modules.vt_cdo_calc_pdf import PDF
from cwsl.vt_modules.vt_cdo_clim_statistics import ClimStatistics


def initialize(*args, **keywords):
Expand Down Expand Up @@ -107,12 +111,19 @@ def initialize(*args, **keywords):
namespace='Statistics')
reg.add_module(TemporalCorrelation, name='Temporal Correlation',
namespace='Statistics')
reg.add_module(ClimStatistics, name='Clim Statistics',
namespace='Statistics')
reg.add_module(Histogram, name='Histogram',
namespace='Statistics')
reg.add_module(PDF, name='PDF',
namespace='Statistics')

#Indices
reg.add_module(IndicesNino34, name='Nino3.4', namespace='Indices')

#Visualisation
reg.add_module(PlotTimeSeries, name='Plot Timeseries', namespace='Visualisation')
reg.add_module(PlotGriddedSeas, name='Plot Gridded', namespace='Visualisation')
#ImageViewerPanel depends on the Spreadsheet package
reg.add_module(ImageViewerPanel, name='Image Viewer', namespace='Visualisation')
reg.add_input_port(ImageViewerPanel, 'in_dataset', 'csiro.au.cwsl:VtDataSet')
Expand Down
97 changes: 97 additions & 0 deletions cwsl/vt_modules/vt_cdo_calc_pdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""
Authors: Craig Heady ([email protected])
Copyright 2015 CSIRO
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This module wraps a shell script that performs time aggregation:
cwsl-ctools/aggregation/cdo_calc_pdf.sh
Part of the CWSLab Model Analysis Service VisTrails plugin.
"""

from vistrails.core.modules import vistrails_module, basic_modules

from cwsl.configuration import configuration
from cwsl.core.constraint import Constraint
from cwsl.core.process_unit import ProcessUnit
from cwsl.core.pattern_generator import PatternGenerator


class PDF(vistrails_module.Module):
"""Calc PDF.
Wraps the cwsl-ctools/statistics/cdo_calc_pdf.sh script.
Inputs:
in_dataset: Can consist of netCDF files
bin_list: Comma seperated list of bin values.
eg temperature -inf,-40,-30,-20,-10,0,10,20,30,40,inf"
eg precipitation 0,20,40,60,80,100,150,200,300,400,inf"
Outputs:
out_dataset: Consists of netCDF files
"""

_input_ports = [('in_dataset', 'csiro.au.cwsl:VtDataSet',
{'labels': str(['Input dataset'])}),
('bin_list', basic_modules.String,
{'labels': str(['Bins'])}),
]

_output_ports = [('out_dataset', 'csiro.au.cwsl:VtDataSet')]

_execution_options = {'required_modules': ['cdo', 'python/2.7.5', 'python-cdat-lite/6.0rc2-py2.7.5']}

command = '${CWSL_CTOOLS}/statistics/cdo_calc_pdf.sh'

def __init__(self):

super(PDF, self).__init__()
self.out_pattern = PatternGenerator('user', 'default').pattern

def compute(self):

in_dataset = self.getInputFromPort('in_dataset')

bin_list = self.getInputFromPort('bin_list')


self.positional_args = [('%s' %bin_list, 0, 'raw'), ]
self.keyword_args = {}

agg_constraint = 'pdf'

new_constraints_for_output = set([Constraint('timeagg_info', [agg_constraint]),
Constraint('suffix', ['nc']),
])

this_process = ProcessUnit([in_dataset],
self.out_pattern,
self.command,
new_constraints_for_output,
execution_options=self._execution_options,
positional_args=self.positional_args,
cons_keywords=self.keyword_args)

try:
this_process.execute(simulate=configuration.simulate_execution)
except Exception as e:
raise vistrails_module.ModuleError(self, repr(e))

process_output = this_process.file_creator

self.setResult('out_dataset', process_output)

114 changes: 114 additions & 0 deletions cwsl/vt_modules/vt_cdo_clim_statistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
"""
Authors: Craig Heady ([email protected])
Copyright 2015 CSIRO
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This module wraps a shell script that performs time aggregation:
cwsl-ctools/statistics/cdo_clim_statistics.sh
Part of the CWSLab Model Analysis Service VisTrails plugin.
"""

from vistrails.core.modules import vistrails_module, basic_modules

from cwsl.configuration import configuration
from cwsl.core.constraint import Constraint
from cwsl.core.process_unit import ProcessUnit
from cwsl.core.pattern_generator import PatternGenerator


class ClimStatistics(vistrails_module.Module):
"""ClimStatistics.
Wraps the cwsl-ctools/statistics/cdo_clim_statistics.sh script.
Inputs:
in_dataset: Can consist of netCDF files
method: Statistical anlaysis method.min, max, sum, mean,avg,var,std.
- min (min: monthly, seasonal and annual Minimum)
- max (sum: monthly, seasonal and annual Maximum)
- sum (sum: monthly, seasonal and annual Sum)
- mean (mean:monthly, seasonal and annual Mean)
- avg (avg: monthly, seasonal and annual Average)
- var (var: monthly, seasonal and annual Variance)
- std (std: monthly, seasonal and annual Standard Deviation)
Outputs:
out_dataset_mon: Consists of netCDF files
out_dataset_seas:Consists of netCDF files
out_dataset_ann: Consists of netCDF files
"""

_input_ports = [('in_dataset', 'csiro.au.cwsl:VtDataSet',
{'labels': str(['Input dataset'])}),
('method', basic_modules.String,
{'labels': str(['Statistic'])}),
]

_output_ports = [('out_dataset_mon', 'csiro.au.cwsl:VtDataSet'),
('out_dataset_seas', 'csiro.au.cwsl:VtDataSet'),
('out_dataset_ann', 'csiro.au.cwsl:VtDataSet'),]

_execution_options = {'required_modules': ['cdo/1.6.4', 'python/2.7.5', 'python-cdat-lite/6.0rc2-py2.7.5']}

command = '${CWSL_CTOOLS}/aggregation/cdo_time_agg.sh'



#output_data = {'mon':'','seas':'','ann':''}

def __init__(self):

super(ClimStatistics, self).__init__()
self.out_pattern = PatternGenerator('user', 'default').pattern

def compute(self):

in_dataset = self.getInputFromPort('in_dataset')
method = self.getInputFromPort('method')

seas_list = {'mon':'ymon','seas':'yseas','ann':'tim'}

### loop over seas_list to generate all 3 season files ###
for seas in seas_list.keys():
self.positional_args = [('%s%s' %(seas_list[seas],method), 0, 'raw'), ]
self.keyword_args = {}

if len(method.split(',')) > 1:
agg_constraint = "".join(method.split(','))
else:
agg_constraint = method

new_constraints_for_output = set([Constraint('timeagg_info', ['%s%s'%(seas_list[seas],method)],),
Constraint('suffix', ['nc']),
])

this_process = ProcessUnit([in_dataset],
self.out_pattern,
self.command,
new_constraints_for_output,
execution_options=self._execution_options,
positional_args=self.positional_args,
cons_keywords=self.keyword_args)

try:
this_process.execute(simulate=configuration.simulate_execution)
except Exception as e:
raise vistrails_module.ModuleError(self, repr(e))

process_output = this_process.file_creator

self.setResult('out_dataset_%s' %seas, process_output)

109 changes: 109 additions & 0 deletions cwsl/vt_modules/vt_cdo_histogram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
"""
Authors: Craig Heady ([email protected])
Copyright 2015 CSIRO
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This module wraps a shell script that performs time aggregation:
cwsl-ctools/aggregation/cdo_histogram.sh
Part of the CWSLab Model Analysis Service VisTrails plugin.
"""

from vistrails.core.modules import vistrails_module, basic_modules

from cwsl.configuration import configuration
from cwsl.core.constraint import Constraint
from cwsl.core.process_unit import ProcessUnit
from cwsl.core.pattern_generator import PatternGenerator


class Histogram(vistrails_module.Module):
"""Histogram.
Wraps the cwsl-ctools/statistics/cdo_histogram.sh script.
Inputs:
in_dataset: Can consist of netCDF files
method: Histogram method.
- histcount (Histogram count: Number of elements in the bin range)
- histsum (Histogram sum: Sum of elements in the bin range)
- histmean (Histogram mean: Mean of elements in the bin range)
- histfreq (Histogram frequency: Relative frequency of elements in the bin range)
bin_list: Comma seperated list of bin values.
eg temperature -inf,-40,-30,-20,-10,0,10,20,30,40,inf"
eg precipitation 0,20,40,60,80,100,150,200,300,400,inf"
Outputs:
out_dataset: Consists of netCDF files
"""

_input_ports = [('in_dataset', 'csiro.au.cwsl:VtDataSet',
{'labels': str(['Input dataset'])}),
('method', basic_modules.String,
{'labels': str(['Hist Method'])}),
('bin_list', basic_modules.String,
{'labels': str(['Hist Bins'])}),
]

_output_ports = [('out_dataset', 'csiro.au.cwsl:VtDataSet')]

_execution_options = {'required_modules': ['cdo', 'python/2.7.5', 'python-cdat-lite/6.0rc2-py2.7.5']}

command = '${CWSL_CTOOLS}/statistics/cdo_histogram.sh'

def __init__(self):

super(Histogram, self).__init__()
self.out_pattern = PatternGenerator('user', 'default').pattern

def compute(self):

in_dataset = self.getInputFromPort('in_dataset')
method = self.getInputFromPort('method')
bin_list = self.getInputFromPort('bin_list')


self.positional_args = [('%s,%s' %(method,bin_list), 0, 'raw'), ]
self.keyword_args = {}

if len(method.split(',')) > 1:
agg_constraint = "".join(method.split(','))
else:
agg_constraint = method


new_constraints_for_output = set([Constraint('timeagg_info', [agg_constraint]),
Constraint('suffix', ['nc']),
])

this_process = ProcessUnit([in_dataset],
self.out_pattern,
self.command,
new_constraints_for_output,
execution_options=self._execution_options,
positional_args=self.positional_args,
cons_keywords=self.keyword_args)

try:
this_process.execute(simulate=configuration.simulate_execution)
except Exception as e:
raise vistrails_module.ModuleError(self, repr(e))

process_output = this_process.file_creator

self.setResult('out_dataset', process_output)

Loading

0 comments on commit 5cda4d0

Please sign in to comment.