Skip to content

Commit

Permalink
Merge pull request #733 from rdaruwala/reader-fires
Browse files Browse the repository at this point in the history
Update VIIRS EDR Active Fires
  • Loading branch information
djhoese authored May 9, 2019
2 parents d13b670 + 9c72cbd commit 81b3334
Show file tree
Hide file tree
Showing 3 changed files with 259 additions and 44 deletions.
49 changes: 36 additions & 13 deletions satpy/etc/readers/viirs_edr_active_fires.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,67 @@ reader:
sensors: [viirs]

file_types:
fires_netcdf_img:
file_reader: !!python/name:satpy.readers.viirs_edr_active_fires.VIIRSActiveFiresFileHandler
variable_prefix: ""
file_patterns:
- 'AFIMG_{satellite_name}_d{start_time:%Y%m%d_t%H%M%S%f}_e{end_time:%H%M%S%f}_b{orbit:5d}_c{creation_time}_{source}.nc'
fires_netcdf:
file_reader: !!python/name:satpy.readers.viirs_edr_active_fires.VIIRSActiveFiresFileHandler
variable_prefix: "Fire Pixels/"
file_patterns:
- 'AFEDR_npp_d{start_time:%Y%m%d_t%H%M%S%f}_e{end_time:%H%M%S%f}_b{orbit:5d}_c{creation_time}_{source}.nc'
- 'AFEDR_{satellite_name}_d{start_time:%Y%m%d_t%H%M%S%f}_e{end_time:%H%M%S%f}_b{orbit:5d}_c{creation_time}_{source}.nc'
- 'AFMOD_{satellite_name}_d{start_time:%Y%m%d_t%H%M%S%f}_e{end_time:%H%M%S%f}_b{orbit:5d}_c{creation_time}_{source}.nc'
fires_text_img:
file_reader: !!python/name:satpy.readers.viirs_edr_active_fires.VIIRSActiveFiresTextFileHandler
file_patterns:
- 'AFIMG_{satellite_name}_d{start_time:%Y%m%d_t%H%M%S%f}_e{end_time:%H%M%S%f}_b{orbit:5d}_c{creation_time}_{source}.txt'
fires_text:
file_reader: !!python/name:satpy.readers.viirs_edr_active_fires.VIIRSActiveFiresTextFileHandler
file_patterns:
- 'AFEDR_npp_d{start_time:%Y%m%d_t%H%M%S%f}_e{end_time:%H%M%S%f}_b{orbit:5d}_c{creation_time}_{source}.txt'
- 'AFMOD_{satellite_name}_d{start_time:%Y%m%d_t%H%M%S%f}_e{end_time:%H%M%S%f}_b{orbit:5d}_c{creation_time}_{source}.txt'
- 'AFEDR_{satellite_name}_d{start_time:%Y%m%d_t%H%M%S%f}_e{end_time:%H%M%S%f}_b{orbit:5d}_c{creation_time}_{source}.txt'

