British-Oceanographic-Data-Centre / COAsT

A Coastal Ocean Assessment Tool built as an extendable python framework for nemo models
https://british-oceanographic-data-centre.github.io/COAsT/
MIT License
24 stars 11 forks source link

nav_lon in gridded.py #610

Closed b-barton closed 1 year ago

b-barton commented 1 year ago

trim_domain_size() in gridded.py needs self.dataset.nav_lat and self.dataset.nav_lon but they are not required in the dataset json.

jpolton commented 1 year ago

It turns out that the trim_domain_size() method does sometimes need to use unCOAsTlike nav_lat and nav_lon. This is a legacy issue that I haven't found a clean solution for. Instead I propose a try/except solution (below). This will get resolved with a PR #607

            # Find the corners of the cut out domain.
            try:
                [j0, i0] = self.find_j_i_domain(
                    lat=self.dataset.latitude[0, 0], lon=self.dataset.longitude[0, 0], dataset_domain=dataset_domain
                )
                [j1, i1] = self.find_j_i_domain(
                    lat=self.dataset.latitude[-1, -1], lon=self.dataset.longitude[-1, -1], dataset_domain=dataset_domain
                )
                debug(f"trim_domain_size(): USED dataset.longitude")
            except: # if called before variables are re-mapped. Not very pretty...
                [j0, i0] = self.find_j_i_domain(
                    lat=self.dataset.nav_lat[0, 0], lon=self.dataset.nav_lon[0, 0], dataset_domain=dataset_domain
                )
                [j1, i1] = self.find_j_i_domain(
                    lat=self.dataset.nav_lat[-1, -1], lon=self.dataset.nav_lon[-1, -1], dataset_domain=dataset_domain
                )
                debug(f"trim_domain_size(): USED dataset.nav_lon")
jpolton commented 1 year ago

fixed