Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added STAC generator #5

Closed
wants to merge 130 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
cc3caca
Added STAC generator
Markus-Goetz Jul 8, 2024
f64d64e
Added pandas as dependency to the pyproject.toml
Markus-Goetz Jul 8, 2024
81d35ef
Merged main
Markus-Goetz Jul 8, 2024
2864ea8
Renamed STAC script to calibration_stac, externalized several strings…
Markus-Goetz Jul 8, 2024
c643217
Updated coverage.svg
github-actions[bot] Jul 8, 2024
eb43fa3
Refactored calibration_stac to reference utils and mappings
Markus-Goetz Jul 8, 2024
db23aba
Merge branch 'features/stac' of github.com:ARTIST-Association/PAINT i…
Markus-Goetz Jul 8, 2024
e119542
Updated coverage.svg
github-actions[bot] Jul 8, 2024
f4722be
Added missing item links in collection
Markus-Goetz Jul 8, 2024
dd04b93
Merge branch 'features/stac' of github.com:ARTIST-Association/PAINT i…
Markus-Goetz Jul 8, 2024
89a25db
Updated coverage.svg
github-actions[bot] Jul 8, 2024
7281a5f
Removed superfluous paths in calibration stac
Markus-Goetz Jul 8, 2024
5909665
Added generator for the catalog
Markus-Goetz Jul 8, 2024
df31ef6
Merge branch 'features/stac' of github.com:ARTIST-Association/PAINT i…
Markus-Goetz Jul 8, 2024
3f7410f
Updated coverage.svg
github-actions[bot] Jul 8, 2024
cb57d7c
Added unit tests for the util functions, refactored heliostat id to s…
Markus-Goetz Jul 10, 2024
fcc13df
Merge branch 'features/stac' of github.com:ARTIST-Association/PAINT i…
Markus-Goetz Jul 10, 2024
d978953
Updated coverage.svg
github-actions[bot] Jul 10, 2024
3220333
Added tests for catalog, refactored generation script to no longer in…
Markus-Goetz Jul 10, 2024
a96f1dd
Merge branch 'features/stac' of github.com:ARTIST-Association/PAINT i…
Markus-Goetz Jul 10, 2024
190b5d5
Moved deepdiff dependency from development to general project dependency
Markus-Goetz Jul 10, 2024
8ce3cd4
Python 3.8 type hint fix
Markus-Goetz Jul 10, 2024
5c43174
Updated coverage.svg
github-actions[bot] Jul 10, 2024
60c3106
added stac folder to gitignore
Filos1992 Jul 10, 2024
566dc56
started with heliostat properties collection. not runnable yet
Filos1992 Jul 10, 2024
94a5c62
Added calibration collection test cases, refactored code to generate …
Markus-Goetz Jul 10, 2024
7738bc4
Merge branch 'features/stac' of github.com:ARTIST-Association/PAINT i…
Markus-Goetz Jul 10, 2024
3b76a99
Updated coverage.svg
github-actions[bot] Jul 10, 2024
f6075f0
Added Converter für Latitude Longitude to meters and vice versa in WGS84
Filos1992 Jul 11, 2024
135cd38
changed from torch to math
Filos1992 Jul 11, 2024
a7edbca
startet writing stac format. not finished yet
Filos1992 Jul 11, 2024
dc9c840
started new stac files creation
Filos1992 Jul 11, 2024
07e57bd
added constants for WGS84 , Altitude of Tower and Heliotat Property F…
Filos1992 Jul 11, 2024
27dfc3a
Updated coverage.svg
github-actions[bot] Jul 11, 2024
f6ad5b3
finalized conversion function
Filos1992 Jul 11, 2024
a0c2024
Merge branch 'stac_heliostat_properties' of github.com:ARTIST-Associa…
Filos1992 Jul 11, 2024
efe9c76
Updated coverage.svg
github-actions[bot] Jul 11, 2024
2d0309f
updated gitignore with json
Filos1992 Jul 11, 2024
b7ce41f
added main script to create catalog. not runnable jet
Filos1992 Jul 11, 2024
6f8841e
Updated coverage.svg
github-actions[bot] Jul 11, 2024
17b17d2
Merge branch 'main' into stac_heliostat_properties
kalebphipps Jul 12, 2024
a1c9988
Merge branch 'main' into features/stac
kalebphipps Jul 12, 2024
35e9de7
merge both stac branches
kalebphipps Jul 12, 2024
cc5de11
Updated coverage.svg
github-actions[bot] Jul 12, 2024
63d0e57
start extraction of binary file - not finished
kalebphipps Jul 12, 2024
e0f5234
Updated coverage.svg
github-actions[bot] Jul 12, 2024
9cb5cdc
add binary data for test
kalebphipps Jul 15, 2024
7638463
first working converter
kalebphipps Jul 15, 2024
a288b86
include test for binary to h5 converter
kalebphipps Jul 15, 2024
e553863
Updated coverage.svg
github-actions[bot] Jul 15, 2024
6006ff7
update test to check download function
kalebphipps Jul 15, 2024
c5158db
adjust python version
kalebphipps Jul 15, 2024
d2454ea
update python version support
kalebphipps Jul 15, 2024
27616f9
update mappings and functino to save heliostat properties as json
kalebphipps Jul 15, 2024
6bec7a6
update test to reflect changes in extractor
kalebphipps Jul 15, 2024
e865357
Updated coverage.svg
github-actions[bot] Jul 15, 2024
566c407
add data for tests
kalebphipps Jul 16, 2024
80388f9
add script to combine heliostat properties and tests for this script
kalebphipps Jul 16, 2024
386fd13
refactor position
kalebphipps Jul 16, 2024
6802f14
remove combining code since it was moved to a separate file
kalebphipps Jul 16, 2024
5997da4
refactor position
kalebphipps Jul 16, 2024
fd1dacf
fix docstrings
kalebphipps Jul 16, 2024
7234ae4
Merge remote-tracking branch 'origin/features/stac' into features/stac
kalebphipps Jul 16, 2024
91a3f8a
update dependencies
kalebphipps Jul 17, 2024
97aabc8
Updated coverage.svg
github-actions[bot] Jul 17, 2024
b17edc7
refactor names
kalebphipps Jul 17, 2024
73feea1
update to generate metadata file
kalebphipps Jul 17, 2024
5aa150d
include function to convert single strings to utc time
kalebphipps Jul 17, 2024
fc44a23
Updated coverage.svg
github-actions[bot] Jul 17, 2024
e44995e
switch to UTC timestamps for saving files
kalebphipps Jul 18, 2024
beecdd3
switch to UTC timestamps for saving files
kalebphipps Jul 18, 2024
7b041ad
fix error which caused the generation to fail when deflectometry data…
kalebphipps Jul 18, 2024
9ada05c
add empty deflectometry stac file
kalebphipps Jul 18, 2024
4a18d8c
Merge remote-tracking branch 'origin/features/stac' into features/stac
kalebphipps Jul 18, 2024
40b59c1
Updated coverage.svg
github-actions[bot] Jul 18, 2024
410a991
update failed fill with boolean
kalebphipps Jul 19, 2024
40cbaee
add facet stac file
kalebphipps Jul 22, 2024
9ea4a3a
full deflectometry stac
kalebphipps Jul 22, 2024
03fd3fe
refactor
kalebphipps Jul 22, 2024
5d37986
scripts for deflectometry stac items and collections
kalebphipps Jul 22, 2024
ac9e240
Merge remote-tracking branch 'origin/features/stac' into features/stac
kalebphipps Jul 22, 2024
d7e2775
remove unused files
kalebphipps Jul 23, 2024
794e9b2
refactor
kalebphipps Jul 23, 2024
f7d8190
remove unused files
kalebphipps Jul 23, 2024
526a06b
include kinematic properties item stac
kalebphipps Jul 23, 2024
054730c
include heliostat properties collection stac
kalebphipps Jul 23, 2024
78742d4
script to generate kinematic stacs
kalebphipps Jul 23, 2024
4f6ac4e
script to generate properties collection stac
kalebphipps Jul 23, 2024
5c09067
adjust for new structure
kalebphipps Jul 23, 2024
97fe730
include csp extension
kalebphipps Jul 23, 2024
9a3f781
refactor - not working
kalebphipps Jul 23, 2024
8983043
script to generate calibration stacs
kalebphipps Jul 23, 2024
ca4358e
refactor
kalebphipps Jul 23, 2024
9471f7f
include weather stacs
kalebphipps Jul 23, 2024
7b3dbd7
remove unused files
kalebphipps Jul 23, 2024
935bb1b
include keys for catalog stacs
kalebphipps Jul 23, 2024
9d6d535
fix catalog stac
kalebphipps Jul 23, 2024
8d1ddae
script to generate catalog
kalebphipps Jul 23, 2024
816c898
create heliostat catalogs and script to generate them
kalebphipps Jul 23, 2024
64b9862
remove unused files
kalebphipps Jul 24, 2024
fe63ee8
refactor and remove csp schema
kalebphipps Jul 24, 2024
532aabf
include motor position asset
kalebphipps Jul 24, 2024
c8f803d
include multiple assets in one stac file
kalebphipps Jul 24, 2024
ff5d4bc
save motor position as json
kalebphipps Jul 24, 2024
2b4f83f
refactor
kalebphipps Jul 24, 2024
b066111
remove item_asset key
kalebphipps Jul 24, 2024
4216b8d
make executable
kalebphipps Jul 24, 2024
825c6dd
make executable
kalebphipps Jul 24, 2024
a67b18a
make executable
kalebphipps Jul 24, 2024
2f54ce0
adjust test to new stac format
kalebphipps Jul 24, 2024
8b8177c
adjust test to new stac format
kalebphipps Jul 24, 2024
409ce30
Updated coverage.svg
github-actions[bot] Jul 24, 2024
0a0e21c
remove unused file
kalebphipps Jul 26, 2024
98c1a80
refactor latitude and longitude conversion to util
kalebphipps Jul 26, 2024
387d8c2
remove unused data
kalebphipps Jul 26, 2024
32aaa2b
fix doc strings and refactor
kalebphipps Jul 26, 2024
50a49ef
add test for deflectometry stac
kalebphipps Jul 26, 2024
51ee0d0
add test for dwd stac
kalebphipps Jul 26, 2024
45be55e
add test for facet stac
kalebphipps Jul 26, 2024
734fc0f
refactor name
kalebphipps Jul 26, 2024
927fc87
refactor preprocessing functions into separate file
kalebphipps Jul 26, 2024
98b59e8
add test for preprocessing functions
kalebphipps Jul 26, 2024
2159793
add test for all util functions
kalebphipps Jul 26, 2024
e5a7c22
add test for kinematic stac
kalebphipps Jul 26, 2024
d62bd13
fix docstrings
kalebphipps Jul 26, 2024
029f9ec
add test for weather collection stac
kalebphipps Jul 26, 2024
a687bba
add test for properties collection
kalebphipps Jul 26, 2024
d66af65
add test for heliostat catalog generation
kalebphipps Jul 26, 2024
0e14ea5
add data for tests
kalebphipps Jul 26, 2024
855237e
Updated coverage.svg
github-actions[bot] Jul 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@main
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# PAINT

