diff --git a/.gitignore b/.gitignore index 58f23fa..1b9ce6d 100644 --- a/.gitignore +++ b/.gitignore @@ -199,6 +199,7 @@ cython_debug/ .pyenv *.pyc *.txt +!src/download_rod_files/*.txt !tests/data/witec/*.txt !examples/witec/txt/*.txt !requirements.txt diff --git a/README.md b/README.md index 2ef201d..a657983 100644 --- a/README.md +++ b/README.md @@ -32,5 +32,6 @@ within the field of raman into a standardized representation using the ## Docs Extensive documentation of this pynxtools plugin is available [here](https://fairmat-nfdi.github.io/pynxtools-raman/). You can find information about getting started, how-to guides, the supported file formats, how to get involved, and much more there. + ## Contact person in FAIRmat for this reader Ron Hildebrandt diff --git a/pyproject.toml b/pyproject.toml index 8080cc9..a041ed9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,12 +23,20 @@ classifiers = [ ] dependencies = [ "pynxtools>=0.7.0", - "gemmi>=0.6.7" + "gemmi>=0.6.7", + "requests>=2.32.3", ] [project.entry-points."pynxtools.reader"] raman = "pynxtools_raman.reader:RamanReader" +[project.entry-points.'nomad.plugin'] +#raman_example = "pynxtools_raman.nomad:raman_example" +raman_app = "pynxtools_raman.nomad:raman_app" + +[project.scripts] +download_rod_file = "pynxtools_raman.rod.rod_get_file:trigger_rod_download" + [tool.setuptools.packages.find] where = [ "src", diff --git a/src/download_rod_files/README.md b/src/download_rod_files/README.md new file mode 100644 index 0000000..57e1afb --- /dev/null +++ b/src/download_rod_files/README.md @@ -0,0 +1,43 @@ +# Downloading multiple .rod files + +## Manually downloading + +You can download a rod file with `ÌD=1000679` via: +`download_rod_file 1000679` + + +## Download_rods_script.sh + +Adjust the file `download_rods_script.sh`to the range of download you want. +Default start is `1` and default end is `3`. +Be careful: Do not trigger unneccsary amounts of downloads. + +Take a look [here](https://solsa.crystallography.net/rod/result), to get valid .rod IDs. +The list of .rod IDs can be accessed [here](https://solsa.crystallography.net/rod/result.php?format=lst&CODSESSION=ooqj2idj19cgpe30275okg42df). +## Add the command as script + +`chmod +x download_rods_script.sh` + +## Exectutute the script + +`./src/download_rod_files/download_rods_script.sh` + + +## Convert the downloaded .rod files + +via the pynxtools-raman command: + +`dataconverter /1000679.rod src/pynxtools_raman/config/config_file_rod.json --reader raman --nxdl NXraman --output rod_example_neuxs.nxs` + +## Downloading all .rod files + +Take a look at the file: "download_all_rod_files_script.sh" + +# Automatec conversion of all .rod files to .nxs files + +## Add the command as script +`chmod +x convert_all_rod_to_nxs.sh` + +## Call the script +`./src/download_rod_files/convert_all_rod_to_nxs.sh` + diff --git a/src/download_rod_files/ROD-numbers.txt b/src/download_rod_files/ROD-numbers.txt new file mode 100644 index 0000000..ea5cab0 --- /dev/null +++ b/src/download_rod_files/ROD-numbers.txt @@ -0,0 +1,1133 @@ +1000000 +1000001 +1000002 +1000003 +1000004 +1000005 +1000006 +1000007 +1000008 +1000009 +1000010 +1000011 +1000012 +1000013 +1000014 +1000015 +1000016 +1000017 +1000018 +1000019 +1000020 +1000021 +1000022 +1000023 +1000024 +1000025 +1000026 +1000027 +1000028 +1000029 +1000030 +1000031 +1000032 +1000033 +1000034 +1000035 +1000036 +1000037 +1000038 +1000039 +1000040 +1000041 +1000042 +1000043 +1000044 +1000045 +1000046 +1000047 +1000048 +1000049 +1000050 +1000051 +1000052 +1000053 +1000054 +1000055 +1000056 +1000057 +1000058 +1000059 +1000060 +1000061 +1000062 +1000063 +1000064 +1000065 +1000066 +1000067 +1000068 +1000069 +1000070 +1000071 +1000072 +1000073 +1000074 +1000075 +1000076 +1000077 +1000078 +1000079 +1000080 +1000081 +1000082 +1000083 +1000084 +1000085 +1000086 +1000087 +1000088 +1000089 +1000090 +1000091 +1000092 +1000093 +1000094 +1000095 +1000096 +1000097 +1000098 +1000099 +1000100 +1000101 +1000102 +1000103 +1000104 +1000105 +1000106 +1000107 +1000108 +1000109 +1000110 +1000111 +1000112 +1000113 +1000114 +1000115 +1000116 +1000117 +1000118 +1000119 +1000120 +1000121 +1000122 +1000123 +1000124 +1000125 +1000126 +1000127 +1000128 +1000129 +1000130 +1000131 +1000132 +1000133 +1000134 +1000135 +1000136 +1000137 +1000138 +1000139 +1000140 +1000141 +1000142 +1000143 +1000144 +1000145 +1000146 +1000147 +1000148 +1000149 +1000150 +1000151 +1000152 +1000153 +1000154 +1000155 +1000156 +1000157 +1000158 +1000159 +1000160 +1000161 +1000162 +1000163 +1000164 +1000165 +1000166 +1000167 +1000168 +1000169 +1000170 +1000171 +1000172 +1000173 +1000174 +1000175 +1000176 +1000177 +1000178 +1000179 +1000180 +1000181 +1000182 +1000183 +1000184 +1000185 +1000186 +1000187 +1000188 +1000189 +1000190 +1000191 +1000192 +1000193 +1000194 +1000195 +1000196 +1000197 +1000198 +1000199 +1000200 +1000201 +1000202 +1000203 +1000204 +1000205 +1000206 +1000207 +1000208 +1000209 +1000210 +1000211 +1000212 +1000213 +1000214 +1000215 +1000216 +1000217 +1000218 +1000219 +1000220 +1000221 +1000222 +1000223 +1000224 +1000225 +1000226 +1000227 +1000228 +1000229 +1000230 +1000231 +1000232 +1000233 +1000234 +1000235 +1000236 +1000237 +1000238 +1000239 +1000240 +1000241 +1000242 +1000243 +1000244 +1000245 +1000246 +1000247 +1000248 +1000249 +1000250 +1000251 +1000252 +1000253 +1000254 +1000255 +1000256 +1000257 +1000258 +1000259 +1000260 +1000261 +1000262 +1000263 +1000264 +1000265 +1000266 +1000267 +1000268 +1000269 +1000270 +1000271 +1000272 +1000273 +1000274 +1000275 +1000276 +1000277 +1000278 +1000279 +1000280 +1000281 +1000282 +1000283 +1000284 +1000285 +1000286 +1000287 +1000288 +1000289 +1000290 +1000291 +1000292 +1000293 +1000294 +1000295 +1000296 +1000297 +1000298 +1000299 +1000300 +1000301 +1000302 +1000303 +1000304 +1000305 +1000306 +1000307 +1000308 +1000309 +1000310 +1000311 +1000312 +1000313 +1000314 +1000315 +1000316 +1000317 +1000318 +1000319 +1000320 +1000321 +1000322 +1000323 +1000324 +1000325 +1000326 +1000327 +1000328 +1000329 +1000330 +1000331 +1000332 +1000333 +1000334 +1000335 +1000336 +1000337 +1000338 +1000339 +1000340 +1000341 +1000342 +1000343 +1000344 +1000345 +1000346 +1000347 +1000348 +1000349 +1000350 +1000351 +1000352 +1000353 +1000354 +1000355 +1000356 +1000357 +1000358 +1000359 +1000360 +1000361 +1000362 +1000363 +1000364 +1000365 +1000366 +1000367 +1000368 +1000369 +1000370 +1000371 +1000372 +1000373 +1000374 +1000375 +1000376 +1000377 +1000378 +1000379 +1000380 +1000381 +1000382 +1000383 +1000384 +1000385 +1000386 +1000387 +1000388 +1000389 +1000390 +1000391 +1000392 +1000393 +1000394 +1000395 +1000396 +1000397 +1000398 +1000399 +1000400 +1000401 +1000402 +1000403 +1000404 +1000405 +1000406 +1000407 +1000408 +1000409 +1000410 +1000411 +1000412 +1000413 +1000414 +1000415 +1000416 +1000417 +1000418 +1000419 +1000420 +1000421 +1000422 +1000423 +1000424 +1000425 +1000426 +1000427 +1000428 +1000429 +1000430 +1000431 +1000432 +1000433 +1000434 +1000435 +1000436 +1000437 +1000438 +1000439 +1000440 +1000441 +1000442 +1000443 +1000444 +1000445 +1000446 +1000447 +1000448 +1000449 +1000450 +1000451 +1000452 +1000453 +1000454 +1000455 +1000456 +1000457 +1000458 +1000459 +1000460 +1000461 +1000462 +1000463 +1000464 +1000465 +1000466 +1000467 +1000468 +1000469 +1000470 +1000471 +1000472 +1000473 +1000474 +1000475 +1000476 +1000477 +1000478 +1000479 +1000480 +1000481 +1000482 +1000483 +1000484 +1000485 +1000486 +1000487 +1000488 +1000489 +1000490 +1000491 +1000492 +1000493 +1000494 +1000495 +1000496 +1000497 +1000498 +1000499 +1000500 +1000501 +1000502 +1000503 +1000504 +1000505 +1000506 +1000507 +1000508 +1000509 +1000510 +1000511 +1000512 +1000513 +1000514 +1000515 +1000516 +1000517 +1000518 +1000519 +1000520 +1000521 +1000522 +1000523 +1000524 +1000525 +1000526 +1000527 +1000528 +1000529 +1000530 +1000531 +1000532 +1000533 +1000534 +1000535 +1000536 +1000537 +1000538 +1000539 +1000540 +1000541 +1000542 +1000543 +1000544 +1000545 +1000546 +1000547 +1000548 +1000549 +1000550 +1000551 +1000552 +1000553 +1000554 +1000555 +1000556 +1000557 +1000558 +1000559 +1000560 +1000561 +1000562 +1000563 +1000564 +1000565 +1000566 +1000567 +1000568 +1000569 +1000570 +1000571 +1000572 +1000573 +1000574 +1000575 +1000576 +1000577 +1000578 +1000579 +1000580 +1000581 +1000582 +1000583 +1000584 +1000585 +1000586 +1000587 +1000588 +1000589 +1000590 +1000591 +1000592 +1000593 +1000594 +1000595 +1000596 +1000597 +1000598 +1000599 +1000600 +1000601 +1000602 +1000603 +1000604 +1000605 +1000606 +1000607 +1000608 +1000609 +1000610 +1000611 +1000612 +1000613 +1000614 +1000615 +1000616 +1000617 +1000618 +1000619 +1000620 +1000621 +1000622 +1000623 +1000624 +1000625 +1000626 +1000627 +1000628 +1000629 +1000630 +1000631 +1000632 +1000633 +1000634 +1000635 +1000636 +1000637 +1000638 +1000639 +1000640 +1000641 +1000642 +1000643 +1000644 +1000645 +1000646 +1000647 +1000648 +1000649 +1000650 +1000651 +1000652 +1000653 +1000654 +1000655 +1000656 +1000657 +1000658 +1000659 +1000660 +1000661 +1000662 +1000663 +1000664 +1000665 +1000666 +1000667 +1000668 +1000669 +1000670 +1000671 +1000672 +1000673 +1000674 +1000675 +1000676 +1000677 +1000678 +1000679 +2000000 +2000001 +2000002 +2000003 +2000004 +2000005 +2000006 +2100000 +2100001 +2100002 +2100003 +2100004 +2100005 +2100006 +2100007 +2100008 +2100009 +2100010 +2100011 +2100012 +2100013 +2100014 +2100015 +2100016 +2100017 +2100018 +2100019 +2100020 +2100021 +2100022 +2100023 +2100024 +2100025 +2100026 +2100027 +2100028 +2100029 +2100030 +2100031 +2100032 +2100033 +2100034 +2100035 +2100036 +2100037 +2100038 +2100039 +2100040 +2100041 +2100042 +2100043 +2100044 +2100045 +2100046 +2100047 +2100048 +2100049 +2100050 +2100051 +2100052 +2100053 +2100054 +2100055 +2100056 +2100057 +2100058 +2100059 +2100060 +2100061 +2200000 +2200001 +2200002 +2200003 +2200004 +2200005 +2200006 +2200007 +2200008 +2200009 +2200010 +2300000 +2300001 +2300002 +2300003 +2300004 +2300005 +2300006 +2300007 +2310000 +2310001 +2310002 +2310003 +2310004 +2310005 +2310006 +2310007 +2310008 +2310009 +2310010 +2310011 +2310012 +3500000 +3500001 +3500002 +3500003 +3500004 +3500005 +3500006 +3500007 +3500008 +3500009 +3500010 +3500011 +3500012 +3500013 +3500014 +3500015 +3500016 +3500017 +3500018 +3500019 +3500020 +3500021 +3500022 +3500023 +3500024 +3500025 +3500026 +3500027 +3500028 +3500029 +3500030 +3500031 +3500032 +3500033 +3500034 +3500035 +3500036 +3500037 +3500038 +3500039 +3500040 +3500041 +3500042 +3500043 +3500044 +3500045 +3500046 +3500047 +3500048 +3500049 +3500050 +3500051 +3500052 +3500053 +3500054 +3500055 +3500056 +3500057 +3500058 +3500059 +3500060 +3500061 +3500062 +3500063 +3500064 +3500065 +3500066 +3500067 +3500068 +3500069 +3500070 +3500071 +3500072 +3500073 +3500074 +3500075 +3500076 +3500077 +3500078 +3500079 +3500080 +3500081 +3500082 +3500083 +3500084 +3500085 +3500086 +3500087 +3500088 +3500089 +3500090 +3500091 +3500092 +3500093 +3500094 +3500095 +3500096 +3500097 +3500098 +3500099 +3500100 +3500101 +3500102 +3500103 +3500104 +3500105 +3500106 +3500107 +3500108 +3500109 +3500110 +3500111 +3500112 +3500113 +3500114 +3500115 +3500116 +3500117 +3500118 +3500119 +3500120 +3500121 +3500122 +3500123 +3500124 +3500125 +3500126 +3500127 +3500128 +3500129 +3500130 +3500131 +3500132 +3500133 +3500134 +3500135 +3500136 +3500137 +3500138 +3500139 +3500140 +3500141 +3500142 +3500143 +3500144 +3500145 +3500146 +3500147 +3500148 +3500149 +3500150 +3500151 +3500152 +3500153 +3500154 +3500155 +3500156 +3500157 +3500158 +3500159 +3500160 +3500161 +3500162 +3500163 +3500164 +3500165 +3500166 +3500167 +3500168 +3500169 +3500170 +3500171 +3500172 +3500173 +3500174 +3500175 +3500176 +3500177 +3500178 +3500179 +3500180 +3500181 +3500182 +3500183 +3500184 +3500185 +3500186 +3500187 +3500188 +3500189 +3500190 +3500191 +3500192 +3500193 +3500194 +3500195 +3500196 +3500197 +3500198 +3500199 +3500200 +3500201 +3500202 +3500203 +3500204 +3500205 +3500206 +3500207 +3500208 +3500209 +3500210 +3500211 +3500212 +3500213 +3500214 +3500215 +3500216 +3500217 +3500218 +3500219 +3500220 +3500221 +3500222 +3500223 +3500224 +3500225 +3500226 +3500227 +3500228 +3500229 +3500230 +3500231 +3500232 +3500233 +3500234 +3500235 +3500236 +3500237 +3500238 +3500239 +3500240 +3500241 +3500242 +3500243 +3500244 +3500245 +3500246 +3500247 +3500248 +3500249 +3500250 +3500251 +3500252 +3500253 +3500254 +3500255 +3500256 +3500257 +3500258 +3500259 +3500260 +3500261 +3500262 +3500263 +3500264 +3500265 +3500266 +3500267 +3500268 +3500269 +3500270 +3500271 +3500272 +3500273 +3500274 +3500275 +3500276 +3500277 +3500278 +3500279 +3500280 +3500281 +3500282 +3500283 +3500284 +4020000 +4020001 +7200000 +7200001 +7200002 +7200003 +7200004 +7200005 +8100000 +8100001 +8100002 +8100003 +8100004 +8100005 +8100006 +8100007 +8100008 +8100009 +8100010 +8100011 +8100012 +8100013 +8100014 +8100015 +8100016 +8100017 +8100018 +8100019 +8100020 +8100021 +8100022 +8100023 +8100024 +8100025 +8100026 +8100027 +8100028 +8100029 +8100030 +8100031 +8100032 +8100033 +8100034 +8100035 +8100036 +8100037 +8100038 +8100039 +8100040 +8100041 +8100042 +8100043 +8100044 +8100045 +8100046 +8100047 +8100048 +8100049 +8100050 +8100051 +8100052 +8100053 +8100054 +8100055 +8100056 +8100057 +8100058 diff --git a/src/download_rod_files/ROD-numbers_subset_test.txt b/src/download_rod_files/ROD-numbers_subset_test.txt new file mode 100644 index 0000000..b5409c7 --- /dev/null +++ b/src/download_rod_files/ROD-numbers_subset_test.txt @@ -0,0 +1,19 @@ +1000000 +1000001 +1000002 +1000003 +1000004 +1000005 +1000006 +1000007 +1000008 +1000009 +1000010 +1000011 +1000012 +1000013 +1000014 +1000015 +1000016 +1000017 +1000018 \ No newline at end of file diff --git a/src/download_rod_files/analyse_rod_db.py b/src/download_rod_files/analyse_rod_db.py new file mode 100644 index 0000000..af78d62 --- /dev/null +++ b/src/download_rod_files/analyse_rod_db.py @@ -0,0 +1,36 @@ +import os +from pynxtools_raman.rod.rod_reader import RodParser + + +# Path to the folder +rod_dir = "pynxtools-raman/src/download_rod_files/rod_statistics" + + +print(os.listdir()) + +# Get a list of .nxs files in the folder +nxs_files = [file for file in os.listdir(rod_dir) if file.endswith(".rod")] + +# Initialize a counter for keys +key_counts = {} + + +for nxs_file in nxs_files: + rod = RodParser() + # read the rod file + rod.get_cif_file_content(rod_dir + "/" + nxs_file) + # get the key and value pairs from the rod file + dict = rod.extract_keys_and_values_from_cif() + + # Iterate through all dictionaries + for key in dict.keys(): + key_counts[key] = key_counts.get(key, 0) + 1 + +output_file = "rod_statistics.txt" + +# Write to the file +with open(output_file, "w") as file: + for key, value in key_counts.items(): + file.write(f"{key}\t{value}\n") # \t for tab spacing + +print(f"Data successfully written to {output_file}") diff --git a/src/download_rod_files/convert_all_rod_to_nxs.sh b/src/download_rod_files/convert_all_rod_to_nxs.sh new file mode 100755 index 0000000..53d9630 --- /dev/null +++ b/src/download_rod_files/convert_all_rod_to_nxs.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Define the folder containing the .rod files +folder_path="." # took about 8min + +# Loop over all .rod files in the folder +for file in "$folder_path"/*.rod; do + # Extract the base name (without extension) + base_name=$(basename "$file" .rod) + + # Execute the command with the base name + dataconverter "$file" src/pynxtools_raman/config/config_file_rod.json \ + --reader raman --nxdl NXraman --output "${base_name}.nxs" +done \ No newline at end of file diff --git a/src/download_rod_files/download_all_rod_files_script.sh b/src/download_rod_files/download_all_rod_files_script.sh new file mode 100755 index 0000000..e19c808 --- /dev/null +++ b/src/download_rod_files/download_all_rod_files_script.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Define your input file +input_file="src/download_rod_files/ROD-numbers_subset_test.txt" +# Change it to this line, to download all .rod files. +#input_file="src/download_rod_files/ROD-numbers.txt" # took 7 minutes to download all files + +# Ask for confirmation before proceeding +read -p "Are you sure you want to proceed with the download? (y/n): " confirmation + +# Check user input +if [[ "$confirmation" != "y" && "$confirmation" != "Y" ]]; then + echo "Operation cancelled." + exit 1 +fi + + +# Read all numbers from the file +while read -r num; do + # Loop over your desired range + download_rod_file "$num" +done < "$input_file" \ No newline at end of file diff --git a/src/download_rod_files/download_rods_script.sh b/src/download_rod_files/download_rods_script.sh new file mode 100755 index 0000000..fb9557e --- /dev/null +++ b/src/download_rod_files/download_rods_script.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +#for X in {1..3}; do +for X in {1000001..1000003}; do + download_rod_file "$X" +done \ No newline at end of file diff --git a/src/download_rod_files/rod_keys_statistics_sorted.txt b/src/download_rod_files/rod_keys_statistics_sorted.txt new file mode 100644 index 0000000..0cf2108 --- /dev/null +++ b/src/download_rod_files/rod_keys_statistics_sorted.txt @@ -0,0 +1,206 @@ +_publ_author_name 1133 +_publ_section_title 1133 +_journal_year 1133 +_rod_database.code 1133 +_journal_name_full 1133 +_chemical_formula_sum 1133 +_rod_data_source.block 1132 +_rod_data_source.file 1132 +_raman_spectrum.intensity 1131 +_raman_measurement.integration_time 1131 +_raman_measurement.baseline_correction_details 1131 +_raman_spectrum.raman_shift 1131 +_raman_measurement.baseline_correction 1131 +_raman_measurement.background_subtraction_details 1131 +_raman_measurement.background_subtraction 1131 +_raman_measurement.pressure 1131 +_raman_measurement.temperature 1131 +_raman_measurement.environment_details 1131 +_raman_measurement.environment 1131 +_raman_measurement_device.spot_size 1131 +_raman_measurement_device.direction_polarization 1131 +_raman_measurement_device.power_on_sample 1131 +_raman_measurement_device.resolution 1131 +_raman_measurement_device.configuration 1131 +_raman_measurement_device.excitation_laser_wavelength 1131 +_raman_measurement_device.excitation_laser_type 1131 +_raman_measurement_device.company 1131 +_raman_measurement_device.microscope_objective_magnification 1130 +_chemical_compound_source 1130 +_raman_measurement_device.microscope_numerical_aperture 1130 +_raman_measurement_device_calibration.standard 1130 +_raman_measurement_device.microscope_system 1130 +_raman_measurement_device.location 1129 +_raman_determination_method 1124 +_raman_measurement_device_calibration.id 1116 +_raman_complementary.method 1116 +_raman_complementary.id 1116 +_raman_measurement_device.diffraction_grating 1115 +_raman_measurement_device.model 1115 +_raman_measurement_device.optics_type 1110 +_rod_related_entry.id 1108 +_rod_related_entry.code 1108 +_rod_related_entry.database 1108 +_rod_related_entry.uri 1108 +_rod_related_entry.description 1108 +_cell_length_c 1107 +_cell_angle_gamma 1107 +_cell_angle_beta 1107 +_cell_angle_alpha 1107 +_cell_length_b 1107 +_cell_length_a 1107 +_space_group_IT_number 1086 +_symmetry_space_group_name_H-M 1073 +_chemical_name_mineral 1071 +_symmetry_space_group_name_Hall 1053 +_cell_volume 850 +_journal_page_first 848 +_journal_volume 848 +_journal_page_last 843 +_cod_database_code 797 +_cod_original_formula_sum 768 +_exptl_crystal_density_diffrn 744 +_journal_paper_doi 389 +_chemical_formula_structural 358 +_chemical_name_systematic 339 +_[local]_chemical_compound_state 325 +_[local]_chemical_compound_color 325 +_cell_formula_units_Z 319 +_raman_measurement.datetime_initiated 303 +_raman_measurement.range_max 197 +_raman_measurement.range_min 197 +_solsa_sample.id 156 +_symmetry_cell_setting 149 +_cod_original_sg_symbol_H-M 138 +_rod_maintainer_comment.text 73 +_rod_maintainer_comment.date 73 +_rod_maintainer_comment.id 73 +_rod_maintainer_comment.author 73 +_cod_original_cell_volume 69 +_journal_issue 51 +_diffrn_ambient_temperature 45 +_space_group_name_H-M_alt 30 +_space_group_crystal_system 28 +_space_group_name_Hall 28 +_cod_data_source_file 23 +_cod_data_source_block 23 +_chemical_formula_weight 22 +_chemical_name_common 22 +_chemical_formula_moiety 19 +_raman_spectrum.raw_intensity 16 +_raman_measurement_device_calibration.standard_details 14 +_journal_coden_ASTM 14 +_[local]_database_code_rod 13 +_cell_measurement_temperature 13 +_raman_prediction.mode_count 12 +_raman_prediction.method 12 +_journal_coeditor_code 12 +_citation_journal_id_ASTM 12 +_raman_prediction.active_bands 12 +_raman_prediction.id 12 +_audit_creation_method 10 +_chemical_formula_iupac 10 +_cell_measurement_reflns_used 9 +_cell_measurement_theta_min 9 +_cell_measurement_theta_max 9 +_raman_determination.method 9 +_symmetry_Int_Tables_number 8 +_atom_sites_solution_secondary 7 +_cod_related_entry 7 +_atom_sites_solution_primary 7 +_atom_sites_solution_hydrogens 7 +_computing_cell_refinement 7 +_computing_data_collection 7 +_computing_data_reduction 7 +_diffrn_reflns_limit_k_min 6 +_diffrn_reflns_limit_l_max 6 +_diffrn_reflns_limit_l_min 6 +_diffrn_reflns_number 6 +_diffrn_reflns_theta_full 6 +_diffrn_reflns_theta_max 6 +_diffrn_reflns_theta_min 6 +_diffrn_measured_fraction_theta_full 6 +_diffrn_measured_fraction_theta_max 6 +_diffrn_measurement_device_type 6 +_diffrn_measurement_method 6 +_diffrn_radiation_type 6 +_diffrn_radiation_wavelength 6 +_diffrn_reflns_av_R_equivalents 6 +_diffrn_reflns_limit_h_max 6 +_diffrn_reflns_limit_h_min 6 +_diffrn_reflns_limit_k_max 6 +_computing_structure_solution 6 +_computing_structure_refinement 6 +_exptl_crystal_size_min 5 +_exptl_absorpt_coefficient_mu 5 +_computing_publication_material 5 +_computing_molecular_graphics 5 +_exptl_absorpt_correction_T_max 5 +_exptl_absorpt_correction_T_min 5 +_exptl_absorpt_correction_type 5 +_diffrn_radiation_monochromator 5 +_exptl_absorpt_process_details 5 +_exptl_crystal_density_method 5 +_exptl_crystal_description 5 +_diffrn_reflns_av_sigmaI/netI 5 +_exptl_crystal_F_000 5 +_exptl_crystal_size_max 5 +_exptl_crystal_size_mid 5 +_diffrn_ambient_pressure 4 +_refine_diff_density_min 4 +_refine_ls_R_factor_all 4 +_refine_diff_density_max 4 +_refine_ls_weighting_scheme 3 +_reflns_number_total 3 +_reflns_threshold_expression 3 +_refine_ls_weighting_details 3 +_refine_ls_shift/su_mean 3 +_refine_ls_shift/su_max 3 +_refine_ls_R_factor_gt 3 +_refine_ls_wR_factor_gt 3 +_refine_ls_restrained_S_all 3 +_refine_ls_number_restraints 3 +_refine_ls_number_reflns 3 +_refine_ls_number_parameters 3 +_refine_ls_matrix_type 3 +_refine_ls_hydrogen_treatment 3 +_reflns_number_gt 3 +_refine_ls_goodness_of_fit_ref 3 +_refine_ls_structure_factor_coef 3 +_space_group_symop_operation_xyz 3 +_refine_ls_extinction_method 3 +_refine_ls_extinction_coef 3 +_space_group_symop_id 3 +_refine_ls_wR_factor_ref 3 +_dft_atom_basisset 2 +_tcod_model 2 +_dft_XC_exchange_functional_name 2 +_raman_theoretical_model.temperature 2 +_raman_theoretical_model.pressure 2 +_raman_theoretical_model.excitation_laser_wavelength 2 +_citation.id 2 +_citation.doi 2 +_raman_theoretical_mode.shift 2 +_raman_theoretical_mode.symmetry 2 +_raman_theoretical_mode.intensity 2 +_raman_theoretical_spectrum.raman_shift 2 +_raman_theoretical_spectrum.intensity 2 +_dft_cell_magn_spin_moment 2 +_dft_BZ_integration_method 2 +_dft_BZ_integration_grid_Z 2 +_dft_BZ_integration_grid_Y 2 +_dft_BZ_integration_grid_X 2 +_dft_atom_basisset_citation_id 2 +_audit_update_record 2 +_refine_ls_R_Fsqd_factor 2 +_tcod_software_package 2 +_tcod_structure_type 2 +_diffrn_reflns_av_unetI/netI 1 +_diffrn_reflns_Laue_measured_fraction_full 1 +_diffrn_reflns_point_group_measured_fraction_max 1 +_diffrn_reflns_point_group_measured_fraction_full 1 +_diffrn_reflns_Laue_measured_fraction_max 1 +_audit_creation_date 1 +_solsa_sample_id 1 +_diffrn_detector_area_resol_mean 1 +_exptl_crystal_density_meas 1 \ No newline at end of file diff --git a/src/pynxtools_raman/config/config_file_rod.json b/src/pynxtools_raman/config/config_file_rod.json index 62d4982..2285d62 100644 --- a/src/pynxtools_raman/config/config_file_rod.json +++ b/src/pynxtools_raman/config/config_file_rod.json @@ -10,7 +10,8 @@ "/ENTRY[entry]/INSTRUMENT[instrument]/detector_TYPE[detector_ccd]/count_time/@units": "s", "/ENTRY[entry]/INSTRUMENT[instrument]/detector_TYPE[detector_ccd]/count_time": "@data:_raman_measurement.integration_time", "/ENTRY[entry]/INSTRUMENT[instrument]/detector_TYPE[detector_ccd]/detector_channel_type":"single-channel", - "/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source_532nmlaser]/type": "@data:_raman_measurement_device.excitation_laser_type", + "/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source_532nmlaser]/type": "Laser", + "/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source_532nmlaser]/type_other": "@data:_raman_measurement_device.excitation_laser_type", "/ENTRY[entry]/INSTRUMENT[instrument]/FABRICATION[device_information]/vendor":"@data:_raman_measurement_device.company", "/ENTRY[entry]/INSTRUMENT[instrument]/FABRICATION[device_information]/model": "@data:_raman_measurement_device.model", "/ENTRY[entry]/INSTRUMENT[instrument]/LENS_OPT[objective_lens]/type": "@data:_raman_measurement_device.optics_type", @@ -18,31 +19,46 @@ "/ENTRY[entry]/INSTRUMENT[instrument]/LENS_OPT[objective_lens]/numerical_aperture": "@data:_raman_measurement_device.microscope_numerical_aperture", "/ENTRY[entry]/INSTRUMENT[instrument]/MONOCHROMATOR[monochromator]/grating/period": "@data:_raman_measurement_device.diffraction_grating", "/ENTRY[entry]/INSTRUMENT[instrument]/MONOCHROMATOR[monochromator]/grating/period/@units": "lines/mm", - "/ENTRY[entry]/SAMPLE[sample]/name":"@data:_chemical_name_systematic", + "/ENTRY[entry]/INSTRUMENT[instrument]/RESOLUTION[wavelength_resolution]/physical_quantity": "@data", + "/ENTRY[entry]/INSTRUMENT[instrument]/RESOLUTION[wavelength_resolution]/resolution": "@data", + "/ENTRY[entry]/INSTRUMENT[instrument]/RESOLUTION[wavelength_resolution]/resolution/@units": "@data", + "/ENTRY[entry]/SAMPLE[sample]/name":"@data:_chemical_name_mineral", "/ENTRY[entry]/SAMPLE[sample]/physical_form":"@data:_[local]_chemical_compound_state", - "/ENTRY[entry]/SAMPLE[sample]/chemical_formula":"@data:_chemical_formula_structural", + "/ENTRY[entry]/SAMPLE[sample]/chemical_formula":"['@data:_cod_original_formula_sum','@data:_chemical_formula_sum','@data:_chemical_formula_structural']", "/ENTRY[entry]/SAMPLE[sample]/ENVIRONMENT[medium]/sample_medium":"@data:_raman_measurement.environment", "/ENTRY[entry]/SAMPLE[sample]/ENVIRONMENT[env_temperature]/SENSOR[temperature_sensor]/measurement":"temperature", "/ENTRY[entry]/SAMPLE[sample]/ENVIRONMENT[env_temperature]/SENSOR[temperature_sensor]/value":"@data:_raman_measurement.temperature", "/ENTRY[entry]/SAMPLE[sample]/ENVIRONMENT[env_temperature]/SENSOR[temperature_sensor]/value/@units":"K", + "/ENTRY[entry]/SAMPLE[sample]/ENVIRONMENT[env_temperature]/description":"@data:_raman_measurement.environment_details", "/ENTRY[entry]/SAMPLE[sample]/ENVIRONMENT[env_pressure]/SENSOR[sensor]/measurement":"pressure", "/ENTRY[entry]/SAMPLE[sample]/ENVIRONMENT[env_pressure]/SENSOR[sensor]/value":"@data:_raman_measurement.pressure", "/ENTRY[entry]/SAMPLE[sample]/ENVIRONMENT[env_pressure]/SENSOR[sensor]/value/@units":"kPa", + "/ENTRY[entry]/SAMPLE[sample]/ENVIRONMENT[env_pressure]/description":"@data:_raman_measurement.environment_details", + "/ENTRY[entry]/SAMPLE[sample]/unit_cell_abc":"@data:rod_unit_cell_length_abc", + "/ENTRY[entry]/SAMPLE[sample]/unit_cell_abc/@units":"angstrom", + "/ENTRY[entry]/SAMPLE[sample]/unit_cell_alphabetagamma":"@data:rod_unit_cell_angles_alphabetagamma", + "/ENTRY[entry]/SAMPLE[sample]/unit_cell_alphabetagamma/@units":"degree", + "/ENTRY[entry]/SAMPLE[sample]/density":"@data:_exptl_crystal_density_diffrn", + "/ENTRY[entry]/SAMPLE[sample]/density/@units":"g/cm³", + "/ENTRY[entry]/SAMPLE[sample]/unit_cell_volume":"@data:_cell_volume", + "/ENTRY[entry]/SAMPLE[sample]/unit_cell_volume/@units":"angstrom^3", + "/ENTRY[entry]/SAMPLE[sample]/space_group":"@data:_space_group_IT_number", + "/ENTRY[entry]/SAMPLE[sample]/identifier/service":"@data:COD_service_name", + "/ENTRY[entry]/SAMPLE[sample]/identifier/identifier":"@data:_cod_database_code", "/ENTRY[entry]/definition/@url": "Remove_this_if_pynxtools_issue_#469_is_solved", "/ENTRY[entry]/experiment_type": "Raman spectroscopy", "/ENTRY[entry]/raman_experiment_type": "other", - "/ENTRY[entry]/title": "@data:_chemical_name_mineral", + "/ENTRY[entry]/title": "['@data:_cod_original_formula_sum','@data:_chemical_formula_sum','@data:_chemical_formula_structural','@data:_chemical_name_mineral','@data:_chemical_name_systematic']", "/ENTRY[entry]/start_time": "@data:_raman_measurement.datetime_initiated", "/ENTRY[entry]/@default": "data", "/ENTRY[entry]/DATA[data]/@signal": "y_values", "/ENTRY[entry]/DATA[data]/y_values": "@data:_raman_spectrum.intensity", "/ENTRY[entry]/DATA[data]/y_values/@units": "arb. units", - "/ENTRY[entry]/DATA[data]/y_values/@long_name": "Intensity", + "/ENTRY[entry]/DATA[data]/y_values/@long_name": "Intensity [arb.u.]", "/ENTRY[entry]/DATA[data]/@axes":"x_values_raman", - "/ENTRY[entry]/DATA[data]/x_values_raman/@long_name": "Raman Shift", + "/ENTRY[entry]/DATA[data]/x_values_raman/@long_name": "Raman Shift [1/cm]", "/ENTRY[entry]/DATA[data]/x_values_raman": "@data:_raman_spectrum.raman_shift", "/ENTRY[entry]/DATA[data]/x_values_raman/@units": "1/cm", - "/ENTRY[entry]/experiment_identifier/service": "DOI", "/ENTRY[entry]/experiment_identifier/identifier": "@data:_journal_paper_doi", "/ENTRY[entry]/entry_identifier/service": "Raman open databse ID", "/ENTRY[entry]/entry_identifier/identifier": "@data:_rod_database.code" diff --git a/src/pynxtools_raman/nomad/__init__.py b/src/pynxtools_raman/nomad/__init__.py new file mode 100644 index 0000000..bfc4914 --- /dev/null +++ b/src/pynxtools_raman/nomad/__init__.py @@ -0,0 +1,172 @@ +try: + from nomad.config.models.plugins import AppEntryPoint +except ImportError as exc: + raise ImportError( + "Could not import nomad package. Please install the package 'nomad-lab'." + ) from exc + +from nomad.config.models.ui import ( + App, + Column, + Menu, + MenuItemHistogram, + MenuItemPeriodicTable, + MenuItemTerms, + SearchQuantities, +) + +schema = "pynxtools.nomad.schema.Root" + +raman_app = AppEntryPoint( + name="RamanApp", + description="Simple Raman app.", + app=App( + # Label of the App + label="Raman", + # Path used in the URL, must be unique + path="ramanapp", + # Used to categorize apps in the explore menu + category="Experiment", + # Brief description used in the app menu + description="A simple search app customized for Raman data.", + # Longer description that can also use markdown + readme="This is a simple App to support basic search for Raman based Experiment Entries.", + # If you want to use quantities from a custom schema, you need to load + # the search quantities from it first here. Note that you can use a glob + # syntax to load the entire package, or just a single schema from a + # package. + search_quantities=SearchQuantities( + include=[f"*#{schema}"], + # include=[f"data.Raman.*#{schema}"], + ), + # Controls which columns are shown in the results table + columns=[ + Column(quantity="entry_id", selected=True), + # Column(quantity=f"entry_type", selected=True), + # Column( + # title="definition", + # quantity=f"data.*.ENTRY[*].definition__field#{schema}", + # selected=True, + # ), + Column( + title="start_time", + quantity=f"data.ENTRY[*].start_time__field#{schema}", + selected=True, + ), + Column( + title="title", + quantity=f"data.ENTRY[*].title__field#{schema}", + selected=True, + ), + Column( + title="scattering_config", + quantity=f"data.ENTRY[*].INSTRUMENT[*].scattering_configuration__field#{schema}#str", + selected=True, + ), + Column( + title="unit_cell_volume", + quantity=f"data.ENTRY[*].SAMPLE[*].unit_cell_volume__field#{schema}", + selected=True, + ), + # Only 311 of 1131 ROD entries have this field... + # Column( + # title="physical_form", + # quantity=f"data.*.ENTRY[*].SAMPLE[*].physical_form__field#{schema}", + # selected=True, + # ), + # add this: + # exfitation wavelength --> need deeper search for quantities in nexus + ], + # Dictionary of search filters that are always enabled for queries made + # within this app. This is especially important to narrow down the + # results to the wanted subset. Any available search filter can be + # targeted here. This example makes sure that only entries that use + # MySchema are included. + # filters_locked={"section_defs.definition_qualified_name": [schema]}, + filters_locked={f"data.ENTRY.definition__field#{schema}": ["NXraman"]}, + # Controls the menu shown on the left + menu=Menu( + title="Material", + items=[ + Menu( + title="elements", + items=[ + MenuItemPeriodicTable( + quantity="results.material.elements", + ), + MenuItemTerms( + quantity="results.material.chemical_formula_hill", + width=6, + options=0, + ), + MenuItemTerms( + quantity="results.material.chemical_formula_iupac", + width=6, + options=0, + ), + MenuItemHistogram( + x="results.material.n_elements", + ), + ], + ) + ], + ), + # Controls the default dashboard shown in the search interface + dashboard={ + "widgets": [ + { + "type": "histogram", + "show_input": False, + "autorange": True, + "nbins": 30, + "scale": "linear", + "quantity": f"data.ENTRY.start_time__field#{schema}", + "title": "Start Time", + "layout": { + "lg": {"minH": 3, "minW": 3, "h": 4, "w": 12, "y": 0, "x": 0} + }, + }, + { + "type": "terms", + "show_input": False, + "scale": "linear", + "quantity": f"data.ENTRY.INSTRUMENT.scattering_configuration__field#{schema}#str", + "title": "Scattering Config", + "layout": { + "lg": {"minH": 3, "minW": 3, "h": 4, "w": 4, "y": 0, "x": 12} + }, + }, + { + "type": "terms", + "show_input": False, + "scale": "linear", + "quantity": f"data.ENTRY.raman_experiment_type__field#{schema}#str", + "title": "Raman Type", + "layout": { + "lg": {"minH": 3, "minW": 3, "h": 4, "w": 8, "y": 0, "x": 16} + }, + }, + { + "type": "periodic_table", + "scale": "linear", + "quantity": f"results.material.elements", + "layout": { + "lg": {"minH": 3, "minW": 3, "h": 6, "w": 12, "y": 4, "x": 0} + }, + }, + { + "type": "histogram", + "show_input": False, + "autorange": True, + "nbins": 30, + "scale": "linear", + "quantity": f"data.ENTRY.SAMPLE.unit_cell_volume__field#{schema}", # data.Raman.ENTRY.SAMPLE.unit_cell_volume__field#pynxtools.nomad.schema.NeXus + "title": "Unit Cell Volume", + "layout": { + "lg": {"minH": 3, "minW": 3, "h": 6, "w": 12, "y": 4, "x": 12} + }, + }, + ] + }, + ), +) diff --git a/src/pynxtools_raman/reader.py b/src/pynxtools_raman/reader.py index 5021697..3cf8f4c 100644 --- a/src/pynxtools_raman/reader.py +++ b/src/pynxtools_raman/reader.py @@ -22,12 +22,14 @@ from typing import Dict, Any from pathlib import Path from typing import Any, Dict, List, Tuple # Optional, Union, Set +import re from pynxtools.dataconverter.readers.multi.reader import MultiFormatReader from pynxtools.dataconverter.readers.utils import parse_yml from pynxtools_raman.rod.rod_reader import RodParser +from pynxtools_raman.rod.rod_reader import post_process_rod from pynxtools_raman.witec.witec_reader import post_process_witec from pynxtools_raman.witec.witec_reader import parse_txt_file @@ -90,37 +92,89 @@ def handle_rod_file(self, filepath) -> Dict[str, Any]: # get the key and value pairs from the rod file self.raman_data = rod.extract_keys_and_values_from_cif() + if self.raman_data.get("_raman_theoretical_spectrum.intensity"): + logger.warning( + f"Theoretical Raman Data .rod file found. File parsing aborted." + ) + # prevent file parsing to setting an invalid config file name. + self.config_file = Path() + + # unit_cell_alphabetagamma + # replace the [ and ] to avoid confliucts in processing with pynxtools NXclass assignments + self.raman_data = { + key.replace("_[local]_", "_local_"): value + for key, value in self.raman_data.items() + } + self.missing_meta_data = copy.deepcopy(self.raman_data) + if self.raman_data.get("_cod_database_code") is not None or "": + self.raman_data["COD_service_name"] = "Crystallography Open Database" + del self.missing_meta_data["_cod_database_code"] + + if self.raman_data.get("_cell_length_a") is not None or "": + # transform 9.40(3) to 9.40 + length_a = re.sub(r"\(\d+\)", "", self.raman_data.get("_cell_length_a")) + length_b = re.sub(r"\(\d+\)", "", self.raman_data.get("_cell_length_b")) + length_c = re.sub(r"\(\d+\)", "", self.raman_data.get("_cell_length_c")) + self.raman_data["rod_unit_cell_length_abc"] = [ + float(length_a), + float(length_b), + float(length_c), + ] + del self.missing_meta_data["_cell_length_a"] + del self.missing_meta_data["_cell_length_b"] + del self.missing_meta_data["_cell_length_c"] + if self.raman_data.get("_cell_angle_alpha") is not None or "": + # transform 9.40(3) to 9.40 + angle_alpha = re.sub( + r"\(\d+\)", "", self.raman_data.get("_cell_angle_alpha") + ) + angle_beta = re.sub(r"\(\d+\)", "", self.raman_data.get("_cell_angle_beta")) + angle_gamma = re.sub( + r"\(\d+\)", "", self.raman_data.get("_cell_angle_gamma") + ) + self.raman_data["rod_unit_cell_angles_alphabetagamma"] = [ + float(angle_alpha), + float(angle_beta), + float(angle_gamma), + ] + del self.missing_meta_data["_cell_angle_alpha"] + del self.missing_meta_data["_cell_angle_beta"] + del self.missing_meta_data["_cell_angle_gamma"] + # This changes all uppercase string elements to lowercase string elements for the given key, within a given key value pair key_to_make_value_lower_case = "_raman_measurement.environment" - self.raman_data[key_to_make_value_lower_case] = self.raman_data.get( - key_to_make_value_lower_case - ).lower() + environment_name_str = self.raman_data.get(key_to_make_value_lower_case) + if environment_name_str is not None: + self.raman_data[key_to_make_value_lower_case] = environment_name_str.lower() # transform the string into a datetime object time_key = "_raman_measurement.datetime_initiated" date_time_str = self.raman_data.get(time_key) - date_time_obj = datetime.datetime.strptime(date_time_str, "%Y-%m-%d") - # assume UTC for .rod data, as this is not specified in detail - tzinfo = datetime.timezone.utc - if isinstance(date_time_obj, datetime.datetime): - if tzinfo is not None: - # Apply the specified timezone to the datetime object - date_time_obj = date_time_obj.replace(tzinfo=tzinfo) - - # assign the dictionary the corrrected date format - self.raman_data[time_key] = date_time_obj.isoformat() + if date_time_str is not None: + date_time_obj = datetime.datetime.strptime(date_time_str, "%Y-%m-%d") + # assume UTC for .rod data, as this is not specified in detail + tzinfo = datetime.timezone.utc + if isinstance(date_time_obj, datetime.datetime): + if tzinfo is not None: + # Apply the specified timezone to the datetime object + date_time_obj = date_time_obj.replace(tzinfo=tzinfo) + + # assign the dictionary the corrrected date format + self.raman_data[time_key] = date_time_obj.isoformat() # remove capitalization objective_type_key = "_raman_measurement_device.optics_type" - self.raman_data[objective_type_key] = self.raman_data.get( - objective_type_key - ).lower() - # set a valid raman NXDL value, but only if it matches one of the correct ones: - objective_type_list = ["objective", "lens", "glass fiber", "none"] - if self.raman_data.get(objective_type_key) not in objective_type_list: - self.raman_data[objective_type_key] = "other" + objective_type_str = self.raman_data.get(objective_type_key) + if objective_type_str is not None: + self.raman_data[objective_type_key] = objective_type_str.lower() + # set a valid raman NXDL value, but only if it matches one of the correct ones: + objective_type_list = ["objective", "lens", "glass fiber", "none"] + if self.raman_data.get(objective_type_key) not in objective_type_list: + self.raman_data[objective_type_key] = "other" + + self.post_process = post_process_rod.__get__(self, RamanReader) return {} @@ -198,8 +252,14 @@ def get_data(self, key: str, path: str) -> Any: # this filters out the meta data, which is up to now only created for .rod files + if (path is None or path is "") and key is not None: + return self.raman_data.get(key) + if self.missing_meta_data: - del self.missing_meta_data[path] + # this if condition is required, to only delete keys which are abaialble by the data. + # e.g. is defined to extract it via config.json, but there is no value in meta data + if path in self.missing_meta_data.keys(): + del self.missing_meta_data[path] if value is not None: try: diff --git a/src/pynxtools_raman/rod/rod_get_file.py b/src/pynxtools_raman/rod/rod_get_file.py new file mode 100644 index 0000000..804de4c --- /dev/null +++ b/src/pynxtools_raman/rod/rod_get_file.py @@ -0,0 +1,45 @@ +import argparse + +import requests + +rod_id = 1000679 + + +def save_rod_file_from_ROD_via_API(rod_id: int): + url = "https://solsa.crystallography.net/rod/" + str(rod_id) + ".rod" + + print(f"Initialized download of .rod file with ID '{rod_id}' from '{url}'.") + + try: + response = requests.post(url) + response.raise_for_status() # Raise HTTP error for bad + + print(f"Successfully received .rod file with ID '{rod_id}'") + + filename = str(rod_id) + + with open(filename + ".rod", "w", encoding="utf-8") as file: + file.write(response.text) + print(f"Saved .rod file with ID '{rod_id}' to file '{filename}'") + + except requests.exceptions.ConnectionError as con_err: + print(f"ConnectionError occured: {con_err}") + except requests.exceptions.HTTPError as http_err: + print(f"CHTTPError occured: {http_err}") + except requests.exceptions.RequestException as req_exc: + print(f"RequestException occured: {req_exc}") + + +def trigger_rod_download(): + # Create an argument parser + parser = argparse.ArgumentParser(description="Download a CIF file.") + parser.add_argument( + "rod_id", # The argument's name + type=str, # Argument type (e.g., string) + help="The name of the file to download", # Help message + ) + + # Parse the command-line arguments + args = parser.parse_args() + + save_rod_file_from_ROD_via_API(args.rod_id) diff --git a/src/pynxtools_raman/rod/rod_reader.py b/src/pynxtools_raman/rod/rod_reader.py index eaf9b08..8233b65 100644 --- a/src/pynxtools_raman/rod/rod_reader.py +++ b/src/pynxtools_raman/rod/rod_reader.py @@ -3,6 +3,7 @@ from pathlib import Path import logging +import numpy as np logger = logging.getLogger("pynxtools") @@ -129,6 +130,8 @@ def get_cif_value_from_key( value = value.replace("\n", " ") return value.lstrip() # remove leading space if it is present if value.count("\n") == 0: + if value[0] == "'": + return value.replace("'", "") return value if is_cif_loop_value: # if block like value via loop_ = [....] output_list = [] @@ -161,3 +164,30 @@ def extract_keys_and_values_from_cif(self): ) return cif_dict_key_value_pair_dict + + +def post_process_rod(self) -> None: + wavelength_nm = float( + self.raman_data.get("_raman_measurement_device.excitation_laser_wavelength") + ) + resoltion_invers_cm = float( + self.raman_data.get("_raman_measurement_device.resolution") + ) + + if wavelength_nm is not None and resoltion_invers_cm is not None: + # assume the resolution is referd to the resolution at the laser wavelength + wavelength_invers_cm = 1e7 / wavelength_nm + resolution_nm = resoltion_invers_cm / wavelength_invers_cm * wavelength_nm + + # update the data dictionary + self.raman_data[ + "/ENTRY[entry]/INSTRUMENT[instrument]/RESOLUTION[wavelength_resolution]/physical_quantity" + ] = "wavelength" + self.raman_data[ + "/ENTRY[entry]/INSTRUMENT[instrument]/RESOLUTION[wavelength_resolution]/resolution" + ] = resolution_nm + self.raman_data[ + "/ENTRY[entry]/INSTRUMENT[instrument]/RESOLUTION[wavelength_resolution]/resolution/@units" + ] = "nm" + # remove this key from original input data + del self.missing_meta_data["_raman_measurement_device.resolution"] diff --git a/tests/data/rod/example.nxs b/tests/data/rod/example.nxs index 55e64f1..9fcde00 100644 Binary files a/tests/data/rod/example.nxs and b/tests/data/rod/example.nxs differ diff --git a/tests/data/witec/example.nxs b/tests/data/witec/example.nxs index c903413..7a352dc 100644 Binary files a/tests/data/witec/example.nxs and b/tests/data/witec/example.nxs differ