Skip to content

Commit

Permalink
Use h5py for lonlat reading also.
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Raspaud <martin.raspaud@smhi.se>
  • Loading branch information
mraspaud committed Dec 12, 2014
1 parent 76fabef commit 600ba06
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions mpop/satin/nc_pps_l2.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,21 +459,26 @@ def __init__(self, filename=None):

def get_lonlat(filename):
"""Read lon,lat from netCDF4 CF file"""
from netCDF4 import Dataset
import h5py

col_indices = None
row_indices = None

LOG.debug("Geo File = " + filename)
rootgrp = Dataset(filename, 'r')

lon = rootgrp.variables['lon']
lons = np.ma.masked_equal(lon[:], lon._FillValue)
lat = rootgrp.variables['lat']
lats = np.ma.masked_equal(lat[:], lat._FillValue)
h5f = h5py.File(filename, 'r')

lon = h5f['lon']
lons = (lon[:] * lon.attrs.get("scale_factor", 1)
+ lon.attrs.get("add_offset", 0))
lons = np.ma.masked_equal(lons, lon.attrs["_FillValue"])
lat = h5f['lat']
lats = (lat[:] * lat.attrs.get("scale_factor", 1)
+ lat.attrs.get("add_offset", 0))
lats = np.ma.masked_equal(lats, lat.attrs["_FillValue"])

# FIXME: this is to mask out the npp bowtie deleted pixels...
if rootgrp.platform == "Suomi-NPP":
if h5f.attrs['platform'] == "Suomi-NPP":

new_mask = np.zeros((16, 3200), dtype=bool)
new_mask[0, :1008] = True
Expand All @@ -488,10 +493,10 @@ def get_lonlat(filename):
lons = np.ma.masked_where(new_mask, lons)
lats = np.ma.masked_where(new_mask, lats)

if "column_indices" in rootgrp.variables:
col_indices = rootgrp.variables["column_indices"][:]
if "row_indices" in rootgrp.variables:
row_indices = rootgrp.variables["row_indices"][:]
if "column_indices" in h5f.keys():
col_indices = h5f["column_indices"][:]
if "row_indices" in h5f.keys():
row_indices = h5f["row_indices"][:]

return {'lon': lons,
'lat': lats,
Expand Down

0 comments on commit 600ba06

Please sign in to comment.