Skip to content
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

Minor misuse of timing info in Blackrock headers #1200

Closed
cboulay opened this issue Nov 19, 2022 · 3 comments
Closed

Minor misuse of timing info in Blackrock headers #1200

cboulay opened this issue Nov 19, 2022 · 3 comments
Assignees
Labels
Milestone

Comments

@cboulay
Copy link
Contributor

cboulay commented Nov 19, 2022

Describe the bug

There are a couple instances in blackrockrawio.py where the information about timestamp resolution and sample resolution are misused. So far this has proven innocuous because the resulting variables are unused, and even if they were used the mistake happens to yield the same value, for now.

That's about to change. There is an upcoming change to Blackrock files in the timestamp resolution (30_000/s -> 1e9/s, i.e., nanoseconds); sample resolution remains unchanged (30_000/s). Technically, this does not require a FileSpec version change because all of the required information is already in the existing FileSpec; it just needs to be used correctly. If NEO remains unchanged, its misuse of the header information will lead to incorrect entries in self._nsx_params, which are currently unused, but we should correct them anyway in case they are ever used in the future.

Note: The NEV header has both timestamp resolution (current: 30_000 -> new: 1e9) and sample resolution (30_000 -> 30_000). The NSx header only has timestamp resolution (30_000 -> 1e9) and, as per the filespec, we are expected to assume that the NSx sample resolution is 30_000. If the NSX header is modified in the future to include sample resolution then this would be an explicit change to the file spec; for the new file spec we would replace the hard-coded 30_000 with the header-provided value.

To Reproduce
The FileSpec doc is attached LB-0023-7.00_NEV_File_Format.pdf. We can discuss if the proposed changes are feasible, and worthwhile, but there's actually no bug to trigger currently because the misused values aren't used anywhere.

Expected behaviour
NEO correctly loads both current files with clock values corresponding to sample counts (increment 1 per sample, 1 second = 30_000) and upcoming files with clock values corresponding to nanoseconds (increment 33_333 per sample, 1 second = 1_000_000_000).

Additional context

Here are the errors I have identified.

Error 1:

'sampling_rate':
self.__nsx_basic_header[nsx_nb]['timestamp_resolution']
/ self.__nsx_basic_header[nsx_nb]['period'] * pq.Hz,

The 'sampling_rate' entry in the nsx_parameters is calculated as timestamp_resolution / period. This should be sample_resolution / period. However, as nsx files don't have sample resolution, this must be 30_000 / period.

Luckily, nsx_parameters['sampling_rate'] doesn't appear to be used anywhere! In fact, the location we might expect it to be used actually calculates sampling rate denovo using exactly 30_000 / period.

sr = float(main_sampling_rate / self.__nsx_basic_header[nsx_nb]['period'])
self.sig_sampling_rates[nsx_nb] = sr

I propose in the header-based calculation of 'sampling_rate' that the 'timestamp_resolution' is replaced with hard-coded 30_000 and this calculated sample rate is used in the nsx load body via: self.__nsx_params[self.__nsx_spec[nsx_nb]]('sampling_rate', nsx_nb)

Error 2:
'time_unit' immediately following above

'time_unit': pq.CompoundUnit("1.0/{}*s".format(
self.__nsx_basic_header[nsx_nb]['timestamp_resolution']
/ self.__nsx_basic_header[nsx_nb]['period']))}

I suspect that this should be 1 / 30_000, based on how waveform_time_unit is used, but I don't actually know because it isn't used anywhere!

@cboulay cboulay added the bug label Nov 19, 2022
@JuliaSprenger JuliaSprenger self-assigned this Apr 3, 2023
@JuliaSprenger JuliaSprenger added this to the 0.12.1 milestone Apr 3, 2023
@JuliaSprenger JuliaSprenger modified the milestones: 0.12.1, 0.13.0 Jul 19, 2023
@apdavison apdavison added the IO label Jul 28, 2023
@apdavison apdavison modified the milestones: 0.13.0, 0.14.0 Feb 23, 2024
@zm711
Copy link
Contributor

zm711 commented May 7, 2024

@cboulay,

I'm just reading through old issues. I haven't read this in detail, but did you 1) address this in your recent PR or 2) would be willing to address this in a future PR?

@zm711
Copy link
Contributor

zm711 commented Aug 1, 2024

@cboulay,

just wanted to bump this one more time. Did you fix the issues you have pointed out in your recent PRs such that this can be closed? At minimum a small PR indicating with comments why you believe there is a problem would be nice.

@cboulay
Copy link
Contributor Author

cboulay commented Sep 4, 2024

Hey, sorry for being absent on this. Yes, I'm fairly certain this is solved with #1338

@cboulay cboulay closed this as completed Sep 4, 2024
@zm711 zm711 modified the milestones: 0.14.0, 0.13.4 Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants