Skip to content

Conversation

@santisoler
Copy link
Member

Fix code style issues in gravity notebooks. Fix code style issues in magnetic notebooks. Fix long commented line in pgi notebook.

@santisoler
Copy link
Member Author

ruff is still complaining about some undefined variables in the FDEM and TDEM notebooks. These undefined variables belong to the cells that save the outputs, which are not being run in the notebooks (that's why notebooks run properly without any issue).

I think we should either fix those cells or remove them directly (specially considering that we are not "testing" those bits because they are not being run). @dccowan, what do you think?

Here I paste the output of running ruff on the notebooks:

Output
nbqa ruff "notebooks"
notebooks/07-fdem/fwd_fdem_3d.ipynb:cell_21:12:15: F821 Undefined name `bz_real`
    |
299 |     # Write data with 2% noise added
300 |     fname = dir_path + "fdem_data.obs"
301 |     bz_real = bz_real + 1e-14 * np.random.rand(len(bz_real))
    |               ^^^^^^^ F821
302 |     bz_imag = bz_imag + 1e-14 * np.random.rand(len(bz_imag))
303 |     f_vec = np.kron(frequencies, np.ones(ntx))
    |

notebooks/07-fdem/fwd_fdem_3d.ipynb:cell_21:12:52: F821 Undefined name `bz_real`
    |
299 |     # Write data with 2% noise added
300 |     fname = dir_path + "fdem_data.obs"
301 |     bz_real = bz_real + 1e-14 * np.random.rand(len(bz_real))
    |                                                    ^^^^^^^ F821
302 |     bz_imag = bz_imag + 1e-14 * np.random.rand(len(bz_imag))
303 |     f_vec = np.kron(frequencies, np.ones(ntx))
    |

notebooks/07-fdem/fwd_fdem_3d.ipynb:cell_21:13:15: F821 Undefined name `bz_imag`
    |
300 |     fname = dir_path + "fdem_data.obs"
301 |     bz_real = bz_real + 1e-14 * np.random.rand(len(bz_real))
302 |     bz_imag = bz_imag + 1e-14 * np.random.rand(len(bz_imag))
    |               ^^^^^^^ F821
303 |     f_vec = np.kron(frequencies, np.ones(ntx))
304 |     receiver_locations = np.kron(np.ones((len(frequencies), 1)), receiver_locations)
    |

notebooks/07-fdem/fwd_fdem_3d.ipynb:cell_21:13:52: F821 Undefined name `bz_imag`
    |
300 |     fname = dir_path + "fdem_data.obs"
301 |     bz_real = bz_real + 1e-14 * np.random.rand(len(bz_real))
302 |     bz_imag = bz_imag + 1e-14 * np.random.rand(len(bz_imag))
    |                                                    ^^^^^^^ F821
303 |     f_vec = np.kron(frequencies, np.ones(ntx))
304 |     receiver_locations = np.kron(np.ones((len(frequencies), 1)), receiver_locations)
    |

notebooks/07-fdem/fwd_fdem_3d.ipynb:cell_21:14:42: F821 Undefined name `ntx`
    |
301 |     bz_real = bz_real + 1e-14 * np.random.rand(len(bz_real))
302 |     bz_imag = bz_imag + 1e-14 * np.random.rand(len(bz_imag))
303 |     f_vec = np.kron(frequencies, np.ones(ntx))
    |                                          ^^^ F821
304 |     receiver_locations = np.kron(np.ones((len(frequencies), 1)), receiver_locations)
    |

notebooks/07-fdem/fwd_fdem_3d.ipynb:cell_21:15:66: F821 Undefined name `receiver_locations`
    |
302 |     bz_imag = bz_imag + 1e-14 * np.random.rand(len(bz_imag))
303 |     f_vec = np.kron(frequencies, np.ones(ntx))
304 |     receiver_locations = np.kron(np.ones((len(frequencies), 1)), receiver_locations)
    |                                                                  ^^^^^^^^^^^^^^^^^^ F821
305 |
306 |     np.savetxt(fname, np.c_[f_vec, receiver_locations, bz_real, bz_imag], fmt="%.4e")
    |

notebooks/07-fdem/fwd_fdem_3d.ipynb:cell_21:20:35: F821 Undefined name `model`
    |
308 |     # Plot true model
309 |     output_model = plotting_map * model
    |                                   ^^^^^ F821
310 |     output_model[np.isnan(output_model)] = 1e-8
    |

notebooks/07-fdem/fwd_fdem_cyl.ipynb:cell_7:4:89: E501 Line too long (90 > 88)
    |
126 | dpred = simulation.dpred(model)
127 |
128 | # Data are organized by transmitter location, then component, then frequency. We had nFreq
    |                                                                                         ^^ E501
129 | # transmitters and each transmitter had 2 receivers (real and imaginary component). So
130 | # first we will pick out the real and imaginary data
    |

notebooks/08-tdem/fwd_tdem_3d.ipynb:cell_23:14:29: F821 Undefined name `ntx`
    |
302 |     noise = rng.uniform(low=0.0, high=0.02 * np.abs(dpred), size=len(dpred))
303 |     dpred += noise
304 |     t_vec = np.kron(np.ones(ntx), time_channels)
    |                             ^^^ F821
305 |     receiver_locations = np.kron(receiver_locations, np.ones((len(time_channels), 1)))
    |

notebooks/08-tdem/fwd_tdem_3d.ipynb:cell_23:15:34: F821 Undefined name `receiver_locations`
    |
303 |     dpred += noise
304 |     t_vec = np.kron(np.ones(ntx), time_channels)
305 |     receiver_locations = np.kron(receiver_locations, np.ones((len(time_channels), 1)))
    |                                  ^^^^^^^^^^^^^^^^^^ F821
306 |
307 |     np.savetxt(fname, np.c_[receiver_locations, t_vec, dpred], fmt="%.4e")
    |

notebooks/08-tdem/fwd_tdem_3d.ipynb:cell_23:20:35: F821 Undefined name `model`
    |
309 |     # Plot true model
310 |     output_model = plotting_map * model
    |                                   ^^^^^ F821
311 |     output_model[np.isnan(output_model)] = 1e-8
    |

Found 11 errors.

@santisoler santisoler marked this pull request as ready for review November 20, 2024 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants