Beispiel #1
0
    def _getPackParams(self, dataset):
        packed_dtype = dataset.dtype
        packed_missing = dataset.attrs.get('missing', None)
        if packed_missing and isinstance(packed_missing, basestring):
            if isFloat(packed_missing): packed_missing = float(packed_missing)
            elif isInteger(packed_missing):
                packed_missing = int(packed_missing)
            elif isNanString(packed_missing):
                packed_missing = N.nan
        multiplier = dataset.attrs.get('multiplier', None)
        if multiplier and isinstance(multuplier, basestring):
            if isFloat(multiplier): multiplier = float(multiplier)
            elif isInteger(multiplier): multiplier = int(multiplier)
        params = [packed_dtype, packed_missing, multiplier]

        unpack = dataset.attrs.get('unpack', None)
        print '\n\n', unpack, '\n', dict(dataset.attrs), '\n\n'
        if unpack is None:
            params.extend([packed_dtype, packed_missing])
        else:
            if isinstance(unpack, basestring):
                unpack = tupleFromString(unpack)
            if len(unpack) == 1:
                data_missing = packed_missing
            else:
                data_missing = unpack[1]
                if isFloat(data_missing): data_missing = float(data_missing)
                elif isInteger(data_missing): data_missing = int(data_missing)
                elif isNanString(data_missing): data_missing = N.nan
            data_dtype = N.dtype(unpack[0])
            params.extend([data_dtype, data_missing])
        return tuple(params)
source = factory.getSourceConfig(source_key)

region_key = args[1]
if len(region_key) == 2: region_key = region_key.upper()
region = factory.getRegionConfig(region_key)
bbox = region.data
if verbose:
    print '\nregion :\n', region
    print '\nbbox', bbox

reader = factory.getStaticFileReader(source, factory.getRegionConfig('conus'))
print 'reading from :', reader.filepath
# set lat/lon coordinate bounds - in order to find exactly 1 matching
# node for each corner of the bounding box, use a tight 0.009 degree
# search tolerance in stead of the source file's default search radius
reader.setCoordinateBounds(tupleFromString(bbox, float), 0.009)
if 'lon' in reader.dataset_names:
    lon_dsn = 'lon'
    lat_dsn = 'lat'
else:
    lon_dsn = 'lons'
    lat_dsn = 'lats'

builder = factory.getStaticFileBuilder(source, region, bbox=bbox)
print 'building file :', builder.filepath
#builder.initFileAttributes()

print '    creating %s and %s datasets' % (lat_dsn, lon_dsn)
builder.initLonLatData(reader.getDataInBounds(lon_dsn),
                       reader.getDataInBounds(lat_dsn))