source: cows_wps/trunk/process_modules/get_weather_stations.py @ 6873

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows_wps/trunk/process_modules/get_weather_stations.py@6873
Revision 6873, 3.0 KB checked in by astephen, 10 years ago (diff)

Added and updated various code to match security, download URLs that are
secured and chunking of MIDAS outputs.

Line 
1"""
2get_weather_stations.py
3===================
4
5Process get_weather_stations that holds the GetWeatherStations class.
6
7"""
8
9import os, stat, time
10import sys
11import logging
12
13from cows_wps.process_handler.fileset import FileSet, FLAG
14import cows_wps.process_handler.ddp_process_support as ddp_process_support
15from cows_wps.process_handler.context.process_status import STATUS
16
17#sys.path.append("/usr/local/cwps/cows_wps")
18import process_modules.lib_get_weather_stations.utils as gws_utils
19
20# Import local modules
21#sys.path.append("/home/badc/software/datasets/ukmo-midas/scripts/extract")
22# MIDAS Station search code
23#import getStations
24
25log = logging.getLogger(__name__)
26log.setLevel(logging.DEBUG)
27
28
29class GetWeatherStations(object):
30    def __call__(self, context):
31       
32        startTime = time.time()
33        jobId = os.path.basename(context.processDir)
34
35        # Parse the inputs
36        Username = context.inputs['Username']
37        Counties = context.inputs.get('Counties', [])
38        if Counties == []:
39            BBox = context.inputs.get("BBox", None)
40            if BBox == None:
41                raise Exception("Invalid arguments provided. Must provide either a geographical bounding box or a list of counties.")
42
43        DataTypes = context.inputs.get("DataTypes", [])
44        StartDateTime = context.inputs['StartDateTime']
45        StartDateTime = gws_utils.revertDateTimeToLongString(StartDateTime)
46        log.warn("DATE TIME: %s, type = %s" % (StartDateTime, type(StartDateTime)))
47        EndDateTime = context.inputs['EndDateTime']
48        EndDateTime = gws_utils.revertDateTimeToLongString(EndDateTime)
49       
50        context.setStatus(STATUS.STARTED, 'Job is now running', 0)
51
52        # Always need a FileSet, even if empty
53        fileSet = context.outputs['FileSet'] = FileSet()
54
55        # Make path to output file
56        WFile = 'weather_stations.txt'
57        MyFilePath = context.processDir + '/outputs/' + WFile
58
59        # Call code to get Weather Stations
60        station_list = gws_utils.getStationList(Counties, BBox, DataTypes, StartDateTime,
61                           EndDateTime, MyFilePath)
62#        st_getter = getStations.StationIDGetter(Counties, bbox=BBox, dataTypes=DataTypes,
63#                       startTime=StartDateTime, endTime=EndDateTime, outputFile=MyFilePath, noprint=1)
64
65        context.outputs['ProcessSpecificContent'] = {
66                                    "WeatherStations": " ".join(station_list)} 
67
68        context.log.info('Written output file: %s' % WFile)
69        filesize = os.stat(MyFilePath)[stat.ST_SIZE]
70
71        fileSet = context.outputs['FileSet'] = FileSet()
72        fileSet.contents.append(FileSet(FLAG.DATA, WFile, filesize, 'Weather Stations File'))
73
74        context.setStatus(STATUS.COMPLETED, 'The End', 100)
75       
76        completionTime = time.time()
77        ddp_process_support.updateJobDetailsAfterCompletion(context, startTime, completionTime)
78
79
80    def dryRun(self, context):
81
82        # Not implemented for sync jobs
83        pass
Note: See TracBrowser for help on using the repository browser.