source: TI03-DataExtractor/branches/old_stuff/extractor/products.py @ 793

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/branches/old_stuff/extractor/products.py@793
Revision 793, 3.4 KB checked in by astephen, 13 years ago (diff)

Put all the old code in the old_stuff branch.

Line 
1"""
2products.py
3===========
4
5Procucts module for the extractor package.
6
7This module holds the Product, Plot, DataFile and other classes
8used to generate products from the data extractor.
9
10Version history
11===============
12
13Version 1.0:  - 01/03/2004
14              - Ag Stephens, British Atmospheric Data Centre.
15              - First version.
16
17"""
18
19# Import required modules
20import os
21import cdms
22import vcs
23import sys
24
25# Import global variables
26from shared_data import *
27
28class Product:
29 
30    def __init__(self, filename, request):
31         self.file=cdms.open(filename)
32         self.request=request
33         self.getParam()
34
35    def getParam(self):
36         domain=self.request["domain"]
37         start="%.4d-%.2d-%.2d %.2d:%.2d:%.2d" % domain["start_time"]
38         end="%.4d-%.2d-%.2d %.2d:%.2d:%.2d" % domain["end_time"]
39         (north, east, south, west)=domain["horiz_domain"]
40         levels=domain["vertical_domain"]
41         variable_name=(self.request["variable"].split('[')[-1].split(']'))[0].strip("]\"()' ")
42         #variable_name=(self.request["variable"].split(','))[0].strip("\"'()")
43         if variable_name[0] in "0123456789": variable_name="no"+variable_name
44
45
46         stdout=sys.stdout
47         sys.stdout=RedirectStdout()
48         if levels:
49             self.var=self.file(variable_name, time=(start, end), longitude=(west, east), latitude=(south, north), level=levels)
50         else:
51             self.var=self.file(variable_name, time=(start, end), longitude=(west, east), latitude=(south, north))
52         num_time_steps=len(self.var.getTime()[:])
53         print "<P><B>Estimated job duration: %d seconds.</B><P>" % (num_time_steps*20)
54         sys.stdout=stdout
55         sys.stdout.flush()
56
57class DataFile(Product):
58
59    def process(self):
60         self.ext=".nc"
61         outfile=os.path.join("/var/www/html/nctemp", "output"+self.ext)
62         if os.path.isfile(outfile): os.unlink(outfile)
63         fout=cdms.open(outfile, "w")
64         fout.write(self.var)
65         fout.close()
66         fileByBrowser=os.path.join("/nctemp", "output"+self.ext)
67         return fileByBrowser
68   
69     
70class Plot(DataFile):
71
72   def process(self):
73         ncfile=DataFile.process(self)
74         self.ext=".gif"
75         outfile=os.path.join("/var/www/html/nctemp", "output"+self.ext)
76         if os.path.isfile(outfile): os.unlink(outfile)
77         canvas=vcs.init()
78         canvas.plot(self.var, bg=1)
79         canvas.gif(outfile)
80         fileByBrowser=os.path.join("/nctemp", "output"+self.ext)
81         return (fileByBrowser, ncfile)
82
83
84class GribFile:
85
86    def __init__(self, filename, request):
87         self.request=request
88
89    def process(self):
90         domain=self.request["domain"]
91         start="%.4d-%.2d-%.2d %.2d:%.2d:%.2d" % domain["start_time"]
92         end="%.4d-%.2d-%.2d %.2d:%.2d:%.2d" % domain["end_time"]
93         (north, east, south, west)=domain["horiz_domain"]
94         self.ext=".grb"
95         outfile=os.path.join("/var/www/html/nctemp", "output"+self.ext)
96         if os.path.isfile(outfile): os.unlink(outfile)
97         pretend_file="/badc/ecmwf-e40/data/gp/as/1999/01/01/gpas199901010010u.grb"
98         output_text=commands.getoutput("/home/tornado/internal/badc/software/datasets/ecmwf/badc_grib_utilities/subsetter.exe %s %s %s %s %s %s 1.0 1.0" % (pretend_file, outfile, north, east, south, west))
99         fileByBrowser=os.path.join("/nctemp", "output"+self.ext)
100         return fileByBrowser
101   
Note: See TracBrowser for help on using the repository browser.