Giter Club home page Giter Club logo

csdmpy's People

Contributors

deepanshs avatar dependabot[bot] avatar mgiammar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

csdmpy's Issues

Unable to pass csdmpy.abstract_list.DimensionList as dimensions argument

Did you find a bug? Please help us improve by fill out the sections below. ๐Ÿ‘

Describe the bug

Passing the dimensions attribute from one CSDM object when instantiating another CSDM object raises a ValueError

To Reproduce

Steps to reproduce the behavior:

new_obj = cp.CSDM(
    dimensions=old_obj.x,
    dependent_variables=[some_dv]
)

raises

ValueError: A list of valid Dimension objects or equivalent dictionary objects is required, found <class 'csdmpy.abstract_list.DimensionList'>

However, the following code works

new_obj = cp.CSDM(
    dimensions=[old_obj.x[0]],  # one dimension only
    dependent_variables=[some_dv]
)

Expected behavior

Dimension of new CSDM object is the same as previous, no error.

Desktop (please complete the following information):

  • OS: macOS intel
  • Python version 3.9
  • csdmpy version: 0.4.1

Additional context

Add any other context about the problem here.

Function to simplify units of a dimension object?

Describe the reason for the request

I have a situation where I am multiplying something in Hz by something in s. The result of this is an object that has units of Hz*s. There is an astropy function, .decompose() that simplifies the units down to dimensionless, as expected, but I need to manually do this to all attributes, including ones hidden from the user.

Describe the solution you'd like

A function, perhaps of the form dimension.decompose() or something similar, that goes through a dimension object and simplifies the units everywhere.

Here's the code I have that removes units from the attributes I've found, where f_12 starts off as the 2D result of an mrsimulator simulation:

f_2d.x[0].to('Hz','nmr_frequency_ratio')
f_2d.x[1].to('Hz','nmr_frequency_ratio')
f_2d.x[0] = f_2d.x[0]*cp.ScalarQuantity("s")
f_2d.x[1] = f_2d.x[1]*cp.ScalarQuantity("s")


f_2d.x[0].increment = f_2d.x[0].increment.decompose()
f_2d.x[1].increment = f_2d.x[1].increment.decompose()
f_2d.x[0].origin_offset = f_2d.x[0].origin_offset.decompose()
f_2d.x[1].origin_offset = f_2d.x[1].origin_offset.decompose()
f_2d.x[0].period = f_2d.x[0].period.decompose()
f_2d.x[1].period = f_2d.x[1].period.decompose()
f_2d.x[0]._equivalent_unit = (f_2d.x[0]._equivalent_unit*(cp.ScalarQuantity("s").quantity.unit)).decompose()
f_2d.x[1]._equivalent_unit = (f_2d.x[1]._equivalent_unit*(cp.ScalarQuantity("s").quantity.unit)).decompose()
f_2d.x[0]._unit = f_2d.x[0].coordinates.unit.decompose()
f_2d.x[1]._unit = f_2d.x[1].coordinates.unit.decompose()

Numpy casting error when applying FFT along non-float data

Did you find a bug? Please help us improve by fill out the sections below. ๐Ÿ‘

Creating a CSDM object from an integer numpy array causes a same_kind casting error in numpy. Internally, csdmpy is trying to divide an integer array by a float array; this is disallowed in numpy when same_kind is set to True

Steps to reproduce the behavior:

import csdmpy as cp
import numpy as np
dataset = cp.as_csdm(np.arange(20))  # Integer type by default
dataset.fft()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/.../csdmpy/csdmpy/csdm.py", line 1144, in fft
    return fft(self, axis)
  File "/Users/.../csdmpy/csdmpy/numpy_wrapper/__init__.py", line 63, in fft
    item.subtype._components[slice_] /= scale_factor
numpy.core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'divide' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'with casting rule 'same_kind'

Expected behavior

Successful Fourier transform without error

Screenshots

If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: macOS
  • Python version: 3.10.8
  • csdmpy version: 0.6.dev2

Additional context

Casting the original numpy array to a float type resolves this issue.

import csdmpy as cp
import numpy as np
dataset = cp.as_csdm(np.arange(20, dtype=np.float64))  # Now a float type
dataset.fft()

Improve motivation in README

It would be nice to see (a bit more up-front) how csdmpy fits in-between the basic data format of a CSV (e.g. X-Y data) and the much more complex data format of GEMD geared towards handling information like sequential experimental processing data and metadata. As well as:

  • Why would I want to use CSD as opposed to a CSV, JPG, etc.?
  • Who else has used this so far and to what end? (esp. citing publications)

Btw, nice documentation and nice package!

Unable to multiply quantities by numbers

Did you find a bug? Please help us improve by fill out the sections below. ๐Ÿ‘

Describe the bug

It's no longer possible to generate a quantity by multiplying a number by a ScalarQuantity unit

To Reproduce

Steps to reproduce the behavior:

cptest = 10*cp.ScalarQuantity('Hz')
TypeError: unsupported operand type(s) for *: 'int' and 'ScalarQuantity'

Expected behavior

I would expect the same result as:
cptest = cp.ScalarQuantity('10 Hz')

Desktop (please complete the following information):

  • OS: Windows
  • Python version: 3.9.7
  • csdmpy version: 0.6.0
  • astropy version (in case you need it): 6.0.0

Allow dependent variables to handle arithmetic operations

Describe the reason for the request

Dependent variables cannot currently handle arithmetic, like multiplication:


test = cp.as_dependent_variable(np.array([1,2,3,4,5]))
print(test*2)
TypeError: unsupported operand type(s) for *: 'DependentVariable' and 'int'

