forked from metoppv/improver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IMPRO-1779 get local day (metoppv#1375)
* Starts to add a TimezoneExtraction plugin * Sets up output_cube - Adds method and test to build the output_cube with appropriate meta-data * Sets up output_cube - Adds support for multiple utc_times * Removes xy-coord function (unnecessary) - And tidies up a bit * Completes plugin and unit-tests. - Removes support for multiple output UTC times (no use-case) - Adds tests to ensure input cubes are compatible * Adds check for spatial coords * Improves doc-string * isort * Improves documentation - Input datetime is now called local_time as this better describes what it is for - time_units definition moved to __init__ as not dependent on any inputs * Adds dtype checking * generate_timezone_mask now outputs masks as int8, not int32 * generate_timezone_mask now outputs cubes with UTC_offset coords that have units * generate_timezone_mask now outputs cubes with correctly-defined UTC_offset coords. * Adds CLI and acceptance tests * Adds unit-test for TypeError * Adds handling for time-bounds on input_cube and refactors create_output_cube to be run last. * Bug fix and update of checksums following inclusion of time-bounds. * Removes the trailing Z from input local-time argument. * Extends unit-test coverage - Tests input as either cube or list - Tests input with and without bounds on the time coord * Changes coord representation of local time from "utc" to "time_in_local_timezone" - Updates code and unit-tests - Updates doc-strings - Updates add_coordinate method to be more explicit in which time coords require an update of forecast_period coord - Updates acceptance test data checksums * Updates acceptance-test checksums following merge with least-significant-digit change. * Simplifies creation of time_in_local_timezone coord to avoid using add_coordinate method for this simple requirement. * First review - Improves an error message - Tweaks doc-strings - Simplifies unit-tests slightly * Second review - Corrects calculation of local-time using the offset (reverses sign) * Second review - Recreates acceptance test inputs and KGO - Because the UK input times were asymmetric, I needed to recreate them. Because I used pytest parameterize (and I got the data from the Alpha suite), I therefore had to recreate the global too. * Second review - Improves doc-strings and comments - Refactors dtype enforcement from temporal.py and cube_combiner.py into check_datatypes.py * Modifies code to handle an extra dimension (e.g. percentile) on the input cube. - Modifies the unit tests so that the dimensions are not all len(3) as this can mask broadcasting errors. * Second review - Modifies plugin to copy any cell_methods on the input_cube onto the output_cube - Improves doc-strings and comments * isort eyesore a puddy tat * Methods that aren't tested directly are now private methods. * Second review: Moves call to spatial_coords_match into check_input_cube_dims. * Updates checksums for cell-method change. * Corrects test for spatial coords mismatch so that it raises an error if necessary.
- Loading branch information
Showing
13 changed files
with
799 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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,67 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# ----------------------------------------------------------------------------- | ||
# (C) British Crown Copyright 2017-2020 Met Office. | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
# | ||
# * Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# | ||
# * Neither the name of the copyright holder nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
"""Script to map multiple forecast times into a local time grid""" | ||
|
||
from improver import cli | ||
|
||
|
||
@cli.clizefy | ||
@cli.with_output | ||
def process( | ||
timezone_cube: cli.inputcube, local_time: str, *cubes: cli.inputcube, | ||
): | ||
"""Calculates timezone-offset data for the specified UTC output times | ||
Args: | ||
timezone_cube (iris.cube.Cube): | ||
Cube describing the UTC offset for the local time at each grid location. | ||
Must have the same spatial coords as input_cube. | ||
Use generate-timezone-mask-ancillary to create this. | ||
local_time (str): | ||
The "local" time of the output cube as %Y%m%dT%H%M. This will form a | ||
scalar "time_in_local_timezone" coord on the output cube, while the "time" | ||
coord will be auxillary to the spatial coords and will show the UTC time | ||
that matches the local_time at each point. | ||
cubes (list of iris.cube.Cube): | ||
Source data to be remapped onto time-zones. Must contain an exact 1-to-1 | ||
mapping of times to time-zones. Multiple input files will be merged into one | ||
cube. | ||
Returns: | ||
iris.cube.Cube: | ||
Processed cube. | ||
""" | ||
from datetime import datetime | ||
from improver.utilities.temporal import TimezoneExtraction | ||
|
||
local_datetime = datetime.strptime(local_time, "%Y%m%dT%H%M") | ||
return TimezoneExtraction()(cubes, timezone_cube, local_datetime) |
This file contains 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 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 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 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 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
Oops, something went wrong.