Skip to content
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

Merge new subsetting code into framework #327

Closed
jpolton opened this issue Sep 24, 2021 · 1 comment
Closed

Merge new subsetting code into framework #327

jpolton opened this issue Sep 24, 2021 · 1 comment
Assignees

Comments

@jpolton
Copy link
Collaborator

jpolton commented Sep 24, 2021

Revisiting Steve Loch's subsetting edits for wrapped coordinates.

Merged in new develop.
Differences:

  • moved calculate_haversine_distance from coast.py to general_utils.py

  • Rewrite of coast/subset_indices_lonlat_box(self, lonbounds, latbounds). Now general_utils/subset_indices_lonlat_box(self, ww=np.NaN, ee=np.NaN, ss=np.NaN, nn=np.NaN) With new arguments.

  • preserved old structure (not sure if this is good practise or not):

def coast/subset_indices_lonlat_box(self, ww=np.NaN, ee=np.NaN, ss=np.NaN, nn=np.NaN):
return general_utils/subset_indices_lonlat_box(self, ww=np.NaN, ee=np.NaN, ss=np.NaN, nn=np.NaN)
  • Removed option of the cheap and dirty (and fast method):
    def subset_indices_lonlat_box(self, lonbounds, latbounds):
         """Generates array indices for data which lies in a given lon/lat box.
        Keyword arguments:
         lon       -- Longitudes, 1D or 2D.
         lat       -- Latitudes, 1D or 2D
         lonbounds -- Array of form [min_longitude=-180, max_longitude=180]
         latbounds -- Array of form [min_latitude, max_latitude]

         return: Indices corresponding to datapoints inside specified box
         """
         debug(f"Subsetting {get_slug(self)} indices within lon/lat")

         lon_str = "longitude"
         lat_str = "latitude"
         lon = self.dataset[lon_str].copy()  # TODO Add a comment explaining why this needs to be copied
         lat = self.dataset[lat_str]
         ff = lon > lonbounds[0]
         ff *= lon < lonbounds[1]
         ff *= lat > latbounds[0]
         ff *= lat < latbounds[1]

         return np.where(ff)
  • Added some examples scripts:

example_scripts/subsetting_by_lon_lat.py (Requires no input data)
example_scripts/find_models_nearest_point.py (Requires input data)

@jpolton jpolton self-assigned this Mar 28, 2022
@jpolton
Copy link
Collaborator Author

jpolton commented Mar 28, 2022

Actions:

  • Check location of Haversine unit test

  • Make unit test for subsetting by lat lon, based on the example script.

  • Assess what to do with the new JSON files and example data.

  • Assess how to edit the docs, if at all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
1 participant