-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #375 from oist/feature/datamodules
Add: separate datamodules
- Loading branch information
Showing
16 changed files
with
340 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import numpy as np | ||
import pandas as pd | ||
|
||
from optinist.api.dataclass.base import BaseData | ||
from optinist.api.utils.filepath_creater import join_filepath | ||
from optinist.api.utils.json_writer import JsonWriter | ||
|
||
|
||
class BarData(BaseData): | ||
def __init__(self, data, index=None, file_name='bar'): | ||
super().__init__(file_name) | ||
data = np.array(data) | ||
|
||
assert data.ndim <= 2, 'Bar Dimension Error' | ||
|
||
if data.ndim == 1: | ||
data = data[np.newaxis] | ||
|
||
assert data.ndim == 2, 'Bar Dimesion is not 2' | ||
|
||
self.data = data | ||
|
||
# indexを指定 | ||
if index is not None: | ||
self.index = index | ||
else: | ||
self.index = np.arange(len(self.data)) | ||
|
||
def save_json(self, json_dir): | ||
self.json_path = join_filepath([json_dir, f"{self.file_name}.json"]) | ||
df = pd.DataFrame( | ||
self.data, | ||
index=self.index, | ||
) | ||
JsonWriter.write_as_split(self.json_path, df) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import gc | ||
|
||
|
||
class BaseData: | ||
def __init__(self, file_name): | ||
self.file_name = file_name | ||
|
||
def save_json(self, json_dir): | ||
pass | ||
|
||
def __del__(self): | ||
del self | ||
gc.collect() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import numpy as np | ||
import pandas as pd | ||
|
||
from optinist.api.dataclass.base import BaseData | ||
|
||
from optinist.api.utils.filepath_creater import create_directory, join_filepath | ||
from optinist.api.utils.json_writer import JsonWriter | ||
|
||
|
||
class CsvData(BaseData): | ||
def __init__(self, data, params, file_name='csv'): | ||
super().__init__(file_name) | ||
|
||
if isinstance(data, str): | ||
self.data = pd.read_csv(data, header=None).values | ||
|
||
if params["transpose"]: | ||
self.data = self.data.T | ||
|
||
if params["setHeader"] is not None: | ||
header = params["setHeader"] | ||
self.data = self.data[header:] | ||
else: | ||
self.data = np.array(data) | ||
|
||
if self.data.ndim == 1: | ||
self.data = self.data[np.newaxis, :] | ||
|
||
def save_json(self, json_dir): | ||
# timeseriesだけはdirを返す | ||
self.json_path = join_filepath([json_dir, self.file_name]) | ||
create_directory(self.json_path) | ||
|
||
for i, data in enumerate(self.data): | ||
JsonWriter.write_as_split( | ||
join_filepath([self.json_path, f'{str(i)}.json']), | ||
data | ||
) |
Oops, something went wrong.