-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add FEFF schema #41
Open
msegal347
wants to merge
7
commits into
AI-multimodal:main
Choose a base branch
from
msegal347:feff_dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add FEFF schema #41
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aecd753
update 2022OCT14 0921
msegal347 afe5b50
Updated feff schemas and ingestion 2022OCT22
msegal347 69b7b8d
moved notebooks, included tests
msegal347 aac4c9e
updated notebook with output cleaning
msegal347 6269e1b
cleared outputs
msegal347 edf3720
need help fixing the ingestion to client
msegal347 96ce6d7
cleared outputs
msegal347 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,38 @@ | ||
import copy | ||
import pandas as pd | ||
from pathlib import Path | ||
|
||
from aimmdb.ingest import load_feff_data | ||
|
||
|
||
DATA_PATH = Path("aimmdb/_tests/data/feff/65272_C_007") | ||
|
||
|
||
def test_load_feff_data(): | ||
|
||
data, metadata = load_feff_data(DATA_PATH) | ||
|
||
assert isinstance(data, pd.DataFrame) | ||
assert isinstance(metadata, dict) | ||
assert isinstance(metadata["feff.inp"], str) | ||
assert isinstance(metadata["feff.out"], str) | ||
assert isinstance(metadata["xmu.dat-comments"], str) | ||
|
||
|
||
def copy_feff_data(): | ||
|
||
data, metadata = load_feff_data(DATA_PATH) | ||
|
||
data_copy = copy.deepcopy(data) | ||
|
||
assert data.equals(data_copy) | ||
|
||
metadata_copy = copy.deepcopy(metadata) | ||
|
||
assert metadata.equals(metadata_copy) | ||
|
||
assert isinstance(data_copy, pd.DataFrame) | ||
assert isinstance(metadata_copy, dict) | ||
assert isinstance(metadata_copy["feff.inp"], str) | ||
assert isinstance(metadata_copy["feff.out"], str) | ||
assert isinstance(metadata_copy["xmu.dat-comments"], str) |
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,6 @@ | ||
from tiled.adapters.dataframe import DataFrameAdapter | ||
|
||
|
||
# dataframe adapter representing FEFF data | ||
class FEFFAdapter(DataFrameAdapter): | ||
specs = ["FEFF"] |
Empty file.
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,65 @@ | ||
import copy | ||
import pathlib | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
from tiled.client import from_uri | ||
from tiled.examples.xdi import read_xdi | ||
from tiled.queries import Key | ||
|
||
import pandas as pd | ||
from pathlib import Path | ||
|
||
def load_feff_data(data_path, verbose=True): | ||
""" | ||
Parameters | ||
---------- | ||
data_path : os.PathLike | ||
path to the feff.inp, feff.out, and xmu.dat file. | ||
verbose : bool, optional | ||
Prints debug information if True. | ||
|
||
Returns | ||
------- | ||
feff_data : pandas.Dataframe | ||
dataframe containing the xmu.dat data | ||
metadata : dict | ||
dictionary containing the feff.inp, feff.out, and xmu.dat metadata | ||
""" | ||
|
||
data_path = Path(data_path) | ||
|
||
feff_inp = data_path / "feff.inp" | ||
feff_out = data_path / "feff.out" | ||
xmu_dat = data_path / "xmu.dat" | ||
|
||
data = pd.read_csv( | ||
xmu_dat, | ||
sep="\s+", | ||
header=None, | ||
names=["omega", "e", "k", "mu", "mu0", "chi"], | ||
comment="#", | ||
) | ||
|
||
metadata = { | ||
"feff.inp": feff_inp.read_text(), | ||
"feff.out": feff_out.read_text(), | ||
} | ||
|
||
dat = [ | ||
line | ||
for line in xmu_dat.read_text().splitlines() | ||
if line.startswith("#") | ||
] | ||
metadata["xmu.dat-comments"] = "\n".join(dat) | ||
|
||
if verbose: | ||
print("FEFF Input:", feff_inp) | ||
print("FEFF Output:", feff_out) | ||
print("FEFF Data:", xmu_dat) | ||
print(data) | ||
print(metadata) | ||
|
||
# returns data and metadata, a pd.DataFrame and dict, respectively. | ||
return data, metadata |
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
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
File renamed without changes.
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,189 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import copy\n", | ||
"from pathlib import Path\n", | ||
"\n", | ||
"import numpy as np\n", | ||
"import pandas as pd\n", | ||
"import nbconvert" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from tiled.client import from_uri\n", | ||
"client = from_uri(\"http://localhost:8000/api\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\n", | ||
"import os\n", | ||
"from pathlib import Path\n", | ||
"\n", | ||
"\n", | ||
"DATA_PATH = Path(\"C:/Users/msega/aimmdb/aimmdb/_tests/data/feff/65272_C_007/\")\n", | ||
"\n", | ||
"#DATA_PATH = Path(\"aimmdb/data/feff/65272_C_007\")\n", | ||
"print(\"Data Path:\", DATA_PATH)\n", | ||
"\n", | ||
"contents = os.listdir(DATA_PATH)\n", | ||
"print(\"Contents:\", contents)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from aimmdb.ingest.load_FEFF_Data import load_feff_data\n", | ||
"\n", | ||
"data, metadata = load_feff_data(DATA_PATH)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def ingest_feff(client, data_path, verbose=False):\n", | ||
" \"\"\"\n", | ||
" Parameters\n", | ||
" ----------\n", | ||
" client : tiled.client.Client\n", | ||
" The client to use to connect to the server.\n", | ||
" data : os.PathLike\n", | ||
" path to the feff.inp, feff.out, and xmu.dat files.\n", | ||
" verbose : bool, optional\n", | ||
" Prints debug information if True.\n", | ||
" \"\"\"\n", | ||
" client = from_uri(\"http://localhost:8000/api\")\n", | ||
" data_path = Path(\"C:/Users/msega/aimmdb/aimmdb/_tests/data/feff/65272_C_007/\")\n", | ||
"\n", | ||
" files = list(data_path.rglob(\"*\"))\n", | ||
" print(\"found {len(files)} files to ingest\")\n", | ||
" print(\"Ingesting FEFF data from:\", data_path)\n", | ||
"\n", | ||
"\n", | ||
" feff_data, metadata = load_feff_data(data_path, verbose=False)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from aimmdb.ingest.load_FEFF_Data import load_feff_data\n", | ||
"from tiled.client import from_uri\n", | ||
"from aimmdb.ingest.load_FEFF_Data import load_feff_data\n", | ||
"\n", | ||
"client = from_uri(\"http://localhost:8000/api\")\n", | ||
"\n", | ||
"data, metadata = load_feff_data(DATA_PATH, verbose=False)\n", | ||
"\n", | ||
"client[\"uid\"].write_dataframe(data, metadata, specs=[\"FEFF\"])\n", | ||
"\n", | ||
"#ingest_feff(client, DATA_PATH, verbose=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"print(\"starting ingestion...\")\n", | ||
"ingest_feff(client, DATA_PATH, verbose=True)\n", | ||
"print(\"finished.\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import aimmdb.schemas as schemas\n", | ||
"\n", | ||
"schemas.FEFFInputMetadata.schema()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import aimmdb.schemas as schemas\n", | ||
"\n", | ||
"schemas.FEFFOutputMetadata.schema()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\n", | ||
"import aimmdb.schemas as schemas\n", | ||
"schemas.FEFFcards.schema()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#show feff.inp as a schema\n", | ||
"import aimmdb.schemas as schemas\n", | ||
"\n", | ||
"schemas.FEFFInputMetadata.schema()\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3.9.13 ('aimm')", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.13" | ||
}, | ||
"orig_nbformat": 4, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "189d756eac8438d33e11f8e23aa09bdc4c99760ed11a3bfefa464e31dcca4c4a" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as my previous comment: