-
Notifications
You must be signed in to change notification settings - Fork 19
Adds a global model application for CURV #2091
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
Draft
David Flack (daflack)
wants to merge
24
commits into
main
Choose a base branch
from
2089_global_CURV
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
db67b9b
Adds a global model application for CURV
daflack ddbfdea
Adds operators into CSET operators init and documentation
daflack 8a7d2b7
Near full version of a slow CURV operator
daflack 7149a7c
Update to a comment for code if current testing works
daflack 48baa8a
Update to basic CURV operator
daflack 0daa334
Update CURV operator to show it is for global CURV
daflack da0eb9c
Adds basic recipe and plumbing into workflow
daflack e75842d
Adds CURV to example conf
daflack 46ed154
Update rose-meta.conf
daflack b5b6ebf
Updates recipe to use the faster operator, and creates a tentative fast
daflack fef18fd
Switches to linear interpolation and adds options to change radius and
daflack 458ddb2
Removes slow version of code, renames fast version, updates recipe
daflack 1c23526
Adds new colorbar for curv
daflack 2afa271
Updates colorbar
daflack 7df24d6
Updates colorbar
daflack a17ee54
Update colorbar and default tolerance
daflack 0fb9689
Adds regridding to recipe
daflack 55a665f
Update recipe to default tolerance
daflack f28a3db
Fix precommit checkes
daflack 3c94959
Update recipe with new pressure variable name
daflack c98da69
Remove regridding from recipe and add tolerance as a variable
daflack 2a794ee
Update documentation
daflack 2e6b49c
Fix spacing in docs
daflack f13ddb9
Update for pre-commit tests
daflack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| # © Crown copyright, Met Office (2022-2026) and CSET contributors. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """A module containing different implementations of CURV. | ||
|
|
||
| The diagnostics here are separate implementations of CURV for both | ||
| global models and limited-area models. | ||
| """ | ||
|
|
||
| import logging | ||
|
|
||
| import iris | ||
| import numpy as np | ||
|
|
||
| from CSET._common import iter_maybe | ||
|
|
||
|
|
||
| def _lat_lon_identifier(original_lat, original_lon, distance, bearing): | ||
| """Find the latitude and longitude of new points based on great circle distance.""" | ||
| R = 6371.0 # km. | ||
| lat_rad = np.radians(original_lat) | ||
| lon_rad = np.radians(original_lon) | ||
| bearing_rad = np.radians(bearing) | ||
|
|
||
| new_lat = np.arcsin( | ||
| np.sin(lat_rad) * np.cos(distance / R) | ||
| + np.cos(lat_rad) * np.sin(distance / R) * np.cos(bearing_rad) | ||
| ) | ||
| new_lon = lon_rad + np.arctan2( | ||
| np.sin(bearing_rad) * np.sin(distance / R) * np.cos(lat_rad), | ||
| np.cos(distance / R) - np.sin(lat_rad) * np.sin(new_lat), | ||
| ) | ||
|
|
||
| new_lat = np.degrees(new_lat) | ||
| new_lon = np.degrees(new_lon) | ||
| new_lon = np.where(new_lon > 180.0, new_lon - 360.0, new_lon) | ||
|
|
||
| return new_lat, new_lon | ||
|
|
||
|
|
||
| def global_curv(central, radius, num_radial_points=16, tol=400.0): | ||
| """Calculate the CURV diagnostic for a global model VERSION 2 for faster calculation speed.""" | ||
| if (num_radial_points == 8) or (num_radial_points == 16): | ||
| bearing = np.linspace(0.0, 360.0, num_radial_points + 1)[:-1] | ||
| else: | ||
| raise ValueError( | ||
| f"Number of radial points should be 8 or 16. You have provided {num_radial_points}." | ||
| ) | ||
|
|
||
| logging.info( | ||
| f"CURV calculated base on {num_radial_points} radial points, a {radius} km radius and {tol} tolerance." | ||
| ) | ||
| curv_cubes = iris.cube.CubeList([]) | ||
| for cube in iter_maybe(central): | ||
| curv = cube.copy() | ||
| surroundings = [] | ||
| lats, lons = np.meshgrid( | ||
| cube.coord("latitude").points, cube.coord("longitude").points | ||
| ) | ||
| for b in bearing: | ||
| target_data = cube.copy() | ||
| new_lat, new_lon = _lat_lon_identifier( | ||
| lats, | ||
| lons, | ||
| radius, | ||
| b, | ||
| ) | ||
| new_lat_points = new_lat[0, :] | ||
| new_lon_points = new_lon[:, 0] | ||
| surround = target_data.interpolate( | ||
| [("latitude", new_lat_points), ("longitude", new_lon_points)], | ||
| iris.analysis.Linear(), | ||
| ) | ||
| surroundings.append(surround.data) | ||
| surroundings = np.array(surroundings) | ||
| curv_data = surroundings - cube.data | ||
| curv_data_binary = np.zeros(curv_data.shape) | ||
| curv_data_binary[curv_data > tol] = -1.0 | ||
| curv_data_binary[curv_data < -tol] = 1.0 | ||
| curv_data_collapsed = np.sum(curv_data_binary, 0) | ||
| curv.data = curv_data_collapsed | ||
| curv.rename(f"CURV_calculated_from_{num_radial_points}_radial_points") | ||
| curv.units = "1" | ||
| curv_cubes.append(curv) | ||
| if len(curv_cubes) == 1: | ||
| return curv_cubes[0] | ||
| else: | ||
| return curv_cubes | ||
31 changes: 31 additions & 0 deletions
31
src/CSET/recipes/derived_diagnostics/daily_weather/curv_spatial_plot.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| category: Daily Weather | ||
| title: $MODEL_NAME CURV spatial plot from $CURV_POINTS points and radius of $CURV_RADIUS km | ||
| description: | | ||
| Generates the curvature (CURV) from MSLP and creates a spatial plot. | ||
| It uses $CURV_POINTS points and a radius of $CURV_RADIUS km and a | ||
| tolerance of $CURV_TOLERANCE Pa. | ||
| +$CURV_POINTS is a full anticyclone and -$CURV_POINTS is a full cyclone. | ||
| steps: | ||
| - operator: read.read_cubes | ||
| file_paths: $INPUT_PATHS | ||
| model_names: $MODEL_NAME | ||
| constraint: | ||
| operator: constraints.combine_constraints | ||
| varname_constraint: | ||
| operator: constraints.generate_var_constraint | ||
| varname: air_pressure_at_sea_level | ||
| cell_methods_constraint: | ||
| operator: constraints.generate_cell_methods_constraint | ||
| cell_methods: [] | ||
| subarea_type: $SUBAREA_TYPE | ||
| subarea_extent: $SUBAREA_EXTENT | ||
|
|
||
| - operator: curvature.global_curv | ||
| radius: $CURV_RADIUS | ||
| num_radial_points: $CURV_POINTS | ||
| tol: $CURV_TOLERANCE | ||
|
|
||
| - operator: plot.spatial_pcolormesh_plot | ||
|
|
||
| - operator: write.write_cube_to_nc | ||
| overwrite: True |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.