LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
LSSTDataManagementBasePackage
Functions
astshim.fitsChanContinued Namespace Reference

Functions

def length (self)
 
def iter (self)
 
def next (self)
 
def to_string (self)
 
def contains (self, name)
 
def getitem (self, name)
 
def setitem (self, name, value)
 
def delitem (self, name)
 
def items (self)
 

Function Documentation

◆ contains()

def astshim.fitsChanContinued.contains (   self,
  name 
)
Returns True if either the supplied name is present in the FitsChan
or the supplied integer is acceptable to the FitsChan.

Definition at line 126 of file fitsChanContinued.py.

126 def contains(self, name):
127  """Returns True if either the supplied name is present in the FitsChan
128  or the supplied integer is acceptable to the FitsChan.
129  """
130  if isinstance(name, int):
131  # index will be zero-based
132  if name >= 0 and name < self.nCard:
133  return True
134  elif isinstance(name, str):
135  currentCard = self.getCard()
136  try:
137  self.clearCard()
138  result = self.findFits(name, False)
139  finally:
140  self.setCard(currentCard)
141  if result.found:
142  return True
143 
144  return False
145 
146 
147 FitsChan.__contains__ = contains
148 
149 

◆ delitem()

def astshim.fitsChanContinued.delitem (   self,
  name 
)
Delete an item from the FitsChan either by index (0-based) or by name.

Parameters
----------
name : `str` or `int`
    If the name is an integer index the card at that position will be
    removed.  The index is zero-based.  A negative index counts from the
    end of the FitsChan.
    If the name is a string all cards matching that name will be removed.

Raises
------
IndexError
    Raised if the supplied index is out of range.
KeyError
    Raised if the supplied name is not found in the FitsChan.

Definition at line 317 of file fitsChanContinued.py.

317 def delitem(self, name):
318  """Delete an item from the FitsChan either by index (0-based) or by name.
319 
320  Parameters
321  ----------
322  name : `str` or `int`
323  If the name is an integer index the card at that position will be
324  removed. The index is zero-based. A negative index counts from the
325  end of the FitsChan.
326  If the name is a string all cards matching that name will be removed.
327 
328  Raises
329  ------
330  IndexError
331  Raised if the supplied index is out of range.
332  KeyError
333  Raised if the supplied name is not found in the FitsChan.
334  """
335  if isinstance(name, int):
336  # Correct to 1-based
337  newpos = _calc_card_pos(self, name)
338  if newpos <= 0 or newpos > self.nCard:
339  # AST will ignore this but we raise if the index is out of range
340  raise IndexError(f"No FITS card at index {name}")
341  self.setCard(newpos)
342  self.delFits()
343  return
344 
345  if not isinstance(name, str):
346  raise KeyError(f"Supplied key, '{name}' of unsupported type")
347 
348  self.clearCard()
349  # Delete any cards with matching keyword
350  deleted = False
351  while True:
352  found = self.findFits(name, False)
353  if not found.found:
354  break
355  self.delFits()
356  deleted = True
357 
358  if not deleted:
359  raise KeyError(f"No FITS card named {name}")
360 
361 
362 FitsChan.__delitem__ = delitem
363 
364 

◆ getitem()

def astshim.fitsChanContinued.getitem (   self,
  name 
)
Return a value associated with the supplied name.

Parameters
----------
name : `str` or `int`
    If the FitsChan is being accessed by integer index the returned value
    will be the corresponding 80-character card.  Index values are 0-based.
    A negative index counts from the end of the FitsChan.
    If the FitsChan is being accessed by string the returned value will
    be the scalar value associated with the first card that matches the
    supplied name.

Returns
-------
value : `str`, `int`, `float`, `bool`, or `None`
    The complete 80-character header card if an integer index is supplied,
    else the first matching value of the named header.

Raises
------
IndexError
    Raised if an integer index is provided and the index is out of range.
KeyError
    Raised if a string is provided and that string is not present in
    the FitsChan. Also raised if the supplied name is neither an integer
    not a string.
RuntimeError
    Raised if there is some problem accessing the value in the FitsChan.

Definition at line 150 of file fitsChanContinued.py.

