Coder Social home page Coder Social logo

irfu-python's Introduction

pyRFU

License_ Python_ PyPi_ Format_ Wheel_ Status_ Downloads_ CI_ PyLintB_ CodeQL_ CodeCov_ Issues_ Commits_ Readthedocs_ Matrix_ Black_ Doi_

The Python package pyrfu is a software based on the IRFU-MATLAB library to work with space data, particularly the Magnetospheric MultiScale (MMS) mission.

It is distributed under the open-source MIT license.

Quickstart

Installing pyrfu with pip (more details here):

$ python -m pip install pyrfu
# or
$ python -m pip install --user pyrfu

Import pyrfu.mms package with routines specific to work with the Magnetospheric Multiscale mission (MMS)

from pyrfu import mms

Setup path to MMS data

mms.db_init("/Volumes/mms")

Load magnetic field and ion bulk velocity data

tint = ["2019-09-14T07:54:00.000", "2019-09-14T08:11:00.000"]
b_gsm = mms.get_data("b_gsm_fgm_srvy_l2", tint, 1)
v_gse_i = mms.get_data("vi_gse_fpi_fast_l2", tint, 1)

Import pyrfu.pyrf package with generic routines

from pyrfu import pyrf

Transform ion bulk velocity to geocentric solar magnetospheric (GSM) coordinates

v_gsm_i = pyrf.cotrans(v_gse_i, "gse>gsm")

Import pyrfu.plot package with plotting routines

from pyrfu import plot

Plot time series of magnetic field and ion bulk velocity

import matplotlib.pyplot as plt

f, axs = plt.subplots(2, sharex="all")
plot.plot_line(axs[0], b_gsm)
axs[0].set_ylabel("$B~[\\mathrm{nT}]$")
axs[0].legend(["$B_{x}$", "$B_{y}$", "$B_{z}$"], ncol=4)

plot.plot_line(axs[1], v_gsm_i)
axs[1].set_ylabel("$V_i~[\\mathrm{km}~\\mathrm{s}^{-1}]$")
axs[1].legend(["$V_{ix}$", "$V_{iy}$", "$V_{iz}$"], ncol=4)

Documentation

Full documentation can be found on pyrfu.readthedocs.io

Examples

A list of examples is available here

Credits

This software was developed by Louis RICHARD ([email protected]) based on the IRFU-MATLAB library.

Acknowledgement

Please use the following to acknowledge use of pyrfu in your publications: Data analysis was performed using the pyrfu analysis package available at https://github.com/louis-richard/irfu-python

Additional Information

MMS Science Data Center: https://lasp.colorado.edu/mms/sdc/public/

MMS Datasets: https://lasp.colorado.edu/mms/sdc/public/datasets/

MMS - Goddard Space Flight Center: http://mms.gsfc.nasa.gov/

irfu-python's People

Contributors

dependabot[bot] avatar louis-richard avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

irfu-python's Issues

mms_keys.json missing perp/parallel ion moments

The required entries to the table would be:

        "tperpi_fpi_brst_l2": {
            "dtype": "dis-moms",
            "cdf_name": "dis_tempperp_brst"
        },
        "tparai_fpi_brst_l2": {
            "dtype": "dis-moms",
            "cdf_name": "dis_temppara_brst"
        },

pyrfu/mms/make_model_vdf.py import error

within the file pyrfu/mms/make_model_vdf.py there is an error TypeError: 'module' object is not callable on line 104.

I believe this is because on line 15 you are importing the module not the function within that module. When I changed line 15 to from .rotate_tensor import rotate_tensor it fixed the problem.

Problems using mms.get_data() without restarting Kernel

Hi Louis,

I created a new virtual environment to demonstrate this issue. I'm having it on my work copy of pyrfu (2.4.1) as well as the latest version which I installed today. The problem occurs when using get_data() on local files when it has not been downloaded in the same kernel run. It throws out an exception: AttributeError: 'NoneType' object has no attribute 'items'.

  1. Downloading the data to a local file then loading it in (1 cell in jupyter notebook)
