-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
85 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 |
---|---|---|
@@ -1,91 +1,51 @@ | ||
import argparse | ||
import pandas as pd | ||
import get_data | ||
import json | ||
import matplotlib.pyplot as plt | ||
import argparse | ||
import os | ||
|
||
def read_json(file_path): | ||
with open(file_path, 'r') as f: | ||
field_name_dict = json.load(f) | ||
return dict(field_name_dict) | ||
|
||
# def load_data(file_path): | ||
# # Assuming the input data file is a CSV for simplicity | ||
# return pd.read_csv(file_path) | ||
# | ||
# | ||
# def perform_analysis(data, analysis_config, output_prefix): | ||
# # Example: Perform some analysis on the data based on the config | ||
# result = data.describe() # Simple analysis: describe data | ||
# | ||
# # Save results to CSV | ||
# result_csv = f"{output_prefix}_derived_file.csv" | ||
# result.to_csv(result_csv) | ||
# return result_csv | ||
# | ||
# | ||
# def create_plots(data, output_prefix): | ||
# # Example: Create and save plots | ||
# sample_plot = f"{output_prefix}_sample_plot.png" | ||
# analysis_plot = f"{output_prefix}_analysis_plot.png" | ||
# | ||
# plt.figure() | ||
# data.plot() | ||
# plt.title('Sample Plot') | ||
# plt.savefig(sample_plot) | ||
# | ||
# plt.figure() | ||
# data.hist() | ||
# plt.title('Analysis Plot') | ||
# plt.savefig(analysis_plot) | ||
# | ||
# return sample_plot, analysis_plot | ||
# | ||
# | ||
# def main(): | ||
# parser = argparse.ArgumentParser(description='Data retrieval and analysis.') | ||
# parser.add_argument('-i', '--input', action='append', required=True, help='Input files.') | ||
# args = parser.parse_args() | ||
# | ||
# # Input files | ||
# data_file = None | ||
# python_file = None | ||
# json_file = None | ||
# | ||
# for file_path in args.input: | ||
# if file_path.endswith('.csv'): | ||
# data_file = file_path | ||
# elif file_path.endswith('.py'): | ||
# python_file = file_path | ||
# elif file_path.endswith('.json'): | ||
# json_file = file_path | ||
# | ||
# if not data_file or not python_file or not json_file: | ||
# raise ValueError("Missing required input files.") | ||
# | ||
# # Load JSON configuration | ||
# with open(json_file, 'r') as f: | ||
# config = json.load(f) | ||
# | ||
# # Create an output directory | ||
# output_dir = 'output' | ||
# os.makedirs(output_dir, exist_ok=True) | ||
# | ||
# # Set the output file prefix | ||
# output_prefix = os.path.join(output_dir, os.path.splitext(os.path.basename(data_file))[0]) | ||
# | ||
# # Load and process data | ||
# data = load_data(data_file) | ||
# | ||
# # Perform analysis | ||
# derived_file = perform_analysis(data, config, output_prefix) | ||
# | ||
# # Create and save plots | ||
# sample_plot, analysis_plot = create_plots(data, output_prefix) | ||
# | ||
# # Return paths of the created files | ||
# print(f"Derived file: {derived_file}") | ||
# print(f"Sample plot: {sample_plot}") | ||
# print(f"Analysis plot: {analysis_plot}") | ||
# | ||
|
||
parser = argparse.ArgumentParser(description='Data retrieval and analysis.') | ||
|
||
# Separate flags for each type of input | ||
parser.add_argument('--data-file', '-d', required=True, help='File name to the data file (e.g., .mat, .nwb, .txt).') | ||
parser.add_argument('--python-file', '-p', required=True, help='File name to the Python file for custom processing.') | ||
parser.add_argument('--json-file', '-j', required=True, help='File name to the JSON configuration file.') | ||
parser.add_argument('--filepath', '-f', required=True, help='Path for additional use.') | ||
|
||
args = parser.parse_args() | ||
|
||
# Input files | ||
data_file = args.data_file | ||
python_file = args.python_file | ||
json_file = args.json_file | ||
f_path = args.filepath | ||
|
||
supported_ext = ["mat", "nwb", "csv", "txt", "adicht", "rhd"] | ||
|
||
# Extract the file extension | ||
data_file_ext = os.path.splitext(data_file)[1].lower() | ||
|
||
# Ensure data file has a supported extension | ||
if data_file_ext not in supported_ext: | ||
raise ValueError(f"Unsupported data file extension: {data_file_ext}") | ||
|
||
field_name_dict = read_json(os.path.join(json_file, f_path)) | ||
get_final_df = get_data.run(data_file_ext, data_file, field_name_dict, f_path) | ||
|
||
# # Create an output directory | ||
# output_dir = 'output' | ||
# os.makedirs(output_dir, exist_ok=True) | ||
# | ||
# if __name__ == '__main__': | ||
# main() | ||
# # Set the output file prefix | ||
# output_prefix = os.path.join(output_dir, os.path.splitext(os.path.basename(data_file))[0]) | ||
|
||
# Save the DataFrame to a CSV file | ||
csv_file_path = f"derived_file.csv" | ||
get_final_df.to_csv(csv_file_path, index=False) | ||
|
||
print("hello world") | ||
print("files saved successfully") |