Ticket #2839: vera.py

File vera.py, 1.7 KB (added by willie, 8 months ago)
Line 
1#!/usr/bin/python
2#
3# W. McGinty
4# 28 Mar 2019
5#
6# Fix for Julia's start dump - see ticket 2839
7#
8# By printing out all the values of the sfc temp field below 10K we find
9# the zeroes at about -2.663 deg N, 351.30 deg Lat.
10#
11# The zero K points are at [176,314] and [177,314].  Thet are
12# surrounded by values near 297.3 degK, which is neither a minimum or
13# a maximum.  So we have to insert this value directly.
14#
15import mule
16import mule.operators
17
18class FixOperator(mule.DataOperator):
19    """Operator which overwrite zero deg K"""
20    def __init__(self, fix_val):
21        """Initialise the operator, setting the exponent value"""
22        self.fix_val = fix_val
23    def new_field(self, source_field):
24        """Creates the new field object"""
25        field = source_field.copy()
26        return field
27    def transform(self, source_field, new_field):
28        """Performs the data manipulation"""
29        data = source_field.get_data()
30       
31        mask = (data < 10)  # 10K is well below the rest of the values
32        data_out=data
33        data_out[mask] = self.fix_val
34       
35        # If the field defines MDI, reset missing points from original
36        # field back to MDI in the output
37        if hasattr(source_field, "bmdi"):
38            mdi = source_field.bmdi
39            mask = (data == mdi)
40            data_out[mask] = mdi
41        return data_out
42
43
44dump = mule.DumpFile.from_file("xmrjca.da20140601_00")
45
46print 'model = ', dump.fixed_length_header.model_version
47
48fix_temp = 297.3 # deg K
49
50fix_op = FixOperator(fix_temp)
51
52
53stash_sfc_temp = 24
54
55for ifield, field in enumerate(dump.fields):
56  if field.lbrel in (2,3) and field.lbuser4 == stash_sfc_temp:
57     dump.fields[ifield] = fix_op(field)
58
59       
60dump.to_file("xmrjca.da20140601_00.fixed")