isgri 0.6.0__py3-none-any.whl → 0.6.1__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.
isgri/__version__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.6.0"
1
+ __version__ = "0.6.1"
isgri/catalog/scwquery.py CHANGED
@@ -345,24 +345,29 @@ class ScwQuery:
345
345
  return self.catalog[combined_mask]
346
346
 
347
347
  def write(
348
- self, output_path: Union[str, Path], swid_only: Optional[str] = False, overwrite: Optional[bool] = False
349
- ):
348
+ self,
349
+ output_path: Union[str, Path],
350
+ swid_only: Optional[bool] = False,
351
+ overwrite: Optional[bool] = False,
352
+ columns: Optional[list[str]] = None,
353
+ ) -> None:
350
354
  """Write filtered catalog to the file.
351
355
 
352
356
  Parameters
353
357
  ----------
354
358
  output_path : str or Path
355
- Path to output file. Format auto-detected from extension:
356
- - .txt: SWID list (one per line)
357
- - .fits: FITS table
358
- - .csv: CSV table
359
+ Path to output file. Supports auto-detectable formats of astropy Table (e.g. fits, csv, qdp) and if failed, plain text in aligned columns.
359
360
  swid_only : bool, optional
360
- If True, write only SWID list regardless of extension
361
+ If True, write only SWID list regardless of columns
361
362
  overwrite : bool, optional
362
363
  Whether to overwrite existing file, by default False
364
+ columns : list of str, optional
365
+ List of columns to write. If None, writes all columns or only SWID if swid_only=True
363
366
 
364
367
  Raises
365
368
  ------
369
+ TypeError
370
+ If output_path is not str or Path
366
371
  FileExistsError
367
372
  If file exists and overwrite=False
368
373
 
@@ -373,18 +378,39 @@ class ScwQuery:
373
378
  >>> query.write("scws.csv")
374
379
  >>> query.write("output", swid_only=True) # Force SWID list regardless of extension
375
380
  """
381
+ if columns is None:
382
+ columns = self.catalog.colnames if not swid_only else ["SWID"]
376
383
 
377
- results = self.get()
378
- if isinstance(output_path, str):
384
+ results = self.get()[columns]
385
+ try:
379
386
  output_path = Path(output_path)
387
+ except TypeError:
388
+ raise TypeError(f"output_path must be str or Path, got {type(output_path)}")
389
+
380
390
  if output_path.exists() and not overwrite:
381
391
  raise FileExistsError(f"Output file already exists: {output_path}")
382
- if swid_only or output_path.suffix == ".txt":
383
- with open(output_path, "w") as f:
384
- for swid in results["SWID"]:
385
- f.write(f"{swid}\n")
386
- else:
392
+
393
+ try:
387
394
  results.write(output_path, overwrite=overwrite)
395
+ return
396
+ except Exception:
397
+ pass
398
+
399
+ # Manual write as aligned columns (plain text)
400
+ colnames = results.colnames
401
+ rows = [[str(val) for val in row] for row in results]
402
+ columns = list(zip(*([colnames] + rows))) # Include headers
403
+ widths = [max(len(item) for item in col) for col in columns]
404
+
405
+ def format_row(file, row: list[str], header: bool = False) -> None:
406
+ if len(row) == 1 and header:
407
+ return
408
+ file.write(" ".join(f"{item:<{widths[i]}}" for i, item in enumerate(row)) + "\n")
409
+
410
+ with open(output_path, "w") as f:
411
+ format_row(f, colnames, header=True)
412
+ for row in rows:
413
+ format_row(f, row)
388
414
 
389
415
  def count(self) -> int:
