Code Monkey home page Code Monkey logo

Comments (12)

aperezhortal avatar aperezhortal commented on June 9, 2024

Hi @Fangyh09, can you provide the error message (the complete traceback) and the OS that you are using?

from pysteps.

Fangyh09 avatar Fangyh09 commented on June 9, 2024
from matplotlib import cm, pyplot
import numpy as np
import os
from pprint import pprint
from pysteps import io, rcparams
from pysteps.noise.fftgenerators import initialize_param_2d_fft_filter
from pysteps.noise.fftgenerators import initialize_nonparam_2d_fft_filter
from pysteps.noise.fftgenerators import generate_noise_2d_fft_filter
from pysteps.utils import conversion, rapsd, transformation
from pysteps.visualization import plot_precip_field, plot_spectrum1d

# Import the example radar composite
root_path = rcparams.data_sources["mch"]["root_path"]
filename = os.path.join(root_path, "20160711", "AQC161932100V_00005.801.gif")
R, _, metadata = io.import_mch_gif(filename, product="AQC", unit="mm", accutime=5.0)

# Convert to mm/h
R, metadata = conversion.to_rainrate(R, metadata)

# Nicely print the metadata
pprint(metadata)

# Plot the rainfall field
plot_precip_field(R, geodata=metadata)

# Log-transform the data
R, metadata = transformation.dB_transform(R, metadata, threshold=0.1, zerovalue=-15.0)

# Assign the fill value to all the Nans
R[~np.isfinite(R)] = metadata["zerovalue"]


# Fit the parametric PSD to the observation
Fp = initialize_param_2d_fft_filter(R)

# Compute the observed and fitted 1D PSD
L = np.max(Fp["input_shape"])
if L % 2 == 0:
    wn = np.arange(0, int(L / 2) + 1)
else:
    wn = np.arange(0, int(L / 2))
R_, freq = rapsd(R, fft_method=np.fft, return_freq=True)
f = np.exp(Fp["model"](np.log(wn), *Fp["pars"]))

# Extract the scaling break in km, beta1 and beta2
w0 = L / np.exp(Fp["pars"][0])
b1 = Fp["pars"][2]
b2 = Fp["pars"][3]

# Plot the observed power spectrum and the model
fig, ax = pyplot.subplots()
plot_scales = [512, 256, 128, 64, 32, 16, 8, 4]
plot_spectrum1d(
    freq,
    R_,
    x_units="km",
    y_units="dBR",
    color="k",
    ax=ax,
    label="Observed",
    wavelength_ticks=plot_scales,
)
plot_spectrum1d(
    freq,
    f,
    x_units="km",
    y_units="dBR",
    color="r",
    ax=ax,
    label="Fit",
    wavelength_ticks=plot_scales,
)
pyplot.legend()
ax.set_title(
    "Radially averaged log-power spectrum of R\n"
    r"$\omega_0=%.0f km, \beta_1=%.1f, \beta_2=%.1f$" % (w0, b1, b2)
)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-b4008649c42f> in <module>()
      1 # Fit the parametric PSD to the observation
----> 2 Fp = initialize_param_2d_fft_filter(R)
      3 
      4 # Compute the observed and fitted 1D PSD
      5 L = np.max(Fp["input_shape"])

~/miniconda2/envs/maskrcnn_benchmark/lib/python3.6/site-packages/pysteps-1.0.0-py3.6-linux-x86_64.egg/pysteps/noise/fftgenerators.py in initialize_param_2d_fft_filter(X, **kwargs)
     98         raise ValueError("the input is not two- or three-dimensional array")
     99     if np.any(~np.isfinite(X)):
--> 100         raise ValueError("X contains non-finite values")
    101 
    102     # defaults

ValueError: X contains non-finite values
uname -a
Linux nonews 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

from pysteps.

Fangyh09 avatar Fangyh09 commented on June 9, 2024

@aperezhortal
I found the reason, R is all nan after io.import_mch_gif.
What are the possible reasons?

from pysteps.

aperezhortal avatar aperezhortal commented on June 9, 2024

I can't reproduce the error in my enviroment.

One possibility is that the file is corrupt. To discard that possibility, try using a different file, like:

filename = os.path.join(root_path, "20150515", "AQC151351605F_00005.801.gif")

Also, you can try to sync the pysteps-data dir using git pull.

from pysteps.

aperezhortal avatar aperezhortal commented on June 9, 2024

If that does not work, another thing to try is reinstalling the PIL package used to read the GIFs:
conda install PIL --force-reinstall

from pysteps.

Fangyh09 avatar Fangyh09 commented on June 9, 2024

I installed using this way:

git clone https://github.com/pySTEPS/pysteps.git
python setup.py install

from pysteps.

aperezhortal avatar aperezhortal commented on June 9, 2024

python setup.py install will try to install only missing dependencies, it won't update any package.

From your error log , it seems that you installed Pystepst in an anaconda environment (maskrcnn_benchmark). Hence, I think that you can update PIL using:

source activate maskrcnn_benchmark 

conda install PIL --force-reinstall

from pysteps.

aperezhortal avatar aperezhortal commented on June 9, 2024

To discard any issues with the pysteps-data files, try cloning that repo again.

from pysteps.

Fangyh09 avatar Fangyh09 commented on June 9, 2024

When fix old errors, I met with new error
"ImportError: cannot import name 'create_prompt_application".

Reproduce

conda create -n pysteps
conda install pysteps
jupyter notebook

I tried "sudo pip3 install 'prompt-toolkit<2.1.0,>=2.0.0' --force-reinstall", but failed.

from pysteps.

Fangyh09 avatar Fangyh09 commented on June 9, 2024

@aperezhortal Could you reproduce the error?
Any other way to install the enviroment?

from pysteps.

aperezhortal avatar aperezhortal commented on June 9, 2024

@Fangyh09, that error is related to the jupyter package, and not pysteps.

I tryied the following steps to install both packages in the new environment and everything worked fine.

conda create -n pysteps
source activate pysteps   ( activate the environment, otherwise pysteps will be installed in the base env)
conda install pysteps jupyter

jupyter notebook

from pysteps.

Fangyh09 avatar Fangyh09 commented on June 9, 2024

@aperezhortal You are right.
Thanks for your quick reply. It works after

conda create -n pysteps # <--- important
source activate pysteps   
conda config --env --set channel_priority strict
conda config --env --prepend channels conda-forge
conda install pysteps jupyter
jupyter notebook

from pysteps.

Related Issues (20)

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.