checksit.rules.rule_funcs
Rule functions for checks.
This module contains functions that are used to check values against rules. Each function takes a value and returns a list of errors if the value does not meet the rule.
Functions
|
Check for proposed_standard_name if standard_name not given |
|
Check if the platform is in the CEDA catalogue API |
|
Check QC flag values and meanings meet NCAS-General requirements |
|
Check date given is in ISO 8601 format and in UTC |
|
Check value is valid for NCAS Image headline tag. |
|
Check if the value is within -90 and +90 |
|
Check list of names matches expected pattern. |
|
Check if the value is within -180 and +180 |
|
Check if value matches the file name. |
|
Check if value matches one of the options. |
|
Check one or more values for matches against options. |
|
Check if the platform is in the NCAS platform list |
|
Check relation field is in the correct format and that the url exists. |
|
Check string is of a certain length. |
|
Check if title matches the filename. |
|
Check URL exists and is reachable. |
|
Check value meets date and time format. |
|
Check value meets ORCID URL format. |
- checksit.rules.rule_funcs.allow_proposed(value, context, extras=None, label='')[source]
Check for proposed_standard_name if standard_name not given
Used in CFRadial and the NCAS-Radar standard, this function takes the value of both the standard_name attribute and the proposed_standard_name attribute (if they exist) and compares each to the expected value, as given in extras.
- Parameters:
value – value of the standard_name attribute
context – value of the proposed_standard_name attribute
extras – list of expected values
label – label to prepend to error message returned
- Returns:
List with error string if neither value matches the expected value
- checksit.rules.rule_funcs.ceda_platform(value: str, context: Any, extras: List[str] | None = None, label: str = '') List[str][source]
Check if the platform is in the CEDA catalogue API
Attempt to find the platform in the CEDA catalogue API, at https://api.catalogue.ceda.ac.uk/api/v2/identifiers.json/?url={value}.
- Parameters:
value – platform value to check
label – label to prepend to error message returned
- Returns:
List with error string if platform is not in the CEDA catalogue
- checksit.rules.rule_funcs.check_qc_flags(value: Any, context: str, extras: List[str] | None = None, label: str = '') List[str][source]
Check QC flag values and meanings meet NCAS-General requirements
Checks the QC flag values and meanings. The flag values must be an array or tuple of byte values, with at least two values, starting with 0 and 1. The flag meanings must be space separated and the first two must start with ‘not_used’ and ‘good_data’. The number of flag values must equal the number of flag meanings.
- Parameters:
value – flag values, as defined in the netCDF file
context – flag meanings, as defined in the netCDF file
label – label to prepend to error message returned
- Returns:
List with error string if QC flag values and meanings do not meet requirements
- checksit.rules.rule_funcs.check_utc_date_iso_format(value: str, context: Any, extras: List[str] | None = None, label: str = '') List[str][source]
Check date given is in ISO 8601 format and in UTC
- Parameters:
value – date string to check
label – label to prepend to error message returned
- Returns:
List with error string if date string does not meet
- checksit.rules.rule_funcs.headline(value: str, context: Any, extras: List[str] | None = None, label: str = '') List[str][source]
Check value is valid for NCAS Image headline tag.
Check if the value is valid for the NCAS Image headline tag. The headline should be a single sentence, starting with a capital letter, and should not exceed 150 characters.
- Parameters:
value – value to check
label – label to prepend to error message returned
- Returns:
List with error string if headline format does not match.
- checksit.rules.rule_funcs.latitude(value: str, context: Any, extras: List[str] | None = None, label: str = '') List[str][source]
Check if the value is within -90 and +90
- Parameters:
value – value to check
label – label to prepend to error message returned
- Returns:
List with error string if latitude is not within -90 and +90
- checksit.rules.rule_funcs.list_of_names(value: str | List[str], context: Any, extras: List[str] | None = None, label: str = '') List[str][source]
Check list of names matches expected pattern.
Check if a given name or list of names matches the expected pattern. The pattern is <last name>, <first name> <middle initials(s)> or <last name>, <first name> <middle name(s)>. Designed for checks with the NCAS-Image standard.
- Parameters:
value – name(s) to check
label – label to prepend to error message returned
- Returns:
List with error string if name format does not match.
- checksit.rules.rule_funcs.longitude(value: str, context: Any, extras: List[str] | None = None, label: str = '') List[str][source]
Check if the value is within -180 and +180
- Parameters:
value – value to check
label – label to prepend to error message returned
- Returns:
List with error string if longitude is not within -180 and +180
- checksit.rules.rule_funcs.match_file_name(value: str, context: Dict[str, str], extras: List[str] | None = None, label: str = '') List[str][source]
Check if value matches the file name.
Check if the value matches the file name. The file name is extracted from the context dictionary, which should contain the file path as a value with the key ‘file_path’.
- Parameters:
value – value to check
context – dictionary containing the file path
extras – list of preprocessors to run on the value
label – label to prepend to error message returned
- Returns:
List of errors.
- checksit.rules.rule_funcs.match_one_of(value: str, context: Any, extras: List[str] | None = None, label: str = '') List[str][source]
Check if value matches one of the options.
Check if the value matches one of the options defined in the extras list. The options are separated by the rule splitter, which is defined in the checksit.ini file. The default rule splitter is ‘|’.
- Parameters:
value – value to check
extras – list with string of options to match, options separated by rule splitter (default ‘|’)
label – label to prepend to error message returned
- Returns:
List with error string if no match found.
- checksit.rules.rule_funcs.match_one_or_more_of(value: str, context: Any, extras: List[str] | None = None, label: str = '') List[str][source]
Check one or more values for matches against options.
Check if the value or values given can be found in the options list specified in extras. The options in extras are a string separated by the rule splitter, and the value is a string with values separated by commas. Checks if all values are found within the options.
- Parameters:
value – value to check
extras – list with string of options to match, options separated by rule splitter (default ‘|’)
label – label to prepend to error message returned
- Returns:
List with error string if no match found.
- checksit.rules.rule_funcs.ncas_platform(value: str, context: Any, extras: List[str] | None = None, label: str = '') List[str][source]
Check if the platform is in the NCAS platform list
Attempt to find the platform in the NCAS platform list, in the latest release of https://github.com/ncasuk/ncas-data-platform-vocabs.
- Parameters:
value – platform value to check
label – label to prepend to error message returned
- Returns:
List with error string if platform is not in the NCAS platform list
- checksit.rules.rule_funcs.relation_url_checker(value: str, context: Any, extras: List[str] | None = None, label: str = '') List[str][source]
Check relation field is in the correct format and that the url exists.
Designed for checking the Relation tag matches the expected format in the NCAS-Image standard, and the URL is reachable using the url_checker function.
- Parameters:
value – value to check
label – label to prepend to error message returned
- Returns:
- List with error string if Relation tag does not match expected format or URL is
not reachable
- checksit.rules.rule_funcs.string_of_length(value: str, context: Any, extras: List[str] | None = None, label: str = '') List[str][source]
Check string is of a certain length.
Check if the string is of a certain length. The length is defined in the extras list, which should contain the length as a string. If the length is followed by a ‘+’ sign, the string must be at least that length. If the length is not followed by a ‘+’, the string must be exactly that length.
- Parameters:
value – value to check
extras – list with length as string
label – label to prepend to error message returned
- Returns:
List with error string if length does not match.
- checksit.rules.rule_funcs.title_check(value: str, context: Any, extras: List[str] | None = None, label: str = '') List[str][source]
Check if title matches the filename.
For NCAS-Image standard, check if the value (from the title tag) matches the name of the file (given in the context).
- Parameters:
value – value to check
context – file path
label – label to prepend to error message returned
- Returns:
List with error string if title does not match file name.
- checksit.rules.rule_funcs.url_checker(value: str, context: Any, extras: List[str] | None = None, label: str = '') List[str][source]
Check URL exists and is reachable.
- Parameters:
value – URL to check
label – label to prepend to error message returned
- Returns:
List with error string if URL is not reachable.
- checksit.rules.rule_funcs.validate_image_date_time(value: str, context: Any, extras: List[str] | None = None, label: str = '') List[str][source]
Check value meets date and time format.
Check if the value meets the date and time format that is expected for the NCAS-Image standard. The expected format is ‘YYYY:MM:DD HH:MM:SS’ or ‘YYYY:MM:DD HH:MM:SS.s’.
- Parameters:
value – value to check
label – label to prepend to error message returned
- Returns:
List with error string if date and time format does not match.
- checksit.rules.rule_funcs.validate_orcid_ID(value: str, context: Any, extras: List[str] | None = None, label: str = '') List[str][source]
Check value meets ORCID URL format.
Check if the value meets the ORCID URL format (i.e. https://orcid.org/XXXX-XXXX-XXXX-XXXX).
- Parameters:
value – value to check
label – label to prepend to error message returned
- Returns:
List with error string if ORCID ID format does not match.