diff --git a/mlair/helpers/helpers.py b/mlair/helpers/helpers.py index 5ddaa3ee3fe505eeb7c8082274d9cd888cec720f..40fd98b93796c7b32a1e767e0c9179f429b9a0c9 100644 --- a/mlair/helpers/helpers.py +++ b/mlair/helpers/helpers.py @@ -2,10 +2,14 @@ __author__ = 'Lukas Leufen, Felix Kleinert' __date__ = '2019-10-21' +import glob import inspect +import json import math +import os import numpy as np +import pandas as pd import xarray as xr import dask.array as da @@ -179,3 +183,40 @@ def convert2xrda(arr: Union[xr.DataArray, xr.Dataset, np.ndarray, int, float], kwargs.update({'dims': dims, 'coords': coords}) return xr.DataArray(arr, **kwargs) + + +class TOARMeta2Coords: + + def __init__(self, meta_file_path, station_lat='station_lat', station_lon='station_lon'): + self.meta_file_path = meta_file_path + self.station_lat = station_lat + self.station_lon = station_lon + self.coord_name_list = None + + def get_filenames(self, meta_file_ending='.csv'): + file_list = glob.glob(f"{os.path.join(self.meta_file_path, f'*{meta_file_ending}')}") + return file_list + + def set_coord_name_list(self): + coord_list = [] + files = self.get_filenames() + for file in files: + df = pd.read_csv(file, index_col=0) + lat_coord, lon_coord = [s[0].replace('.', '_') for s in df.loc[[self.station_lat, self.station_lon]].values] + coord_name = f"coords__{lat_coord}__{lon_coord}" + coord_list.append(coord_name) + self.coord_name_list = coord_list + + def store_to_file(self, path): + if self.coord_name_list is not None: + with open(path, 'w') as f: + json.dump(self.coord_name_list, f) + + +if __name__ == '__main__': + tm2c = TOARMeta2Coords("/home/felix/PycharmProjects/mlair/raw_input_IntelliO3-ts") + tm2c.set_coord_name_list() + tm2c.store_to_file("/home/felix/PycharmProjects/mlair/coord_list.json") + print(123) + +