Skip to content

Commit

Permalink
expose lat lon, region, and timestep filters
Browse files Browse the repository at this point in the history
  • Loading branch information
MRossol committed Jun 16, 2020
1 parent 711b7ff commit fb79caa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions rex/resource_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _init_tree(self, tree=None, compute_tree=False):

return tree

def _get_nearest(self, lat_lon):
def lat_lon_gid(self, lat_lon):
"""
Get nearest gid to given (lat, lon) pair or pairs
Expand All @@ -275,7 +275,7 @@ def _get_nearest(self, lat_lon):
_, gids = self.tree.query(lat_lon)
return gids

def _get_region(self, region, region_col='state'):
def region_gids(self, region, region_col='state'):
"""
Get the gids for given region
Expand All @@ -296,7 +296,7 @@ def _get_region(self, region, region_col='state'):

return gids

def _get_timestep_idx(self, timestep):
def timestep_idx(self, timestep):
"""
Get the index of the desired timestep
Expand Down Expand Up @@ -381,7 +381,7 @@ def get_lat_lon_ts(self, ds_name, lat_lon):
site_ts : ndarray
Time-series for given site(s) and dataset
"""
gid = self._get_nearest(lat_lon)
gid = self.lat_lon_gid(lat_lon)
site_ts = self.get_gid_ts(ds_name, gid)

return site_ts
Expand All @@ -403,7 +403,7 @@ def get_lat_lon_df(self, ds_name, lat_lon):
site_df : pandas.DataFrame
Time-series DataFrame for given site and dataset
"""
gid = self._get_nearest(lat_lon)
gid = self.lat_lon_gid(lat_lon)
site_df = self.get_gid_df(ds_name, gid)

return site_df
Expand All @@ -427,7 +427,7 @@ def get_region_ts(self, ds_name, region, region_col='state'):
Time-series array of desired dataset for all sites in desired
region
"""
gids = self._get_region(region, region_col=region_col)
gids = self.region_gids(region, region_col=region_col)
region_ts = self[ds_name, :, gids]

return region_ts
Expand All @@ -452,7 +452,7 @@ def get_region_df(self, ds_name, region, region_col='state'):
Time-series array of desired dataset for all sites in desired
region
"""
gids = self._get_region(region, region_col=region_col)
gids = self.region_gids(region, region_col=region_col)
region_df = pd.DataFrame(self[ds_name, :, gids], columns=gids,
index=self.time_index)
region_df.name = ds_name
Expand Down Expand Up @@ -518,7 +518,7 @@ def get_SAM_lat_lon(self, lat_lon, out_path=None, **kwargs):
If multiple lat, lon pairs are given a list of DatFrames is
returned
"""
gid = self._get_nearest(lat_lon)
gid = self.lat_lon_gid(lat_lon)
SAM_df = self.get_SAM_gid(gid, out_path=out_path, **kwargs)

return SAM_df
Expand Down Expand Up @@ -546,10 +546,10 @@ def get_timestep_map(self, ds_name, timestep, region=None,
DataFrame of map values
"""
lat_lons = self.lat_lon
ts_idx = self._get_timestep_idx(timestep)
ts_idx = self.timestep_idx(timestep)
gids = slice(None)
if region is not None:
gids = self._get_region(region, region_col=region_col)
gids = self.region_gids(region, region_col=region_col)
lat_lons = lat_lons[gids]

ts_map = self[ds_name, ts_idx, gids]
Expand Down Expand Up @@ -786,7 +786,7 @@ def get_SAM_lat_lon(self, hub_height, lat_lon, out_path=None, **kwargs):
If multiple lat, lon pairs are given a list of DatFrames is
returned
"""
gid = self._get_nearest(lat_lon)
gid = self.lat_lon_gid(lat_lon)
SAM_df = self.get_SAM_gid(hub_height, gid, out_path=out_path, **kwargs)

return SAM_df
Expand Down
2 changes: 1 addition & 1 deletion rex/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""rex Version number"""

__version__ = "0.1.11"
__version__ = "0.1.12"

0 comments on commit fb79caa

Please sign in to comment.