From 27fdb9844d83d88659372142278f12f1bfe18592 Mon Sep 17 00:00:00 2001 From: Alain Klotz Date: Sat, 16 Sep 2023 20:01:53 +0200 Subject: [PATCH] Debug WCS. --- src/guitastro/astrotables.py | 26 +++++++++++++++++++++++++- src/guitastro/dates.py | 2 ++ src/guitastro/ima.py | 46 +++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/guitastro/astrotables.py b/src/guitastro/astrotables.py index 1af4422..9ea0247 100644 --- a/src/guitastro/astrotables.py +++ b/src/guitastro/astrotables.py @@ -149,7 +149,7 @@ class AstroTable(AstroTableException, GuitastroTools): * **rencol**: Rename a given column named. To manage rows: - * **gelrow**: Returns a row of a given line index. + * **getrow**: Returns a row of a given line index. * **setrow**: Insert a new row at before a given line index. * **delrow**: Delete a row of a given line index. * **delrows**: Delete rows. @@ -159,6 +159,7 @@ class AstroTable(AstroTableException, GuitastroTools): * **getcell**: Returns the value of column name at a given row index. * **setcell**: Modify the value of column name at a given row index. + * **getcells**: Returns a list of a list of all the table cell contents. To manage metadata: @@ -771,6 +772,26 @@ class AstroTable(AstroTableException, GuitastroTools): msg = f"Input row index {index} must be from 0 to {nrow-1}" raise AstroTableException(AstroTableException.BAD_IDXLIG, msg) + def getcells(self): + """Returns a list of a list of all the table cell contents. + + Example: + + :: + + at = AstroTable() + at.table(None) + at.getcells() + + """ + nrow, ncol = self.shape() + cols = [] + colnames = self.getcols() + for colname in colnames: + col = self.getcol(colname) + cols.append(col) + return cols + # ============================================= # Manage table rows # ============================================= @@ -1856,6 +1877,9 @@ class AstroTable(AstroTableException, GuitastroTools): if output_type=="IDRADECVAR" or output_type=="VAR": columns = ['Name', 'RAJ2000', 'DEJ2000', 'max', 'min', 'Type', 'Epoch', 'Period'] # '_tab1_15' colnames = ['id', 'ra', 'dec', 'magVmax', 'magVmin', 'VarType', 'EpochMax', 'Period'] + elif cat_name == "ASTROTABLE": + # use at.read() before to have a table in memory + return else: msg = f"Catalog name {cat_name} must be amongst: " msg += "GAIA, PS1, SDSS, UCAC, USNOA2, USNOB1, TYCHO, NOMAD, HIPARCOS, 2MASS, GCVS, VSX" diff --git a/src/guitastro/dates.py b/src/guitastro/dates.py index 9aa0fb8..06a7b73 100644 --- a/src/guitastro/dates.py +++ b/src/guitastro/dates.py @@ -272,6 +272,8 @@ class Date(GuitastroTools): str_date = str(date).upper() str_split = str_date.split(" ") str_nsplit = len(str_split) + if str_date == "": + str_date = "NOW" if str_date == "NOW": # style NOW utc_datetime = datetime.datetime.utcnow() diff --git a/src/guitastro/ima.py b/src/guitastro/ima.py index 9ea797c..fea9398 100644 --- a/src/guitastro/ima.py +++ b/src/guitastro/ima.py @@ -125,8 +125,9 @@ class ImaException(GuitastroException): KEY_NOT_FOUND = 10 NOT_ENOUGH_ARGS = 11 FILE_DOES_NOT_EXIST = 12 + ARG_MUST_BE_ASTROTABLE_TYPE= 13 - errors = [""]*13 + errors = [""]*14 errors[BUFFER_EMPTY] = "Ima is empty" errors[SHAPES_NOT_SAME] = "Shapes of images are not the same" errors[WCS_KEYS_NOT_FOUND] = "WCS keys not found or not valid in the FITS header" @@ -140,7 +141,7 @@ class ImaException(GuitastroException): errors[KEY_NOT_FOUND] = "key not found in the FITS header" errors[NOT_ENOUGH_ARGS] = "Not enough arguments" errors[FILE_DOES_NOT_EXIST] = "The file does not exist" - + errors[ARG_MUST_BE_ASTROTABLE_TYPE] = "The argument must be of Astrotable type" class Ima(ImaException, FileNames): """ Class to analyze or process an image for astronomy @@ -2812,13 +2813,33 @@ class Ima(ImaException, FileNames): self._verify_buffer() self._array = np.multiply(self._array, cste) + def ngain(self, meanvalue:float): + """Normalize the current mean value of the pixels to meanvalue. + + Args: + meanvalue: Normalization value. + + Example, normalize to 200 : + + :: + + ima = Ima() + ima.load("m57") + ima.ngain(200) + + """ + self._verify_buffer() + mean = np.mean(self._array) + mult = meanvalue / mean + self._array = np.multiply(self._array, mult) + def offset(self, cste:float): """Add a constant value to all the pixels of the image. Args: cste: Constant value to add to all pixels. - Example, add a valuie of 1023 to all the pixels: + Example, add a value of 1023 to all the pixels: :: @@ -3082,8 +3103,23 @@ class Ima(ImaException, FileNames): kwarg_catas[key] = val fov1 = self.etc._etc["comp1"]["FoV1"][0] fov2 = self.etc._etc["comp1"]["FoV2"][0] - print(f"kwarg_catas={kwarg_catas}") - at.catalog(ra, dec, fov1, fov2, *args, **kwarg_catas) + #print(f"kwarg_catas={kwarg_catas}") + if args[0].upper() == "ASTROTABLE": + att = args[1] + if str(type(att)) == "": + cols = att.getcells() + names = att.getcols() + kwds = att.getkwds() + meta = {} + for kwd in kwds: + val = att.getkwd(kwd) + meta[kwd] = val + at.table(cols, names=names, meta=meta) + else: + texte = f"Args[1] {str(type(att))}" + raise ImaException(ImaException.ARG_MUST_BE_ASTROTABLE_TYPE,texte) + else: + at.catalog(ra, dec, fov1, fov2, *args, **kwarg_catas) at.radec2xy() cols = at.getcols() for col in cols: -- libgit2 0.21.2