Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/blaylockbk/goes2go
Browse files Browse the repository at this point in the history
  • Loading branch information
blaylockbk committed Aug 10, 2021
2 parents ff4a8f9 + 1c2e0f5 commit dd38775
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 82 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
17 changes: 12 additions & 5 deletions goes2go/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ def _expand(self):
# goes2go configuration file
# Configuration file is save in `~/config/goes2go/config.toml`
_config_path = Path("~/.config/goes2go/config.toml").expand()
_save_dir = str(Path('~/data').expand())

# NOTE: The `\\` is an escape character in TOML.
# For Windows paths "C:\\user\\"" needs to be "C:\\\\user\\\\""
_save_dir = str(Path('~/data').expand())
_save_dir = _save_dir.replace('\\', '\\\\')

########################################################################
# Default TOML Configuration
default_toml = f"""
['default']
save_dir = "{str(Path('~/data').expand())}"
["default"]
save_dir = "{_save_dir}"
satellite = "noaa-goes16"
product = "ABI-L2-MCMIP"
domain = "C"
Expand All @@ -52,20 +58,21 @@ def _expand(self):
s3_refresh = true
verbose = true
['timerange']
["timerange"]
s3_refresh = false
['latest']
["latest"]
return_as = "xarray"
['nearesttime']
["nearesttime"]
within = "1H"
return_as = "xarray"
"""

########################################################################
# If a config file isn't found, make one
if not _config_path.exists():
_config_path.parent.mkdir(parents=True, exist_ok=True)
with open(_config_path, "w") as f:
toml_string = toml.dump(toml.loads(default_toml), f)
print(f"⚙ Created config file [{_config_path}] with default values.")
Expand Down
81 changes: 4 additions & 77 deletions goes2go/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def _gamma_correction(a, gamma, verbose=False):

def _normalize(value, lower_limit, upper_limit, clip=True):
"""
_normalize values between 0 and 1.
Normalize values between 0 and 1.
_normalize between a lower and upper limit. In other words, it
Normalize between a lower and upper limit. In other words, it
converts your number to a value in the range between 0 and 1.
Follows `normalization formula
<https://stats.stackexchange.com/a/70807/220885>`_
Expand Down Expand Up @@ -87,8 +87,8 @@ def _normalize(value, lower_limit, upper_limit, clip=True):
# RGB Accessor


@xr.register_dataset_accessor("geo")
class GeoAccessor:
@xr.register_dataset_accessor("rgb")
class rgbAccessor:
def __init__(self, xarray_obj):
self._obj = xarray_obj
self._center = None
Expand Down Expand Up @@ -157,79 +157,6 @@ def get_latlon(self):
self._obj.coords["longitude"] = (("y", "x"), lons)
self._obj.coords["latitude"] = (("y", "x"), lats)


@xr.register_dataset_accessor("rgb")
class GeoAccessor:
def __init__(self, xarray_obj):
self._obj = xarray_obj
self._center = None

@property
def center(self):
"""Return the geographic center point of this dataset."""
if self._center is None:
# we can use a cache on our accessor objects, because accessors
# themselves are cached on instances that access them.
lon = self._obj.x
lat = self._obj.y
self._center = (float(lon.mean()), float(lat.mean()))
return self._center

@property
def sat_h(self):
if self._sat_h is None:
ds = self._obj
self._sat_h = ds.goes_imager_projection.perspective_point_height
return self._sat_h

@property
def crs(self):
if self._crs is None:
ds = self._obj
# Convert x, y points to latitude/longitude
_, crs = field_of_view(ds)
self._crs = crs
return self._crs

@property
def get_x(self):
"""x sweep in crs units (m); x * sat_height"""
if self._x is None:
self._x = self._obj.x * sat_h
return self._x

@property
def get_y(self):
"""x sweep in crs units (m); x * sat_height"""
if self._y is None:
self._y = self._obj.y * sat_h
return self._y

@property
def get_imshow_kwargs(self):
if self._imshow_kwargs is None:
self._imshow_kwargs = dict(
extent=[
self._x2.data.min(),
self._x2.data.max(),
self._y2.data.min(),
self._y2.data.max(),
],
transform=self._crs,
origin="upper",
interpolation="none",
)
return self._imshow_kwargs

def get_latlon(self):
"""Get lat/lon of all points"""
X, Y = np.meshgrid(self._x, self._y)
a = ccrs.PlateCarree().transform_points(self._crs, X, Y)
lons, lats, _ = a[:, :, 0], a[:, :, 1], a[:, :, 2]

self._obj.coords["longitude"] = (("y", "x"), lons)
self._obj.coords["latitude"] = (("y", "x"), lats)

####################################################################
# Helpers
def _load_RGB_channels(self, channels):
Expand Down
1 change: 1 addition & 0 deletions goes2go/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from goes2go import config

0 comments on commit dd38775

Please sign in to comment.