From bb4070ecc7d92cb8ce3211ca7f637e07756eaae8 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 26 Jun 2020 12:06:20 +0200 Subject: Implement dimension part of event expansion, and clean up tests --- tests/CMakeLists.txt | 32 +++++++++++++++------ tests/ev_enum1.c | 26 +++++++++-------- tests/ev_enum2.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/ev_enum2.geom | 14 +++++++++ tests/ev_enum2.h5 | Bin 0 -> 9064 bytes tests/evparse1.c | 3 +- tests/evparse2.c | 3 +- tests/evparse3.c | 2 +- tests/evparse4.c | 2 +- tests/evparse5.c | 2 +- tests/evparse6.c | 2 +- tests/evparse7.c | 3 +- tests/gen-ev-test.py | 8 +++++- 13 files changed, 147 insertions(+), 28 deletions(-) create mode 100644 tests/ev_enum2.c create mode 100644 tests/ev_enum2.geom create mode 100644 tests/ev_enum2.h5 (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8be42f28..7eee69aa 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -103,43 +103,59 @@ target_include_directories(polarisation_check PRIVATE ${COMMON_INCLUDES}) target_link_libraries(polarisation_check ${COMMON_LIBRARIES}) add_test(polarisation_check polarisation_check) -add_executable(evparse1 evparse1.c) +add_executable(evparse1 evparse1.c + ${CMAKE_CURRENT_SOURCE_DIR}/../libcrystfel/src/image-hdf5.c) target_include_directories(evparse1 PRIVATE ${COMMON_INCLUDES}) target_link_libraries(evparse1 ${COMMON_LIBRARIES} -lhdf5) add_test(evparse1 evparse1) -add_executable(evparse2 evparse2.c) +add_executable(evparse2 evparse2.c + ${CMAKE_CURRENT_SOURCE_DIR}/../libcrystfel/src/image-hdf5.c) target_include_directories(evparse2 PRIVATE ${COMMON_INCLUDES}) target_link_libraries(evparse2 ${COMMON_LIBRARIES} -lhdf5) add_test(evparse2 evparse2) -add_executable(evparse3 evparse3.c) +add_executable(evparse3 evparse3.c + ${CMAKE_CURRENT_SOURCE_DIR}/../libcrystfel/src/image-hdf5.c) target_include_directories(evparse3 PRIVATE ${COMMON_INCLUDES}) target_link_libraries(evparse3 ${COMMON_LIBRARIES} -lhdf5) add_test(evparse3 evparse3) -add_executable(evparse4 evparse4.c) +add_executable(evparse4 evparse4.c + ${CMAKE_CURRENT_SOURCE_DIR}/../libcrystfel/src/image-hdf5.c) target_include_directories(evparse4 PRIVATE ${COMMON_INCLUDES}) target_link_libraries(evparse4 ${COMMON_LIBRARIES} -lhdf5) add_test(evparse4 evparse4) -add_executable(evparse5 evparse5.c) +add_executable(evparse5 evparse5.c + ${CMAKE_CURRENT_SOURCE_DIR}/../libcrystfel/src/image-hdf5.c) target_include_directories(evparse5 PRIVATE ${COMMON_INCLUDES}) target_link_libraries(evparse5 ${COMMON_LIBRARIES} -lhdf5) add_test(evparse5 evparse5) -add_executable(evparse6 evparse6.c) +add_executable(evparse6 evparse6.c + ${CMAKE_CURRENT_SOURCE_DIR}/../libcrystfel/src/image-hdf5.c) target_include_directories(evparse6 PRIVATE ${COMMON_INCLUDES}) target_link_libraries(evparse6 ${COMMON_LIBRARIES} -lhdf5) add_test(evparse6 evparse6) -add_executable(evparse7 evparse7.c) +add_executable(evparse7 evparse7.c + ${CMAKE_CURRENT_SOURCE_DIR}/../libcrystfel/src/image-hdf5.c) target_include_directories(evparse7 PRIVATE ${COMMON_INCLUDES}) target_link_libraries(evparse7 ${COMMON_LIBRARIES} -lhdf5) add_test(evparse7 evparse7) -add_executable(ev_enum1 ev_enum1.c) +add_executable(ev_enum1 ev_enum1.c + ${CMAKE_CURRENT_SOURCE_DIR}/../libcrystfel/src/image-hdf5.c) target_include_directories(ev_enum1 PRIVATE ${COMMON_INCLUDES}) target_link_libraries(ev_enum1 ${COMMON_LIBRARIES} -lhdf5) add_test(NAME ev_enum1 COMMAND ev_enum1 ${CMAKE_CURRENT_SOURCE_DIR}/ev_enum1.h5) + +add_executable(ev_enum2 ev_enum2.c + ${CMAKE_CURRENT_SOURCE_DIR}/../libcrystfel/src/image-hdf5.c) +target_include_directories(ev_enum2 PRIVATE ${COMMON_INCLUDES}) +target_link_libraries(ev_enum2 ${COMMON_LIBRARIES} -lhdf5) +add_test(NAME ev_enum2 + COMMAND ev_enum2 ${CMAKE_CURRENT_SOURCE_DIR}/ev_enum2.h5 + ${CMAKE_CURRENT_SOURCE_DIR}/ev_enum2.geom) diff --git a/tests/ev_enum1.c b/tests/ev_enum1.c index 9c414dc5..c1a93320 100644 --- a/tests/ev_enum1.c +++ b/tests/ev_enum1.c @@ -33,9 +33,11 @@ #include #include +#include +#include #include -#include "../libcrystfel/src/image-hdf5.c" +extern char **expand_paths(hid_t fh, char *pattern, int *n_evs); int main(int argc, char *argv[]) { @@ -46,7 +48,7 @@ int main(int argc, char *argv[]) fh = H5Fopen(argv[1], H5F_ACC_RDONLY, H5P_DEFAULT); if ( fh < 0 ) { - ERROR("Couldn't open file\n"); + printf("Couldn't open file\n"); return 1; } @@ -55,32 +57,32 @@ int main(int argc, char *argv[]) &n_event_ids); if ( event_ids == NULL ) { - STATUS("event_ids = NULL\n"); + printf("event_ids = NULL\n"); return 1; } if ( n_event_ids != 4 ) { - STATUS("Number of event IDs = %i\n", n_event_ids); + printf("Number of event IDs = %i\n", n_event_ids); return 1; } - if ( strcmp(event_ids[0], "/ev_1/dataABCset") != 0 ) { - STATUS("Wrong event id '%s'\n", event_ids[0]); + if ( strcmp(event_ids[0], "ev_1/dataABCset//") != 0 ) { + printf("Wrong event id '%s'\n", event_ids[0]); return 1; } - if ( strcmp(event_ids[1], "/ev_2/dataDEFset") != 0 ) { - STATUS("Wrong event id '%s'\n", event_ids[1]); + if ( strcmp(event_ids[1], "ev_2/dataDEFset//") != 0 ) { + printf("Wrong event id '%s'\n", event_ids[1]); return 1; } - if ( strcmp(event_ids[2], "/ev_3/dataGHIset") != 0 ) { - STATUS("Wrong event id '%s'\n", event_ids[2]); + if ( strcmp(event_ids[2], "ev_3/dataGHIset//") != 0 ) { + printf("Wrong event id '%s'\n", event_ids[2]); return 1; } - if ( strcmp(event_ids[3], "/ev_5/dataNOPset") != 0 ) { - STATUS("Wrong event id '%s'\n", event_ids[3]); + if ( strcmp(event_ids[3], "ev_5/dataNOPset//") != 0 ) { + printf("Wrong event id '%s'\n", event_ids[3]); return 1; } diff --git a/tests/ev_enum2.c b/tests/ev_enum2.c new file mode 100644 index 00000000..f1934a2a --- /dev/null +++ b/tests/ev_enum2.c @@ -0,0 +1,78 @@ +/* + * ev_enum2.c + * + * Check that event enumeration works + * + * Copyright © 2020 Deutsches Elektronen-Synchrotron DESY, + * a research centre of the Helmholtz Association. + * + * Authors: + * 2020 Thomas White + * + * This file is part of CrystFEL. + * + * CrystFEL is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * CrystFEL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with CrystFEL. If not, see . + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + + +#include +#include +#include +#include + +#include + +int main(int argc, char *argv[]) +{ + char **event_ids; + int n_event_ids; + int i; + DataTemplate *dtempl; + + dtempl = data_template_new_from_file(argv[2]); + if ( dtempl == NULL ) { + ERROR("Failed ot load data template\n"); + return 1; + } + + event_ids = image_expand_frames(dtempl, argv[1], &n_event_ids); + + if ( event_ids == NULL ) { + printf("event_ids = NULL\n"); + return 1; + } + + for ( i=0; i +#include #include -#include "../libcrystfel/src/image-hdf5.c" +extern char **read_path_parts(const char *ev_orig, int *pn_plvals); int main(int argc, char *argv[]) { diff --git a/tests/evparse2.c b/tests/evparse2.c index 1499b13b..6b81ae70 100644 --- a/tests/evparse2.c +++ b/tests/evparse2.c @@ -32,9 +32,10 @@ #include +#include #include -#include "../libcrystfel/src/image-hdf5.c" +extern char **read_path_parts(const char *ev_orig, int *pn_plvals); int main(int argc, char *argv[]) { diff --git a/tests/evparse3.c b/tests/evparse3.c index ef6733d0..a7d41629 100644 --- a/tests/evparse3.c +++ b/tests/evparse3.c @@ -34,7 +34,7 @@ #include #include -#include "../libcrystfel/src/image-hdf5.c" +extern char **read_path_parts(const char *ev_orig, int *pn_plvals); int main(int argc, char *argv[]) { diff --git a/tests/evparse4.c b/tests/evparse4.c index ca28fa24..7a975c96 100644 --- a/tests/evparse4.c +++ b/tests/evparse4.c @@ -34,7 +34,7 @@ #include #include -#include "../libcrystfel/src/image-hdf5.c" +extern int *read_dim_parts(const char *ev_orig, int *pn_dvals); int main(int argc, char *argv[]) { diff --git a/tests/evparse5.c b/tests/evparse5.c index ed0d9b85..06daba13 100644 --- a/tests/evparse5.c +++ b/tests/evparse5.c @@ -34,7 +34,7 @@ #include #include -#include "../libcrystfel/src/image-hdf5.c" +extern int *read_dim_parts(const char *ev_orig, int *pn_dvals); int main(int argc, char *argv[]) { diff --git a/tests/evparse6.c b/tests/evparse6.c index 235c6204..63152dda 100644 --- a/tests/evparse6.c +++ b/tests/evparse6.c @@ -34,7 +34,7 @@ #include #include -#include "../libcrystfel/src/image-hdf5.c" +extern int *read_dim_parts(const char *ev_orig, int *pn_dvals); int main(int argc, char *argv[]) { diff --git a/tests/evparse7.c b/tests/evparse7.c index 7e7ff104..fca5055d 100644 --- a/tests/evparse7.c +++ b/tests/evparse7.c @@ -32,9 +32,10 @@ #include +#include #include -#include "../libcrystfel/src/image-hdf5.c" +extern char *substitute_path(const char *ev, const char *pattern); int main(int argc, char *argv[]) { diff --git a/tests/gen-ev-test.py b/tests/gen-ev-test.py index dc7c0f0a..ddfc273d 100644 --- a/tests/gen-ev-test.py +++ b/tests/gen-ev-test.py @@ -5,7 +5,7 @@ import numpy blank = numpy.zeros((1,1), dtype=float) -with h5py.File('ev_enum1.h5', 'w') as fh: +with h5py.File('tests/ev_enum1.h5', 'w') as fh: fh.create_dataset('/data/panelA/ev_1/panel_data1t/dataABCset/array', data=blank) fh.create_dataset('/data/panelA/ev_2/panel_data1t/dataDEFset/array', data=blank) fh.create_dataset('/data/panelA/ev_3/panel_data1t/dataGHIset/array', data=blank) @@ -21,3 +21,9 @@ with h5py.File('ev_enum1.h5', 'w') as fh: fh.create_dataset('/data/panelB/ev_3/dataGHIset/array', data=blank) fh.create_dataset('/data/panelB/ev_4/dataKLMset/array', data=blank) fh.create_dataset('/data/panelB/ev_5/dataNOPset/array', data=blank) + +array = numpy.zeros((100,1,1,2), dtype=float) + +with h5py.File('tests/ev_enum2.h5', 'w') as fh: + fh.create_dataset('/data/a/data_array', data=array) + fh.create_dataset('/data/b/data_array', data=array) -- cgit v1.2.3