from pyrfu import mms

data_path = "D://MMS"
mms.db_init(data_path)

tint = ["2017-07-11T22:33:00.000", "2017-07-11T22:34:00.000"]

mms.download_data("pdi_fpi_brst_l2", tint, 1, data_path=data_path)
result = mms.get_data("pdi_fpi_brst_l2", tint, 1, data_path=data_path)
  1. In another cell of the same Jupyter notebook, without restarting Kernel or re-downloading:
result = mms.get_data("pdi_fpi_brst_l2", tint, 1, data_path=data_path)

Throws the AttributeError exception.

I have this issue on most of my data intervals, but some do work. Another member in my department has the same problem on her installation, even when not using previously-downloaded data.

The full error is:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], [line 1](vscode-notebook-cell:?execution_count=2&line=1)
----> [1](vscode-notebook-cell:?execution_count=2&line=1) result = mms.get_data("pdi_fpi_brst_l2", tint, 1, data_path=data_path)

File [d:\Anaconda\envs\helpingcara\lib\site-packages\pyrfu\mms\get_data.py:126], in get_data(var_str, tint, mms_id, verbose, data_path, from_sdc)
    [123] file = os.path.normpath(file_name)
    [125] if "-dist" in var["dtype"]:
--> [126]     out = dist_append(out, get_dist(file, cdf_name, tint))
    [128] else:
    [129]     out = ts_append(out, get_ts(file, cdf_name, tint))

File [d:\Anaconda\envs\helpingcara\lib\site-packages\pyrfu\mms\get_dist.py:88] in get_dist(file_path, cdf_name, tint)
     [84]file = load(file_path)
     [86]# with CDF(file_path) as file:
     [87]# Get the relevant CDF file information (zVariables)
---> [88]z_vars = [z_var[0] for z_var in file.items()]
     [90]# Get the global attributes
     [91] glob_attrs = _pycdfpp_attributes_to_dict(file.attributes)

AttributeError: 'NoneType' object has no attribute 'items'

Some Question

