from jasmin_cis.data_io.products.AProduct import AProduct from jasmin_cis.data_io.Coord import Coord, CoordList from jasmin_cis.data_io.ungridded_data import UngriddedData from jasmin_cis.data_io.ungridded_data import Metadata import jasmin_cis.data_io.hdf as hdf import logging from pyhdf import SD import numpy as np class SEVIRI_L2_Apollo(AProduct): """ Reads cloud top temperature variable from a CMSAF (CTX version 001) HDF file containing non CF compliant metadata. Applies scale and offset to data. Masks fill values. Creates variable metadata. Reads latitude and longitude values from a separate HDF file. Returns data, metadata and coordinates. """ def get_file_signature(self): "Returns a list of regular expressions, which are used to decided which files require this plugin." return [r'clouds_MET08*'] def create_data_object(self, filenames, variable): "Read in and return the relevant data, metadata and coords for the specified filename." logging.debug("Creating data object for variable " + variable) # reading coordinates coords = self.create_coords(filenames, variable) # reading variables variables=[variable,'mask'] sdata, vdata = hdf.read(filenames, variables) # retrieve variable var = sdata[variable] var_data = hdf.read_data(var,"SD") # apply offset to variable var_data = var_data * 0.01 # mask variable fill values var_data = np.ma.masked_less_equal(var_data ,0.0) # read mask cloud_mask = sdata['mask'] cloud_mask = hdf.read_data(cloud_mask,"SD") # apply mask to variable var_data = np.ma.array(var_data, mask = (cloud_mask != 100)) # create variable metadata metadata = Metadata(name='Cloud_Top_Temperature',units='K') logging.info(type(var_data)) logging.info(type(metadata)) logging.info(type(coords)) return UngriddedData(var_data,metadata,coords) def create_coords(self, filenames, variable=None): "Read in the relevant coordinates for the specified file and return them as a list." # list of coordinates to be read in coordinates = ['latitude','longitude'] logging.info("Listing coordinates: " + str(coordinates)) # in this case, the coord information is in a separate file filenames=['seviri-geolocation.hdf'] # get coord data sdata,vdata = hdf.read(filenames,coordinates) lat = sdata['latitude'] lon = sdata['longitude'] # mask out fill values lat_data = hdf.read_data(lat,"SD",[999.9]) lon_data = hdf.read_data(lon,"SD",[999.9]) # create metedata logging.info("gathering coordinates metadata") lat_metadata = Metadata(name='latitude',units='degrees', missing_value=999.9) lon_metadata = Metadata(name='longitude',units='degrees',missing_value=999.9) # create x and y coord objects to be passed back to CIS lon_coord = Coord(lon_data, lon_metadata,'X') lat_coord = Coord(lat_data, lat_metadata,'Y') return CoordList([lat_coord,lon_coord])