Skip to content

Commit c0bdd6c

Browse files
committed
Update dumpers to write relative to yaml, make loader/dumper tests independent
1 parent ad32157 commit c0bdd6c

File tree

196 files changed

+1615
-93
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+1615
-93
lines changed

poetry.lock

Lines changed: 21 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/linkml_arrays/dumpers/yaml_array_file_dumper.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,17 @@ def _iterate_element(
6161
else:
6262
output_file_name = f"{found_slot.name}"
6363

64-
# if output_dir is absolute, make it relative to current working directory
65-
# and create the directory if it does not exist
66-
if output_dir.is_absolute():
67-
output_dir = Path(os.path.relpath(output_dir, start=os.getcwd()))
68-
output_dir.mkdir(exist_ok=True)
69-
output_file_path_no_suffix = output_dir / output_file_name
64+
output_file_path_no_suffix = (output_dir / output_file_name)
7065

7166
# save the numpy array to file and write the file path to the dictionary
7267
output_file_path = write_array(v, output_file_path_no_suffix)
68+
69+
# write the path to the array file relative to the output directory where the yaml is written
70+
relative_output_file_path = os.path.relpath(output_file_path, start=output_dir)
7371
ret_dict[k] = {
7472
"source": [
7573
{
76-
"file": f"./{output_file_path}",
74+
"file": f"{relative_output_file_path}",
7775
"format": format,
7876
}
7977
]
@@ -100,6 +98,21 @@ class YamlArrayFileDumper(Dumper, metaclass=ABCMeta):
10098

10199
# FORMAT is a class attribute that must be set by subclasses
102100

101+
def dump(
102+
self,
103+
element: Union[YAMLRoot, BaseModel],
104+
to_file: str,
105+
schemaview: SchemaView,
106+
**kwargs,
107+
):
108+
"""Dump the element to a YAML file with paths to array files."""
109+
output_dir = Path(to_file).parent
110+
input = _iterate_element(
111+
element, schemaview, Path(output_dir), self.write_array, self.FORMAT
112+
)
113+
with open(to_file, "w") as f:
114+
yaml.dump(input, f)
115+
103116
def dumps(
104117
self,
105118
element: Union[YAMLRoot, BaseModel],

tests/input/container_yaml_hdf5.yaml renamed to tests/test_dumpers/ground_truth/container_yaml_hdf5.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ latitude_series:
33
name: my_latitude
44
values:
55
source:
6-
- file: ./out/my_latitude.values.h5
6+
- file: my_latitude.values.h5
77
format: hdf5
88
longitude_series:
99
name: my_longitude
1010
values:
1111
source:
12-
- file: ./out/my_longitude.values.h5
12+
- file: my_longitude.values.h5
1313
format: hdf5
1414
temperature_dataset:
1515
date:
1616
values:
1717
source:
18-
- file: ./out/my_temperature.date.values.h5
18+
- file: my_temperature.date.values.h5
1919
format: hdf5
2020
day_in_d:
2121
reference_date: '2020-01-01'
2222
values:
2323
source:
24-
- file: ./out/my_temperature.day_in_d.values.h5
24+
- file: my_temperature.day_in_d.values.h5
2525
format: hdf5
2626
latitude_in_deg: my_latitude
2727
longitude_in_deg: my_longitude
@@ -30,5 +30,5 @@ temperature_dataset:
3030
conversion_factor: 1000.0
3131
values:
3232
source:
33-
- file: ./out/my_temperature.temperatures_in_K.values.h5
33+
- file: my_temperature.temperatures_in_K.values.h5
3434
format: hdf5

tests/input/container_yaml_numpy.yaml renamed to tests/test_dumpers/ground_truth/container_yaml_numpy.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ latitude_series:
33
name: my_latitude
44
values:
55
source:
6-
- file: "./out/my_latitude.values.npy"
6+
- file: my_latitude.values.npy
77
format: numpy
88
longitude_series:
99
name: my_longitude
1010
values:
1111
source:
12-
- file: "./out/my_longitude.values.npy"
12+
- file: my_longitude.values.npy
1313
format: numpy
1414
temperature_dataset:
1515
date:
1616
values:
1717
source:
18-
- file: "./out/my_temperature.date.values.npy"
18+
- file: my_temperature.date.values.npy
1919
format: numpy
2020
day_in_d:
2121
reference_date: '2020-01-01'
2222
values:
2323
source:
24-
- file: "./out/my_temperature.day_in_d.values.npy"
24+
- file: my_temperature.day_in_d.values.npy
2525
format: numpy
2626
latitude_in_deg: my_latitude
2727
longitude_in_deg: my_longitude
@@ -30,5 +30,5 @@ temperature_dataset:
3030
conversion_factor: 1000.0
3131
values:
3232
source:
33-
- file: "./out/my_temperature.temperatures_in_K.values.npy"
33+
- file: my_temperature.temperatures_in_K.values.npy
3434
format: numpy

tests/input/container_yaml_xarray_netcdf.yaml renamed to tests/test_dumpers/ground_truth/container_yaml_xarray_netcdf.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ latitude_series:
33
name: my_latitude
44
values:
55
source:
6-
- file: "./out/my_latitude.values.nc"
6+
- file: my_latitude.values.nc
77
format: netcdf
88
longitude_series:
99
name: my_longitude
1010
values:
1111
source:
12-
- file: "./out/my_longitude.values.nc"
12+
- file: my_longitude.values.nc
1313
format: netcdf
1414
temperature_dataset:
1515
date:
1616
values:
1717
source:
18-
- file: "./out/my_temperature.date.values.nc"
18+
- file: my_temperature.date.values.nc
1919
format: netcdf
2020
day_in_d:
2121
reference_date: '2020-01-01'
2222
values:
2323
source:
24-
- file: "./out/my_temperature.day_in_d.values.nc"
24+
- file: my_temperature.day_in_d.values.nc
2525
format: netcdf
2626
latitude_in_deg: my_latitude
2727
longitude_in_deg: my_longitude
@@ -30,5 +30,5 @@ temperature_dataset:
3030
conversion_factor: 1000.0
3131
values:
3232
source:
33-
- file: "./out/my_temperature.temperatures_in_K.values.nc"
33+
- file: my_temperature.temperatures_in_K.values.nc
3434
format: netcdf

tests/input/container_yaml_xarray_zarr.yaml renamed to tests/test_dumpers/ground_truth/container_yaml_xarray_zarr.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ latitude_series:
33
name: my_latitude
44
values:
55
source:
6-
- file: "./out/my_latitude.values.zarr"
6+
- file: my_latitude.values.zarr
77
format: zarr
88
longitude_series:
99
name: my_longitude
1010
values:
1111
source:
12-
- file: "./out/my_longitude.values.zarr"
12+
- file: my_longitude.values.zarr
1313
format: zarr
1414
temperature_dataset:
1515
date:
1616
values:
1717
source:
18-
- file: "./out/my_temperature.date.values.zarr"
18+
- file: my_temperature.date.values.zarr
1919
format: zarr
2020
day_in_d:
2121
reference_date: '2020-01-01'
2222
values:
2323
source:
24-
- file: "./out/my_temperature.day_in_d.values.zarr"
24+
- file: my_temperature.day_in_d.values.zarr
2525
format: zarr
2626
latitude_in_deg: my_latitude
2727
longitude_in_deg: my_longitude
@@ -30,5 +30,5 @@ temperature_dataset:
3030
conversion_factor: 1000.0
3131
values:
3232
source:
33-
- file: "./out/my_temperature.temperatures_in_K.values.zarr"
33+
- file: my_temperature.temperatures_in_K.values.zarr
3434
format: zarr
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"zarr_format": 2
3+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"metadata": {
3+
".zattrs": {},
4+
".zgroup": {
5+
"zarr_format": 2
6+
},
7+
"__xarray_dataarray_variable__/.zarray": {
8+
"chunks": [
9+
2,
10+
2
11+
],
12+
"compressor": {
13+
"blocksize": 0,
14+
"clevel": 5,
15+
"cname": "lz4",
16+
"id": "blosc",
17+
"shuffle": 1
18+
},
19+
"dtype": "<f8",
20+
"fill_value": "NaN",
21+
"filters": null,
22+
"order": "C",
23+
"shape": [
24+
2,
25+
2
26+
],
27+
"zarr_format": 2
28+
},
29+
"__xarray_dataarray_variable__/.zattrs": {
30+
"_ARRAY_DIMENSIONS": [
31+
"dim_0",
32+
"dim_1"
33+
]
34+
}
35+
},
36+
"zarr_consolidated_format": 1
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"chunks": [
3+
2,
4+
2
5+
],
6+
"compressor": {
7+
"blocksize": 0,
8+
"clevel": 5,
9+
"cname": "lz4",
10+
"id": "blosc",
11+
"shuffle": 1
12+
},
13+
"dtype": "<f8",
14+
"fill_value": "NaN",
15+
"filters": null,
16+
"order": "C",
17+
"shape": [
18+
2,
19+
2
20+
],
21+
"zarr_format": 2
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"_ARRAY_DIMENSIONS": [
3+
"dim_0",
4+
"dim_1"
5+
]
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"zarr_format": 2
3+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"metadata": {
3+
".zattrs": {},
4+
".zgroup": {
5+
"zarr_format": 2
6+
},
7+
"__xarray_dataarray_variable__/.zarray": {
8+
"chunks": [
9+
2,
10+
2
11+
],
12+
"compressor": {
13+
"blocksize": 0,
14+
"clevel": 5,
15+
"cname": "lz4",
16+
"id": "blosc",
17+
"shuffle": 1
18+
},
19+
"dtype": "<f8",
20+
"fill_value": "NaN",
21+
"filters": null,
22+
"order": "C",
23+
"shape": [
24+
2,
25+
2
26+
],
27+
"zarr_format": 2
28+
},
29+
"__xarray_dataarray_variable__/.zattrs": {
30+
"_ARRAY_DIMENSIONS": [
31+
"dim_0",
32+
"dim_1"
33+
]
34+
}
35+
},
36+
"zarr_consolidated_format": 1
37+
}

0 commit comments

Comments
 (0)