Permalink
Browse files

Added more nuanced valid range & fill value handling to CTP after dis…

…cussion with Rich
  • Loading branch information...
1 parent d2572ce commit 082536bf377098c4bfdfb3d8b7b97c6231ea15c2 @nbearson nbearson committed Feb 12, 2014
Showing with 33 additions and 6 deletions.
  1. +23 −2 stg/ctp_guidebook.py
  2. +10 −4 stg/ctp_io.py
View
@@ -83,8 +83,29 @@
CLOUD_FRACTION_NAME ,
LAND_FRACTION_NAME ,
RESULTS_FLAG_NAME ,
- UTLS_FLAG_NAME ,])
-
+ UTLS_FLAG_NAME ,])
+
+VALID_RANGES = {
+ LATITUDE_NAME :[-90.0, 90.0],
+ LONGITUDE_NAME :[-180.0, 180.0],
+ DAY_NIGHT_FLAG_NAME :[1, 2],
+ DIRECTION_FLAG_NAME :[1, 2],
+ VIEWING_ZENITH_NAME :[0, 90],
+ SCAN_LINE_TIME_NAME :[0, 86400000],
+ CLOUD_FRACTION_NAME :[0, 1],
+ LAND_FRACTION_NAME :[0, 1],
+ RESULTS_FLAG_NAME :[0, 3],
+ UTLS_FLAG_NAME :[0, 2],
+}
+
+FILL_VALUES = {
+ CLOUD_TOP_PRESS_NAME : -99.9,
+ CLOUD_TOP_HEIGHT_NAME : -99.9,
+ CLOUD_TOP_TEMP_NAME : -99.9,
+ EFFECTIVE_CLOUD_AMOUNT_NAME : -99.9,
+ METHOD_FLAG_NAME : -99,
+}
+
# TODO, move this up to the general_guidebook
def _clean_off_path_if_needed(file_name_string) :
View
@@ -106,10 +106,16 @@ def load_variable_from_file (variable_name, file_path=None, file_object=None,
data = file_object[variable_name]
-# FIXME: everything appears to have negative fill values (aside from lat/lon), verify with RichF
- if variable_name not in [ctp_guidebook.LONGITUDE_NAME, ctp_guidebook.LATITUDE_NAME]:
- fill_mask = (data < 0)
- data[fill_mask] = numpy.nan
+ # Mask off fill values fill values
+ if variable_name in ctp_guidebook.FILL_VALUES:
+ fill_value = ctp_guidebook.FILL_VALUES[variable_name]
+ data[data == fill_value] = numpy.nan
+
+ # Mask off anything outside the valid range
+ if variable_name in ctp_guidebook.VALID_RANGES:
+ valid_range = ctp_guidebook.VALID_RANGES[variable_name]
+ data[data < valid_range[0]] = numpy.nan
+ data[data > valid_range[1]] = numpy.nan
data_to_return = data.astype(data_type_for_output) if data_type_for_output is not None else data
return file_object, data

0 comments on commit 082536b

Please sign in to comment.