-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
variable length of a dimension in DataArray #1265
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
Comments
Xarray adds labels to NumPy array, so it can't handle variable length arrays any better than NumPy. Basically, your options are to either (a) store stored numpy arrays using dtype=object (not really recommended), (b) pad each array up to a common length with NaNs (used to mark missing values in xarray) or (c) put multiple variables in an Depending on your exact use case, either (b) or (c) could be a good solution. |
I believe that this is a common problem in simulation of quantum mechanical problems. I will try to come with a bit more realistic / practical example that I hope will help with choosing the best solution. |
I'm definitely happy to look at a more realistic / complete example. My PhD work was actually doing quantum simulations. |
Hi, I tried to came with a bit more interesting but still simple example from itertools import product
import numpy as np
import pandas as pd
import holoviews as hv
hv.notebook_extension()
def energies(L, a):
k = np.pi * np.arange(1, L//a) / L
return {'exact': k**2, 'approx': 2*(1 - np.cos(k * a)) / a**2}
L = np.arange(10, 21, 2)
a = np.array([1, .5, .25])
data = []
for Li, ai in product(L, a):
output = dict(L=Li, a=ai)
output.update(**energies(Li, ai))
data.append(output)
df = pd.DataFrame(data)
hmap_data = {}
for n, row in df.iterrows():
key = row.L, row.a
val = (hv.Points((np.arange(len(row.exact)), row.exact), kdims=['n', 'E']) *
hv.Points((np.arange(len(row.approx)), row.approx), kdims=['n', 'E']))
hmap_data[key] = val
hv.HoloMap(hmap_data, kdims=['L', 'a']).select(n=(0, 20), E=(0, 20)) example is simple and don't include any serious simulation. I compare here energies of particle in 1D box vs what would came out from tight-binding simulation. Example is very simple but it captures situation that happens often when calculating spectrum of a finite system: for different system size we get different amount of energy levels. That simple example is manageable without any pandas or xarray machinery but imagine real simulation made with kwant for series of different input parameters (system dimensions, gate voltages, chemical potentials, etc...) |
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity If this issue remains relevant, please comment here; otherwise it will be marked as closed automatically |
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity If this issue remains relevant, please comment here or remove the |
instead of the workarounds mentioned in #1265 (comment) this should work once the integration with |
I am having the following issue, say I have this code where I find eigenvalues of some system composed of the variables
A
,B
,C
, andD
.In my example the number of eigenvalues (
num_eigs
) is constant.However, in general this number is not constant. Is there a way in
xarray
to handle this issue?For those that ask why I would need this: I do numerics in quantum mechanics and create quantum systems with certain parameters. Some of these parameters could be the system size. This would result in different Hamiltonians (a matrix describing the system) and therefore in a different number of eigenvalues.
The text was updated successfully, but these errors were encountered: