source: cows_wps/trunk/process_modules/lib_extract_uk_station_data/utils.py @ 6873

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows_wps/trunk/process_modules/lib_extract_uk_station_data/utils.py@6873
Revision 6873, 1.8 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"""
2utils.py
3========
4
5Util functions for process extract_uk_station_data that holds the ExtractUKStationData class.
6
7"""
8
9import os, stat, time, sys
10
11from cows_wps.utils.duration_splitter import *
12
13# Import local modules
14sys.path.append("/home/badc/software/datasets/ukmo-midas/scripts/extract")
15# MIDAS Station search code
16import midasSubsetter
17
18
19def extractStationDataByTimeChunk(obs_tables, startTime, endTime, src_ids, time_chunk, 
20                    output_file_base, ext, tempDir):
21    """
22    Loops through time chunks extracting data to files in required time chunks.
23    Returns a list of output file paths produced.
24    """ 
25    start_hr_min = startTime[8:12]
26    end_hr_min = endTime[8:12]
27
28    # Split the time chunks appropriately
29    ds = DurationSplitter()
30    time_splits = ds.splitDuration(startTime[:8], endTime[:8], time_chunk)
31    first_date = True
32
33    # Create list to return
34    output_file_paths = []
35
36    for (start_date, end_date) in time_splits: 
37
38        # Add appropriate hours and minutes to date strings to make 12 character times
39        if first_date == True:
40            start = "%s%s" % (start_date.date, start_hr_min)
41            first_date = False
42        else:
43            start = "%s0000" % (start_date.date)
44       
45        if end_date == time_splits[-1][-1]:
46            end = "%s%s" % (end_date.date, end_hr_min)
47        else:
48            end = "%s2359" % (end_date.date)
49
50        # Decide the output file path
51        output_file_path = "%s-%s-%s.%s" % (output_file_base, start, end, ext)
52        output_file_paths.append(output_file_path)
53 
54        # Call subsetter to extract and write the data   
55        midasSubsetter.MIDASSubsetter(obs_tables, output_file_path, startTime = start,
56                       endTime = end, src_ids = src_ids, tempDir = tempDir)
57       
58    return output_file_paths
Note: See TracBrowser for help on using the repository browser.