[![](https://img.shields.io/badge/Python-3.8+-blue.svg)](https://www.python.org/downloads/)
[![](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://www.python.org/downloads/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![](https://img.shields.io/badge/Contact-artist%40lists.kit.edu-orange?label=Contact)]([email protected])
![](./coverage.svg)
Expand All @@ -14,7 +14,7 @@
PAINT is a FAIR database for Concentrating Solar Power plants (CSP).

## Installation
We heavily recommend installing the `PAINT` package in a dedicated `Python3.8+` virtual environment. You can
We heavily recommend installing the `PAINT` package in a dedicated `Python3.9+` virtual environment. You can
install ``PAINT`` directly from the GitHub repository via:
```bash
pip install git+https://github.com/ARTIST-Association/PAINT
Expand Down
6 changes: 3 additions & 3 deletions coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
236 changes: 236 additions & 0 deletions paint/data/binary_extractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
import json
import struct
from pathlib import Path
from typing import Union

import h5py
import torch

import paint.util.paint_mappings as mappings
from paint.util.utils import to_utc_single


class BinaryExtractor:
"""
Implement an extractor that extracts data from a binary file and saves it to h5 and json.

This extractor considers data form a binary file that contains deflectometry data and heliostat properties. The data
is extracted and the deflectometry data saved in a h5 format and the heliostat properties as a json.

Attributes
----------
input_path : Path
The file path to the binary data file that will be converted.
output_path : Path
The file path to save the converted h5 file.
file_name : str
The file name of the converted h5 file.
raw_data : bool
Whether the raw data or filled data is extracted.
heliostat_id : str
The heliostat ID of the heliostat considered in the binary file.
json_handle : str
The file path to save the json containing the heliostat properties data.
deflectometry_created_at : str
The time stamp for when the deflectometry data was created. Required for properties later.
surface_header_name : str
The name for the surface header in the binary file.
facet_header_name : str
The name for the facet header in the binary file.
points_on_facet_struct_name : str
The name of the point on facet structure in the binary file.

Methods
-------
nwu_to_enu()
Cast from an NWU to an ENU coordinate system.
convert_to_h5_and_extract_properties()
Convert binary data to h5 and extract heliostat properties not to be saved in the deflectometry file.
"""

def __init__(
self,
input_path: Union[str, Path],
output_path: Union[str, Path],
surface_header_name: str,
facet_header_name: str,
points_on_facet_struct_name: str,
) -> None:
"""
Initialize the extractor.

Parameters
----------
input_path : Union[str, Path]
The file path to the binary data file that will be converted.
output_path : Union[str, Path]
The file path to save the converted h5 deflectometry file.
surface_header_name : str
The name for the surface header in the binary file.
facet_header_name : str
The name for the facet header in the binary file.
points_on_facet_struct_name : str
The name of the point on facet structure in the binary file.
"""
self.input_path = Path(input_path)
self.output_path = Path(output_path)
name_string = self.input_path.name.split("_")
if len(name_string) == 6:
file_name = (
name_string[1]
+ "-"
+ name_string[4]
+ "-"
+ str(to_utc_single(name_string[-1].split(".")[0]))
)
self.raw_data = False
else:
file_name = (
name_string[1] + "-" + str(to_utc_single(name_string[-1].split(".")[0]))
)
self.raw_data = True
self.heliostat_id = name_string[1]
self.file_name = file_name + mappings.DEFLECTOMETRY_SUFFIX
self.json_handle = name_string[1] + mappings.FACET_PROPERTIES_SUFFIX
self.deflectometry_created_at = to_utc_single(name_string[-1].split(".")[0])
self.surface_header_name = surface_header_name
self.facet_header_name = facet_header_name
self.points_on_facet_struct_name = points_on_facet_struct_name

@staticmethod
def nwu_to_enu(nwu_tensor: torch.Tensor) -> torch.Tensor:
"""
Cast the coordinate system from NWU to ENU.

Parameters
----------
nwu_tensor : torch.Tensor
The tensor in the NWU coordinate system.

Returns
-------
torch.Tensor
The converted tensor in the ENU coordinate system.
"""
return torch.tensor(
[-nwu_tensor[1], nwu_tensor[0], nwu_tensor[2]], dtype=torch.float
)

def convert_to_h5_and_extract_properties(
self,
) -> None:
"""
Extract data from a binary file and save the deflectometry measurements and heliostat properties.

The binary files we consider, contain both deflectometry measurements and certain heliostat properties, such as
the number of facets, the facet translation vectors, and the facet canting vectors. Therefore, the deflectometry
measurements are extracted and saved as a h5 file, whilst the heliostat properties are extracted and saved in a
json file.
"""
# Create structures for reading binary file correctly.
surface_header_struct = struct.Struct(self.surface_header_name)
facet_header_struct = struct.Struct(self.facet_header_name)
points_on_facet_struct = struct.Struct(self.points_on_facet_struct_name)

with open(self.input_path, "rb") as file:
surface_header_data = surface_header_struct.unpack_from(
file.read(surface_header_struct.size)
)

# Calculate the number of facets.
n_xy = surface_header_data[5:7]
number_of_facets = int(n_xy[0] * n_xy[1])

# Create empty tensors for storing data.
facet_translation_vectors = torch.empty(number_of_facets, 3)
canting_e = torch.empty(number_of_facets, 3)
canting_n = torch.empty(number_of_facets, 3)
surface_points_with_facets = torch.empty(0)
surface_normals_with_facets = torch.empty(0)
for f in range(number_of_facets):
facet_header_data = facet_header_struct.unpack_from(
file.read(facet_header_struct.size)
)

facet_translation_vectors[f] = torch.tensor(
facet_header_data[1:4], dtype=torch.float
)
canting_n[f] = self.nwu_to_enu(
torch.tensor(
facet_header_data[4:7],
dtype=torch.float,
)
)
canting_e[f] = self.nwu_to_enu(
torch.tensor(
facet_header_data[7:10],
dtype=torch.float,
)
)
number_of_points = facet_header_data[10]
if f == 0:
surface_points_with_facets = torch.empty(
number_of_facets, number_of_points, 3
)
surface_normals_with_facets = torch.empty(
number_of_facets, number_of_points, 3
)

points_data = points_on_facet_struct.iter_unpack(
file.read(points_on_facet_struct.size * number_of_points)
)
for i, point_data in enumerate(points_data):
surface_points_with_facets[f, i, :] = torch.tensor(
point_data[:3], dtype=torch.float
)
surface_normals_with_facets[f, i, :] = torch.tensor(
point_data[3:6], dtype=torch.float
)

# to maintain consistency, we cast the west direction to east direction
canting_e[:, 0] = -canting_e[:, 0]

# extract deflectometry data and save
saved_deflectometry_path = (
Path(self.output_path)
/ self.heliostat_id
/ mappings.SAVE_DEFLECTOMETRY
/ self.file_name
)
saved_deflectometry_path.parent.mkdir(parents=True, exist_ok=True)
with h5py.File(saved_deflectometry_path, "w") as file:
for i in range(number_of_facets):
facet = file.create_group(name=f"{mappings.FACET_KEY}{i+1}")
facet.create_dataset(
name=f"{mappings.SURFACE_NORMAL_KEY}",
data=surface_normals_with_facets[i, :, :],
)
facet.create_dataset(
name=f"{mappings.SURFACE_POINT_KEY}",
data=surface_points_with_facets[i, :, :],
)

# extract facet properties data and save
saved_facet_path = (
Path(self.output_path)
/ self.heliostat_id
/ mappings.SAVE_PROPERTIES
/ self.json_handle
)
saved_facet_path.parent.mkdir(parents=True, exist_ok=True)
if self.raw_data:
with open(saved_facet_path, "w") as handle:
properties = {
mappings.NUM_FACETS: number_of_facets,
mappings.FACETS_LIST: [
{
mappings.TRANSLATION_VECTOR: facet_translation_vectors[
i, :
].tolist(),
mappings.CANTING_E: canting_e[i, :].tolist(),
mappings.CANTING_N: canting_n[i, :].tolist(),
}
for i in range(number_of_facets)
],
}
json.dump(properties, handle)
Loading