Hi, when I use the mms.psd_moments function, (I'm using the example you gave) I always get the following error: Traceback (most recent call last).
File "C:\Users\eric\AppData\Roaming\JetBrains\PyCharmCE2023.1\scratches\demo6.py", line 585, in
moments_e = mms.psd_moments(vdf_e, scpot, **options)
File "C:\anaconda\envs\pyrfu\lib\site-packages\pyrfu\mms\psd_moments.py", line 251, in psd_moments
field_name = vdf.attrs["FIELDNAM"]
KeyError: 'FIELDNAM'

from pyrfu import mms

tint_brst = ["2015-09-01T12:15:28.000", "2015-09-01T12:24:00.000"]

mms.download_data('pdi_fpi_brst_l2',tint_brst,1,data_path="C:\MMS\volumes")
scpot = mms.get_data("V_edp_brst_l2", tint_brst, 1)
vdf_e = mms.get_data("pde_fpi_brst_l2", tint_brst, 1)
options = dict(energy_range=[1, 1000])
moments_e = mms.psd_moments(vdf_e, scpot, **options)

How to set the database of MMS?

Dear Louis Richard,

      I do not know how to set the path of MMS database of pyrfu. 
   for example, in irf-matlab-master, we have to type: 
                        mms.db_init (' local_file_db ', path of database);
    But I do not know how to do it in this python code

thanks a lot!

metadata-generation-failed when installing Pyrfu 2.4.12 to a conda environment

Hi Louis,

I created a new environment to install the latest pyrfu version, and I encounter an error with metadata generation during installation of the package dependencies. I do not encounter the problem for pyrfu version 2.4.11.

I am using pip to install the pyrfu package on a fresh conda environment (version 22.9.0). It seems as though this might be an error with the pycdfpp package?

I am not an expert in these things so I thought I would bring this to your attention in case any of this is within your control.

Collecting pycdfpp==0.6.0 (from pyrfu)
  Using cached pycdfpp-0.6.0.tar.gz (1.2 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [22 lines of output]
      + meson setup /private/var/folders/w1/vm9pp8qn443d01jr2j6tw41r0000gp/T/pip-install-zl9wk08i/pycdfpp_dd5575d2677f45aea33b2dd730546a9a /private/var/folders/w1/vm9pp8qn443d01jr2j6tw41r0000gp/T/pip-install-zl9wk08i/pycdfpp_dd5575d2677f45aea33b2dd730546a9a/.mesonpy-639kkxhx -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md -Doptimization=3 --native-file=/private/var/folders/w1/vm9pp8qn443d01jr2j6tw41r0000gp/T/pip-install-zl9wk08i/pycdfpp_dd5575d2677f45aea33b2dd730546a9a/.mesonpy-639kkxhx/meson-python-native-file.ini
      WARNING: Recommend using either -Dbuildtype or -Doptimization + -Ddebug. Using both is redundant since they override each other. See: https://mesonbuild.com/Builtin-options.html#build-type-options
      The Meson build system
      Version: 1.4.0
      Source dir: /private/var/folders/w1/vm9pp8qn443d01jr2j6tw41r0000gp/T/pip-install-zl9wk08i/pycdfpp_dd5575d2677f45aea33b2dd730546a9a
      Build dir: /private/var/folders/w1/vm9pp8qn443d01jr2j6tw41r0000gp/T/pip-install-zl9wk08i/pycdfpp_dd5575d2677f45aea33b2dd730546a9a/.mesonpy-639kkxhx
      Build type: native build
      WARNING: You should add the boolean check kwarg to the run_command call.
               It currently defaults to false,
               but it will default to true in future releases of meson.
               See also: https://github.com/mesonbuild/meson/issues/9300
      Project name: pycdfpp
      Project version: 0.6.0
      
      ../meson.build:1:0: ERROR: Unknown compiler(s): [['cc'], ['gcc'], ['clang'], ['nvc'], ['pgcc'], ['icc'], ['icx']]
      The following exception(s) were encountered:
      Running `nvc --version` gave "[Errno 2] No such file or directory: 'nvc'"
      Running `pgcc --version` gave "[Errno 2] No such file or directory: 'pgcc'"
      Running `icc --version` gave "[Errno 2] No such file or directory: 'icc'"
      Running `icx --version` gave "[Errno 2] No such file or directory: 'icx'"
      
      A full log can be found at /private/var/folders/w1/vm9pp8qn443d01jr2j6tw41r0000gp/T/pip-install-zl9wk08i/pycdfpp_dd5575d2677f45aea33b2dd730546a9a/.mesonpy-639kkxhx/meson-logs/meson-log.txt
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.

I hope this helps,
Harry

plot_projection() is unable to plot VDFs where energy bins are equivalent to less than the spacecraft potential

The problem seems to come from the vdf_projection function, which is taking the square root of shifted energy bins. When the bins are smaller than the spacecraft potential, they are shifted to negative numbers and the np.sqrt() function is returning nan. The pcolormesh function can't accept nans as bin coordinates, which causes an error in plot_projection.py.

To fix this, I suggest np.sqrt(..., dtype=np.csingle) or np.emath.sqrt(...) on line 348 of vdf_projection.py.

Doing this gives 0 for the "negative" velocity bins, which I believe to be your intention based on the np.real() function on line 349. However, it might not be the perfect solution as it stretches the innermost bin to the center of the polar plot.

If you need an example timestep, use 1475257837.6974614 a.k.a ['2016-09-30T17:50:37.697'].

Running on pyrfu version 2.4.12 but with dependencies installed for 2.4.11 (see my other issue).

Hope this helps.

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.