this functionality could be useful in some circumstances

Metadata from csdm.application key doesn't get serialized with csdm.save().

Describe the bug

The metadata from the csdm.application key doesn't get serialized to file when using the csdm.save() method.

To Reproduce

import csdmpy as cp

# create dimensions and dependent variables
dimension1 = cp.as_dimension(np.arange(10), application = {"test": "d0"})
dimension1.reciprocal.application = {"test": "reciprocal-d0"}
dimension2 = cp.as_dimension(np.arange(20), application = {"test": "d1"})
dimension2.reciprocal.application = {"test": "reciprocal-d1"}
data = cp.as_dependent_variable(np.random.rand(20, 10), application = {"test": "dv0"})

# create csdm object
before = cp.new()
before.application = {"test": "root"}
before.add_dimension(dimension1)
before.add_dimension(dimension2)
before.add_dependent_variable(data)

# save
before.save('test_file.csdf')

# expected the result to be same
after = cp.load('test_file.csdf', application=True)
print(before.application, after.application)
print(before.dimensions[0].application, after.dimensions[0].application)
print(before.dimensions[0].reciprocal.application, after.dimensions[0].reciprocal.application)
print(before.dimensions[1].application, after.dimensions[1].application)
print(before.dimensions[1].reciprocal.application, after.dimensions[1].reciprocal.application)
print(before.dependent_variables[0].application, after.dependent_variables[0].application)

Output

{'test': 'root'} {}
{'test': 'd0'} {'test': 'd0'}
{'test': 'reciprocal-d0'} {'test': 'reciprocal-d0'}
{'test': 'd1'} {'test': 'd1'}
{'test': 'reciprocal-d1'} {'test': 'reciprocal-d1'}
{'test': 'dv0'} {'test': 'dv0'}

Expected behavior
The value of the root csdm.application key should be {'test': 'root'}.

Additional context
The bug was first reported by Erwan Chesneau.

Error when saving CSDM objects

When I create a csdm object, I can save it with no issues. When I try to change the csdm object, by replacing scaling a dimension or replacing a dimension, the object then will not save

Exact error message: "TypeError: Object of type PhysicalType is not JSON serializable"

Windows, python 3.9.7, csdmpy 0.4.1

The as_dependent_variable method cannot accept Fortran contagious >1D numpy arrays

Did you find a bug? Please help us improve by fill out the sections below. ๐Ÿ‘

Describe the bug

When calling the csdmpy.as_dependent_variable method with a >1D numpy array which is Fortran contagious, an error from numpy is raised:

AttributeError: Incompatible shape for in-place modification. Use `.reshape()` to make a copy with the desired shape.

>1D numpy arrays which are C contagious do not raise this error.

To Reproduce

Steps to reproduce the behavior:

import numpy as np
import csdmpy as cp

arr_c = np.zeros((1028, 1028))
arr_f = np.zeros((1028, 1028))
arr_f = np.asfortranarray(arr_f)

print(arr_c.data.c_contigious)  # True
print(arr_c.data.f_contigious)  # False
print(arr_f.data.c_contigious)  # False
print(arr_f.data.f_contigious)  # True

dv_c = cp.as_dependent_variable(arr_c)  # works
dv_f = cp.as_dependent_variable(arr_f)  # throws following error
AttributeError                            Traceback (most recent call last)
/var/folders/rx/hp_ntm7x7vxfstm8twywpgdw0000gn/T/ipykernel_22510/210171252.py in <module>
    12 dv_c = cp.as_dependent_variable(arr_c)  # works
---> 13dv_f = cp.as_dependent_variable(arr_f)  # throws following error

~/opt/anaconda3/envs/mrsimulator-dev/lib/python3.9/site-packages/csdmpy/dependent_variable/__init__.py in as_dependent_variable(array, **kwargs)
    820         kwargs["quantity_type"] = "scalar"
    821 
--> 822     return DependentVariable(type="internal", components=array, **kwargs)

~/opt/anaconda3/envs/mrsimulator-dev/lib/python3.9/site-packages/csdmpy/dependent_variable/__init__.py in __init__(self, *args, **kwargs)
     94         self._type = "internal" if dictionary["type"] == "internal" else "external"
     95         self.subtype = (
---> 96             InternalDataset(**dictionary)
     97             if dictionary["type"] == "internal"
     98             else ExternalDataset(**dictionary)

~/opt/anaconda3/envs/mrsimulator-dev/lib/python3.9/site-packages/csdmpy/dependent_variable/internal.py in __init__(self, **kwargs)
     55         size = self._components.size
     56         p = self.quantity_type.p
---> 57         self._components.shape = (p, int(size / p))
     58 
     59     def dict(self, filename=None, dataset_index=None, for_display=False):

AttributeError: Incompatible shape for in-place modification. Use `.reshape()` to make a copy with the desired shape.

Expected behavior

Both arrays load the same dependent variables without error

Desktop (please complete the following information):

  • OS: MacOS
  • Python version: 3.9
  • csdmpy version: 0.5

Additional context

Possible solutions to this problem:

  1. Check if array is Fortran contagious and if so, call numpy.ascontiguousarray()
  2. (easiest solution) Call np.ravel() on all passed arrays before reshaping.

Check dimensions to the same within machine precision instead of exactly identical

When I take the difference of two CSDM objects, I often get an error: "Exception: Cannot operate on CSDM objects with different dimensions." I have manually taken the difference between the arrays, and find that the largest difference is on the order of 10^-12. Can we change this check to within machine precision instead of exactly equal?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.