Skip to content

read gridded forecast with lat/lon values swapped in the file #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion csep/core/forecasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def from_custom(cls, func, func_args=(), **kwargs):
return cls(data=data, region=region, magnitudes=magnitudes, **kwargs)

@classmethod
def load_ascii(cls, ascii_fname, start_date=None, end_date=None, name=None):
def load_ascii(cls, ascii_fname, start_date=None, end_date=None, name=None, swap_latlon=False):
""" Reads Forecast file from CSEP1 ascii format.

The ascii format from CSEP1 testing centers. The ASCII format does not contain headers. The format is listed here:
Expand All @@ -376,6 +376,7 @@ def load_ascii(cls, ascii_fname, start_date=None, end_date=None, name=None):

Args:
ascii_fname: file name of csep forecast in .dat format
swap_latlon (bool): if true, read forecast spatial cells as lat_0, lat_1, lon_0, lon_1
"""
# Load data
data = numpy.loadtxt(ascii_fname)
Expand All @@ -393,6 +394,8 @@ def load_ascii(cls, ascii_fname, start_date=None, end_date=None, name=None):
mws = all_mws[sorted_idx]
# csep1 stores the lat lons as min values and not (x,y) tuples
bboxes = [tuple(itertools.product(bbox[:2], bbox[2:])) for bbox in unique_poly]
if swap_latlon:
bboxes = [tuple(itertools.product(bbox[2:], bbox[:2])) for bbox in unique_poly]
# the spatial cells are arranged fast in latitude, so this only works for the specific csep1 file format
dh = float(unique_poly[0,3] - unique_poly[0,2])
# create CarteisanGrid of points
Expand Down