datasets:
detection_confidence:
name: detection_confidence
standard_name: fire_confidence
confidence_cat:
name: confidence_cat
file_type: [fires_netcdf_img, fires_text_img]
file_key: "{variable_prefix}FP_confidence"
coordinates: [longitude, latitude]
units: '[7,8,9]->[lo,med,hi]'
confidence_pct:
name: confidence_pct
file_type: [fires_netcdf, fires_text]
file_key: "Fire Pixels/FP_confidence"
file_key: "{variable_prefix}FP_confidence"
coordinates: [longitude, latitude]
units: '%'
longitude:
name: longitude
standard_name: longitude
file_type: [fires_netcdf, fires_text]
file_key: "Fire Pixels/FP_longitude"
file_type: [fires_netcdf_img, fires_netcdf, fires_text_img, fires_text]
file_key: "{variable_prefix}FP_longitude"
units: 'degrees'
latitude:
name: latitude
standard_name: latitude
file_type: [fires_netcdf, fires_text]
file_key: "Fire Pixels/FP_latitude"
file_type: [fires_netcdf_img, fires_netcdf, fires_text_img, fires_text]
file_key: "{variable_prefix}FP_latitude"
units: 'degrees'
power:
name: power
file_type: [fires_netcdf, fires_text]
file_key: "Fire Pixels/FP_power"
file_type: [fires_netcdf_img, fires_netcdf, fires_text_img, fires_text]
file_key: "{variable_prefix:s}FP_power"
coordinates: [longitude, latitude]
units: 'MW'
T13:
name: T13
file_type: [fires_netcdf, fires_text]
file_key: "Fire Pixels/FP_T13"
file_key: "{variable_prefix}FP_T13"
coordinates: [longitude, latitude]
units: 'K'
T4:
name: T4
file_type: [fires_netcdf_img, fires_text_img]
file_key: "{variable_prefix}FP_T4"
coordinates: [longitude, latitude]
units: 'K'
39 changes: 28 additions & 11 deletions satpy/readers/viirs_edr_active_fires.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class VIIRSActiveFiresFileHandler(NetCDF4FileHandler):
"""NetCDF4 reader for VIIRS Active Fires
"""

def __init__(self, filename, filename_info, filetype_info,
auto_maskandscale=False, xarray_kwargs=None):
super(VIIRSActiveFiresFileHandler, self).__init__(
filename, filename_info, filetype_info)
self.prefix = filetype_info.get('variable_prefix')

def get_dataset(self, dsid, dsinfo):
"""Get dataset function
Expand All @@ -43,11 +49,15 @@ def get_dataset(self, dsid, dsinfo):
Dask DataArray: Data
"""
data = self[dsinfo.get('file_key', dsid.name)]

key = dsinfo.get('file_key', dsid.name).format(variable_prefix=self.prefix)
data = self[key]
data.attrs.update(dsinfo)

data.attrs["platform_name"] = self['/attr/satellite_name']
data.attrs["sensor"] = self['/attr/instrument_name']
platform_key = {"NPP": "Suomi-NPP", "J01": "NOAA-20", "J02": "NOAA-21"}

data.attrs["platform_name"] = platform_key.get(self.filename_info['satellite_name'].upper(), "unknown")
data.attrs["sensor"] = "VIIRS"

return data

Expand Down Expand Up @@ -79,21 +89,28 @@ def __init__(self, filename, filename_info, filetype_info):
filename_info: Filename information
filetype_info: Filetype information
"""

if filetype_info.get('file_type') == 'fires_text_img':
self.file_content = dd.read_csv(filename, skiprows=15, header=None,
names=["latitude", "longitude",
"T4", "Along-scan", "Along-track", "confidence_cat",
"power"])
else:
self.file_content = dd.read_csv(filename, skiprows=15, header=None,
names=["latitude", "longitude",
"T13", "Along-scan", "Along-track", "confidence_pct",
"power"])

super(VIIRSActiveFiresTextFileHandler, self).__init__(filename, filename_info, filetype_info)

if not os.path.isfile(filename):
return
platform_key = {"NPP": "Suomi-NPP", "J01": "NOAA-20", "J02": "NOAA-21"}

self.file_content = dd.read_csv(filename, skiprows=15, header=None,
names=["latitude", "longitude",
"T13", "Along-scan", "Along-track", "detection_confidence",
"power"])
self.platform_name = platform_key.get(self.filename_info['satellite_name'].upper(), "unknown")

def get_dataset(self, dsid, dsinfo):
ds = self[dsid.name].to_dask_array(lengths=True)
data_array = xr.DataArray(ds, dims=("y",), attrs={"platform_name": "unknown", "sensor": "viirs"})
data_array = xr.DataArray(ds, dims=("y",), attrs={"platform_name": self.platform_name, "sensor": "VIIRS"})
data_array.attrs.update(dsinfo)

return data_array

@property
Expand Down
Loading

0 comments on commit 81b3334

Please sign in to comment.