Skip to content

Commit bc7158c

Browse files
committed
fix format
1 parent 3810a0d commit bc7158c

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

src/access_mopper/configurations.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def cmorise(self, file_paths, compound_name, cmor_dataset_json, mip_table):
381381
# Append coordinates and transpose data axes
382382
# 2d data
383383
if data.ndim == 3:
384-
#The order of axes follows the specification in CMIP6_Omon.json.
384+
# The order of axes follows the specification in CMIP6_Omon.json.
385385
cmor_axes.append(grid_id)
386386
cmor_axes.append(cmorTime)
387387
data = np.transpose(data, (1, 2, 0))
@@ -403,7 +403,9 @@ def cmorise(self, file_paths, compound_name, cmor_dataset_json, mip_table):
403403
bounds = np.zeros((len(depth), 2))
404404
bounds[1:, 0] = 0.5 * (depth[1:] + depth[:-1])
405405
bounds[:-1, 1] = 0.5 * (depth[1:] + depth[:-1])
406-
bounds[0, 0] = max(0.0, depth[0] - (depth[1] - depth[0]) / 2)
406+
bounds[0, 0] = max(
407+
0.0, depth[0] - (depth[1] - depth[0]) / 2
408+
)
407409
bounds[-1, 1] = depth[-1] + (depth[-1] - depth[-2]) / 2
408410
cell_bounds = bounds
409411
axis_units = "m"
@@ -416,12 +418,12 @@ def cmorise(self, file_paths, compound_name, cmor_dataset_json, mip_table):
416418
cell_bounds=cell_bounds,
417419
units=axis_units,
418420
)
419-
#The order of axes follows the specification in CMIP6_Omon.json.
421+
# The order of axes follows the specification in CMIP6_Omon.json.
420422
cmor_axes.append(grid_id)
421423
cmor_axes.append(cmor_axis)
422424
cmor_axes.append(cmorTime)
423425
# Transpose data shape to match the order of axis
424-
data = np.transpose(data,(2, 3, 1, 0))
426+
data = np.transpose(data, ( 2, 3, 1, 0))
425427

426428
# Define CMOR variable
427429
cmorVar = cmor.variable(cmor_name, variable_units, cmor_axes, positive=positive)

tests/test_mop.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ def model():
3535
def model_om3():
3636
# Create and save the om3 model
3737
model_instance = ACCESS_OM3_CMIP6(
38-
experiment_id = "historical",
38+
experiment_id="historical",
3939
realization_index="1",
4040
initialization_index="1",
4141
physics_index="1",
4242
forcing_index="1",
4343
parent_mip_era="CMIP6",
4444
parent_activity_id="CMIP",
45-
parent_experiment_id= "piControl",
46-
parent_source_id = "ACCESS-ESM1-5",
47-
parent_variant_label = "r1i1p1f1",
48-
parent_time_units = "days since 0101-1-1",
49-
branch_method = "standard",
45+
parent_experiment_id="piControl",
46+
parent_source_id ="ACCESS-ESM1-5",
47+
parent_variant_label ="r1i1p1f1",
48+
parent_time_units ="days since 0101-1-1",
49+
branch_method ="standard",
5050
branch_time_in_child = 0.0,
5151
branch_time_in_parent = 0.0,
5252
)
@@ -69,14 +69,14 @@ def load_filtered_variables_om3_2d(mappings):
6969
# Load and filter variables from the JSON file
7070
with resources.files("access_mopper.mappings").joinpath(mappings).open() as f:
7171
df = pd.read_json(f, orient="index")
72-
list_2d = [var for var in df.index if len(df.loc[var,"dimensions"])==3]
72+
list_2d = [var for var in df.index if len(df.loc[var,"dimensions"]) == 3]
7373
return list_2d
7474

7575
def load_filtered_variables_om3_3d(mappings):
7676
# Load and filter variables from the JSON file
7777
with resources.files("access_mopper.mappings").joinpath(mappings).open() as f:
7878
df = pd.read_json(f, orient="index")
79-
list_3d = [var for var in df.index if len(df.loc[var,"dimensions"])==4]
79+
list_3d = [var for var in df.index if len(df.loc[var,"dimensions"]) == 4]
8080
return list_3d
8181

8282
@pytest.mark.parametrize(
@@ -131,7 +131,9 @@ def test_cmorise_CMIP6_Emon(model, cmor_name):
131131
"cmor_name", load_filtered_variables_om3_2d("Mappings_OM3_Omon.json")
132132
)
133133
def test_cmorise_OM3_2d(model_om3, cmor_name):
134-
file_pattern = DATA_DIR / f"om3/2d/access-om3.mom6.2d.{cmor_name}.1mon.mean.1902_01.nc"
134+
file_pattern = (
135+
DATA_DIR / f"om3/2d/access-om3.mom6.2d.{cmor_name}.1mon.mean.1902_01.nc"
136+
)
135137
try:
136138
model_om3.supergrid = DATA_DIR / "supergrid/ocean_hgrid.nc"
137139
model_om3.cmorise(
@@ -148,7 +150,9 @@ def test_cmorise_OM3_2d(model_om3, cmor_name):
148150
"cmor_name", load_filtered_variables_om3_3d("Mappings_OM3_Omon.json")
149151
)
150152
def test_cmorise_OM3_3d(model_om3, cmor_name):
151-
file_pattern = DATA_DIR / f"om3/3d/access-om3.mom6.3d.{cmor_name}.1mon.mean.1924_01.nc"
153+
file_pattern = (
154+
DATA_DIR / f"om3/3d/access-om3.mom6.3d.{cmor_name}.1mon.mean.1924_01.nc"
155+
)
152156
try:
153157
model_om3.supergrid = DATA_DIR / "supergrid/ocean_hgrid.nc"
154158
model_om3.cmorise(
@@ -158,4 +162,4 @@ def test_cmorise_OM3_3d(model_om3, cmor_name):
158162
mip_table="CMIP6_Omon.json",
159163
)
160164
except Exception as e:
161-
pytest.fail(f"Failed processing {cmor_name} with table CMIP6_Omon.json: {e}")
165+
pytest.fail(f"Failed processing {cmor_name} with table CMIP6_Omon.json: {e}")

0 commit comments

Comments
 (0)