def test_lcc_fail1(self): lon_arr = create_test_longitude(-15.0, 15.0, (50, 100)) lat_arr = create_test_latitude(18.0, 40.0, (50, 100)) grid_info = static_lcc.copy() points_in_grid, lon_res, lat_res = ll2cr.ll2cr(lon_arr, lat_arr, grid_info) assert points_in_grid == 0, "none of these test points should fall in this grid" assert lon_arr is lon_res assert lat_arr is lat_res
def test_lcc_basic1(self): lon_arr = create_test_longitude(-95.0, -75.0, (50, 100)) lat_arr = create_test_latitude(18.0, 40.0, (50, 100)) grid_info = static_lcc.copy() points_in_grid, lon_res, lat_res = ll2cr.ll2cr(lon_arr, lat_arr, grid_info) assert points_in_grid == lon_arr.size, "all these test points should fall in this grid" assert lon_arr is lon_res assert lat_arr is lat_res
def test_latlong_basic1(self): lon_arr = create_test_longitude(-95.0, -75.0, (50, 100)) lat_arr = create_test_latitude(15.0, 30.0, (50, 100)) grid_info = dynamic_wgs84.copy() points_in_grid, lon_res, lat_res = ll2cr.ll2cr(lon_arr, lat_arr, grid_info) assert points_in_grid == lon_arr.size, "all points should be contained in a dynamic grid" assert lon_arr is lon_res assert lat_arr is lat_res assert lon_arr[0, 0] == 0, "ll2cr returned the wrong result for a dynamic latlong grid" assert lat_arr[-1, 0] == 0, "ll2cr returned the wrong result for a dynamic latlong grid"
def run_ll2cr(self, swath_definition, grid_definition, swath_usage=SWATH_USAGE): geo_id = swath_definition["swath_name"] grid_name = grid_definition["grid_name"] if (geo_id, grid_name) in self.ll2cr_cache: return self.ll2cr_cache[(geo_id, grid_name)] LOG.debug("Swath '%s' -> Grid '%s'", geo_id, grid_name) rows_fn = "ll2cr_rows_%s_%s.dat" % (grid_name, geo_id) cols_fn = "ll2cr_cols_%s_%s.dat" % (grid_name, geo_id) # lon_arr = swath_definition.get_longitude_array() # lat_arr = swath_definition.get_latitude_array() if os.path.isfile(rows_fn): if not self.overwrite_existing: LOG.error("Intermediate remapping file already exists: %s" % (rows_fn,)) raise RuntimeError("Intermediate remapping file already exists: %s" % (rows_fn,)) else: LOG.warning("Intermediate remapping file already exists, will overwrite: %s", rows_fn) if os.path.isfile(cols_fn): if not self.overwrite_existing: LOG.error("Intermediate remapping file already exists: %s" % (cols_fn,)) raise RuntimeError("Intermediate remapping file already exists: %s" % (cols_fn,)) else: LOG.warning("Intermediate remapping file already exists, will overwrite: %s", cols_fn) try: rows_arr = swath_definition.copy_latitude_array(filename=rows_fn, read_only=False) cols_arr = swath_definition.copy_longitude_array(filename=cols_fn, read_only=False) points_in_grid, _, _ = ll2cr.ll2cr(cols_arr, rows_arr, grid_definition, fill_in=swath_definition["fill_value"]) # rows_arr = numpy.memmap(rows_fn, dtype=lat_arr.dtype, mode="w+", shape=lat_arr.shape) # cols_arr = numpy.memmap(cols_fn, dtype=lat_arr.dtype, mode="w+", shape=lat_arr.shape) # points_in_grid, _, _ = ll2cr.ll2cr(lon_arr, lat_arr, grid_definition, # fill_in=swath_definition["fill_value"], # cols_out=cols_arr, rows_out=rows_arr) grid_str = str(grid_definition).replace("\n", "\n\t") LOG.debug("Grid information:\n\t%s", grid_str) except StandardError: LOG.error("Unexpected error encountered during ll2cr gridding for %s -> %s", geo_id, grid_name) LOG.debug("ll2cr error exception: ", exc_info=True) self._safe_remove(rows_fn, cols_fn) raise # if 5% of the grid will have data in it then it fits fraction_in = points_in_grid / float(rows_arr.size) swath_used = fraction_in > swath_usage if not swath_used: self._safe_remove(rows_fn, cols_fn) LOG.error("Data does not fit in grid %s because it only %f%% of the swath is used" % (grid_name, fraction_in * 100)) raise RuntimeError("Data does not fit in grid %s" % (grid_name,)) else: LOG.debug("Data fits in grid %s and uses %f%% of the swath", grid_name, fraction_in * 100) self.ll2cr_cache[(geo_id, grid_name)] = (cols_fn, rows_fn) return cols_fn, rows_fn
def test_latlong_dateline1(self): lon_arr = create_test_longitude(165.0, -165.0, (50, 100), twist_factor=0.6) lat_arr = create_test_latitude(15.0, 30.0, (50, 100), twist_factor=-0.1) grid_info = dynamic_wgs84.copy() points_in_grid, lon_res, lat_res = ll2cr.ll2cr(lon_arr, lat_arr, grid_info) assert points_in_grid == lon_arr.size, "all points should be contained in a dynamic grid" assert lon_arr is lon_res assert lat_arr is lat_res assert lon_arr[0, 0] == 0, "ll2cr returned the wrong result for a dynamic latlong grid over the dateline" assert lat_arr[-1, 0] == 0, "ll2cr returned the wrong result for a dynamic latlong grid over the dateline" assert numpy.all(numpy.diff(lon_arr[0]) >= 0), "ll2cr didn't return monotonic columns over the dateline"
def run_ll2cr(self, swath_definition, grid_definition, swath_usage=SWATH_USAGE): geo_id = swath_definition["swath_name"] grid_name = grid_definition["grid_name"] if (geo_id, grid_name) in self.ll2cr_cache: return self.ll2cr_cache[(geo_id, grid_name)] LOG.debug("Swath '%s' -> Grid '%s'", geo_id, grid_name) rows_fn = "ll2cr_rows_%s_%s.dat" % (grid_name, geo_id) cols_fn = "ll2cr_cols_%s_%s.dat" % (grid_name, geo_id) # lon_arr = swath_definition.get_longitude_array() # lat_arr = swath_definition.get_latitude_array() if os.path.isfile(rows_fn): if not self.overwrite_existing: LOG.error("Intermediate remapping file already exists: %s" % (rows_fn,)) raise RuntimeError("Intermediate remapping file already exists: %s" % (rows_fn,)) else: LOG.warning("Intermediate remapping file already exists, will overwrite: %s", rows_fn) if os.path.isfile(cols_fn): if not self.overwrite_existing: LOG.error("Intermediate remapping file already exists: %s" % (cols_fn,)) raise RuntimeError("Intermediate remapping file already exists: %s" % (cols_fn,)) else: LOG.warning("Intermediate remapping file already exists, will overwrite: %s", cols_fn) try: rows_arr = swath_definition.copy_latitude_array(filename=rows_fn, read_only=False) cols_arr = swath_definition.copy_longitude_array(filename=cols_fn, read_only=False) points_in_grid, _, _ = ll2cr.ll2cr(cols_arr, rows_arr, grid_definition, fill_in=swath_definition["fill_value"]) grid_str = str(grid_definition).replace("\n", "\n\t") LOG.debug("Grid information:\n\t%s", grid_str) except StandardError: LOG.error("Unexpected error encountered during ll2cr gridding for %s -> %s", geo_id, grid_name) LOG.debug("ll2cr error exception: ", exc_info=True) self._safe_remove(rows_fn, cols_fn) raise # if 5% of the grid will have data in it then it fits fraction_in = points_in_grid / float(rows_arr.size) swath_used = fraction_in > swath_usage if not swath_used: self._safe_remove(rows_fn, cols_fn) LOG.error("Data does not fit in grid %s because it only %f%% of the swath is used" % (grid_name, fraction_in * 100)) raise RuntimeError("Data does not fit in grid %s" % (grid_name,)) else: LOG.debug("Data fits in grid %s and uses %f%% of the swath", grid_name, fraction_in * 100) self.ll2cr_cache[(geo_id, grid_name)] = (cols_fn, rows_fn) return cols_fn, rows_fn