150 def getitem(self, name):
151  """Return a value associated with the supplied name.
152 
153  Parameters
154  ----------
155  name : `str` or `int`
156  If the FitsChan is being accessed by integer index the returned value
157  will be the corresponding 80-character card. Index values are 0-based.
158  A negative index counts from the end of the FitsChan.
159  If the FitsChan is being accessed by string the returned value will
160  be the scalar value associated with the first card that matches the
161  supplied name.
162 
163  Returns
164  -------
165  value : `str`, `int`, `float`, `bool`, or `None`
166  The complete 80-character header card if an integer index is supplied,
167  else the first matching value of the named header.
168 
169  Raises
170  ------
171  IndexError
172  Raised if an integer index is provided and the index is out of range.
173  KeyError
174  Raised if a string is provided and that string is not present in
175  the FitsChan. Also raised if the supplied name is neither an integer
176  not a string.
177  RuntimeError
178  Raised if there is some problem accessing the value in the FitsChan.
179  """
180 
181  # Save current card position
182  currentCard = self.getCard()
183 
184  if isinstance(name, int):
185  # Calculate position in FitsChan (0-based to 1-based)
186  newpos = _calc_card_pos(self, name)
187  self.setCard(newpos)
188  try:
189  result = self.findFits("%f", False)
190  finally:
191  self.setCard(currentCard)
192  if not result.found:
193  raise IndexError(f"No FITS card at index {name}")
194  return result.value
195 
196  elif isinstance(name, str):
197 
198  try:
199  # Rewind FitsChan so we search all cards
200  self.clearCard()
201 
202  # We are only interested in the first matching card
203  result = self.findFits(name, False)
204  if not result.found:
205  raise KeyError(f"{name}'")
206 
207  this_name, value = _get_current_card_value(self)
208  if this_name != name:
209  raise RuntimeError(f"Internal inconsistency in get: {this_name} != {name}")
210 
211  finally:
212  # Reinstate the original card position
213  self.setCard(currentCard)
214 
215  return value
216 
217  raise KeyError(f"Supplied key, '{name}' of unsupported type")
218 
219 
220 FitsChan.__getitem__ = getitem
221 
222 

◆ items()

def astshim.fitsChanContinued.items (   self)
Iterate over each card, returning the keyword and value in a tuple.

Returns
-------
key : `str`
    The key associated with the card.  Can be an empty string for some
    comment styles.  The same key name can be returned multiple times
    and be associated with different values.
value : `str`, `int`, `bool`, `float`
    The value.

Notes
-----
The position of the iterator is internal to the FitsChan.  Do not
change the card position when iterating.

Definition at line 365 of file fitsChanContinued.py.

365 def items(self):
366  """Iterate over each card, returning the keyword and value in a tuple.
367 
368  Returns
369  -------
370  key : `str`
371  The key associated with the card. Can be an empty string for some
372  comment styles. The same key name can be returned multiple times
373  and be associated with different values.
374  value : `str`, `int`, `bool`, `float`
375  The value.
376 
377  Notes
378  -----
379  The position of the iterator is internal to the FitsChan. Do not
380  change the card position when iterating.
381  """
382  self.clearCard()
383  nCards = self.nCard
384  thisCard = self.getCard()
385 
386  while thisCard <= nCards:
387  name, value = _get_current_card_value(self)
388  yield name, value
389  self.setCard(thisCard + 1)
390  thisCard = self.getCard()
391 
392 
393 FitsChan.items = items
394 
std::vector< SchemaItem< Flag > > * items

◆ iter()

def astshim.fitsChanContinued.iter (   self)
The FitsChan is its own iterator, incrementing the card position on
each call.

The position of the iterator is handled internally in the FitsChan and
is moved to the start of the FitsChan by this call.
Whilst iterating do not change the internal card position.

The iterator will return 80-character header cards.

Definition at line 87 of file fitsChanContinued.py.

87 def iter(self):
88  """The FitsChan is its own iterator, incrementing the card position on
89  each call.
90 
91  The position of the iterator is handled internally in the FitsChan and
92  is moved to the start of the FitsChan by this call.
93  Whilst iterating do not change the internal card position.
94 
95  The iterator will return 80-character header cards.
96  """
97  self.clearCard()
98  return self
99 
100 
101 FitsChan.__iter__ = iter
102 
103 

◆ length()

def astshim.fitsChanContinued.length (   self)

Definition at line 80 of file fitsChanContinued.py.

80 def length(self):
81  return self.nCard
82 
83 
84 FitsChan.__len__ = length
85 
86 

◆ next()

def astshim.fitsChanContinued.next (   self)
Return each 80-character header card until we run out of cards.

Definition at line 104 of file fitsChanContinued.py.

104 def next(self):
105  """Return each 80-character header card until we run out of cards.
106  """
107  card = self.findFits("%f", True)
108  if not card.found:
109  raise StopIteration
110  return card.value
111 
112 
113 FitsChan.__next__ = next
114 
115 

◆ setitem()

def astshim.fitsChanContinued.setitem (   self,
  name,
  value 
)
Set a new value.

