How to create SFR input for a MF6 DISV grid in Flopy? - flopy

I'm creating a MF6 disv-grid model in Flopy and want to represent a creek using the SFR package. Does anyone have experience adding SFR input to a MF6 DISV grid from a shapefile (or Shapely LineString)?
I've tried using the SFRmaker package. But unfortunately, the support for unstructured grids aren't fully implemented, and I haven't managed to find a suitable workaround.
Does anyone know of a way to create SFR input from a shapefile using Python & Flopy?

Related

Forest Plot for meta-analysis (including weight total)

So my problem lies within Rstudio. I have a data set with three columns (study name, effect size (derived from odds ratios) and sample size). Once I have run my meta-regression model I cannot find a code that allows me to generate a forest plot similar to the one included in the link. I am quite new to R and would consider myself a beginner so apologies for a potentially silly question.
I am using a MacBook pro and Rstudio version 2022.02.0+443

How to use the same kde used by seaborn

I'm trying to use kernel density estimator to obtain the distribution of my data. Using the seaborn, I can simply call sns.kdeplot(temp, shade=True) and that will plot the kde or the distribution of my data. However, with seaborn, I cannot obtain scores for new data points. However, if I'm using the sklearn library, I can simply call kde.score_samples(data). Therefore, how can I achieve the same thing with seaborn? Or, is there a way I can return the kde obtained from seaborn?
Any help is much appreciated!
After looking through the documentation https://github.com/mwaskom/seaborn/blob/a9577e705023873de7c7bbf3e9b6ae0dc1880b51/seaborn/distributions.py#L2641, the bandwidth of the kernel is calculated as: bw = stats.gaussian_kde(a).scotts_factor() * a.std(ddof=1) Consequently, I've used the bw with kde from sklearn as: kde = KernelDensity(kernel='gaussian', bandwidth=bw).fit(temp.reshape(-1, 1)).
Thus, now I'm able to call: kde.score_samples(x_axis.reshape(-1, 1)).

pyLDAvis arguments for specifying principal components

Need assistance regarding the Principal components to be displayed in pyLDAvis. It shows PC1 and PC2 by default, however I am interested in exploring other components as well.
I referred this documentation but the specified option plot_opts={'xlab': 'PC1', 'ylab': 'PC2'} only changes plot labels.
I am using pyLDAvis through gensim:
pyLDAvis.enable_notebook()
vis = pyLDAvis.gensim.prepare(lda_model, corpus, id2word)
You can not change the dimensions in this library. However, you could do a multidimensional scaling on your own. In this package, they use "Dimension reduction via Jensen-Shannon Divergence & Principal Coordinate Analysis (aka Classical Multidimensional Scaling)".
Just replicate this method and set dimensions to more the amount you want.
You can do it with scikit-learn: https://scikit-learn.org/stable/auto_examples/manifold/plot_mds.html

Medical image processing using DICOM images

Im new to medical image processing. how can i convert 3D DICOM medical images to numerical matrix format using either python or c++?
Another option, if you really want "3D" dicom image support (ie CT/MR/NM/PET 3d series - as opposed to purely 2D image handling) and you want do anything really 3d related and/or more complex, you might want to check out simple ITK.
That gives you very powerful true 3d handling and is fast (it's wrapped around complied C). It includes, for example, full 3D image registration and various filters/tools etc.
It can read an entire series at once and automatically create a fully spatially aware 3D numpy array for you (ie it takes care of processing all the dicom 3D spatial orientation/spacing etc tags for you)
However, because it's a lot more powerful than pydicom, it also has a much steeper learning curve - but does have many examples and online jupyter notebook tutorials.
...so, depending on your needs it might be good for you. However, if you only really want basic 2d image-at-a-time type processing, pydicom is the way to go.
You can use pydicom package in python. You can install it in python by:
pip install pydicom
Here is a simple example of reading DICOM images and converting to numpy array:
import os
import pydicom
import numpy as np
dicom_dir = your_dicom_folder_of_slices
file_names = os.listdir(dicom_dir)
file_names.sort()
dicom_data = []
for name in file_names:
path = os.path.join(dicom_dir, name)
dicom_data.append(pydicom.read_file(path))
array = [data.pixel_array for data in dicom_data]
array = np.stack(array, axis=-1) # or 0 if 'channel_first'
Here is a detailed example.
I prefer using SimpleElastix for medical image processing. it has many methods for segmentations and many other helpful methods. it is available in both python and C++. In my experience SimpleElastix handled DICOMS and niftis better than other Packages.

Point Cloud triangulation using marching-cubes in Python 3

I'm working on a 3D reconstruction system and want to generate a triangular mesh from the registered point cloud data using Python 3. My objects are not convex, so the marching cubes algorithm seems to be the solution.
I prefer to use an existing implementation of such method, so I tried scikit-image and Open3d but both the APIs do not accept raw point clouds as input (note that I'm not expert of those libraries). My attempts to convert my data failed and I'm running out of ideas since the documentation does not clarify the input format of the functions.
These are my desired snippets where pcd_to_volume is what I need.
scikit-image
import numpy as np
from skimage.measure import marching_cubes_lewiner
N = 10000
pcd = np.random.rand(N,3)
def pcd_to_volume(pcd, voxel_size):
#TODO
volume = pcd_to_volume(pcd, voxel_size=0.05)
verts, faces, normals, values = marching_cubes_lewiner(volume, 0)
open3d
import numpy as np
import open3d
N = 10000
pcd = np.random.rand(N,3)
def pcd_to_volume(pcd, voxel_size):
#TODO
volume = pcd_to_volume(pcd, voxel_size=0.05)
mesh = volume.extract_triangle_mesh()
I'm not able to find a way to properly write the pcd_to_volume function. I do not prefer a library over the other, so both the solutions are fine to me.
Do you have any suggestions to properly convert my data? A point cloud is a Nx3 matrix where dtype=float.
Do you know another implementation [of the marching cube algorithm] that works on raw point cloud data? I would prefer libraries like scikit and open3d, but I will also take into account github projects.
Do you know another implementation [of the marching cube algorithm] that works on raw point cloud data?
Hoppe's paper Surface reconstruction from unorganized points might contain the information you needed and it's open sourced.
And latest Open3D seems to be containing surface reconstruction algorithms like alphaShape, ballPivoting and PoissonReconstruction.
From what I know, marching cubes is usually used for extracting a polygonal mesh of an isosurface from a three-dimensional discrete scalar field (that's what you mean by volume). The algorithm does not work on raw point cloud data.
Hoppe's algorithm works by first generating a signed distance function field (a SDF volume), and then passing it to marching cubes. This can be seen as an implementation to you pcd_to_volume and it's not the only way!
If the raw point cloud is all you have, then the situation is a little bit constrained. As you might see, the Poisson reconstruction and Screened Poisson reconstruction algorithm both implement pcd_to_volume in their own way (they are highly related). However, they needs additional point normal information, and the normals have to be consistently oriented. (For consistent orientation you can read this question).
While some Delaunay based algorithm (they do not use marching cubes) like alphaShape and this may not need point normals as input, for surfaces with complex topology, it's hard to get a satisfactory result due to orientation problem. And the graph cuts method can use visibility information to solve that.
Having said that, if your data comes from depth images, you will usually have visibility information. And you can use TSDF to build a good surface mesh. Open3D have already implemented that.

Resources