390
416
  """
isgri/cli/query.py CHANGED
@@ -78,23 +78,15 @@ def query_direct(
78
78
  if revolution:
79
79
  q = q.revolution(revolution)
80
80
 
81
- results = q.get()
82
-
83
81
  if count:
84
- click.echo(len(results))
85
-
86
- elif list_swids:
87
- for swid in results["SWID"]:
88
- click.echo(swid)
89
-
82
+ click.echo(q.count())
83
+
90
84
  elif output:
91
- if output.endswith(".csv"):
92
- results.write(output, format="ascii.csv", overwrite=True)
93
- else:
94
- results.write(output, format="fits", overwrite=True)
95
- click.echo(f"Saved {len(results)} SCWs to {output}")
85
+ q.write(output, overwrite=True, swid_only=list_swids)
86
+ click.echo(f"Saved {q.count()} SCWs to {output}")
96
87
 
97
88
  else:
89
+ results = q.get()
98
90
  click.echo(f"Found {len(results)}/{initial_count} SCWs")
99
91
  if len(results) > 0:
100
92
  display_cols = ["SWID", "TSTART", "TSTOP", "RA_SCX", "DEC_SCX"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: isgri
3
- Version: 0.6.0
3
+ Version: 0.6.1
4
4
  Summary: Python package for INTEGRAL IBIS/ISGRI lightcurve analysis
5
5
  Author: Dominik Patryk Pacholski
6
6
  License: MIT
@@ -30,7 +30,7 @@ Query catalogs directly from the terminal:
30
30
  Query INTEGRAL Science Window catalogs with a fluent Python API:
31
31
  - Filter by time, position, quality, revolution
32
32
  - Calculate detector offsets
33
- - Export results to FITS/CSV
33
+ - Export results to any auto detectable astropy table extension or in table aligned data for any other extension.
34
34
 
35
35
  ### Light Curve Analysis
36
36
  Extract and analyze ISGRI light curves:
@@ -87,6 +87,9 @@ results = (cat
87
87
  .get()
88
88
  )
89
89
 
90
+ # Save selected columns to the file
91
+ cat.write('example_file.any_extension',columns=['SWID','TSTART','TSTOP'])
92
+
90
93
  print(f"Found {len(results)} observations")
91
94
  ```
92
95
 
@@ -1,21 +1,21 @@
1
1
  isgri/__init__.py,sha256=V2hnOxXKcjMiusdGP8sOAR4QsBlWHQ0pZZMN2Cean6o,38
2
- isgri/__version__.py,sha256=DS49q_bFynltwBtgneHYeVXTHLg5bjAOFWvTkv-jYmY,21
2
+ isgri/__version__.py,sha256=XvHFZM0padtrqitt9-p2enlBUGqc6vGvWNLx2iJv09g,21
3
3
  isgri/config.py,sha256=i1ibczZsmgqELv4ik2h2nWLnHyl68_5KGsz5Ec8Uf4E,4365
4
4
  isgri/catalog/__init__.py,sha256=CT9Zd1WISpv7kowf3bqagKewZ8SjLr1rZzVSFkwEj3o,58
5
5
  isgri/catalog/builder.py,sha256=Ure_erpyApjSiAmIvhJahuf6c11VNXBn5R6-nQzsDw4,3488
6
- isgri/catalog/scwquery.py,sha256=HobS4Im1GF28ZFYWrdXjUbCGJahBE3aS23bkGkYPjGc,19233
6
+ isgri/catalog/scwquery.py,sha256=3X9Es79UNGedhsS7EvArNGo8KMAMuUU9hMQIsrfRuBs,20259
7
7
  isgri/catalog/wcs.py,sha256=mD6bZxiBxKYpuYCl8f2tSCc8uuWFzMRL2jf5SuFAhfg,5562
8
8
  isgri/cli/__init__.py,sha256=-bBNFYOq80A2Egtpo5V5zWJtYOxQfRZFQ_feve5lkFU,23
9
9
  isgri/cli/main.py,sha256=pOwTbJ7nuOC48cdVm-e84GGjlOFic1ZMEvU2e3yKP4k,5613
10
- isgri/cli/query.py,sha256=s_9p09nct4KnU3RVWW1BytLIY4cuY0SlGIobaCf_VMs,5772
10
+ isgri/cli/query.py,sha256=dUzLsEjjyzCQ1lbG3pVe0pvIWcDcNs-6T57ugUFUTdk,5542
11
11
  isgri/utils/__init__.py,sha256=H83Al7urc6LNW5KUzUBRdtRBUTahiZmkehKFiK90RrU,183
12
12
  isgri/utils/file_loaders.py,sha256=g-LUfYw35hPePlFeicymaL-NbZXzZWfNmM127XJjCKY,12497
13
13
  isgri/utils/lightcurve.py,sha256=Pjys-eIyKShDKHqFpGa9SZ0Dzz7LiLIwBpUkp_6s41g,14133
14
14
  isgri/utils/pif.py,sha256=LixlkShy1j_ymfdJLyCV8zl0EeHgfVDVjddSex18GLQ,8648
15
15
  isgri/utils/quality.py,sha256=Na-sNEX1E4xWQJx0FYe9vbOAgPrTcLohHeUAnmlKYSw,13348
16
16
  isgri/utils/time_conversion.py,sha256=MNPVjrsrmwRDbCWmqdWN0xRs8PtHkFGli-H2cYwF9Ns,5204
17
- isgri-0.6.0.dist-info/METADATA,sha256=OqyGmCzgW4fH3E__TwlEa-txR5wHlwtBWxme0miwwRc,3417
18
- isgri-0.6.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
19
- isgri-0.6.0.dist-info/entry_points.txt,sha256=aM2K4RGihbwsj9crjPG-BvWhErcdtZt3tJqT6AaOojU,46
20
- isgri-0.6.0.dist-info/licenses/LICENSE,sha256=Q8oxmHR1cSnEXSHCjY3qeXMtupZI_1ZQZ1MBt4oeANE,1102
21
- isgri-0.6.0.dist-info/RECORD,,
17
+ isgri-0.6.1.dist-info/METADATA,sha256=89GNYk4YvwD6xxSHjFyZJbF9ZquuuSFND7jWj-DKu_k,3613
18
+ isgri-0.6.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
19
+ isgri-0.6.1.dist-info/entry_points.txt,sha256=aM2K4RGihbwsj9crjPG-BvWhErcdtZt3tJqT6AaOojU,46
20
+ isgri-0.6.1.dist-info/licenses/LICENSE,sha256=Q8oxmHR1cSnEXSHCjY3qeXMtupZI_1ZQZ1MBt4oeANE,1102
21
+ isgri-0.6.1.dist-info/RECORD,,
File without changes