fargopy 0.2.0__py3-none-any.whl → 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fargopy/sys.py CHANGED
@@ -27,6 +27,7 @@ class Sys(object):
27
27
  QERROR = True
28
28
  STDERR = ''
29
29
  STDOUT = ''
30
+ OUT = ''
30
31
 
31
32
  @staticmethod
32
33
  def run(cmd,quiet=True):
@@ -35,8 +36,8 @@ class Sys(object):
35
36
  Parameters:
36
37
  cmd: string:
37
38
  Command to run
38
- verbose: boolean, default = True:
39
- When True the output of the command is shown.
39
+ quiet: boolean, default = True:
40
+ When False the output of the command is shown.
40
41
 
41
42
  Output:
42
43
  error: integer:
@@ -82,6 +83,7 @@ class Sys(object):
82
83
  elif Sys.QERROR==0:
83
84
  fargopy.Debug.trace(f"sysrun::Done. You're great. Check Sys.STDOUT for details.")
84
85
 
86
+ Sys.OUT = out
85
87
  return Sys.QERROR,out
86
88
 
87
89
  @staticmethod
@@ -99,23 +101,44 @@ class Sys(object):
99
101
  def simple(cmd):
100
102
  return os.system(cmd)
101
103
 
102
- @staticmethod
103
- def compile_fargo3d(self,clean=True):
104
- if Conf._check_fargo(Conf.FARGO3D_FULLDIR):
105
- if clean:
106
- Sys.sysrun(f'make -C {Conf.FARGO3D_FULLDIR} clean mrproper')
107
-
108
- error,out = Sys.sysrun(f'make -C {Conf.FARGO3D_FULLDIR} PARALLEL={self.parallel} GPU={self.gpu}',verbose=False)
109
- if error:
110
- if not Conf._check_fargo_binary(Conf.FARGO3D_FULLDIR,quiet=True):
111
- print("An error compiling the code arose. Check dependencies.")
112
- print(Sys.STDERR)
113
- return False
114
-
115
- return True
116
-
117
104
  @staticmethod
118
105
  def get_memory():
119
106
  svmem = psutil.virtual_memory()
120
107
  return svmem
121
-
108
+
109
+ @staticmethod
110
+ def lock(pid):
111
+ """Create a lock file
112
+ """
113
+ if Sys.check_lock(verbose=False):
114
+ print(f"You cannot lock FARGO3D because it is already locked")
115
+ return
116
+ lock_file = open(fargopy.FP_FARGO3D_LOCKFILE,"w")
117
+ lock_file.write(pid)
118
+ lock_file.close()
119
+
120
+ @staticmethod
121
+ def unlock():
122
+ """Unlock a fargopy instance
123
+ """
124
+ if Sys.check_lock(verbose=False):
125
+ print(f"Unlocking FARGO3D")
126
+ # Kill process
127
+ error,output = Sys.run(f"kill -9 {pid}")
128
+ if error:
129
+ print(f"The locking process {pid} does not exist.")
130
+ else:
131
+ print(f"The locking process {pid} has been killed.")
132
+ # Remove locking file
133
+ print(f"Removing locking file")
134
+ error,output = Sys.run(f"rm -rf {fargopy.FP_FARGO3D_LOCKFIL}")
135
+
136
+ @staticmethod
137
+ def check_lock(verbose=True):
138
+ """Check if fargopy is locked by a running process
139
+ """
140
+ if os.path.isfile(fargopy.FP_FARGO3D_LOCKFILE):
141
+ if verbose:
142
+ print(f"There is a lockfile in {fargopy.FP_FARGO3D_LOCKFILE}")
143
+ return True
144
+ return False
fargopy/util.py CHANGED
@@ -8,6 +8,10 @@ import fargopy
8
8
  ###############################################################
9
9
  import matplotlib.pyplot as plt
10
10
 
11
+ ###############################################################
12
+ # Constants
13
+ ###############################################################
14
+
11
15
  ###############################################################
12
16
  # Classes
13
17
  ###############################################################
fargopy/version.py CHANGED
@@ -1 +1 @@
1
- version='0.2.0'
1
+ version='0.3.0'
@@ -0,0 +1,243 @@
1
+ Metadata-Version: 2.1
2
+ Name: fargopy
3
+ Version: 0.3.0
4
+ Summary: FARGO3D Wrapping
5
+ Home-page: https://pypi.org/project/fargopy
6
+ Author: Jorge Zuluaga, Matias Montesinos
7
+ Author-email: jorge.zuluaga@gmail.com
8
+ License: MIT
9
+ Keywords: astronomy MHD CFD
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: scipy
16
+ Requires-Dist: matplotlib
17
+ Requires-Dist: tqdm
18
+ Requires-Dist: numpy
19
+ Requires-Dist: ipython
20
+ Requires-Dist: celluloid
21
+ Requires-Dist: psutil
22
+ Requires-Dist: gdown
23
+
24
+ # FARGOpy
25
+ ## Wrapping FRAGO3D
26
+
27
+ <!-- This are visual tags that you may add to your package at the beginning with useful information on your package -->
28
+ [![version](https://img.shields.io/pypi/v/fargopy?color=blue)](https://pypi.org/project/fargopy/)
29
+ [![downloads](https://img.shields.io/pypi/dw/fargopy)](https://pypi.org/project/fargopy/)
30
+
31
+ `FARGOpy` is a python wrapping for [`FARGO3D`](https://fargo3d.bitbucket.io/intro.html)., the well-knwon hydrodynamics and magnetohydrodynamics parallel code. This wrapping is intended to ensue the interaction with FARGO3D especially for those starting using the code, for instance for teaching and training purposes, but also provide functionalities for most advanced users in tasks related to the postprocessing of output files and plotting.
32
+
33
+ This is an example of what can be done using `FARGOpy`:
34
+
35
+ <p align="center"><img src="https://github.com/seap-udea/fargopy/blob/main/gallery/fargo-animation.gif?raw=true" alt="Animation""/></p>
36
+
37
+ ## Install `FARGOpy`
38
+
39
+ To install the package run:
40
+
41
+ ```bash
42
+ $ pip3 install fargopy
43
+ ```
44
+
45
+ Since `FARGOpy` is a python wrap for `FARGO3D` the ideal environment to work with the package is `IPython` or other similar environments such as `jupyter-lab`, `Google Colab`, etc.
46
+
47
+ If you are working on a Linux server it is better to run the package for the first time using the `IPython` initialization command:
48
+
49
+ ```bash
50
+ $ ifargopy
51
+ ```
52
+
53
+ The first time you run this command, it will create the configuration directory `$HOME/.fargopy`. This directory contains a set of basic configuration variables `$HOME/.fargopy/fargopyrc`, that can be customized, and the `IPython` initialization script `$HOME/.fargopy/ifargopy.py`.
54
+
55
+ If you are working in `Jupyter` or in `Google Colab`, the configuration directory and its content will be crated the first time you import the package:
56
+
57
+
58
+ ```python
59
+ import fargopy as fp
60
+ %load_ext autoreload
61
+ %autoreload 2
62
+ ```
63
+
64
+ Running FARGOpy version 0.2.1
65
+
66
+
67
+ ## Download and install FARGO3D
68
+
69
+ `FARGOpy` can be used either to *control* `FARGO3D`, ie. download, compile and run it, and/or read and manipulate the output of simulations. In either case it would be convenient to obtain a copy of the package and all its prerequisites. For a detailed guide please see the [FARGO documentation](https://fargo3d.bitbucket.io/index.html) or the [project repo at bitbucket](https://bitbucket.org/fargo3d/public/src/ae0fcdc67bb7c83aed85fc9a4d4a2d5061324597/?at=release%2Fpublic).
70
+
71
+ > **NOTE**: It is important to understand that `FARGO3D` works especially well on Linux plaforms (including `MacOS`). The same condition applies for `FARGOpy`. Because of that, most internal as well as public features of the packages are designed to work in a `Linux` environment. For working in another operating systems, for instance for teaching or training purposes, please consider to use virtual machines.
72
+
73
+ `FARGOpy` provides a simple way to get the latest version of `FARGO3D`. In the terminal run:
74
+
75
+ ```shell
76
+ $ ifargopy download
77
+ ```
78
+
79
+ A copy of `FARGO3D` will be download in the HOME directory `~/fargo3d/`.
80
+
81
+ If you are working in a `Jupyter` environment you may run:
82
+
83
+
84
+ ```python
85
+ fp.initialize('download')
86
+ ```
87
+
88
+ Downloading FARGOpy...
89
+ FARGO3D directory already present in '/home/jzuluaga/fargo3d/'
90
+ Header file for FARGO3D is in the fargo directory /home/jzuluaga/fargo3d/
91
+
92
+
93
+ > **NOTE**: As you may see the default directory where FARGO3D is download is `~/` and the name of the directory is `fargo3d`. You may change this by setting the configuration variables `FP_FARGO3D_BASEDIR` or `FP_FARGO3D_PACKDIR` brefore downloading the package.
94
+
95
+ ## Quickstart
96
+
97
+ Here we will illustrate the minimal commands you may run to test the package. A more detailed set of examples can be found in [this file](TUTORIAL.md).
98
+
99
+ For this example we will assume that you already have a set of FARGO3D simulation results. You may download a precomputed set of results prepared by the developers of `FARGOpy` using the command:
100
+
101
+
102
+ ```python
103
+ fp.Simulation.download_precomputed(setup='fargo')
104
+ ```
105
+
106
+ Precomputed output directory '/tmp/fargo' already exist
107
+
108
+
109
+
110
+
111
+
112
+ '/tmp/fargo'
113
+
114
+
115
+
116
+ Create a simulation object:
117
+
118
+
119
+ ```python
120
+ sim = fp.Simulation()
121
+ ```
122
+
123
+ Your simulation is now connected with '/home/jzuluaga/fargo3d/'
124
+
125
+
126
+ Set the output directory (in this case, the directory where the precomputed simulation has been stored):
127
+
128
+
129
+ ```python
130
+ sim.set_output_dir('/tmp/fargo')
131
+ ```
132
+
133
+ Now you are connected with output directory '/tmp/fargo'
134
+
135
+
136
+ Load the properties of the simulation:
137
+
138
+
139
+ ```python
140
+ sim.load_properties()
141
+ ```
142
+
143
+ Loading variables
144
+ 84 variables loaded
145
+ Simulation in 2 dimensions
146
+ Loading domain in cylindrical coordinates:
147
+ Variable phi: 384 [[0, -3.1334114227210694], [-1, 3.1334114227210694]]
148
+ Variable r: 128 [[0, 0.408203125], [-1, 2.491796875]]
149
+ Variable z: 1 [[0, 0.0], [-1, 0.0]]
150
+ Number of snapshots in output directory: 51
151
+ Configuration variables and domains load into the object. See e.g. <sim>.vars
152
+
153
+
154
+ Load gas density from a given snapshot:
155
+
156
+
157
+ ```python
158
+ gasdens = sim.load_field('gasdens',snapshot=20)
159
+ ```
160
+
161
+ Create a `meshslice` of the field:
162
+
163
+
164
+ ```python
165
+ gasdens_r, mesh = gasdens.meshslice(slice='z=0,phi=0')
166
+ ```
167
+
168
+ And plot the slice:
169
+
170
+
171
+ ```python
172
+ import matplotlib.pyplot as plt
173
+ plt.ioff() # Drop this out of this tutorial
174
+ fig,ax = plt.subplots()
175
+ ax.semilogy(mesh.r,gasdens_r)
176
+ ax.set_xlabel(r"$r$ [cu]")
177
+ ax.set_ylabel(r"$\rho$ [cu]")
178
+ fp.Util.fargopy_mark(ax)
179
+ fig.savefig('gallery/example-dens_r.png') # Drop this out of this tutorial
180
+ ```
181
+
182
+ <p align="center"><img src="https://github.com/seap-udea/fargopy/blob/main/gallery/example-dens_r.png?raw=true" alt="Animation""/></p>
183
+
184
+ You may also create a 2-dimensional slice:
185
+
186
+
187
+ ```python
188
+ gasdens_plane, mesh = gasdens.meshslice(slice='z=0')
189
+ ```
190
+
191
+ And plot it:
192
+
193
+
194
+ ```python
195
+ plt.ioff() # Drop this out of this tutorial
196
+ fig,axs = plt.subplots(1,2,figsize=(12,6))
197
+
198
+ ax = axs[0]
199
+ ax.pcolormesh(mesh.phi,mesh.r,gasdens_plane,cmap='prism')
200
+ ax.set_xlabel('$\phi$ [rad]')
201
+ ax.set_ylabel('$r$ [UL]')
202
+ fp.Util.fargopy_mark(ax)
203
+
204
+ ax = axs[1]
205
+ ax.pcolormesh(mesh.x,mesh.y,gasdens_plane,cmap='prism')
206
+ ax.set_xlabel('$x$ [UL]')
207
+ ax.set_ylabel('$y$ [UL]')
208
+ fp.Util.fargopy_mark(ax)
209
+ ax.axis('equal')
210
+ fig.savefig('gallery/example-dens_disk.png') # Drop this out of this tutorial
211
+ ```
212
+
213
+ <p align="center"><img src="https://github.com/seap-udea/fargopy/blob/main/gallery/example-dens_disk.png?raw=true" alt="Animation""/></p>
214
+
215
+ ## What's new
216
+
217
+
218
+ Version 0.3.*:
219
+
220
+ - Refactoring of initializing routines.
221
+ - Improvements in documentation of basic classes in `__init__.py`.
222
+
223
+ Version 0.2.*:
224
+
225
+ - First real applications tested with FARGOpy.
226
+ - All basic routines for reading output created.
227
+ - Major refactoring.
228
+
229
+ Version 0.1.*:
230
+
231
+ - Package is now provided with a script 'ifargopy' to run 'ipython' with fargopy initialized.
232
+ - A new 'progress' mode has been added to status method.
233
+ - All the dynamics of loading/compiling/running/stoppìng/resuming FARGO3D has been developed.
234
+
235
+ Version 0.0.*:
236
+
237
+ - First classes created.
238
+ - The project is started!
239
+
240
+ ------------
241
+
242
+ This package has been designed and written mostly by Jorge I. Zuluaga with advising and contributions by Matías Montesinos (C) 2023
243
+
@@ -0,0 +1,13 @@
1
+ fargopy/__init__.py,sha256=q_tpw5_Mi4zmowrMUxQFrhHlTPVCUsmU3RX88-pRBE8,9326
2
+ fargopy/fields.py,sha256=-f0Q-3J1dq2oZYpmiaAuT-B48qECCLhvmjiIUSjyXhg,8700
3
+ fargopy/simulation.py,sha256=NPZes8MZ8xtbmfZqrhuGAGhYvEs2vUdJSpRFNB1hfjo,32901
4
+ fargopy/sys.py,sha256=-RnUZJ5GnYHwIlI7UtjPlnyS88ptnrSBa9FvnF_2gDM,4311
5
+ fargopy/util.py,sha256=y39aTcvK1lM3vbuK11lE2bfj-eCcOzc0lKMvyBRW2-M,1584
6
+ fargopy/version.py,sha256=14vICHbg-AX_96xiJkVH7VdMy15awdqU6glK1dWQttc,16
7
+ fargopy-0.3.0.data/scripts/ifargopy,sha256=t5E07jKzOLtNnlNyElQZbzjCW6wnR0bc8uCaZpw9yS8,382
8
+ fargopy-0.3.0.dist-info/LICENSE,sha256=aIckKnNVrkXQMqEKlzGn_REfTwc82TF35BHMCRwPXCI,1097
9
+ fargopy-0.3.0.dist-info/METADATA,sha256=nUDcNFKH-P0X7UM_cn0JuEaPIpFANqb1wPp_ahdkfeg,7823
10
+ fargopy-0.3.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
11
+ fargopy-0.3.0.dist-info/entry_points.txt,sha256=555NPKYbLCN0fgJbdW4b4azZ5sqjhqVqTUxujBBYEJY,49
12
+ fargopy-0.3.0.dist-info/top_level.txt,sha256=_r66v1_-9T7dB5sQa12AdxaAdsv9-OTwtR-vft4OPBU,8
13
+ fargopy-0.3.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.41.3)
2
+ Generator: bdist_wheel (0.42.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5