Parameters
----------
name : `str` or `int`
    If the name is an integer index this corresponds to a position within
    the FitsChan.  Index values are 0-based. A negative index counts
    from the end of the FitsChan.  If the index matches the number of
    cards (e.g. the return value of `len()`) the new value will be
    appended to the end of the FitsChan.
    If the name is an empty string or `None`, the value will be inserted
    at the current card position as a comment card.
    If the name is a string corresponding to a header card that is already
    present in the FitsChan, the new value will overwrite the existing
    value leaving the header name and any comment unchanged.
    Any other cards matching that name later in the header will
    be removed.  If there is no header with that name, a new card will
    be inserted at the end of the FitsChan.
value : `str`, `int`, `float`, `bool`, `None`
    The new value to be inserted.  If an integer index is given it must be
    a complete FITS header card.  The string will be padded to 80
    characters.

Raises
------
IndexError
    Raised if the supplied integer index is out of range.
KeyError
    Raised if the supplied name is neither a string or an integer.
TypeError
    Raised if an integer index is given but the supplied value is not
    a string.

Definition at line 223 of file fitsChanContinued.py.

223 def setitem(self, name, value):
224  """Set a new value.
225 
226  Parameters
227  ----------
228  name : `str` or `int`
229  If the name is an integer index this corresponds to a position within
230  the FitsChan. Index values are 0-based. A negative index counts
231  from the end of the FitsChan. If the index matches the number of
232  cards (e.g. the return value of `len()`) the new value will be
233  appended to the end of the FitsChan.
234  If the name is an empty string or `None`, the value will be inserted
235  at the current card position as a comment card.
236  If the name is a string corresponding to a header card that is already
237  present in the FitsChan, the new value will overwrite the existing
238  value leaving the header name and any comment unchanged.
239  Any other cards matching that name later in the header will
240  be removed. If there is no header with that name, a new card will
241  be inserted at the end of the FitsChan.
242  value : `str`, `int`, `float`, `bool`, `None`
243  The new value to be inserted. If an integer index is given it must be
244  a complete FITS header card. The string will be padded to 80
245  characters.
246 
247  Raises
248  ------
249  IndexError
250  Raised if the supplied integer index is out of range.
251  KeyError
252  Raised if the supplied name is neither a string or an integer.
253  TypeError
254  Raised if an integer index is given but the supplied value is not
255  a string.
256  """
257 
258  if isinstance(name, int):
259  # Calculate position in FitsChan (0-based to 1-based)
260  newpos = _calc_card_pos(self, name)
261  self.setCard(newpos)
262 
263  if not value:
264  value = " "
265 
266  # Overwrite the entire value
267  self.putFits(value, True)
268  return
269 
270  # A blank name results in a comment card being inserted at the
271  # current position
272  if not name:
273  self.setFitsCM(value, False)
274  return
275 
276  if not isinstance(name, str):
277  raise KeyError(f"Supplied key, '{name}' of unsupported type")
278 
279  # Get current card position and rewind
280  currentCard = self.getCard()
281  try:
282  self.clearCard()
283 
284  # Look for a card with the specified name
285  # We do not care about the result, if nothing is found we will be at the
286  # end of the header
287  self.findFits(name, False)
288 
289  # pyast seems to want to delete items if the value is None but
290  # astropy and PropertyList think the key should be undefined.
291  if value is None:
292  self.setFitsU(name, overwrite=True)
293  elif isinstance(value, int):
294  self.setFitsI(name, value, overwrite=True)
295  elif isinstance(value, float):
296  self.setFitsF(name, value, overwrite=True)
297  elif isinstance(value, bool):
298  self.setFitsL(name, value, overwrite=True)
299  else:
300  # Force to string
301  self.setFitsS(name, str(value), overwrite=True)
302 
303  # Delete any later cards with matching keyword
304  while True:
305  found = self.findFits(name, False)
306  if not found.found:
307  break
308  self.delFits()
309  finally:
310  # Try to reinstate the current card
311  self.setCard(currentCard)
312 
313 
314 FitsChan.__setitem__ = setitem
315 
316 
def setitem(self, name, value)

◆ to_string()

def astshim.fitsChanContinued.to_string (   self)
A FitsChan string representation is a FITS header with newlines
after each 80-character header card.

Definition at line 116 of file fitsChanContinued.py.

116 def to_string(self):
117  """A FitsChan string representation is a FITS header with newlines
118  after each 80-character header card.
119  """
120  return "\n".join(c for c in self)
121 
122 
123 FitsChan.__str__ = to_string
124 
125