Skip to content
Snippets Groups Projects
Commit f3015d22 authored by Etor Lucio Eceiza's avatar Etor Lucio Eceiza
Browse files

fix: format

parent d23f851e
No related branches found
No related tags found
No related merge requests found
......@@ -7,38 +7,60 @@ csv_file: Path = BASE_DIR.parent / "Tables/original_tables/ct_ecmwf.rc"
json_output_path: Path = BASE_DIR.parent / "Tables/era5-cmor-tables/Tables"
search_dirs: List[Path] = [
BASE_DIR.parent / "Tables/source_tables/obs4MIPs-cmor-tables/Tables",
BASE_DIR.parent / "Tables/source_tables/cmip6-cmor-tables/Tables"
BASE_DIR.parent / "Tables/source_tables/cmip6-cmor-tables/Tables",
]
# Frequency priority
frequency_priority: Dict[str, List[str]] = {
"1hr": [
"A1hr", "A3hr", "A6hr", # Atmospheric hourly tables
"E1hr", "E3hr", "E6hrZ", # Earth system / energy hourly
"E1hrClimMon", "E3hrPt", # Other energy system hourly
"CF3hr", "CFsubhr", "Esubhr", # High-res and subhourly
"3hr", "6hrLev", "6hrPlev", "6hrPlevPt", # More coarse-hourly or pressure-level
"AERhr" # Aerosol-specific hourly
"A1hr",
"A3hr",
"A6hr", # Atmospheric hourly tables
"E1hr",
"E3hr",
"E6hrZ", # Earth system / energy hourly
"E1hrClimMon",
"E3hrPt", # Other energy system hourly
"CF3hr",
"CFsubhr",
"Esubhr", # High-res and subhourly
"3hr",
"6hrLev",
"6hrPlev",
"6hrPlevPt", # More coarse-hourly or pressure-level
"AERhr", # Aerosol-specific hourly
],
"day": [
"Aday", "Eday", "EdayZ", # Standard and energy/dynamics daily
"CFday", # High-res daily
"SIday", # Sea ice daily
"Oday", # Ocean daily
"AERday", # Aerosol daily
"day" # Generic fallback
"Aday",
"Eday",
"EdayZ", # Standard and energy/dynamics daily
"CFday", # High-res daily
"SIday", # Sea ice daily
"Oday", # Ocean daily
"AERday", # Aerosol daily
"day", # Generic fallback
],
"mon": [
"Amon", "Lmon", "Omon", # Atmosphere, land, ocean monthly
"Emon", "EmonZ", # Energy system monthly
"CFmon", # High-res monthly
"SImon", # Sea ice monthly
"AERmon", "AERmonZ", # Aerosol monthly
"ImonAnt", "ImonGre", "LImon" # Ice-specific monthly
"Amon",
"Lmon",
"Omon", # Atmosphere, land, ocean monthly
"Emon",
"EmonZ", # Energy system monthly
"CFmon", # High-res monthly
"SImon", # Sea ice monthly
"AERmon",
"AERmonZ", # Aerosol monthly
"ImonAnt",
"ImonGre",
"LImon", # Ice-specific monthly
],
"fx": [
"fx", "Ofx", "Efx", "IfxAnt", "IfxGre" # Fixed fields (land, ocean, earth system, ice)
]
"fx",
"Ofx",
"Efx",
"IfxAnt",
"IfxGre", # Fixed fields (land, ocean, earth system, ice)
],
}
# Level groupings
......@@ -46,7 +68,7 @@ level_categories: Dict[str, List[str]] = {
"sfc": ["sfc_an", "sfc_fc"],
"sfc_land": ["sfc_an_land", "sfc_fc_land"],
"pl": ["pl_an", "pl_fc"],
"ml": ["ml_an"]
"ml": ["ml_an"],
}
# Realm → prefix
......@@ -58,19 +80,16 @@ realm_prefix_map: Dict[str, str] = {
"land": "L",
"landIce": "LI",
"ocean": "O",
"seaIce": "SI"
"seaIce": "SI",
}
# Approximate intervals in days
approx_interval_map: Dict[str, float] = {
"1hr": round(1 / 24, 5), # 0.04167
"1hr": round(1 / 24, 5), # 0.04167
"day": 1.00000,
"mon": 30.00000,
"fx": 0.00000
"fx": 0.00000,
}
# Number of levels
level_number: Dict[str, int] = {
"pl": 37,
"ml": 137
}
level_number: Dict[str, int] = {"pl": 37, "ml": 137}
This diff is collapsed.
from typing import Any
import pandas as pd
from typing import Optional, Dict, List, Any
def excel_to_csv(excel_path, csv_path, sheet_name=0, field_separator="|") -> Any:
def excel_to_csv(
excel_path, csv_path, sheet_name=0, field_separator="|"
) -> Any:
"""
Converts an Excel sheet into a delimited CSV file.
Parameters:
excel_path (str or Path): Path to the input Excel file.
csv_path (str or Path): Destination path for the output CSV file.
sheet_name (int or str, optional): Sheet index or name to read from.
Default is the first sheet (0).
field_separator (str, optional): Delimiter to use in the CSV.
Default is '|'.
Returns:
Any: The path to the generated CSV file.
"""
df: pd.DataFrame = pd.read_excel(excel_path, sheet_name=sheet_name)
df.to_csv(csv_path, sep=field_separator, index=False)
return csv_path
def csv_to_excel(csv_path, excel_path, sheet_name="cmor_table", field_separator="|") -> str:
def csv_to_excel(
csv_path, excel_path, sheet_name="cmor_table", field_separator="|"
) -> str:
"""
Converts a delimited CSV file into an Excel sheet.
Parameters:
csv_path (str or Path): Path to the input CSV file.
excel_path (str or Path): Destination path for the output Excel file.
sheet_name (str, optional): Name of the sheet in the Excel file.
Default is 'cmor_table'.
field_separator (str, optional): Delimiter used in the CSV.
Default is '|'.
Returns:
str: The path to the generated Excel file.
"""
df: pd.DataFrame = pd.read_csv(csv_path, sep=field_separator)
df.to_excel(excel_path, sheet_name=sheet_name, index=False)
return excel_path
\ No newline at end of file
return excel_path
import subprocess
import sys
def cf_check(nc_file):
try:
result = subprocess.run(['cfchecks', nc_file], capture_output=True, text=True, check=True)
result = subprocess.run(
["cfchecks", nc_file], capture_output=True, text=True, check=True
)
print(result.stdout)
except subprocess.CalledProcessError as e:
print("CF checker error:", e.stderr, file=sys.stderr)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment