-
Notifications
You must be signed in to change notification settings - Fork 2
T&S | Daily Anomalies with Depth
Required Model Data: Daily model means at all depths, in monthly files. If files are daily, they need to be concatenated into monthly files first.
Required Obs Data: EN4 profile data in monthly files.
This set of files can be used for calculating daily anomalies (EN4 vs model mean) at all depths. Higher frequency model output is avoided due to high storage requirements for high resolution models. 'Mean' profiles and errors with depth can then be derived for user specified regions, or for an entire domain.
There are three steps involved for this analysis.
- Extract model data and do some basic analysis using
analyse_ts_per_file(). - Concatenate output into single file using a tool such as
ncoorcdo. - Average the concatenated analysis into regional analyses using
analyse_ts_regional().
See below for more information and examples on each step.
Extract model data at EN4 locations and times, and calculate errors/ anomalies. Inputs to this routine are a monthly model file and a corresponding monthly EN4 file. It will interpolate the model onto EN4 using a nearest neighbour approach both in time and space. The model will also be interpolated onto observation depths. Output files contain extracted model profiles both on the original and observation depths.
Inputs
def analyse_ts_per_file(fn_nemo_data, fn_nemo_domain, fn_en4, fn_out,
run_name = 'Undefined', surface_def=5, bottom_def=10,
dist_crit=5):
INPUTS:
fn_nemo_data (str) : Absolute filename to a monthly nemo file containing daily mean data.
fn_nemo_domain (str) : Absolute filepath to corresponding NEMO domain_cfg.nc
fn_en4 (str) : Absolute filepath to monthly EN4 profile data file.
fn_out (str) : Absolute filepath for desired output file.
run_name (str) : Name of run. [default='Undefined']
surface_def (float) : Depth of surface for averaging surface variables [default=5m]
bottom_def (float) : Distance from bottom for defining bottom variable averaging [default=10m]
dist_crit (float) : Distance at which to omit datapoints if the resulting interpolated
point is too far from obs point. [default=5km]
This routine is performed per file pair (NEMO and EN4 for a specific month) and should be used as part of a larger looping process over each month. This could be in serial or in parallel (recommended for higher larger datasets). For serial analysis, you just need a list of input files and output files to feed to this routine in a loop.
For parallel analysis, an additional script is available in this repository to help: sample_par_analyse_ts_per_file(). This script can be passed a single index (from the command line), which it will use to find the correct NEMO-EN4 file pair and then pass them to analyse_ts_per_file(). The top part of this script should be modified to match your directory structure and then submitted to a job-array type system (e.g. SLURM job-arrays). For example, using SLURM on JASMIN:
#!/bin/bash
#SBATCH --partition=short-serial
#SBATCH -o %A_%a.out
#SBATCH -e %A_%a.err
#SBATCH --time=30:00
#SBATCH --array=1-132%10
module add jaspy
source ~/envs/coast/bin/activate
python sample_script_mean_profile.py $SLURM_ARRAY_TASK_ID
Output analysis files contain:
- Extracted profiles at observation locations/times at model depths.
- Extracted profiles at observation locations/times interpolated (linearly) onto observation depths.
- Anomalies/Errors between model and obs at observation depths.
- 'Surface' errors defined by taking the mean of some top depths.
- 'Bottom' errors defined by taking the mean of some bottom depths (according to model bathymetry).
Output from the previous step will be into monthly files. These files should be concatenated into a single analysis file before regional analysis.
The output from analyse_ts_per_file() can be averaged into regional sections of the model domain using analyse_ts_regional. This routine is useful for creating 'mean' profiles or mean errors in different regional basins. The routine:
def analyse_ts_regional(fn_nemo_domain, fn_extracted, fn_out, ref_depth,
regional_masks=[], region_names=[]):
INPUTS:
fn_nemo_domain. (str) : Absolute path to NEMO domain_cfg.nc
fn_extracted (str) : Absolute path to single analysis file
fn_out (str) : Absolute path to desired output file
ref_depth. (array) : 1D array describing the reference depths onto which model and observations will be interpolated
regional_masks. (list) : List of 2D bool arrays describing averaging regions. Each array should have same shape as model domain. True
indicates a model point within the defined region. Will always do a 'Whole Domain' region, even when undefined.
region_names. (list) : List of strings. Names for each region in regional masks.
This routine will identify with locations lie within the regional mask and average over all profiles. This will output a single averaged file. Regional masks can be defined by the user manually. COAsT also contains some routines for creating AMM15 masks.